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