1 | //
|
---|
2 | // MINSTALL.DLL (c) Copyright 2002-2005 Martin Kiewitz
|
---|
3 | //
|
---|
4 | // This file is part of MINSTALL.DLL for OS/2 / eComStation
|
---|
5 | //
|
---|
6 | // MINSTALL.DLL is free software: you can redistribute it and/or modify
|
---|
7 | // it under the terms of the GNU General Public License as published by
|
---|
8 | // the Free Software Foundation, either version 3 of the License, or
|
---|
9 | // (at your option) any later version.
|
---|
10 | //
|
---|
11 | // MINSTALL.DLL is distributed in the hope that it will be useful,
|
---|
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
14 | // GNU General Public License for more details.
|
---|
15 | //
|
---|
16 | // You should have received a copy of the GNU General Public License
|
---|
17 | // along with MINSTALL.DLL. If not, see <http://www.gnu.org/licenses/>.
|
---|
18 | //
|
---|
19 |
|
---|
20 | #define INCL_BASE
|
---|
21 | #define INCL_DOSMODULEMGR
|
---|
22 | #define INCL_WINSHELLDATA
|
---|
23 | #include <os2.h>
|
---|
24 | #include <malloc.h>
|
---|
25 |
|
---|
26 | #include <global.h>
|
---|
27 | #include <stdarg.h>
|
---|
28 | #include <crcs.h>
|
---|
29 | #include <dll.h>
|
---|
30 | #include <file.h>
|
---|
31 | #include <globstr.h>
|
---|
32 | #include <msg.h>
|
---|
33 | #include <mmi_public.h>
|
---|
34 | #include <mmi_types.h>
|
---|
35 | #include <mmi_main.h>
|
---|
36 | #include <mmi_helper.h>
|
---|
37 | #include <mmi_msg.h>
|
---|
38 |
|
---|
39 | // ****************************************************************************
|
---|
40 |
|
---|
41 | PMINSTDIR MINSTALL_SearchSourceDirID (ULONG DirectoryID) {
|
---|
42 | PMINSTDIR CurDirPtr = MCF_SourceDirArrayPtr;
|
---|
43 | USHORT CurDirNo = 0;
|
---|
44 |
|
---|
45 | if (MCF_SourceDirCount==0)
|
---|
46 | return NULL;
|
---|
47 |
|
---|
48 | while (CurDirNo<MCF_SourceDirCount) {
|
---|
49 | if (CurDirPtr->ID==DirectoryID)
|
---|
50 | return CurDirPtr;
|
---|
51 | CurDirPtr++; CurDirNo++;
|
---|
52 | }
|
---|
53 | return NULL;
|
---|
54 | }
|
---|
55 |
|
---|
56 | // This will search the ID of the root source directory ("\")
|
---|
57 | PMINSTDIR MINSTALL_SearchRootSourceDirID (void) {
|
---|
58 | PMINSTDIR CurDirPtr = MCF_SourceDirArrayPtr;
|
---|
59 | USHORT CurDirNo = 0;
|
---|
60 |
|
---|
61 | if (MCF_SourceDirCount==0)
|
---|
62 | return NULL;
|
---|
63 |
|
---|
64 | while (CurDirNo<MCF_SourceDirCount) {
|
---|
65 | if (strcmp(CurDirPtr->Name, "\\")==0)
|
---|
66 | return CurDirPtr;
|
---|
67 | CurDirPtr++; CurDirNo++;
|
---|
68 | }
|
---|
69 | return NULL;
|
---|
70 | }
|
---|
71 |
|
---|
72 | PMINSTDIR MINSTALL_SearchDestinDirID (ULONG DirectoryID) {
|
---|
73 | PMINSTDIR CurDirPtr = MCF_DestinDirArrayPtr;
|
---|
74 | USHORT CurDirNo = 0;
|
---|
75 |
|
---|
76 | if (MCF_DestinDirCount==0)
|
---|
77 | return NULL;
|
---|
78 |
|
---|
79 | while (CurDirNo<MCF_DestinDirCount) {
|
---|
80 | if (CurDirPtr->ID==DirectoryID)
|
---|
81 | return CurDirPtr;
|
---|
82 | CurDirPtr++; CurDirNo++;
|
---|
83 | }
|
---|
84 | return NULL;
|
---|
85 | }
|
---|
86 |
|
---|
87 | PMINSTGRP MINSTALL_SearchGroupID (ULONG GroupID) {
|
---|
88 | PMINSTGRP CurGrpPtr = MCF_GroupArrayPtr;
|
---|
89 | USHORT CurGrpNo = 0;
|
---|
90 |
|
---|
91 | if (MCF_GroupCount==0)
|
---|
92 | return NULL;
|
---|
93 |
|
---|
94 | while (CurGrpNo<MCF_GroupCount) {
|
---|
95 | if (CurGrpPtr->ID==GroupID)
|
---|
96 | return CurGrpPtr;
|
---|
97 | CurGrpPtr++; CurGrpNo++;
|
---|
98 | }
|
---|
99 | return NULL;
|
---|
100 | }
|
---|
101 |
|
---|
102 | PMINSTGRP MINSTALL_SearchGroupGeninID (PMINSTFILE CARDINFOFilePtr, ULONG GeninID) {
|
---|
103 | PMINSTGRP CurGrpPtr = MCF_GroupArrayPtr;
|
---|
104 | USHORT CurGrpNo = 0;
|
---|
105 |
|
---|
106 | if (MCF_GroupCount==0)
|
---|
107 | return NULL;
|
---|
108 |
|
---|
109 | while (CurGrpNo<MCF_GroupCount) {
|
---|
110 | if ((CurGrpPtr->GeninDLLFilePtr==CARDINFOFilePtr) && (CurGrpPtr->GeninID==GeninID))
|
---|
111 | return CurGrpPtr;
|
---|
112 | CurGrpPtr++; CurGrpNo++;
|
---|
113 | }
|
---|
114 | return NULL;
|
---|
115 | }
|
---|
116 |
|
---|
117 | PMINSTFILE MINSTALL_SearchFileCRC32 (ULONG FileCRC32) {
|
---|
118 | PMINSTFILE CurFilePtr = FCF_FileArrayPtr;
|
---|
119 | USHORT CurFileNo = 0;
|
---|
120 |
|
---|
121 | if (FCF_FileCount==0)
|
---|
122 | return NULL;
|
---|
123 |
|
---|
124 | while (CurFileNo<FCF_FileCount) {
|
---|
125 | if (CurFilePtr->NameCRC32==FileCRC32)
|
---|
126 | return CurFilePtr;
|
---|
127 | CurFilePtr++; CurFileNo++;
|
---|
128 | }
|
---|
129 | return NULL;
|
---|
130 | }
|
---|
131 |
|
---|
132 | PSZ MINSTALL_GetPointerToMacro (PCHAR *CurPosPtr, PCHAR EndPos) {
|
---|
133 | PCHAR CurPos = *CurPosPtr+2;
|
---|
134 | PCHAR StartPos = CurPos;
|
---|
135 | ULONG CRC32 = 0;
|
---|
136 | ULONG Temp = 0;
|
---|
137 | PMINSTFILE CurFilePtr = 0;
|
---|
138 | PMINSTDIR CurDirPtr = 0;
|
---|
139 |
|
---|
140 | while ((CurPos<EndPos) && (*CurPos!=')')) {
|
---|
141 | *CurPos = tolower(*CurPos);
|
---|
142 | CurPos++;
|
---|
143 | }
|
---|
144 | CRC32 = CRC32_GetFromString (StartPos, CurPos-StartPos); CurPos++;
|
---|
145 |
|
---|
146 | // Update CurPos @ caller...
|
---|
147 | *CurPosPtr = CurPos;
|
---|
148 |
|
---|
149 | switch (CRC32) {
|
---|
150 | case 0xBAAB7A10: // $(DIR) -> Destination-Path by number, without ending "\"
|
---|
151 | StartPos = CurPos;
|
---|
152 | // Pass till non numeric digit or End-Of-Line
|
---|
153 | while ((CurPos<EndPos) & (*CurPos>=0x30) & (*CurPos<=0x39))
|
---|
154 | CurPos++;
|
---|
155 | if (CurPos>StartPos) { // we found any digits?
|
---|
156 | Temp = atol(StartPos);
|
---|
157 | if ((CurDirPtr = MINSTALL_SearchDestinDirID(Temp))!=0) {
|
---|
158 | *CurPosPtr = CurPos;
|
---|
159 | strcpy (MINSTALL_TempMacroSpace, CurDirPtr->FQName);
|
---|
160 | Temp = strlen(CurDirPtr->FQName);
|
---|
161 | if (Temp!=0) Temp--;
|
---|
162 | if (MINSTALL_TempMacroSpace[Temp]=='\\') {
|
---|
163 | // only remove last char, if last char is '\'
|
---|
164 | MINSTALL_TempMacroSpace[Temp] = 0; // Remove last char '\'
|
---|
165 | }
|
---|
166 | return (PCHAR)&MINSTALL_TempMacroSpace;
|
---|
167 | } else {
|
---|
168 | MINSTALL_ErrorMsgID = MINSTMSG_UnknownDestinID;
|
---|
169 | return 0;
|
---|
170 | }
|
---|
171 | } else {
|
---|
172 | MINSTALL_ErrorMsgID = MINSTMSG_NumericValueExpected; return 0; }
|
---|
173 | case 0x88662993: // $(DEST) -> Destination Path of filename
|
---|
174 | StartPos = CurPos;
|
---|
175 | // Pass till ';', '"', ',', ' ' or End-Of-Line
|
---|
176 | while ((CurPos<EndPos) && (*CurPos!=0x22) && (*CurPos!=0x3B) && (*CurPos!=0x2C) && (*CurPos!=0x20)) {
|
---|
177 | *CurPos = tolower(*CurPos);
|
---|
178 | CurPos++;
|
---|
179 | }
|
---|
180 | if (CurPos>StartPos) { // we found anything?
|
---|
181 | CRC32 = CRC32_GetFromString (StartPos, CurPos-StartPos);
|
---|
182 | if ((CurFilePtr = MINSTALL_SearchFileCRC32(CRC32))!=0) {
|
---|
183 | // Got that file, now get destination directory for it
|
---|
184 | return CurFilePtr->DestinPtr->FQName;
|
---|
185 | } else {
|
---|
186 | MSG_SetInsertViaString (2, StartPos, CurPos-StartPos);
|
---|
187 | MINSTALL_ErrorMsgID = MINSTMSG_UnlistedFile;
|
---|
188 | return 0;
|
---|
189 | }
|
---|
190 | } else {
|
---|
191 | MINSTALL_ErrorMsgID = MINSTMSG_StringExpected; return 0; }
|
---|
192 | case 0x46EDAEC4: // $(BOOT) -> Write Boot-Drive Letter (char only)
|
---|
193 | if (*CurPos==0x3A)
|
---|
194 | return (PCHAR)&MINSTALL_BootLetter; // char only (e.g. "D")
|
---|
195 | else
|
---|
196 | return (PCHAR)&MINSTALL_BootDrive; // drive (e.g. "D:")
|
---|
197 | case 0x681DF58F: // $(DRIVE) -> Write MMBase-Drive Letter (char only)
|
---|
198 | if (*CurPos==0x3A)
|
---|
199 | return (PCHAR)&MINSTALL_MMBaseLetter; // char only (e.g. "D")
|
---|
200 | else
|
---|
201 | return (PCHAR)&MINSTALL_BootDrive; // drive (e.g. "D:")
|
---|
202 | }
|
---|
203 | // Unknown macro, so reply NUL string...
|
---|
204 | return "";
|
---|
205 | }
|
---|
206 |
|
---|
207 | // Extracts a string including macro processing (e.g. '"TEST $(DIR)2"')
|
---|
208 | // including error checking. Needs to be called using CurPos == Position of
|
---|
209 | // trailing '"'
|
---|
210 | PCHAR MINSTALL_GetMacrodString (PCHAR DestPtr, ULONG DestMaxSize, PCHAR StartPos, PCHAR EndPos) {
|
---|
211 | PCHAR CurPos = StartPos;
|
---|
212 | ULONG TmpLen = 0;
|
---|
213 | PCHAR CurDestPtr = DestPtr;
|
---|
214 | PCHAR MacroPtr = 0;
|
---|
215 | ULONG MacroLen = 0;
|
---|
216 | CHAR CurChar;
|
---|
217 |
|
---|
218 | // One less, because of terminating Zero
|
---|
219 | DestMaxSize--;
|
---|
220 |
|
---|
221 | if (*StartPos=='"') {
|
---|
222 | CurPos++; // Skip over '"'
|
---|
223 | // Now take over any chars till '"' including escape mechanismn
|
---|
224 | while (CurPos<EndPos) {
|
---|
225 | CurChar = *CurPos;
|
---|
226 | if (CurChar=='"') {
|
---|
227 | *CurDestPtr = 0; // Set terminating NUL
|
---|
228 | return CurPos+1;
|
---|
229 | }
|
---|
230 | if (CurChar==0x0D) break; // End-Of-Line reached during String
|
---|
231 | if (CurChar==0x5C) { // is escape mechanismn
|
---|
232 | CurPos++;
|
---|
233 | if (CurPos<EndPos) {
|
---|
234 | if (!DestMaxSize) {
|
---|
235 | MINSTALL_ErrorMsgID = MINSTMSG_StringTooBig; return 0; }
|
---|
236 | *CurDestPtr++ = *CurPos; DestMaxSize--;
|
---|
237 | CurPos++;
|
---|
238 | }
|
---|
239 | } else if (*(PUSHORT)CurPos==0x2824) { // "$(" Macro found
|
---|
240 | if (!(MacroPtr = MINSTALL_GetPointerToMacro (&CurPos, EndPos)))
|
---|
241 | return 0; // Bad macro, so signal error
|
---|
242 | MacroLen = strlen(MacroPtr);
|
---|
243 | if (DestMaxSize>=MacroLen) {
|
---|
244 | memcpy (CurDestPtr, MacroPtr, MacroLen);
|
---|
245 | CurDestPtr += MacroLen; DestMaxSize -= MacroLen;
|
---|
246 | }
|
---|
247 | } else {
|
---|
248 | if (!DestMaxSize) {
|
---|
249 | MINSTALL_TrappedError (MINSTMSG_StringTooBig); return 0; }
|
---|
250 | *CurDestPtr++ = CurChar; DestMaxSize--;
|
---|
251 | CurPos++;
|
---|
252 | }
|
---|
253 | }
|
---|
254 | MINSTALL_ErrorMsgID = MINSTMSG_UnexpectedEndOfLine;
|
---|
255 | return 0; // End-Of-Line reached during string
|
---|
256 | }
|
---|
257 | MINSTALL_ErrorMsgID = MINSTMSG_StringExpected;
|
---|
258 | return 0;
|
---|
259 | }
|
---|
260 |
|
---|
261 | PCHAR MINSTALL_GetNumericValue (PULONG DestPtr, PCHAR StartPos, PCHAR EndPos) {
|
---|
262 | PCHAR CurPos;
|
---|
263 |
|
---|
264 | CurPos = STRING_GetNumericValue(DestPtr, StartPos, EndPos);
|
---|
265 | if (!CurPos)
|
---|
266 | MINSTALL_ErrorMsgID = MINSTMSG_NumericValueExpected;
|
---|
267 | return CurPos;
|
---|
268 | }
|
---|
269 |
|
---|
270 | ULONG MINSTALL_GetVersionCode (PSZ VersionString) {
|
---|
271 | PCHAR CurPos;
|
---|
272 | ULONG Number1;
|
---|
273 | ULONG Number2 = 0;
|
---|
274 | ULONG Number3 = 0;
|
---|
275 |
|
---|
276 | Number1 = strtol (VersionString, &CurPos, 10);
|
---|
277 | if (*CurPos=='.') {
|
---|
278 | CurPos++;
|
---|
279 | if (*CurPos!=0) {
|
---|
280 | Number2 = strtoul (CurPos, &CurPos, 10);
|
---|
281 | if (*CurPos=='.') {
|
---|
282 | CurPos++;
|
---|
283 | if (*CurPos!=0) {
|
---|
284 | Number3 = strtoul (CurPos, NULL, 10);
|
---|
285 | }
|
---|
286 | }
|
---|
287 | }
|
---|
288 | }
|
---|
289 | if (Number1>255) Number1=255;
|
---|
290 | if (Number2>255) Number2=255;
|
---|
291 | if (Number3>255) Number3=255;
|
---|
292 | return (Number1<<16)+(Number2<<8)+Number3;
|
---|
293 | }
|
---|
294 |
|
---|
295 | VOID MINSTALL_GetInstalledVersion (PSZ GroupName, PSZ DestVersionInstalled) {
|
---|
296 | HINI CompListHandle = 0;
|
---|
297 | ULONG MaxSize = MINSTMAX_STRLENGTH;
|
---|
298 |
|
---|
299 | DestVersionInstalled[0] = 0;
|
---|
300 | // If GroupName is NULL, just set NULL Version
|
---|
301 | if (strlen(GroupName)==0) return;
|
---|
302 |
|
---|
303 | // Open COMPLIST.ini...
|
---|
304 | // MINSTALL_PMHandle may be NULL in here, but this won't matter.
|
---|
305 | CompListHandle = PrfOpenProfile (MINSTALL_PMHandle, MINSTALL_CompListINI);
|
---|
306 | if (CompListHandle==NULLHANDLE) return; // Exit, if Open failed
|
---|
307 |
|
---|
308 | // Query version-number...
|
---|
309 | PrfQueryProfileData(CompListHandle, GroupName, "VERSION_NUMBER", (PVOID)DestVersionInstalled, &MaxSize);
|
---|
310 |
|
---|
311 | // Close COMPLIST.ini...
|
---|
312 | PrfCloseProfile (CompListHandle);
|
---|
313 | }
|
---|
314 |
|
---|
315 | // No real error reporting here, because version saving is somewhat optional
|
---|
316 | // we never abort installation because of errors here!
|
---|
317 | VOID MINSTALL_SetInstalledVersion (PSZ GroupName, PSZ Version) {
|
---|
318 | HINI CompListHandle = 0;
|
---|
319 | ULONG VersionSize = strlen(Version);
|
---|
320 |
|
---|
321 | // If GroupName is NULL, dont set anything
|
---|
322 | if (strlen(GroupName)==0) return;
|
---|
323 |
|
---|
324 | // Open COMPLIST.ini...
|
---|
325 | // MINSTALL_PMHandle may be NULL in here, but this won't matter.
|
---|
326 | CompListHandle = PrfOpenProfile (MINSTALL_PMHandle, MINSTALL_CompListINI);
|
---|
327 | if (CompListHandle==NULLHANDLE) return; // Exit, if Open failed
|
---|
328 |
|
---|
329 | // Set version-number...
|
---|
330 | PrfWriteProfileData(CompListHandle, GroupName, "VERSION_NUMBER", (PVOID)Version, VersionSize);
|
---|
331 |
|
---|
332 | // Also set variable that shows we installed it
|
---|
333 | PrfWriteProfileData(CompListHandle, GroupName, "INSTALLED_BY", (PVOID)"MINSTALL/REMAKE", 15);
|
---|
334 |
|
---|
335 | // Close COMPLIST.ini...
|
---|
336 | PrfCloseProfile (CompListHandle);
|
---|
337 | }
|
---|
338 |
|
---|
339 | ULONG SavedCurrentDiskNum = 0;
|
---|
340 | CHAR SavedCurrentDirectory[MINSTMAX_PATHLENGTH];
|
---|
341 |
|
---|
342 | /* 26.06.2005 - implemented compatibility code */
|
---|
343 | /* saves, restores and sets current drive and directory */
|
---|
344 | /* currently used in mmi_customdll.c */
|
---|
345 | VOID MINSTALL_SaveCurrentDirectory (void) {
|
---|
346 | ULONG DriveMap;
|
---|
347 | ULONG BufSize = MINSTMAX_PATHLENGTH;
|
---|
348 | DosQueryCurrentDisk(&SavedCurrentDiskNum, &DriveMap);
|
---|
349 | DosQueryCurrentDir(0, (PCHAR)&SavedCurrentDirectory, &BufSize);
|
---|
350 | }
|
---|
351 |
|
---|
352 | VOID MINSTALL_RestoreCurrentDirectory (void) {
|
---|
353 | DosSetDefaultDisk(SavedCurrentDiskNum);
|
---|
354 | DosSetCurrentDir((PCHAR)&SavedCurrentDirectory);
|
---|
355 | }
|
---|
356 |
|
---|
357 | VOID MINSTALL_SetCurrentDirectoryToSource (void) {
|
---|
358 | ULONG DiskNum = 0;
|
---|
359 |
|
---|
360 | if ((MINSTALL_SourcePath[0]>='A') && (MINSTALL_SourcePath[0]<='Z'))
|
---|
361 | DiskNum = MINSTALL_SourcePath[0]-'A'+1;
|
---|
362 | else if ((MINSTALL_SourcePath[0]>='a') && (MINSTALL_SourcePath[0]<='z'))
|
---|
363 | DiskNum = MINSTALL_SourcePath[0]-'a'+1;
|
---|
364 | if ((DiskNum!=0) && (MINSTALL_SourcePath[0]!=0) && (MINSTALL_SourcePath[1]!=0)) {
|
---|
365 | DosSetDefaultDisk(DiskNum);
|
---|
366 | DosSetCurrentDir((PCHAR)(((ULONG)&MINSTALL_SourcePath)+2));
|
---|
367 | }
|
---|
368 | }
|
---|
369 |
|
---|
370 | VOID MINSTALL_TrappedError (ULONG ErrorMsgID) {
|
---|
371 | MINSTALL_ErrorMsgID = ErrorMsgID;
|
---|
372 | MSG_Get (MINSTALL_ErrorMsg, 1024, MINSTALL_ErrorMsgID);
|
---|
373 | MINSTLOG_ToFile (MINSTALL_ErrorMsg);
|
---|
374 | }
|
---|
375 |
|
---|
376 | VOID MINSTALL_TrappedWarning (ULONG ErrorMsgID) {
|
---|
377 | MSG_Get (MINSTALL_ErrorMsg, 1024, ErrorMsgID);
|
---|
378 | MINSTLOG_ToFile (MINSTALL_ErrorMsg);
|
---|
379 | }
|
---|
380 |
|
---|
381 | VOID MINSTLOG_OpenFile (void) {
|
---|
382 | MINSTLOG_CloseFile();
|
---|
383 | if (MINSTLOG_FileName[0]!=0)
|
---|
384 | MINSTLOG_FileHandle = fopen(MINSTLOG_FileName, "w+b");
|
---|
385 | }
|
---|
386 |
|
---|
387 | VOID MINSTLOG_CloseFile (void) {
|
---|
388 | if (MINSTLOG_FileHandle) {
|
---|
389 | fclose (MINSTLOG_FileHandle);
|
---|
390 | MINSTLOG_FileHandle = NULL;
|
---|
391 | }
|
---|
392 | }
|
---|
393 |
|
---|
394 | VOID MINSTLOG_ToFile (PSZ FormatStr, ...) {
|
---|
395 | va_list arglist;
|
---|
396 | va_start (arglist, FormatStr);
|
---|
397 | if (MINSTLOG_FileHandle) vfprintf (MINSTLOG_FileHandle, FormatStr, arglist);
|
---|
398 | /* printf ("%s", FormatStr); */
|
---|
399 | va_end (arglist);
|
---|
400 | }
|
---|
401 |
|
---|
402 | VOID MINSTLOG_ToScreen (PSZ FormatStr, ...) {
|
---|
403 | va_list arglist;
|
---|
404 | va_start (arglist, FormatStr);
|
---|
405 | vprintf (FormatStr, arglist);
|
---|
406 | va_end (arglist);
|
---|
407 | }
|
---|
408 |
|
---|
409 | VOID MINSTLOG_ToAll (PSZ FormatStr, ...) {
|
---|
410 | va_list arglist;
|
---|
411 | va_start (arglist, FormatStr);
|
---|
412 | vprintf (FormatStr, arglist);
|
---|
413 | if (MINSTLOG_FileHandle) vfprintf (MINSTLOG_FileHandle, FormatStr, arglist);
|
---|
414 | va_end (arglist);
|
---|
415 | }
|
---|
416 |
|
---|
417 | VOID MINSTALL_printf (PSZ FormatStr, ...) {
|
---|
418 | va_list arglist;
|
---|
419 | va_start (arglist, FormatStr);
|
---|
420 | vprintf (FormatStr, arglist);
|
---|
421 | va_end (arglist);
|
---|
422 | }
|
---|