source: trunk/common_functions/helper.c@ 4

Last change on this file since 4 was 4, checked in by stevenhl, 8 years ago

Import modifications from cwmm-0_2_9-work-01_10_2006.zip dated 2006-08-27

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