[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
|
---|
[103] | 27 | Procedure TranslateIPFEnvironmentVars(const Items: TStrings; ExpandedItems: TStrings );
|
---|
[18] | 28 |
|
---|
| 29 | // Given a filename, which may or may not contain a path or extension,
|
---|
| 30 | // finds the actual file. This can involve searching
|
---|
| 31 | // the help and bookshelf paths.
|
---|
| 32 | Function FindHelpFile( FileName: string ): string;
|
---|
[61] | 33 | Procedure PostNewViewTextMessage( Window: HWND;
|
---|
| 34 | MessageType: ULONG;
|
---|
| 35 | s: string );
|
---|
[18] | 36 |
|
---|
| 37 | var
|
---|
| 38 | SharedMemory: TSubAllocatedSharedMemory;
|
---|
| 39 | GlobalFilelist: TGlobalFilelist;
|
---|
| 40 |
|
---|
| 41 | Implementation
|
---|
| 42 |
|
---|
| 43 | uses
|
---|
[25] | 44 | Dos,
|
---|
| 45 | SysUtils,
|
---|
[43] | 46 | DebugUnit,
|
---|
[25] | 47 | PMWin,
|
---|
[82] | 48 | HelpManagerUnit,
|
---|
[103] | 49 | StringUtilsUnit,
|
---|
[82] | 50 | FileUtilsUnit;
|
---|
[18] | 51 |
|
---|
| 52 | // Look for any items that are actually specifiying environment
|
---|
| 53 | // variables, and expand them to the contents of the variables
|
---|
[103] | 54 | Procedure TranslateIPFEnvironmentVars(const Items: TStrings; ExpandedItems: TStrings );
|
---|
[18] | 55 | var
|
---|
[103] | 56 | i : longint;
|
---|
| 57 | tmpItem: string;
|
---|
| 58 | tmpEnvironmentVarValue: string;
|
---|
[18] | 59 | begin
|
---|
[43] | 60 | LogEvent(LogStartup, 'Translating environment vars' );
|
---|
[18] | 61 | for i := 0 to Items.Count - 1 do
|
---|
| 62 | begin
|
---|
[103] | 63 | tmpItem := Items[ i ];
|
---|
[18] | 64 |
|
---|
[114] | 65 | tmpItem := StrTrimChars(tmpItem, [StrSingleQuote]); // remove single quotes
|
---|
| 66 | tmpItem := StrTrimChars(tmpItem, [StrDoubleQuote]); // remove double quotes
|
---|
[18] | 67 |
|
---|
[103] | 68 | LogEvent(LogStartup, ' Checking for environment var: ' + tmpItem );
|
---|
| 69 | tmpEnvironmentVarValue := GetEnv( Uppercase( tmpItem ) );
|
---|
[18] | 70 | if DosError = 0 then
|
---|
| 71 | begin
|
---|
| 72 | // environment var exists - use it's value
|
---|
[103] | 73 | LogEvent(LogStartup, ' Environment var found; translated to: ' + tmpEnvironmentVarValue);
|
---|
| 74 | StrExtractStrings(ExpandedItems, tmpEnvironmentVarValue, ['+'], #0);
|
---|
[18] | 75 | end
|
---|
| 76 | else
|
---|
| 77 | begin
|
---|
| 78 | // not an environment var
|
---|
[103] | 79 | ExpandedItems.Add( tmpItem );
|
---|
[18] | 80 | end;
|
---|
| 81 | end;
|
---|
| 82 | end;
|
---|
| 83 |
|
---|
| 84 | // Given a filename, which may or may not contain a path or extension,
|
---|
| 85 | // finds the actual file. This can involve searching
|
---|
| 86 | // the help and bookshelf paths.
|
---|
| 87 | Function FindHelpFile( FileName: string ): string;
|
---|
| 88 | var
|
---|
| 89 | AlternativeFileName: string;
|
---|
| 90 | begin
|
---|
| 91 | Result := '';
|
---|
| 92 |
|
---|
| 93 | AlternativeFileName := '';
|
---|
| 94 | if ExtractFileExt( Filename ) = '' then
|
---|
| 95 | begin
|
---|
| 96 | Filename := ChangeFileExt( Filename, '.inf' );
|
---|
| 97 | AlternativeFileName := ChangeFileExt( Filename, '.hlp' );
|
---|
| 98 | end;
|
---|
| 99 |
|
---|
| 100 | if ExtractFilePath( FileName ) <> '' then
|
---|
| 101 | begin
|
---|
| 102 | // Path specified; just see if it exists
|
---|
| 103 |
|
---|
| 104 | // expand out relative paths
|
---|
| 105 | Filename := ExpandFileName( FileName );
|
---|
| 106 | AlternativeFilename := ExpandFileName( AlternativeFilename );
|
---|
| 107 |
|
---|
| 108 | if FileExists( Filename ) then
|
---|
| 109 | Result := Filename
|
---|
| 110 | else if FileExists( AlternativeFilename ) then
|
---|
| 111 | Result := AlternativeFilename;
|
---|
| 112 |
|
---|
| 113 | end
|
---|
| 114 | else
|
---|
| 115 | begin
|
---|
| 116 | // Path not specified; search current
|
---|
| 117 | if FileExists( ExpandFileName( FileName ) ) then
|
---|
| 118 | begin
|
---|
| 119 | Result := ExpandFileName( FileName );
|
---|
| 120 | exit;
|
---|
| 121 | end;
|
---|
| 122 |
|
---|
| 123 | if FileExists( ExpandFileName( AlternativeFilename ) ) then
|
---|
| 124 | begin
|
---|
| 125 | Result := ExpandFileName( AlternativeFilename );
|
---|
| 126 | exit;
|
---|
| 127 | end;
|
---|
| 128 |
|
---|
| 129 | // Search help paths
|
---|
| 130 |
|
---|
| 131 | if not SearchHelpPaths( FileName,
|
---|
| 132 | Result,
|
---|
| 133 | false // don't search our app dir
|
---|
| 134 | ) then
|
---|
| 135 | begin
|
---|
| 136 | // Didn't find as specified or as .inf, try .hlp
|
---|
| 137 | if AlternativeFilename <> '' then
|
---|
| 138 | begin
|
---|
| 139 | if not SearchHelpPaths( AlternativeFileName,
|
---|
| 140 | Result,
|
---|
| 141 | false // don't search our app dir
|
---|
| 142 | ) then
|
---|
| 143 | begin
|
---|
| 144 | Result := '';
|
---|
| 145 | end;
|
---|
| 146 | end;
|
---|
| 147 | end;
|
---|
| 148 | end;
|
---|
| 149 | end;
|
---|
| 150 |
|
---|
| 151 |
|
---|
| 152 | function AccessSharedMemory: TSuballocatedSharedMemory;
|
---|
| 153 | begin
|
---|
| 154 | Result := TSuballocatedSharedMemory.Create( SharedMemName,
|
---|
| 155 | SharedMemSize,
|
---|
| 156 | SharedMemReserveSize );
|
---|
| 157 | end;
|
---|
| 158 |
|
---|
| 159 | procedure PostNewViewTextMessage( Window: HWND;
|
---|
| 160 | MessageType: ULONG;
|
---|
| 161 | s: string );
|
---|
| 162 | var
|
---|
| 163 | ps: pchar;
|
---|
| 164 | begin
|
---|
| 165 | SharedMemory.Allocate( ps, length( s ) + 1 );
|
---|
| 166 | ps ^ := s;
|
---|
| 167 | WinPostMsg( Window,
|
---|
| 168 | MessageType,
|
---|
| 169 | LONG( ps ),
|
---|
| 170 | 0 );
|
---|
| 171 | end;
|
---|
| 172 |
|
---|
| 173 |
|
---|
| 174 | Initialization
|
---|
| 175 | End.
|
---|