[18] | 1 | Unit StartupUnit;
|
---|
| 2 |
|
---|
| 3 | // NewView - a new OS/2 Help Viewer
|
---|
| 4 | // Copyright 2003 Aaron Lawrence (aaronl at consultant dot com)
|
---|
| 5 | // This software is released under the Gnu Public License - see readme.txt
|
---|
| 6 |
|
---|
| 7 | // Code related to startup and finding help files.
|
---|
| 8 | // Shared between NewView.exe and ViewStub.exe
|
---|
| 9 |
|
---|
| 10 | Interface
|
---|
| 11 |
|
---|
| 12 | uses
|
---|
| 13 | OS2Def,
|
---|
| 14 | Classes,
|
---|
| 15 | GlobalFilelistUnit,
|
---|
[25] | 16 | SharedMemoryUnit,
|
---|
| 17 | CmdLineParameterUnit;
|
---|
[18] | 18 |
|
---|
| 19 | const
|
---|
| 20 | OWN_HELP_MARKER = '[NVHELP]';
|
---|
| 21 |
|
---|
| 22 |
|
---|
| 23 | function AccessSharedMemory: TSuballocatedSharedMemory;
|
---|
| 24 |
|
---|
| 25 | // Look for any items that are actually specifiying environment
|
---|
| 26 | // variables, and expand them to the contents of the variables
|
---|
| 27 |
|
---|
| 28 | // Given a filename, which may or may not contain a path or extension,
|
---|
| 29 | // finds the actual file. This can involve searching
|
---|
| 30 | // the help and bookshelf paths.
|
---|
| 31 | Function FindHelpFile( FileName: string ): string;
|
---|
[61] | 32 | Procedure PostNewViewTextMessage( Window: HWND;
|
---|
| 33 | MessageType: ULONG;
|
---|
| 34 | s: string );
|
---|
[18] | 35 |
|
---|
| 36 | var
|
---|
| 37 | SharedMemory: TSubAllocatedSharedMemory;
|
---|
| 38 | GlobalFilelist: TGlobalFilelist;
|
---|
| 39 |
|
---|
| 40 | Implementation
|
---|
| 41 |
|
---|
| 42 | uses
|
---|
[25] | 43 | Dos,
|
---|
| 44 | SysUtils,
|
---|
[43] | 45 | DebugUnit,
|
---|
[25] | 46 | PMWin,
|
---|
[82] | 47 | HelpManagerUnit,
|
---|
[103] | 48 | StringUtilsUnit,
|
---|
[82] | 49 | FileUtilsUnit;
|
---|
[18] | 50 |
|
---|
| 51 |
|
---|
| 52 | // Given a filename, which may or may not contain a path or extension,
|
---|
| 53 | // finds the actual file. This can involve searching
|
---|
| 54 | // the help and bookshelf paths.
|
---|
| 55 | Function FindHelpFile( FileName: string ): string;
|
---|
| 56 | var
|
---|
| 57 | AlternativeFileName: string;
|
---|
| 58 | begin
|
---|
| 59 | Result := '';
|
---|
| 60 |
|
---|
| 61 | AlternativeFileName := '';
|
---|
| 62 | if ExtractFileExt( Filename ) = '' then
|
---|
| 63 | begin
|
---|
| 64 | Filename := ChangeFileExt( Filename, '.inf' );
|
---|
| 65 | AlternativeFileName := ChangeFileExt( Filename, '.hlp' );
|
---|
| 66 | end;
|
---|
| 67 |
|
---|
| 68 | if ExtractFilePath( FileName ) <> '' then
|
---|
| 69 | begin
|
---|
| 70 | // Path specified; just see if it exists
|
---|
| 71 |
|
---|
| 72 | // expand out relative paths
|
---|
| 73 | Filename := ExpandFileName( FileName );
|
---|
| 74 | AlternativeFilename := ExpandFileName( AlternativeFilename );
|
---|
| 75 |
|
---|
| 76 | if FileExists( Filename ) then
|
---|
| 77 | Result := Filename
|
---|
| 78 | else if FileExists( AlternativeFilename ) then
|
---|
| 79 | Result := AlternativeFilename;
|
---|
| 80 |
|
---|
| 81 | end
|
---|
| 82 | else
|
---|
| 83 | begin
|
---|
| 84 | // Path not specified; search current
|
---|
| 85 | if FileExists( ExpandFileName( FileName ) ) then
|
---|
| 86 | begin
|
---|
| 87 | Result := ExpandFileName( FileName );
|
---|
| 88 | exit;
|
---|
| 89 | end;
|
---|
| 90 |
|
---|
| 91 | if FileExists( ExpandFileName( AlternativeFilename ) ) then
|
---|
| 92 | begin
|
---|
| 93 | Result := ExpandFileName( AlternativeFilename );
|
---|
| 94 | exit;
|
---|
| 95 | end;
|
---|
| 96 |
|
---|
| 97 | // Search help paths
|
---|
| 98 |
|
---|
| 99 | if not SearchHelpPaths( FileName,
|
---|
| 100 | Result,
|
---|
| 101 | false // don't search our app dir
|
---|
| 102 | ) then
|
---|
| 103 | begin
|
---|
| 104 | // Didn't find as specified or as .inf, try .hlp
|
---|
| 105 | if AlternativeFilename <> '' then
|
---|
| 106 | begin
|
---|
| 107 | if not SearchHelpPaths( AlternativeFileName,
|
---|
| 108 | Result,
|
---|
| 109 | false // don't search our app dir
|
---|
| 110 | ) then
|
---|
| 111 | begin
|
---|
| 112 | Result := '';
|
---|
| 113 | end;
|
---|
| 114 | end;
|
---|
| 115 | end;
|
---|
| 116 | end;
|
---|
| 117 | end;
|
---|
| 118 |
|
---|
| 119 |
|
---|
| 120 | function AccessSharedMemory: TSuballocatedSharedMemory;
|
---|
| 121 | begin
|
---|
| 122 | Result := TSuballocatedSharedMemory.Create( SharedMemName,
|
---|
| 123 | SharedMemSize,
|
---|
| 124 | SharedMemReserveSize );
|
---|
| 125 | end;
|
---|
| 126 |
|
---|
| 127 | procedure PostNewViewTextMessage( Window: HWND;
|
---|
| 128 | MessageType: ULONG;
|
---|
| 129 | s: string );
|
---|
| 130 | var
|
---|
| 131 | ps: pchar;
|
---|
| 132 | begin
|
---|
| 133 | SharedMemory.Allocate( ps, length( s ) + 1 );
|
---|
| 134 | ps ^ := s;
|
---|
| 135 | WinPostMsg( Window,
|
---|
| 136 | MessageType,
|
---|
| 137 | LONG( ps ),
|
---|
| 138 | 0 );
|
---|
| 139 | end;
|
---|
| 140 |
|
---|
| 141 |
|
---|
| 142 | Initialization
|
---|
| 143 | End.
|
---|