source: branches/2.19_branch/NewView/StartupUnit.pas@ 331

Last change on this file since 331 was 114, checked in by RBRi, 18 years ago

naming fixes

  • Property svn:eol-style set to native
File size: 4.7 KB
Line 
1Unit 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
10Interface
11
12uses
13 OS2Def,
14 Classes,
15 GlobalFilelistUnit,
16 SharedMemoryUnit,
17 CmdLineParameterUnit;
18
19const
20 OWN_HELP_MARKER = '[NVHELP]';
21
22
23function AccessSharedMemory: TSuballocatedSharedMemory;
24
25// Look for any items that are actually specifiying environment
26// variables, and expand them to the contents of the variables
27Procedure TranslateIPFEnvironmentVars(const Items: TStrings; ExpandedItems: TStrings );
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.
32Function FindHelpFile( FileName: string ): string;
33Procedure PostNewViewTextMessage( Window: HWND;
34 MessageType: ULONG;
35 s: string );
36
37var
38 SharedMemory: TSubAllocatedSharedMemory;
39 GlobalFilelist: TGlobalFilelist;
40
41Implementation
42
43uses
44 Dos,
45 SysUtils,
46 DebugUnit,
47 PMWin,
48 HelpManagerUnit,
49 StringUtilsUnit,
50 FileUtilsUnit;
51
52// Look for any items that are actually specifiying environment
53// variables, and expand them to the contents of the variables
54Procedure TranslateIPFEnvironmentVars(const Items: TStrings; ExpandedItems: TStrings );
55var
56 i : longint;
57 tmpItem: string;
58 tmpEnvironmentVarValue: string;
59begin
60 LogEvent(LogStartup, 'Translating environment vars' );
61 for i := 0 to Items.Count - 1 do
62 begin
63 tmpItem := Items[ i ];
64
65 tmpItem := StrTrimChars(tmpItem, [StrSingleQuote]); // remove single quotes
66 tmpItem := StrTrimChars(tmpItem, [StrDoubleQuote]); // remove double quotes
67
68 LogEvent(LogStartup, ' Checking for environment var: ' + tmpItem );
69 tmpEnvironmentVarValue := GetEnv( Uppercase( tmpItem ) );
70 if DosError = 0 then
71 begin
72 // environment var exists - use it's value
73 LogEvent(LogStartup, ' Environment var found; translated to: ' + tmpEnvironmentVarValue);
74 StrExtractStrings(ExpandedItems, tmpEnvironmentVarValue, ['+'], #0);
75 end
76 else
77 begin
78 // not an environment var
79 ExpandedItems.Add( tmpItem );
80 end;
81 end;
82end;
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.
87Function FindHelpFile( FileName: string ): string;
88var
89 AlternativeFileName: string;
90begin
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;
149end;
150
151
152function AccessSharedMemory: TSuballocatedSharedMemory;
153begin
154 Result := TSuballocatedSharedMemory.Create( SharedMemName,
155 SharedMemSize,
156 SharedMemReserveSize );
157end;
158
159procedure PostNewViewTextMessage( Window: HWND;
160 MessageType: ULONG;
161 s: string );
162var
163 ps: pchar;
164begin
165 SharedMemory.Allocate( ps, length( s ) + 1 );
166 ps ^ := s;
167 WinPostMsg( Window,
168 MessageType,
169 LONG( ps ),
170 0 );
171end;
172
173
174Initialization
175End.
Note: See TracBrowser for help on using the repository browser.