[2] | 1 | /*
|
---|
| 2 | * This file is (C) Chris Wohlgemuth 2001/2003
|
---|
| 3 | */
|
---|
| 4 | /*
|
---|
| 5 | * This program is free software; you can redistribute it and/or modify
|
---|
| 6 | * it under the terms of the GNU General Public License as published by
|
---|
| 7 | * the Free Software Foundation; either version 2, or (at your option)
|
---|
| 8 | * any later version.
|
---|
| 9 | *
|
---|
| 10 | * This program is distributed in the hope that it will be useful,
|
---|
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 13 | * GNU General Public License for more details.
|
---|
| 14 | *
|
---|
| 15 | * You should have received a copy of the GNU General Public License
|
---|
| 16 | * along with this program; see the file COPYING. If not, write to
|
---|
| 17 | * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
| 18 | */
|
---|
| 19 | /*
|
---|
| 20 | * If you need another license for your prject/product contact me at
|
---|
[104] | 21 | *
|
---|
[2] | 22 | * http://www.os2world.com/cdwriting
|
---|
| 23 | * http://www.geocities.com/SiliconValley/Sector/5785/
|
---|
| 24 | */
|
---|
| 25 | #define INCL_WIN
|
---|
| 26 | #define INCL_GPI
|
---|
| 27 | #define INCL_DOS
|
---|
| 28 | #define INCL_DOSERRORS
|
---|
| 29 |
|
---|
| 30 | #include <os2.h>
|
---|
| 31 | #include <sys/types.h>
|
---|
| 32 | #include <sys/stat.h>
|
---|
| 33 |
|
---|
| 34 | #include <stdio.h>
|
---|
| 35 | #include <string.h>
|
---|
| 36 | #include <stdarg.h>
|
---|
| 37 | #include "mmprogs_defaults.h"
|
---|
| 38 | #include "sys_funcs.h"
|
---|
| 39 |
|
---|
| 40 | //#define INSTALLDIR 1
|
---|
| 41 |
|
---|
[104] | 42 | #define INI_BGCLR_KEY (PSZ)"bg"
|
---|
| 43 | #define INI_FGCLR_KEY (PSZ)"fg"
|
---|
| 44 | #define INI_BTNBGCLR_KEY (PSZ)"btnbg"
|
---|
| 45 | #define INI_BTNFGCLR_KEY (PSZ)"btnfg"
|
---|
| 46 | #define INI_ACTIVETBBGCLR_KEY (PSZ)"activetbbg"
|
---|
| 47 | #define INI_INACTIVETBBGCLR_KEY (PSZ)"inactivetbbg"
|
---|
| 48 | #define INI_ACTIVETBFGCLR_KEY (PSZ)"activetbfg"
|
---|
| 49 | #define INI_INACTIVETBFGCLR_KEY (PSZ)"inactivetbfg"
|
---|
[2] | 50 |
|
---|
| 51 | /* The subdirectory in the installation directory where to put the log files */
|
---|
| 52 | #define LOGFILE_SUBDIR "Logfiles"
|
---|
| 53 | #define EXCEPTION_LOGFILE_NAME "CWMMCls.log"
|
---|
| 54 |
|
---|
| 55 | #define RESDLLNAME "\\mmres_%c%c.dll"
|
---|
| 56 | #define DEFRESDLLNAME "\\mmres_en.dll"
|
---|
| 57 |
|
---|
[104] | 58 | extern PSZ params[];
|
---|
[2] | 59 | extern HMODULE RESSOURCEHANDLE;
|
---|
| 60 | extern char logName[];
|
---|
| 61 |
|
---|
| 62 | char chrInstallDir[CCHMAXPATH];
|
---|
| 63 |
|
---|
| 64 | SWP swpWindow;
|
---|
| 65 |
|
---|
| 66 | HMODULE _queryResModuleHandle2(char *installDir);
|
---|
[104] | 67 | BOOL IniSaveData(PSZ iniFile, PSZ chrApp, PSZ chrKey, PVOID theData, ULONG ulSize);
|
---|
| 68 | BOOL IniRestoreData(PSZ iniFile, PSZ chrApp, PSZ chrKey, PVOID theData, PULONG ulMaxSize);
|
---|
| 69 | void writeLog(PSZ logText);
|
---|
[2] | 70 | void HlpWriteToTrapLog(const char* chrFormat, ...);
|
---|
| 71 |
|
---|
| 72 |
|
---|
| 73 | void removeLog(void)
|
---|
| 74 | {
|
---|
| 75 | char logNameLocal[CCHMAXPATH];
|
---|
[104] | 76 |
|
---|
[2] | 77 | sprintf(logNameLocal,"%s\\%s\\%s",params[1],LOGFILE_SUBDIR,logName);
|
---|
| 78 |
|
---|
| 79 | remove(logNameLocal);
|
---|
| 80 | }
|
---|
| 81 |
|
---|
| 82 | void removeLog2(char * installDir, char * logName)
|
---|
| 83 | {
|
---|
| 84 | char logNameLocal[CCHMAXPATH];
|
---|
| 85 |
|
---|
| 86 | sprintf(logNameLocal,"%s\\%s\\%s",installDir,LOGFILE_SUBDIR,logName);
|
---|
| 87 | remove(logNameLocal);
|
---|
| 88 | }
|
---|
| 89 |
|
---|
[104] | 90 | void writeLog(PSZ logText)
|
---|
[2] | 91 | {
|
---|
| 92 | char logNameLocal[CCHMAXPATH];
|
---|
| 93 | FILE *fHandle;
|
---|
| 94 |
|
---|
| 95 | sprintf(logNameLocal,"%s\\%s\\%s",params[1],LOGFILE_SUBDIR,logName);
|
---|
| 96 | fHandle=fopen(logNameLocal,"a");
|
---|
| 97 | if(fHandle) {
|
---|
| 98 | fprintf(fHandle,logText);
|
---|
| 99 | fclose(fHandle);
|
---|
| 100 | }
|
---|
| 101 | }
|
---|
| 102 |
|
---|
| 103 | BOOL buildLogName( char * outBuf, char * logName,ULONG ulSize)
|
---|
| 104 | {
|
---|
[126] | 105 | if(sprintf(outBuf, /*ulSize,*/"logfiles\\%s",logName)==EOF)
|
---|
[2] | 106 | return FALSE;
|
---|
| 107 | return TRUE;
|
---|
| 108 | }
|
---|
| 109 |
|
---|
| 110 |
|
---|
| 111 | /* This function launches the wrapper <wrapperExe> */
|
---|
| 112 | /* with the params given as a PM-session */
|
---|
| 113 | /* in PSZ parameter. PSZ folderPath is the path to put the */
|
---|
| 114 | /* write.log. HWND hwnd is the window waiting for the */
|
---|
| 115 | /* WM_APPTERMINATE message */
|
---|
| 116 | ULONG launchPMWrapper(PSZ chrInstallDir, PSZ parameter, PSZ folderPath, PSZ wrapperExe, PSZ pszTitle)
|
---|
| 117 | {
|
---|
| 118 | STARTDATA startData={0};
|
---|
| 119 | PID pid;
|
---|
| 120 | ULONG ulSessionID=0;
|
---|
[104] | 121 | UCHAR chrLoadError[CCHMAXPATH];
|
---|
| 122 | UCHAR startParams[CCHMAXPATH*4];
|
---|
| 123 | UCHAR exename[CCHMAXPATH]={0};
|
---|
| 124 | UCHAR chrFolderPath[CCHMAXPATH+10];
|
---|
| 125 |
|
---|
[2] | 126 | memset(&startData,0,sizeof(startData));
|
---|
| 127 | startData.Length=sizeof(startData);
|
---|
| 128 | startData.Related=SSF_RELATED_INDEPENDENT;
|
---|
| 129 | startData.FgBg=SSF_FGBG_FORE;
|
---|
| 130 | startData.TraceOpt=SSF_TRACEOPT_NONE;
|
---|
| 131 | startData.PgmTitle=pszTitle;
|
---|
[104] | 132 |
|
---|
[2] | 133 | /* sprintf(exename,"%s",buildWrapName(wrapperExe));*/
|
---|
[104] | 134 | sprintf((PCHAR)exename,"%s\\bin\\%s",params[1],wrapperExe);
|
---|
[2] | 135 | /*
|
---|
| 136 | if(!checkHelper(exename))
|
---|
| 137 | return -1;
|
---|
| 138 | */
|
---|
| 139 |
|
---|
| 140 | startData.PgmName=exename;
|
---|
| 141 | startData.InheritOpt=SSF_INHERTOPT_SHELL;
|
---|
| 142 | startData.SessionType=SSF_TYPE_PM;
|
---|
| 143 | startData.PgmControl=0;
|
---|
| 144 | startData.InitXPos=30;
|
---|
| 145 | startData.InitYPos=30;
|
---|
| 146 | startData.InitXSize=500;
|
---|
| 147 | startData.InitYSize=400;
|
---|
| 148 | startData.ObjectBuffer=chrLoadError;
|
---|
| 149 | startData.ObjectBuffLen=(ULONG)sizeof(chrLoadError);
|
---|
| 150 |
|
---|
| 151 | /* Put the exe-path between " " to make sure, spaces are handled correctly */
|
---|
[104] | 152 | strcpy((PCHAR)chrFolderPath,(PCHAR)folderPath);
|
---|
| 153 | sprintf((PCHAR)startParams,"\"%s\" \"%s\" %s",
|
---|
| 154 | (PCHAR)chrInstallDir,(PCHAR)chrFolderPath, (PCHAR)parameter);
|
---|
[2] | 155 | startData.PgmInputs=startParams;
|
---|
| 156 |
|
---|
[104] | 157 | DosStartSession(&startData,&ulSessionID,&pid);
|
---|
| 158 | return 0;
|
---|
[2] | 159 | }
|
---|
| 160 |
|
---|
| 161 |
|
---|
[104] | 162 | BOOL IniRestoreWindowPos(char * iniFile, PSZ chrApp, PSZ chrKey, HWND hwnd)
|
---|
[2] | 163 | {
|
---|
| 164 | HINI hini=0;
|
---|
| 165 | ULONG ulSize;
|
---|
| 166 | BOOL bError=FALSE;
|
---|
| 167 | SWP swp;
|
---|
| 168 |
|
---|
| 169 | /* Open ini-file */
|
---|
| 170 | hini=PrfOpenProfile(WinQueryAnchorBlock(HWND_DESKTOP),(unsigned char *)iniFile);
|
---|
| 171 | do{
|
---|
| 172 | if(!hini) {
|
---|
| 173 | #if 0
|
---|
| 174 | /* profileName: "Warning! Cannot open Ini-file!"
|
---|
| 175 | moduleName: "Data-CD-Creator"
|
---|
| 176 | */
|
---|
| 177 | messageBox( profileName, IDSTR_INIFILEOPENWARNING , sizeof(profileName),
|
---|
| 178 | moduleName, IDSTRD_DATACDCREATOR, sizeof(moduleName),
|
---|
| 179 | RESSOURCEHANDLE, HWND_DESKTOP, MB_OK | MB_ICONEXCLAMATION|MB_MOVEABLE);
|
---|
| 180 | #endif
|
---|
| 181 | break;
|
---|
| 182 | }/* end of if(!hini) */
|
---|
| 183 |
|
---|
[104] | 184 | ulSize=sizeof(swp);
|
---|
[2] | 185 | if(!PrfQueryProfileData(hini, chrApp, chrKey, &swp, &ulSize))
|
---|
| 186 | bError=TRUE;
|
---|
| 187 |
|
---|
| 188 | if(hini)
|
---|
| 189 | PrfCloseProfile(hini);
|
---|
[104] | 190 |
|
---|
[2] | 191 | if(bError)
|
---|
| 192 | break;
|
---|
| 193 | WinSetWindowPos(hwnd, NULLHANDLE, swp.x, swp.y, swp.cx, swp.cy, SWP_MOVE/*|SWP_SIZE*/);
|
---|
| 194 | return TRUE;
|
---|
| 195 | } while(TRUE);
|
---|
| 196 |
|
---|
| 197 | return FALSE;
|
---|
| 198 | }
|
---|
| 199 |
|
---|
[104] | 200 | BOOL IniSaveWindowPos(PSZ iniFile, PSZ chrApp, PSZ chrKey, HWND hwnd)
|
---|
[2] | 201 | {
|
---|
| 202 | HINI hini=0;
|
---|
| 203 | BOOL bError=FALSE;
|
---|
| 204 | SWP swp;
|
---|
| 205 |
|
---|
| 206 | /* Open ini-file */
|
---|
[104] | 207 | hini=PrfOpenProfile(WinQueryAnchorBlock(HWND_DESKTOP),iniFile);
|
---|
[2] | 208 | do{
|
---|
| 209 |
|
---|
| 210 | if(!hini) {
|
---|
| 211 | #if 0
|
---|
| 212 | /* profileName: "Warning! Cannot open Ini-file!"
|
---|
| 213 | moduleName: "Data-CD-Creator"
|
---|
| 214 | */
|
---|
| 215 | messageBox( profileName, IDSTR_INIFILEOPENWARNING , sizeof(profileName),
|
---|
| 216 | moduleName, IDSTRD_DATACDCREATOR, sizeof(moduleName),
|
---|
| 217 | RESSOURCEHANDLE, HWND_DESKTOP, MB_OK | MB_ICONEXCLAMATION|MB_MOVEABLE);
|
---|
| 218 | #endif
|
---|
| 219 | break;
|
---|
| 220 | }/* end of if(!hini) */
|
---|
| 221 |
|
---|
| 222 | WinQueryWindowPos(hwnd, &swp);
|
---|
| 223 | if(!PrfWriteProfileData(hini, chrApp, chrKey, &swp, sizeof(swp)))
|
---|
| 224 | bError=TRUE;
|
---|
| 225 |
|
---|
| 226 | if(hini)
|
---|
| 227 | PrfCloseProfile(hini);
|
---|
[104] | 228 |
|
---|
[2] | 229 | if(bError)
|
---|
| 230 | break;
|
---|
| 231 | return TRUE;
|
---|
| 232 | } while(TRUE);
|
---|
| 233 | return FALSE;
|
---|
| 234 | }
|
---|
| 235 |
|
---|
[104] | 236 | BOOL IniSaveWindowClrs(PSZ chrIniFile, PSZ chrApp , HWND hwnd)
|
---|
[2] | 237 | {
|
---|
| 238 | RGB rgb;
|
---|
| 239 | ULONG attrFound;
|
---|
| 240 |
|
---|
| 241 | // Query the current background colour
|
---|
| 242 | if(WinQueryPresParam(hwnd,
|
---|
| 243 | PP_BACKGROUNDCOLOR,0,&attrFound,sizeof(rgb),
|
---|
| 244 | &rgb,QPF_NOINHERIT))
|
---|
| 245 | {
|
---|
| 246 | IniSaveData(chrIniFile, chrApp, INI_BGCLR_KEY, &rgb, sizeof(RGB));
|
---|
| 247 | }
|
---|
| 248 | // Query the current foreground colour
|
---|
| 249 | if(WinQueryPresParam(hwnd,
|
---|
| 250 | PP_FOREGROUNDCOLOR,0,&attrFound,sizeof(rgb),
|
---|
| 251 | &rgb,QPF_NOINHERIT))
|
---|
| 252 | {
|
---|
| 253 | IniSaveData(chrIniFile, chrApp, INI_FGCLR_KEY, &rgb, sizeof(RGB));
|
---|
| 254 | }
|
---|
| 255 |
|
---|
| 256 | if(WinQueryPresParam(WinWindowFromID(hwnd, FID_TITLEBAR),
|
---|
| 257 | PP_ACTIVECOLOR,0,&attrFound,sizeof(rgb),
|
---|
| 258 | &rgb,QPF_NOINHERIT))
|
---|
| 259 | {
|
---|
| 260 | IniSaveData(chrIniFile, chrApp, INI_ACTIVETBBGCLR_KEY, &rgb, sizeof(RGB));
|
---|
| 261 | }
|
---|
| 262 |
|
---|
| 263 | if(WinQueryPresParam(WinWindowFromID(hwnd, FID_TITLEBAR),
|
---|
| 264 | PP_INACTIVECOLOR,0,&attrFound,sizeof(rgb),
|
---|
| 265 | &rgb,QPF_NOINHERIT))
|
---|
| 266 | {
|
---|
| 267 | IniSaveData(chrIniFile, chrApp, INI_INACTIVETBBGCLR_KEY, &rgb, sizeof(RGB));
|
---|
| 268 | }
|
---|
| 269 | if(WinQueryPresParam(WinWindowFromID(hwnd, FID_TITLEBAR),
|
---|
| 270 | PP_ACTIVETEXTFGNDCOLOR,0,&attrFound,sizeof(rgb),
|
---|
| 271 | &rgb,QPF_NOINHERIT))
|
---|
| 272 | {
|
---|
| 273 | IniSaveData(chrIniFile, chrApp, INI_ACTIVETBFGCLR_KEY, &rgb, sizeof(RGB));
|
---|
| 274 | }
|
---|
| 275 | if(WinQueryPresParam(WinWindowFromID(hwnd, FID_TITLEBAR),
|
---|
| 276 | PP_INACTIVETEXTFGNDCOLOR,0,&attrFound,sizeof(rgb),
|
---|
| 277 | &rgb,QPF_NOINHERIT))
|
---|
| 278 | {
|
---|
| 279 | IniSaveData(chrIniFile, chrApp, INI_INACTIVETBFGCLR_KEY, &rgb, sizeof(RGB));
|
---|
| 280 | }
|
---|
| 281 | return TRUE;
|
---|
| 282 | }
|
---|
| 283 |
|
---|
[104] | 284 | BOOL IniRestoreWindowClrs(PSZ chrIniFile, PSZ chrApp , HWND hwnd)
|
---|
[2] | 285 | {
|
---|
| 286 | RGB rgb;
|
---|
| 287 | ULONG ulSize;
|
---|
[104] | 288 |
|
---|
[2] | 289 | ulSize=sizeof(RGB);
|
---|
| 290 | if(IniRestoreData(chrIniFile, chrApp, INI_BGCLR_KEY, &rgb, &ulSize))
|
---|
| 291 | {
|
---|
| 292 | // Set the background colour
|
---|
| 293 | WinSetPresParam(hwnd,
|
---|
| 294 | PP_BACKGROUNDCOLOR,(ULONG)sizeof(rgb), &rgb);
|
---|
| 295 | }
|
---|
[104] | 296 | ulSize=sizeof(RGB);
|
---|
[2] | 297 | if(IniRestoreData(chrIniFile, chrApp, INI_FGCLR_KEY, &rgb, &ulSize))
|
---|
| 298 | {
|
---|
| 299 | // Set the foreground colour
|
---|
| 300 | WinSetPresParam(hwnd,
|
---|
| 301 | PP_FOREGROUNDCOLOR,(ULONG)sizeof(rgb), &rgb);
|
---|
| 302 | }
|
---|
| 303 | /* Titlebar */
|
---|
| 304 | ulSize=sizeof(RGB);
|
---|
| 305 | if(IniRestoreData(chrIniFile, chrApp, INI_ACTIVETBBGCLR_KEY, &rgb, &ulSize))
|
---|
| 306 | {
|
---|
[104] | 307 |
|
---|
[2] | 308 | WinSetPresParam(WinWindowFromID(hwnd, FID_TITLEBAR),
|
---|
| 309 | PP_ACTIVECOLOR,(ULONG)sizeof(rgb), &rgb);
|
---|
| 310 | WinSetPresParam(WinWindowFromID(hwnd, FID_TITLEBAR),
|
---|
| 311 | PP_ACTIVETEXTBGNDCOLOR,(ULONG)sizeof(rgb), &rgb);
|
---|
| 312 | }
|
---|
| 313 | ulSize=sizeof(RGB);
|
---|
| 314 | if(IniRestoreData(chrIniFile, chrApp, INI_INACTIVETBBGCLR_KEY, &rgb, &ulSize))
|
---|
| 315 | {
|
---|
| 316 | WinSetPresParam(WinWindowFromID(hwnd, FID_TITLEBAR),
|
---|
| 317 | PP_INACTIVECOLOR,(ULONG)sizeof(rgb), &rgb);
|
---|
| 318 | WinSetPresParam(WinWindowFromID(hwnd, FID_TITLEBAR),
|
---|
| 319 | PP_INACTIVETEXTBGNDCOLOR,(ULONG)sizeof(rgb), &rgb);
|
---|
| 320 | }
|
---|
| 321 |
|
---|
| 322 | ulSize=sizeof(RGB);
|
---|
| 323 | if(IniRestoreData(chrIniFile, chrApp, INI_ACTIVETBFGCLR_KEY, &rgb, &ulSize))
|
---|
| 324 | {
|
---|
[104] | 325 |
|
---|
[2] | 326 | // WinSetPresParam(WinWindowFromID(hwnd, FID_TITLEBAR),
|
---|
| 327 | // PP_ACTIVECOLOR,(ULONG)sizeof(rgb), &rgb);
|
---|
| 328 | WinSetPresParam(WinWindowFromID(hwnd, FID_TITLEBAR),
|
---|
| 329 | PP_ACTIVETEXTFGNDCOLOR,(ULONG)sizeof(rgb), &rgb);
|
---|
| 330 | }
|
---|
| 331 | ulSize=sizeof(RGB);
|
---|
| 332 | if(IniRestoreData(chrIniFile, chrApp, INI_INACTIVETBFGCLR_KEY, &rgb, &ulSize))
|
---|
| 333 | {
|
---|
| 334 | // WinSetPresParam(WinWindowFromID(hwnd, FID_TITLEBAR),
|
---|
| 335 | // PP_INACTIVECOLOR,(ULONG)sizeof(rgb), &rgb);
|
---|
| 336 | WinSetPresParam(WinWindowFromID(hwnd, FID_TITLEBAR),
|
---|
| 337 | PP_INACTIVETEXTFGNDCOLOR,(ULONG)sizeof(rgb), &rgb);
|
---|
| 338 | }
|
---|
| 339 | return TRUE;
|
---|
| 340 | }
|
---|
| 341 |
|
---|
[104] | 342 | BOOL IniSaveInt(PSZ iniFile, PSZ chrApp, PSZ chrKey, int theInt)
|
---|
[2] | 343 | {
|
---|
| 344 | HINI hini=0;
|
---|
| 345 | BOOL bError=FALSE;
|
---|
[104] | 346 | UCHAR chrIntString[50];
|
---|
[2] | 347 |
|
---|
| 348 | /* Open ini-file */
|
---|
| 349 | hini=PrfOpenProfile(WinQueryAnchorBlock(HWND_DESKTOP),(unsigned char *)iniFile);
|
---|
| 350 | do{
|
---|
| 351 |
|
---|
| 352 | if(!hini) {
|
---|
| 353 | #if 0
|
---|
| 354 | /* profileName: "Warning! Cannot open Ini-file!"
|
---|
| 355 | moduleName: "Data-CD-Creator"
|
---|
| 356 | */
|
---|
| 357 | messageBox( profileName, IDSTR_INIFILEOPENWARNING , sizeof(profileName),
|
---|
| 358 | moduleName, IDSTRD_DATACDCREATOR, sizeof(moduleName),
|
---|
| 359 | RESSOURCEHANDLE, HWND_DESKTOP, MB_OK | MB_ICONEXCLAMATION|MB_MOVEABLE);
|
---|
| 360 | #endif
|
---|
| 361 | break;
|
---|
| 362 | }/* end of if(!hini) */
|
---|
| 363 |
|
---|
[104] | 364 | sprintf((PCHAR)chrIntString, "%d", theInt);
|
---|
[2] | 365 | if(!PrfWriteProfileString(hini, chrApp, chrKey, chrIntString))
|
---|
| 366 | bError=TRUE;
|
---|
| 367 |
|
---|
| 368 | if(hini)
|
---|
| 369 | PrfCloseProfile(hini);
|
---|
[104] | 370 |
|
---|
[2] | 371 | if(bError)
|
---|
| 372 | break;
|
---|
| 373 | return TRUE;
|
---|
| 374 | } while(TRUE);
|
---|
| 375 | return FALSE;
|
---|
| 376 | }
|
---|
| 377 |
|
---|
[104] | 378 | BOOL IniSaveData(PSZ iniFile, PSZ chrApp, PSZ chrKey, PVOID theData, ULONG ulSize)
|
---|
[2] | 379 | {
|
---|
| 380 | HINI hini=0;
|
---|
| 381 | BOOL bError=FALSE;
|
---|
| 382 |
|
---|
| 383 | /* Open ini-file */
|
---|
[104] | 384 | hini=PrfOpenProfile(WinQueryAnchorBlock(HWND_DESKTOP),iniFile);
|
---|
[2] | 385 | do{
|
---|
| 386 |
|
---|
| 387 | if(!hini) {
|
---|
| 388 | #if 0
|
---|
| 389 | /* profileName: "Warning! Cannot open Ini-file!"
|
---|
| 390 | moduleName: "Data-CD-Creator"
|
---|
| 391 | */
|
---|
| 392 | messageBox( profileName, IDSTR_INIFILEOPENWARNING , sizeof(profileName),
|
---|
| 393 | moduleName, IDSTRD_DATACDCREATOR, sizeof(moduleName),
|
---|
| 394 | RESSOURCEHANDLE, HWND_DESKTOP, MB_OK | MB_ICONEXCLAMATION|MB_MOVEABLE);
|
---|
| 395 | #endif
|
---|
| 396 | break;
|
---|
| 397 | }/* end of if(!hini) */
|
---|
| 398 |
|
---|
| 399 | if(!PrfWriteProfileData(hini, chrApp, chrKey, theData, ulSize))
|
---|
| 400 | bError=TRUE;
|
---|
| 401 |
|
---|
| 402 | if(hini)
|
---|
| 403 | PrfCloseProfile(hini);
|
---|
[104] | 404 |
|
---|
[2] | 405 | if(bError)
|
---|
| 406 | break;
|
---|
| 407 | return TRUE;
|
---|
| 408 | } while(TRUE);
|
---|
| 409 | return FALSE;
|
---|
| 410 | }
|
---|
| 411 |
|
---|
[104] | 412 | BOOL IniRestoreData(PSZ iniFile, PSZ chrApp, PSZ chrKey, PVOID theData, PULONG ulMaxSize)
|
---|
[2] | 413 | {
|
---|
| 414 | HINI hini=0;
|
---|
| 415 | BOOL bError=FALSE;
|
---|
| 416 |
|
---|
| 417 | /* Open ini-file */
|
---|
[104] | 418 | hini=PrfOpenProfile(WinQueryAnchorBlock(HWND_DESKTOP),iniFile);
|
---|
[2] | 419 | do{
|
---|
| 420 |
|
---|
| 421 | if(!hini) {
|
---|
| 422 | #if 0
|
---|
| 423 | /* profileName: "Warning! Cannot open Ini-file!"
|
---|
| 424 | moduleName: "Data-CD-Creator"
|
---|
| 425 | */
|
---|
| 426 | messageBox( profileName, IDSTR_INIFILEOPENWARNING , sizeof(profileName),
|
---|
| 427 | moduleName, IDSTRD_DATACDCREATOR, sizeof(moduleName),
|
---|
| 428 | RESSOURCEHANDLE, HWND_DESKTOP, MB_OK | MB_ICONEXCLAMATION|MB_MOVEABLE);
|
---|
| 429 | #endif
|
---|
| 430 | break;
|
---|
| 431 | }/* end of if(!hini) */
|
---|
| 432 |
|
---|
| 433 | bError=PrfQueryProfileData(hini, chrApp, chrKey, theData, ulMaxSize);
|
---|
[104] | 434 |
|
---|
[2] | 435 | if(hini)
|
---|
| 436 | PrfCloseProfile(hini);
|
---|
[104] | 437 |
|
---|
[2] | 438 | return bError;
|
---|
| 439 | } while(TRUE);
|
---|
| 440 | return FALSE;
|
---|
| 441 | }
|
---|
| 442 |
|
---|
| 443 |
|
---|
[104] | 444 | int IniRestoreInt(PSZ iniFile, PSZ chrApp, PSZ chrKey, int defaultInt)
|
---|
[2] | 445 | {
|
---|
| 446 | HINI hini=0;
|
---|
| 447 | int theInt;
|
---|
| 448 |
|
---|
| 449 | /* Open ini-file */
|
---|
[104] | 450 | hini=PrfOpenProfile(WinQueryAnchorBlock(HWND_DESKTOP),iniFile);
|
---|
[2] | 451 | do{
|
---|
| 452 |
|
---|
| 453 | if(!hini) {
|
---|
| 454 | #if 0
|
---|
| 455 | /* profileName: "Warning! Cannot open Ini-file!"
|
---|
| 456 | moduleName: "Data-CD-Creator"
|
---|
| 457 | */
|
---|
| 458 | messageBox( profileName, IDSTR_INIFILEOPENWARNING , sizeof(profileName),
|
---|
| 459 | moduleName, IDSTRD_DATACDCREATOR, sizeof(moduleName),
|
---|
| 460 | RESSOURCEHANDLE, HWND_DESKTOP, MB_OK | MB_ICONEXCLAMATION|MB_MOVEABLE);
|
---|
| 461 | #endif
|
---|
| 462 | break;
|
---|
| 463 | }/* end of if(!hini) */
|
---|
| 464 |
|
---|
| 465 | theInt=PrfQueryProfileInt(hini, chrApp, chrKey, defaultInt);
|
---|
[104] | 466 |
|
---|
[2] | 467 | if(hini)
|
---|
| 468 | PrfCloseProfile(hini);
|
---|
[104] | 469 |
|
---|
[2] | 470 | return theInt;
|
---|
| 471 | } while(TRUE);
|
---|
| 472 | return defaultInt;
|
---|
| 473 | }
|
---|
| 474 |
|
---|
| 475 |
|
---|
[104] | 476 | BOOL readIni2(PSZ installDir)
|
---|
[2] | 477 | {
|
---|
| 478 | #if 0
|
---|
| 479 | strncpy(chrInstallDir, installDir,sizeof(chrInstallDir));
|
---|
| 480 | /* Build full path for cdrecord.ini file */
|
---|
[104] | 481 | sprintf(profileName,"%s\\cdrecord.ini", installDir);
|
---|
[2] | 482 | /* Insert message in Logfile */
|
---|
| 483 | writeLog("Reading values from ");
|
---|
| 484 | writeLog(profileName);
|
---|
| 485 | writeLog("\n");
|
---|
| 486 |
|
---|
| 487 | /* Open ini-file */
|
---|
[104] | 488 | hini=PrfOpenProfile(WinQueryAnchorBlock(HWND_DESKTOP),profileName);
|
---|
[2] | 489 | do{
|
---|
| 490 | if(!hini) {
|
---|
| 491 | /* profileName: "Warning! Cannot open Ini-file!"
|
---|
| 492 | moduleName: "Data-CD-Creator"
|
---|
| 493 | */
|
---|
| 494 | messageBox( profileName, IDSTR_INIFILEOPENWARNING , sizeof(profileName),
|
---|
| 495 | moduleName, IDSTRD_DATACDCREATOR, sizeof(moduleName),
|
---|
| 496 | RESSOURCEHANDLE, HWND_DESKTOP, MB_OK | MB_ICONEXCLAMATION|MB_MOVEABLE);
|
---|
| 497 | break;
|
---|
| 498 | }/* end of if(!hini) */
|
---|
| 499 |
|
---|
| 500 | if(hini)
|
---|
| 501 | PrfCloseProfile(hini);
|
---|
| 502 |
|
---|
| 503 | if(bError)
|
---|
| 504 | break;
|
---|
| 505 | return TRUE;
|
---|
| 506 | } while(TRUE);
|
---|
| 507 | writeLog("Error while reading cdrecord.ini\n");
|
---|
| 508 | #endif
|
---|
| 509 | return FALSE;
|
---|
| 510 | }
|
---|
| 511 |
|
---|
| 512 | BOOL readIni()
|
---|
| 513 | {
|
---|
| 514 | return readIni2(params[1]);
|
---|
| 515 | }
|
---|
| 516 | #if 0
|
---|
| 517 | static void _HlpBuildProfileName(char* chrBuffer, int iBufferSize)
|
---|
| 518 | {
|
---|
| 519 | /* Build full path for cdrecord.ini file */
|
---|
[126] | 520 | sprintf(chrBuffer, /*iBufferSize,*/ "%s\\cdrecord.ini", chrInstallDir);
|
---|
[2] | 521 | chrBuffer[iBufferSize-1]=0; /* Always terminate with zero */
|
---|
| 522 | }
|
---|
| 523 |
|
---|
| 524 |
|
---|
| 525 | HINI HlpOpenIni()
|
---|
| 526 | {
|
---|
[104] | 527 | UCHAR profileName[CCHMAXPATH];
|
---|
[2] | 528 |
|
---|
| 529 | /* Build full path for cdrecord.ini file */
|
---|
| 530 | _HlpBuildProfileName(profileName, sizeof(profileName));
|
---|
| 531 |
|
---|
| 532 | /* Open ini-file */
|
---|
[104] | 533 | return PrfOpenProfile(WinQueryAnchorBlock(HWND_DESKTOP),profileName);
|
---|
[2] | 534 | }
|
---|
| 535 |
|
---|
| 536 | void HlpCloseIni(HINI hini)
|
---|
| 537 | {
|
---|
| 538 | if(hini)
|
---|
| 539 | PrfCloseProfile(hini);
|
---|
| 540 | }
|
---|
| 541 | #endif
|
---|
[4] | 542 | #if 0
|
---|
| 543 | if(SysQueryHomeDir(chrHomeDir, sizeof(chrHomeDir))) {
|
---|
| 544 | strcpy(chrPath, chrHomeDir);
|
---|
| 545 | strncat(chrPath, "\\WPSWIZZ.INI", size-strlen(chrPath)-1);/* Default is INI file in users home dir */
|
---|
| 546 | return;
|
---|
| 547 | }
|
---|
[2] | 548 |
|
---|
[4] | 549 | strcpy(chrPath, queryHelpPath());
|
---|
| 550 | if((ptrChar=strrchr(chrPath, '\\'))!=NULLHANDLE) {
|
---|
| 551 | *ptrChar=0;
|
---|
| 552 | if((ptrChar=strrchr(chrPath, '\\'))!=NULLHANDLE)
|
---|
| 553 | *ptrChar=0;
|
---|
| 554 | }
|
---|
| 555 | strncat(chrPath, "\\WPSWIZZ.INI", size-strlen(chrPath)-1);
|
---|
| 556 | chrPath[size-1]=0;
|
---|
| 557 | #endif
|
---|
| 558 |
|
---|
| 559 | /*
|
---|
| 560 | Query the path to the INI file used by the MM progs to store the private data.
|
---|
| 561 | If a home dir exists on the users system the INI file will be create there otherwise
|
---|
| 562 | in the directory where the calling EXE is located.
|
---|
| 563 | */
|
---|
[2] | 564 | BOOL HlpBuildMMProgIniFileName(char* chrProgname, char * chrBuffer, ULONG ulBufferSize)
|
---|
| 565 | {
|
---|
[104] | 566 | char * chrPtr;
|
---|
[2] | 567 |
|
---|
[4] | 568 | /* Default is INI file in users home dir */
|
---|
| 569 | if(SysQueryHomeDir(chrBuffer, ulBufferSize)) {
|
---|
| 570 | strlcat(chrBuffer, MMCLS_INI_FILE_NAME, ulBufferSize); /* MMCLS_INI_FILE_NAME = "\\CWMM.INI" */
|
---|
| 571 | return TRUE;
|
---|
| 572 | }
|
---|
| 573 |
|
---|
| 574 | /* No HOME dir for some reason */
|
---|
| 575 | strlcpy(chrBuffer, chrProgname, ulBufferSize);
|
---|
| 576 |
|
---|
[2] | 577 | if((chrPtr=strrchr(chrBuffer,'\\'))==NULLHANDLE)
|
---|
[4] | 578 | return FALSE; // This shouldn't happen!
|
---|
[2] | 579 |
|
---|
| 580 | *chrPtr=0;
|
---|
[4] | 581 | strlcat(chrBuffer, MMCLS_INI_FILE_NAME, ulBufferSize);
|
---|
[2] | 582 |
|
---|
| 583 | return TRUE;
|
---|
| 584 | }
|
---|
| 585 |
|
---|
| 586 |
|
---|
| 587 | #if 0
|
---|
| 588 | /* This function returns the module handle of our ressource dll */
|
---|
[104] | 589 | HMODULE queryResModuleHandle(PSZ chrExePath)
|
---|
[2] | 590 | {
|
---|
| 591 | COUNTRYCODE country= {0};
|
---|
| 592 | COUNTRYINFO countryInfo= {0};
|
---|
[104] | 593 | UCHAR path[CCHMAXPATH];
|
---|
| 594 | UCHAR buf[CCHMAXPATH];
|
---|
| 595 | PUCHAR found;
|
---|
[2] | 596 | APIRET rc;
|
---|
| 597 | ULONG ulInfoLen;
|
---|
[104] | 598 |
|
---|
[2] | 599 | if(!RESSOURCEHANDLE) {
|
---|
| 600 |
|
---|
| 601 | //writeLog("Trying to load ressource DLL.\n");
|
---|
| 602 |
|
---|
[104] | 603 | /* Get the country code of our system and load the
|
---|
[2] | 604 | resource DLL with the right language */
|
---|
| 605 | do {
|
---|
| 606 | rc=DosQueryCtryInfo(sizeof(countryInfo),&country,&countryInfo,&ulInfoLen);
|
---|
| 607 | if(rc!=NO_ERROR) {
|
---|
| 608 | /* Insert message in Logfile */
|
---|
| 609 | // writeLog(__FUNCTION__);
|
---|
| 610 | //writeLog(": Can't get country info. Ressource-DLL will not be loaded.\n");
|
---|
| 611 | break;
|
---|
| 612 | }
|
---|
| 613 | sprintf(path,"%s", chrExePath);
|
---|
| 614 | if((found=strrchr(path, '\\'))!=NULLHANDLE)
|
---|
| 615 | *found=0;
|
---|
| 616 |
|
---|
| 617 | sprintf(buf, RESDLLNAME ,countryInfo.country);
|
---|
| 618 | strcat(path,buf);
|
---|
| 619 | /* Insert message in Logfile */
|
---|
| 620 | //HlpWriteToTrapLog("Using the following DLL path: ");
|
---|
| 621 | //HlpWriteToTrapLog(path);
|
---|
| 622 | //HlpWriteToTrapLog("\n");
|
---|
| 623 |
|
---|
| 624 | rc=DosLoadModule(buf,sizeof(buf),path, &RESSOURCEHANDLE);
|
---|
| 625 | if(rc==NO_ERROR)
|
---|
| 626 | break;
|
---|
| 627 |
|
---|
| 628 | /* Insert message in Logfile */
|
---|
| 629 | // writeLog("Ressource-DLL for the current countrycode not found. Trying to load default one (CDFLD001.DLL).\n");
|
---|
[104] | 630 |
|
---|
[2] | 631 | /* NLS DLL not found. Try to load default */
|
---|
| 632 | found=strrchr(path,'\\');
|
---|
| 633 | if(!found)
|
---|
| 634 | break;
|
---|
| 635 |
|
---|
| 636 | *found=0;
|
---|
| 637 | sprintf(buf, DEFRESDLLNAME);
|
---|
| 638 | strcat(path,buf);
|
---|
| 639 | //HlpWriteToTrapLog("Using the following DLL path: ");
|
---|
| 640 | //HlpWriteToTrapLog(path);
|
---|
| 641 | //HlpWriteToTrapLog("\n");
|
---|
| 642 |
|
---|
[104] | 643 |
|
---|
[2] | 644 | rc=DosLoadModule(buf,sizeof(buf),path, &RESSOURCEHANDLE);
|
---|
| 645 | if(rc!=NO_ERROR) {
|
---|
| 646 | // writeLog("Can't load DLL!\n");
|
---|
| 647 | RESSOURCEHANDLE=NULLHANDLE;
|
---|
| 648 | }
|
---|
| 649 | else {
|
---|
| 650 | //writeLog("Ressource DLL loaded.\n");
|
---|
| 651 | }
|
---|
| 652 | break;
|
---|
| 653 | }while(TRUE);
|
---|
| 654 | }
|
---|
| 655 | return RESSOURCEHANDLE;
|
---|
| 656 | }
|
---|
| 657 | #endif
|
---|
| 658 |
|
---|
| 659 | /* This function returns the module handle of our ressource dll */
|
---|
[104] | 660 | HMODULE queryResModuleHandle(PSZ chrExePath)
|
---|
[2] | 661 | {
|
---|
[104] | 662 | UCHAR path[CCHMAXPATH];
|
---|
| 663 | UCHAR buf[CCHMAXPATH];
|
---|
| 664 | PCHAR found;
|
---|
[2] | 665 | APIRET rc;
|
---|
[104] | 666 |
|
---|
[2] | 667 | if(!RESSOURCEHANDLE) {
|
---|
[104] | 668 |
|
---|
[2] | 669 | //writeLog("Trying to load ressource DLL.\n");
|
---|
[104] | 670 |
|
---|
| 671 | /* Get the language code of our system and load the
|
---|
[2] | 672 | resource DLL with the right language */
|
---|
[104] | 673 | do
|
---|
[2] | 674 | {
|
---|
[104] | 675 | static UCHAR chrLang[]="en_EN";
|
---|
| 676 | PSZ pszLang=NULL;
|
---|
| 677 | PUCHAR chrPtr;
|
---|
| 678 |
|
---|
[2] | 679 | /* Get Language var */
|
---|
[104] | 680 | if(NO_ERROR!=DosScanEnv((PSZ)"LANG", &pszLang)) {
|
---|
[2] | 681 | pszLang=chrLang;
|
---|
[104] | 682 | }
|
---|
[2] | 683 | /* Skip leading spaces */
|
---|
| 684 | chrPtr=pszLang;
|
---|
| 685 | while(*chrPtr==' ')
|
---|
| 686 | chrPtr++;
|
---|
[104] | 687 |
|
---|
[2] | 688 | /* Check if value seems to be valid. The var must be something like xx_XX thus length is 5 */
|
---|
[104] | 689 | if(strlen((PCHAR)chrPtr)<5)
|
---|
[2] | 690 | break;
|
---|
[104] | 691 |
|
---|
| 692 | sprintf((PCHAR)path,"%s", chrExePath);
|
---|
[2] | 693 | // SysWriteToTrapLog(path);
|
---|
[104] | 694 | if((found=strrchr((PCHAR)path, '\\'))!=NULLHANDLE)
|
---|
[2] | 695 | *found=0;
|
---|
| 696 |
|
---|
[104] | 697 | /* Extract the first two chars */
|
---|
| 698 | sprintf((PCHAR)buf, RESDLLNAME, chrPtr[0], chrPtr[1]);
|
---|
| 699 | strcat((PCHAR)path,(const PCHAR)buf);
|
---|
[2] | 700 | /* Insert message in Logfile */
|
---|
| 701 | // SysWriteToTrapLog("Using the following DLL path: %s\n", path);
|
---|
[104] | 702 |
|
---|
[2] | 703 | rc=DosLoadModule(buf,sizeof(buf),path, &RESSOURCEHANDLE);
|
---|
| 704 | if(rc==NO_ERROR)
|
---|
| 705 | break;
|
---|
[104] | 706 |
|
---|
[2] | 707 | /* Insert message in Logfile */
|
---|
| 708 | SysWriteToTrapLog("Ressource-DLL for the current country not found. Trying to load default one.\n");
|
---|
[104] | 709 |
|
---|
[2] | 710 | /* NLS DLL not found. Try to load default */
|
---|
[104] | 711 | found=strrchr((PCHAR)path,(int)'\\');
|
---|
[2] | 712 | if(!found)
|
---|
| 713 | break;
|
---|
[104] | 714 |
|
---|
[2] | 715 | *found=0;
|
---|
[104] | 716 | sprintf((PCHAR)buf, DEFRESDLLNAME);
|
---|
| 717 | strcat((PCHAR)path,(const PCHAR)buf);
|
---|
[2] | 718 | //HlpWriteToTrapLog("Using the following DLL path: ");
|
---|
| 719 | //HlpWriteToTrapLog(path);
|
---|
| 720 | //HlpWriteToTrapLog("\n");
|
---|
[104] | 721 |
|
---|
| 722 |
|
---|
[2] | 723 | rc=DosLoadModule(buf,sizeof(buf),path, &RESSOURCEHANDLE);
|
---|
| 724 | if(rc!=NO_ERROR) {
|
---|
| 725 | // writeLog("Can't load DLL!\n");
|
---|
| 726 | RESSOURCEHANDLE=NULLHANDLE;
|
---|
| 727 | }
|
---|
| 728 | else {
|
---|
| 729 | //writeLog("Ressource DLL loaded.\n");
|
---|
| 730 | }
|
---|
| 731 | break;
|
---|
| 732 | }while(TRUE);
|
---|
| 733 | }
|
---|
| 734 | return RESSOURCEHANDLE;
|
---|
| 735 | }
|
---|
| 736 |
|
---|
[144] | 737 | void freeResHandle(void)
|
---|
[2] | 738 | {
|
---|
| 739 | if(RESSOURCEHANDLE)
|
---|
| 740 | DosFreeModule(RESSOURCEHANDLE);
|
---|
| 741 | }
|
---|
| 742 |
|
---|
[104] | 743 | void HlpSendCommandToObject(PSZ chrObject, PSZ command)
|
---|
[2] | 744 | {
|
---|
| 745 | HOBJECT hObject;
|
---|
[104] | 746 | UCHAR chrCommand[CCHMAXPATH];
|
---|
[2] | 747 |
|
---|
| 748 | hObject=WinQueryObject(chrObject);
|
---|
[104] | 749 | sprintf((PCHAR)chrCommand,"Querying object pointer for: %s\n", chrObject);
|
---|
[2] | 750 | writeLog(chrCommand);
|
---|
| 751 | if(hObject!=NULLHANDLE) {
|
---|
[104] | 752 | strcpy((PCHAR)chrCommand,(const PCHAR)command);
|
---|
[2] | 753 | WinSetObjectData(hObject,chrCommand);
|
---|
[104] | 754 | writeLog((PSZ)"Sending command to object: ");
|
---|
[2] | 755 | writeLog(command);
|
---|
[104] | 756 | writeLog((PSZ)"\n");
|
---|
[2] | 757 | }
|
---|
| 758 | else {
|
---|
[104] | 759 | sprintf((PCHAR)chrCommand,"Can't query object pointer for: %s\n", chrObject);
|
---|
[2] | 760 | writeLog(chrCommand);
|
---|
| 761 | }
|
---|
| 762 | }
|
---|
| 763 |
|
---|