source: branches/v2.9_Lars/common_functions/helper.c

Last change on this file was 130, checked in by erdmann, 21 months ago

merge from trunk CS 129

File size: 22.0 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 (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"
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 PSZ params[];
59extern HMODULE RESSOURCEHANDLE;
60extern char logName[];
61
62char chrInstallDir[CCHMAXPATH];
63
64SWP swpWindow;
65
66HMODULE _queryResModuleHandle2(char *installDir);
67BOOL IniSaveData(PSZ iniFile, PSZ chrApp, PSZ chrKey, PVOID theData, ULONG ulSize);
68BOOL IniRestoreData(PSZ iniFile, PSZ chrApp, PSZ chrKey, PVOID theData, PULONG ulMaxSize);
69void writeLog(PSZ 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(PSZ 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(sprintf(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 PID pid;
120 ULONG ulSessionID=0;
121 UCHAR chrLoadError[CCHMAXPATH];
122 UCHAR startParams[CCHMAXPATH*4];
123 UCHAR exename[CCHMAXPATH]={0};
124 UCHAR chrFolderPath[CCHMAXPATH+10];
125
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;
132
133 /* sprintf(exename,"%s",buildWrapName(wrapperExe));*/
134 sprintf((PCHAR)exename,"%s\\bin\\%s",params[1],wrapperExe);
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 */
152 strcpy((PCHAR)chrFolderPath,(PCHAR)folderPath);
153 sprintf((PCHAR)startParams,"\"%s\" \"%s\" %s",
154 (PCHAR)chrInstallDir,(PCHAR)chrFolderPath, (PCHAR)parameter);
155 startData.PgmInputs=startParams;
156
157 DosStartSession(&startData,&ulSessionID,&pid);
158 return 0;
159}
160
161
162BOOL IniRestoreWindowPos(char * iniFile, PSZ chrApp, PSZ chrKey, HWND hwnd)
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
184 ulSize=sizeof(swp);
185 if(!PrfQueryProfileData(hini, chrApp, chrKey, &swp, &ulSize))
186 bError=TRUE;
187
188 if(hini)
189 PrfCloseProfile(hini);
190
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
200BOOL IniSaveWindowPos(PSZ iniFile, PSZ chrApp, PSZ chrKey, HWND hwnd)
201{
202 HINI hini=0;
203 BOOL bError=FALSE;
204 SWP swp;
205
206 /* Open ini-file */
207 hini=PrfOpenProfile(WinQueryAnchorBlock(HWND_DESKTOP),iniFile);
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);
228
229 if(bError)
230 break;
231 return TRUE;
232 } while(TRUE);
233 return FALSE;
234}
235
236BOOL IniSaveWindowClrs(PSZ chrIniFile, PSZ chrApp , HWND hwnd)
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
284BOOL IniRestoreWindowClrs(PSZ chrIniFile, PSZ chrApp , HWND hwnd)
285{
286 RGB rgb;
287 ULONG ulSize;
288
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 }
296 ulSize=sizeof(RGB);
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 {
307
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 {
325
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
342BOOL IniSaveInt(PSZ iniFile, PSZ chrApp, PSZ chrKey, int theInt)
343{
344 HINI hini=0;
345 BOOL bError=FALSE;
346 UCHAR chrIntString[50];
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
364 sprintf((PCHAR)chrIntString, "%d", theInt);
365 if(!PrfWriteProfileString(hini, chrApp, chrKey, chrIntString))
366 bError=TRUE;
367
368 if(hini)
369 PrfCloseProfile(hini);
370
371 if(bError)
372 break;
373 return TRUE;
374 } while(TRUE);
375 return FALSE;
376}
377
378BOOL IniSaveData(PSZ iniFile, PSZ chrApp, PSZ chrKey, PVOID theData, ULONG ulSize)
379{
380 HINI hini=0;
381 BOOL bError=FALSE;
382
383 /* Open ini-file */
384 hini=PrfOpenProfile(WinQueryAnchorBlock(HWND_DESKTOP),iniFile);
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);
404
405 if(bError)
406 break;
407 return TRUE;
408 } while(TRUE);
409 return FALSE;
410}
411
412BOOL IniRestoreData(PSZ iniFile, PSZ chrApp, PSZ chrKey, PVOID theData, PULONG ulMaxSize)
413{
414 HINI hini=0;
415 BOOL bError=FALSE;
416
417 /* Open ini-file */
418 hini=PrfOpenProfile(WinQueryAnchorBlock(HWND_DESKTOP),iniFile);
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);
434
435 if(hini)
436 PrfCloseProfile(hini);
437
438 return bError;
439 } while(TRUE);
440 return FALSE;
441}
442
443
444int IniRestoreInt(PSZ iniFile, PSZ chrApp, PSZ chrKey, int defaultInt)
445{
446 HINI hini=0;
447 int theInt;
448
449 /* Open ini-file */
450 hini=PrfOpenProfile(WinQueryAnchorBlock(HWND_DESKTOP),iniFile);
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);
466
467 if(hini)
468 PrfCloseProfile(hini);
469
470 return theInt;
471 } while(TRUE);
472 return defaultInt;
473}
474
475
476BOOL readIni2(PSZ installDir)
477{
478#if 0
479 strncpy(chrInstallDir, installDir,sizeof(chrInstallDir));
480 /* Build full path for cdrecord.ini file */
481 sprintf(profileName,"%s\\cdrecord.ini", installDir);
482 /* Insert message in Logfile */
483 writeLog("Reading values from ");
484 writeLog(profileName);
485 writeLog("\n");
486
487 /* Open ini-file */
488 hini=PrfOpenProfile(WinQueryAnchorBlock(HWND_DESKTOP),profileName);
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
512BOOL readIni()
513{
514 return readIni2(params[1]);
515}
516#if 0
517static void _HlpBuildProfileName(char* chrBuffer, int iBufferSize)
518{
519 /* Build full path for cdrecord.ini file */
520 sprintf(chrBuffer, /*iBufferSize,*/ "%s\\cdrecord.ini", chrInstallDir);
521 chrBuffer[iBufferSize-1]=0; /* Always terminate with zero */
522}
523
524
525HINI HlpOpenIni()
526{
527 UCHAR profileName[CCHMAXPATH];
528
529 /* Build full path for cdrecord.ini file */
530 _HlpBuildProfileName(profileName, sizeof(profileName));
531
532 /* Open ini-file */
533 return PrfOpenProfile(WinQueryAnchorBlock(HWND_DESKTOP),profileName);
534}
535
536void HlpCloseIni(HINI hini)
537{
538 if(hini)
539 PrfCloseProfile(hini);
540}
541#endif
542#if 0
543if(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 }
548
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 */
564BOOL HlpBuildMMProgIniFileName(char* chrProgname, char * chrBuffer, ULONG ulBufferSize)
565{
566 char * chrPtr;
567
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
577 if((chrPtr=strrchr(chrBuffer,'\\'))==NULLHANDLE)
578 return FALSE; // This shouldn't happen!
579
580 *chrPtr=0;
581 strlcat(chrBuffer, MMCLS_INI_FILE_NAME, ulBufferSize);
582
583 return TRUE;
584}
585
586
587#if 0
588/* This function returns the module handle of our ressource dll */
589HMODULE queryResModuleHandle(PSZ chrExePath)
590{
591 COUNTRYCODE country= {0};
592 COUNTRYINFO countryInfo= {0};
593 UCHAR path[CCHMAXPATH];
594 UCHAR buf[CCHMAXPATH];
595 PUCHAR found;
596 APIRET rc;
597 ULONG ulInfoLen;
598
599 if(!RESSOURCEHANDLE) {
600
601 //writeLog("Trying to load ressource DLL.\n");
602
603 /* Get the country code of our system and load the
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");
630
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
643
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 */
660HMODULE queryResModuleHandle(PSZ chrExePath)
661{
662 UCHAR path[CCHMAXPATH];
663 UCHAR buf[CCHMAXPATH];
664 PCHAR found;
665 APIRET rc;
666
667 if(!RESSOURCEHANDLE) {
668
669 //writeLog("Trying to load ressource DLL.\n");
670
671 /* Get the language code of our system and load the
672 resource DLL with the right language */
673 do
674 {
675 static UCHAR chrLang[]="en_EN";
676 PSZ pszLang=NULL;
677 PUCHAR chrPtr;
678
679 /* Get Language var */
680 if(NO_ERROR!=DosScanEnv((PSZ)"LANG", &pszLang)) {
681 pszLang=chrLang;
682 }
683 /* Skip leading spaces */
684 chrPtr=pszLang;
685 while(*chrPtr==' ')
686 chrPtr++;
687
688 /* Check if value seems to be valid. The var must be something like xx_XX thus length is 5 */
689 if(strlen((PCHAR)chrPtr)<5)
690 break;
691
692 sprintf((PCHAR)path,"%s", chrExePath);
693 // SysWriteToTrapLog(path);
694 if((found=strrchr((PCHAR)path, '\\'))!=NULLHANDLE)
695 *found=0;
696
697 /* Extract the first two chars */
698 sprintf((PCHAR)buf, RESDLLNAME, chrPtr[0], chrPtr[1]);
699 strcat((PCHAR)path,(const PCHAR)buf);
700 /* Insert message in Logfile */
701 // SysWriteToTrapLog("Using the following DLL path: %s\n", path);
702
703 rc=DosLoadModule(buf,sizeof(buf),path, &RESSOURCEHANDLE);
704 if(rc==NO_ERROR)
705 break;
706
707 /* Insert message in Logfile */
708 SysWriteToTrapLog("Ressource-DLL for the current country not found. Trying to load default one.\n");
709
710 /* NLS DLL not found. Try to load default */
711 found=strrchr((PCHAR)path,(int)'\\');
712 if(!found)
713 break;
714
715 *found=0;
716 sprintf((PCHAR)buf, DEFRESDLLNAME);
717 strcat((PCHAR)path,(const PCHAR)buf);
718 //HlpWriteToTrapLog("Using the following DLL path: ");
719 //HlpWriteToTrapLog(path);
720 //HlpWriteToTrapLog("\n");
721
722
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
737void freeResHandle()
738{
739 if(RESSOURCEHANDLE)
740 DosFreeModule(RESSOURCEHANDLE);
741}
742
743void HlpSendCommandToObject(PSZ chrObject, PSZ command)
744{
745 HOBJECT hObject;
746 UCHAR chrCommand[CCHMAXPATH];
747
748 hObject=WinQueryObject(chrObject);
749 sprintf((PCHAR)chrCommand,"Querying object pointer for: %s\n", chrObject);
750 writeLog(chrCommand);
751 if(hObject!=NULLHANDLE) {
752 strcpy((PCHAR)chrCommand,(const PCHAR)command);
753 WinSetObjectData(hObject,chrCommand);
754 writeLog((PSZ)"Sending command to object: ");
755 writeLog(command);
756 writeLog((PSZ)"\n");
757 }
758 else {
759 sprintf((PCHAR)chrCommand,"Can't query object pointer for: %s\n", chrObject);
760 writeLog(chrCommand);
761 }
762}
763
Note: See TracBrowser for help on using the repository browser.