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