source: trunk/src/mmi_ctrlprc.c@ 2

Last change on this file since 2 was 2, checked in by ktk, 17 years ago

Initial import

File size: 16.9 KB
Line 
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_WINWORKPLACE // for WPS functions
23// #define INCL_OS2MM // Include MMIO functions
24// #define INCL_MMIO_CODEC // ...
25// #define INCL_AUDIO_CODEC_ONLY
26#include <os2.h>
27#define INCL_MCIOS2
28#include <os2me.h>
29#include <malloc.h>
30
31#include <global.h>
32#include <dll.h>
33#include <cfgsys.h> // CONFIG.SYS Changing
34#include <crcs.h>
35#include <file.h>
36#include <globstr.h>
37#include <msg.h>
38#include <mciini.h> // My own MCI-SYSINFO routines...
39#include <mmi_public.h>
40#include <mmi_types.h>
41#include <mmi_main.h>
42#include <mmi_helper.h>
43#include <mmi_msg.h>
44#include <mmi_inistuff.h>
45#include <mmi_imports.h>
46
47BOOL MINSTALL_ProcessConfigControl (ULONG ChangeCount, PVOID ChangeArrayPtr) {
48 LONG CONFIGSYSrc = 0;
49
50 CONFIGSYSrc = CONFIGSYS_Process (0, ChangeCount, (PCONFIGSYSACTION)ChangeArrayPtr, "\nREM *** MMOS/2 ***\n");
51 switch (CONFIGSYSrc) {
52 case CONFIGSYS_DONE:
53 MINSTLOG_ToFile ("Internal: CONFIG.SYS processed, did not get modified\n");
54 return TRUE;
55 case CONFIGSYS_DONE_BackUp:
56 MINSTLOG_ToFile ("Internal: CONFIG.SYS updated, old one backupped\n");
57 return TRUE;
58 case CONFIGSYS_DONE_Changed:
59 MINSTLOG_ToFile ("Internal: CONFIG.SYS updated, w/o backup\n");
60 return TRUE;
61 case CONFIGSYS_ERR_IsReadOnly:
62 MINSTALL_TrappedError (MINSTMSG_CONFIGSYSReadOnly); return FALSE;
63 case CONFIGSYS_ERR_FailedBackUp:
64 MINSTALL_TrappedError (MINSTMSG_CONFIGSYSFailedBackUp); return FALSE;
65 default:
66 MINSTALL_TrappedError (MINSTMSG_CONFIGSYSGenericProblem); return FALSE;
67 }
68 }
69
70BOOL EA_JoinTheseEAs (PSZ JoinToPathName, PFEA2LIST EAListPtr) {
71 EAOP2 EASetStruct;
72 APIRET rc;
73
74 EASetStruct.fpGEA2List = NULL;
75 EASetStruct.fpFEA2List = EAListPtr;
76 EASetStruct.oError = 0;
77 if ((rc = DosSetPathInfo(JoinToPathName, FIL_QUERYEASIZE, &EASetStruct, sizeof(EASetStruct), DSPI_WRTTHRU))!=0) {
78 MINSTLOG_ToFile ("rc = %d...", rc); return FALSE; }
79 return TRUE;
80 }
81
82typedef struct _EA_SETLONGNAMEFEA {
83 ULONG cbList;
84 ULONG oNextEntryOffset;
85 BYTE fEA;
86 BYTE cbName;
87 USHORT cbValue;
88 CHAR szLONGNAME[10];
89 USHORT LongNameVal;
90 USHORT LongNameLen;
91 CHAR LongName[MINSTMAX_PATHLENGTH];
92 } EA_SETLONGNAMEFEA;
93
94BOOL EA_SetLongnameEA (PSZ TargetPathName, PSZ LongName) {
95 ULONG LongNameLen = strlen(LongName);
96 EA_SETLONGNAMEFEA MyFEA;
97
98 MyFEA.cbList = sizeof(MyFEA);
99 MyFEA.oNextEntryOffset = sizeof(MyFEA);
100 MyFEA.fEA = 0;
101 MyFEA.cbName = 9;
102 MyFEA.cbValue = 0x10;
103 strcpy (MyFEA.szLONGNAME, ".LONGNAME");
104 MyFEA.LongNameVal = 0xFFFD;
105 MyFEA.LongNameLen = LongNameLen;
106 strcpy (MyFEA.LongName, LongName);
107 return EA_JoinTheseEAs (TargetPathName, (PFEA2LIST)&MyFEA);
108 }
109
110// Gets .EAs from a file and adds them to a specified file/path
111BOOL EA_JoinFileEA (PSZ JoinToPathName, PSZ EAFileName) {
112 FILECONTROL TEMPFILE;
113 CHAR ProcessFileName[MINSTMAX_PATHLENGTH];
114 BOOL ErrorOccured = FALSE;
115 FILE *FileHandle = 0;
116 ULONG FileSize = 0;
117 PVOID EAFileBuffer = 0;
118
119 FileHandle = fopen(EAFileName, "rb");
120 if (FileHandle==NULL) return FALSE;
121
122 // Get File-Length of INI-File, check for maximum buffer-length
123 fseek (FileHandle, 0, SEEK_END);
124 FileSize = ftell(FileHandle);
125 if (FileSize<524288) { // We dont take files larger 512k
126 EAFileBuffer = malloc(FileSize+4);
127 if (EAFileBuffer) {
128 // Read in EA-data...
129 fseek (FileHandle, 0, SEEK_SET); // Seek back to start
130 if (FileSize != fread((PVOID)(((ULONG)EAFileBuffer)+4), 1, FileSize, FileHandle))
131 ErrorOccured = TRUE;
132 } else ErrorOccured = TRUE;
133 } else ErrorOccured = TRUE;
134 fclose (FileHandle);
135
136 if (!ErrorOccured) {
137 // If no error occured, add those .EAs to file/path...
138 (*(PULONG)EAFileBuffer) = FileSize;
139 if (!EA_JoinTheseEAs(JoinToPathName, (PFEA2LIST)EAFileBuffer))
140 ErrorOccured = TRUE;
141 }
142
143 free (EAFileBuffer);
144 if (!ErrorOccured) return TRUE;
145 return FALSE;
146 }
147
148BOOL PRF_SetProfileData (PPRF_PROFILEDATA CustomPtr) {
149 HMODULE DLLHandle = 0;
150 PVOID ResourcePtr = 0;
151 ULONG ResourceSize = 0;
152 HINI INIHandle = 0;
153 BOOL ErrorOccured = FALSE;
154 BOOL NeedToClose = FALSE;
155
156 if ((DLLHandle = DLL_Load(CustomPtr->Dll))!=0) {
157 if (DLL_GetDataResource (DLLHandle, CustomPtr->Id, &ResourcePtr, &ResourceSize)) {
158 // Uppercase filename...
159 strupr (CustomPtr->Ini);
160
161 // Check for hardcoded SYSTEM/USER...
162 if (strcmp(CustomPtr->Ini, "HINI_SYSTEM")==0) {
163 INIHandle = HINI_SYSTEMPROFILE;
164 } else if (strcmp(CustomPtr->Ini, "HINI_USER")==0) {
165 INIHandle = HINI_USERPROFILE;
166 } else {
167 // We assume that the string is an INI-Filename...
168 if (!(INIHandle = PrfOpenProfile(MINSTALL_PMHandle, CustomPtr->Ini)))
169 ErrorOccured = TRUE;
170 NeedToClose = TRUE;
171 }
172 } else ErrorOccured = TRUE;
173 } else ErrorOccured = TRUE;
174
175 if (INIHandle) {
176 // Got valid INI-Handle, so write the string...
177 ErrorOccured = !PrfWriteProfileData(INIHandle, CustomPtr->AppName, CustomPtr->KeyName, ResourcePtr, ResourceSize);
178 } else ErrorOccured = TRUE;
179
180 if (NeedToClose) PrfCloseProfile(INIHandle);
181 if (DLLHandle) DLL_UnLoad(DLLHandle);
182 return !ErrorOccured;
183 }
184
185BOOL PRF_SetProfileString (PPRF_PROFILESTRING CustomPtr) {
186 HINI INIHandle = 0;
187 BOOL ErrorOccured = FALSE;
188 BOOL NeedToClose = FALSE;
189
190 // Uppercase filename...
191 strupr (CustomPtr->Inis);
192
193 // Check for hardcoded SYSTEM/USER...
194 if (strcmp(CustomPtr->Inis, "HINI_SYSTEM")==0) {
195 INIHandle = HINI_SYSTEMPROFILE;
196 } else if (strcmp(CustomPtr->Inis, "HINI_USER")==0) {
197 INIHandle = HINI_USERPROFILE;
198 } else {
199 // We assume that the string is an INI-Filename...
200 if (!(INIHandle = PrfOpenProfile(MINSTALL_PMHandle, CustomPtr->Inis)))
201 ErrorOccured = TRUE;
202 NeedToClose = TRUE;
203 }
204
205 if (INIHandle) {
206 // Got valid INI-Handle, so write the string...
207 ErrorOccured = !PrfWriteProfileString(INIHandle, CustomPtr->AppNames, CustomPtr->KeyNames, CustomPtr->Datas);
208 } else ErrorOccured = TRUE;
209 if (NeedToClose) PrfCloseProfile(INIHandle);
210 return !ErrorOccured;
211 }
212
213BOOL WPS_CreateObject (PWPS_CREATEOBJECT CustomPtr) {
214 if (!WinCreateObject(CustomPtr->WPClassName, CustomPtr->WPTitle,
215 CustomPtr->WPSetupString, CustomPtr->WPLocation, CustomPtr->WPFlags))
216 return FALSE;
217 return TRUE;
218 }
219
220BOOL WPS_DestroyObject (PWPS_DESTROYOBJECT CustomPtr) {
221 HOBJECT ObjectHandle = 0;
222
223 if (!(ObjectHandle = WinQueryObject(CustomPtr->WPDestroyObjectID)))
224 return FALSE;
225 return WinDestroyObject(ObjectHandle);
226 }
227
228BOOL WPS_WPClass (PWPS_WPCLASS CustomPtr) {
229 CHAR DLLName[MAXFILELENGTH];
230 ULONG CRC32;
231 PMINSTFILE CurFilePtr;
232
233 if (FILE_IncludesPath(CustomPtr->WPDllName)) {
234 strcpy (DLLName, CustomPtr->WPDllName);
235 } else {
236 // If DLL-Name doesnt contain path already, we search for the file in
237 // filelist and add the corresponding path.
238 strlwr (CustomPtr->WPDllName);
239 FILE_SetDefaultExtension (CustomPtr->WPDllName, MINSTMAX_PATHLENGTH, ".dll");
240 CRC32 = CRC32_GetFromPSZ(CustomPtr->WPDllName);
241 if ((CurFilePtr = MINSTALL_SearchFileCRC32(CRC32))!=0) {
242 if (!STRING_CombinePSZ (DLLName, MAXFILELENGTH, CurFilePtr->DestinPtr->FQName, CustomPtr->WPDllName))
243 return FALSE; // buffer-overflow
244 } else {
245 strcpy (DLLName, CustomPtr->WPDllName);
246 }
247 }
248 // Register the class at any time...
249 if (!WinRegisterObjectClass (CustomPtr->WPClassNameNew, DLLName))
250 return FALSE;
251 if (strlen(CustomPtr->WPReplaceClass)>0) {
252 // If Replace-Class set, replace this class with the new one...
253 if (!WinReplaceObjectClass (CustomPtr->WPReplaceClass, CustomPtr->WPClassNameNew, TRUE))
254 return FALSE;
255 }
256 return TRUE;
257 }
258
259BOOL MINSTALL_ProcessINIControl (ULONG ChangeCount, PVOID Change1stEntryPtr) {
260 ULONG CurChangeNo = 0;
261 PMINSTINIHEADER CurEntryPtr = Change1stEntryPtr;
262 PVOID CustomPtr = 0;
263 APIRET rc = 0;
264 BOOL Failed = FALSE;
265 ERRORID ErrorID;
266
267 while (CurChangeNo<ChangeCount) {
268 // CustomPtr points at actual INIChange specific data
269 CustomPtr = (PVOID)(((ULONG)CurEntryPtr)+sizeof(MINSTINIHEADER));
270 switch (CurEntryPtr->ID) {
271 case EA_JOINEA_ID: // ==================== EA - JoinEA
272 MINSTLOG_ToFile (" - JoinEA...");
273 if (!EA_JoinFileEA(((PEA_JOINEA)CurEntryPtr)->JoinFileName, ((PEA_JOINEA)CurEntryPtr)->JoinEAFileName))
274 Failed = TRUE;
275 break;
276 case EA_JOINLONGNAMEEA_ID: // ============ EA - JoinLongNameEA
277 MINSTLOG_ToFile (" - JoinLongNameEA...");
278 if (strlen(((PEA_JOINLONGNAMEEA)CurEntryPtr)->JoinEALongFileName)) {
279 // If file specified, add that one first...
280 if (!EA_JoinFileEA(((PEA_JOINLONGNAMEEA)CurEntryPtr)->JoinLongFileName, ((PEA_JOINLONGNAMEEA)CurEntryPtr)->JoinEALongFileName))
281 Failed = TRUE;
282 }
283 // Now set .LONGNAME-EA manually...
284 if (!EA_SetLongnameEA (((PEA_JOINLONGNAMEEA)CurEntryPtr)->JoinLongFileName, ((PEA_JOINLONGNAMEEA)CurEntryPtr)->JoinLongName))
285 Failed = TRUE;
286 break;
287 case MCI_MCIINSTALLDRV_ID: // ============ MCI - MciInstallDrv
288 MINSTLOG_ToFile (" - MciInstallDrv...");
289 if ((rc = MCIINI_SendSysInfoExtCommand(MCI_SYSINFO_INSTALL_DRIVER, (PMCI_SYSINFO_LOGDEVICE)CustomPtr))!=0) {
290 MINSTLOG_ToFile ("rc = %Xh...", rc); Failed = TRUE; }
291 break;
292 case MCI_MCIINSTALLCONN_ID: // =========== MCI - MciInstallConn
293 MINSTLOG_ToFile (" - MciInstallConn...");
294 if ((rc = MCIINI_SendSysInfoExtCommand(MCI_SYSINFO_SET_CONNECTORS, (PMCI_SYSINFO_CONPARAMS)CustomPtr))!=0) {
295 MINSTLOG_ToFile ("rc = %Xh...", rc); Failed = TRUE; }
296 break;
297 case MCI_MCIINSTALLPARM_ID: // =========== MCI - MciInstallParm
298 MINSTLOG_ToFile (" - MciInstallParm...");
299 if ((rc = MCIINI_SendSysInfoExtCommand(MCI_SYSINFO_SET_PARAMS, (PMCI_SYSINFO_DEVPARAMS)CustomPtr))!=0) {
300 MINSTLOG_ToFile ("rc = %Xh...", rc); Failed = TRUE; }
301 break;
302 case MCI_MCIINSTALLALIAS_ID: // ========== MCI - MciInstallAlias
303 MINSTLOG_ToFile (" - MciInstallAlias...");
304 if ((rc = MCIINI_SendSysInfoExtCommand(MCI_SYSINFO_SET_ALIAS, (PMCI_SYSINFO_ALIAS)CustomPtr))!=0) {
305 MINSTLOG_ToFile ("rc = %Xh...", rc); Failed = TRUE; }
306 break;
307 case MCI_MCIINSTALLEXT_ID: // ============ MCI - MciInstallExt
308 MINSTLOG_ToFile (" - MciInstallExt...");
309 if ((rc = MCIINI_SendSysInfoExtCommand(MCI_SYSINFO_SET_EXTENSIONS, (PMCI_SYSINFO_EXTENSION)CustomPtr))!=0) {
310 MINSTLOG_ToFile ("rc = %Xh...", rc); Failed = TRUE; }
311 break;
312 case MCI_MCIINSTALLTYPES_ID: // ========== MCI - MciInstallTypes
313 MINSTLOG_ToFile (" - MciInstallTypes...");
314 if ((rc = MCIINI_SendSysInfoExtCommand(MCI_SYSINFO_SET_TYPES, (PMCI_SYSINFO_TYPES)CustomPtr))!=0) {
315 MINSTLOG_ToFile ("rc = %Xh...", rc); Failed = TRUE; }
316 break;
317 case MMIO_MMIOINSTALL_ID: // ============= MMIO - mmioInstall
318 MINSTLOG_ToFile (" - mmioInstall...");
319 if ((rc = (*CODE_mmioIniFileHandlerFunc) ((PMMIO_MMIOINSTALL)CustomPtr, MMIO_INSTALLPROC|MMIO_EXTENDED_STRUCT))!=0) {
320 MINSTLOG_ToFile ("rc = %Xh...", rc); Failed = TRUE; }
321 break;
322 case MMIO_MMIOCODECDELETE_ID: // ========= MMIO - mmioCodecDelete
323 MINSTLOG_ToFile (" - mmioCodecDelete...");
324 // We set StructLen by ourselves, just for security
325 ((PMMIO_MMIOCODEC)CurEntryPtr)->ulStructLen = sizeof(MMIO_MMIOCODEC)-sizeof(MINSTINIHEADER);
326 if ((rc = (*CODE_mmioIniFileCODECFunc) ((PMMIO_MMIOCODEC)CustomPtr, MMIO_REMOVEPROC|MMIO_MATCHFOURCC|MMIO_MATCHDLL|MMIO_MATCHPROCEDURENAME|MMIO_MATCHCOMPRESSTYPE))!=0) {
327 MINSTLOG_ToFile ("rc = %Xh...", rc); Failed = TRUE; }
328 break;
329 case MMIO_MMIOCODEC1INSTALL_ID: // ======= MMIO - mmioCodec1Install
330 case MMIO_MMIOCODEC2INSTALL_ID: // ======= MMIO - mmioCodec2Install
331 // We can process both because buffer is exactly the same...
332 MINSTLOG_ToFile (" - mmioCodecInstall...");
333 // We set StructLen by ourselves, just for security
334 ((PMMIO_MMIOCODEC)CurEntryPtr)->ulStructLen = sizeof(MMIO_MMIOCODEC)-sizeof(MINSTINIHEADER);
335 if ((rc = (*CODE_mmioIniFileCODECFunc) ((PMMIO_MMIOCODEC)CustomPtr, MMIO_INSTALLPROC|MMIO_MATCHFOURCC|MMIO_MATCHDLL|MMIO_MATCHPROCEDURENAME|MMIO_MATCHCOMPRESSTYPE))!=0) {
336 MINSTLOG_ToFile ("rc = %Xh...", rc); Failed = TRUE; }
337 break;
338 case PRF_PROFILEDATA_ID: // ============== PRF - ProfileData
339 MINSTLOG_ToFile (" - ProfileData...");
340 if (!PRF_SetProfileData((PPRF_PROFILEDATA)CurEntryPtr))
341 Failed = TRUE;
342 break;
343 case PRF_PROFILESTRING_ID: // ============ PRF - ProfileString
344 MINSTLOG_ToFile (" - ProfileString...");
345 if (!PRF_SetProfileString((PPRF_PROFILESTRING)CurEntryPtr))
346 Failed = TRUE;
347 break;
348 case SPI_SPIINSTALL_ID: // =============== SPI - SpiInstall
349 MINSTLOG_ToFile (" - SpiInstall...");
350 if ((*CODE_SpiInstallFunc) (((PSPI_SPIINSTALL)CurEntryPtr)->SpiDllName))
351 Failed = TRUE;
352 break;
353 case WPS_CREATEOBJECT_ID: // ================= WPS - WPObject
354 MINSTLOG_ToFile (" - WPS-CreateObject...");
355 if (!WPS_CreateObject((PWPS_CREATEOBJECT)CurEntryPtr)) {
356 ErrorID = WinGetLastError (MINSTALL_PMHandle);
357 MINSTLOG_ToFile ("ErrorID = %Xh...", ErrorID); Failed = TRUE; }
358 break;
359 case WPS_DESTROYOBJECT_ID: // ========== WPS - WPDestroyObject
360 MINSTLOG_ToFile (" - WPS-DestroyObject...");
361 if (!WPS_DestroyObject((PWPS_DESTROYOBJECT)CurEntryPtr)) {
362 ErrorID = WinGetLastError (MINSTALL_PMHandle);
363 MINSTLOG_ToFile ("ErrorID = %Xh...", ErrorID); Failed = TRUE; }
364 break;
365 case WPS_WPCLASS_ID: // ================== WPS - WPClass
366 MINSTLOG_ToFile (" - WPClass...");
367 if (!WPS_WPClass((PWPS_WPCLASS)CurEntryPtr)) {
368 ErrorID = WinGetLastError (MINSTALL_PMHandle);
369 MINSTLOG_ToFile ("ErrorID = %Xh...", ErrorID); Failed = TRUE; }
370 break;
371 }
372
373 if (Failed) {
374 MINSTLOG_ToFile ("failed\n");
375 Failed = FALSE;
376 } else {
377 MINSTLOG_ToFile ("success\n");
378 }
379
380 // Go to next INI-Change...
381 CurEntryPtr = CurEntryPtr->NextPtr;
382 CurChangeNo++;
383 }
384
385 return TRUE;
386 }
387
388
389BOOL MINSTALL_ProcessScripts (VOID) {
390 PMINSTGRP CurGroupPtr = MCF_GroupArrayPtr;
391 USHORT CurNo = 0;
392 USHORT CurChangeNo = 0;
393
394 while (CurNo<MCF_GroupCount) {
395 if (CurGroupPtr->Flags & MINSTGRP_Flags_Selected) {
396 MINSTLOG_ToFile (" (Group %d)...\n", CurGroupPtr->ID);
397 if (CurGroupPtr->ConfigChangeCount) {
398 if (!MINSTALL_ProcessConfigControl(CurGroupPtr->ConfigChangeCount, CurGroupPtr->ConfigChangeArray))
399 return FALSE;
400 }
401 if (CurGroupPtr->INIChangeCount) {
402 if (!MINSTALL_ProcessINIControl(CurGroupPtr->INIChangeCount, CurGroupPtr->INIChange1stEntry))
403 return FALSE;
404 }
405 }
406 CurGroupPtr++; CurNo++;
407 }
408 return TRUE;
409 }
Note: See TracBrowser for help on using the repository browser.