source: trunk/mediafolder/c/cddb/pmcddb.cpp@ 142

Last change on this file since 142 was 142, checked in by gyoung, 19 months ago

Fix warnings and error found by C++Check

  • Property svn:eol-style set to native
File size: 20.5 KB
Line 
1/*
2 * pmcddb.cc (C) Chris Wohlgemuth 1999-2002
3 *
4 * This helper queries the CDDB database
5 */
6/*
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
10 * any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; see the file COPYING. If not, write to
19 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21#define INCL_DOS
22#define INCL_DOSFILEMGR
23#define INCL_DOSERRORS
24#define INCL_WIN
25
26#include <os2.h>
27#include <types.h>
28#include <sys\stat.h>
29#include <stdio.h>
30#include <stdlib.h>
31#include <string.h>
32#include <io.h>
33#include <string.h>
34#include "pmcddb.h"
35#include "pmcddbres.h"
36
37#include "cddb.h"
38#include "cddb.hh"
39
40#define CDDB_OK 0
41#define CDDB_MORE 1
42#define CDDB_ERROR -1
43
44/**********************************************************/
45/* CDDB Stuff */
46
47extern int readResponse(int s, char * buffer,int size);
48/* Returns the cddb code. */
49extern int get_cddb_code( char * chrResponse);
50/* Check error codes coming from the server*/
51extern int check_cddb_code(char * chrResponse);
52/* Performing the handshake procedure with the CDDB server */
53/* s: socket handle */
54extern int cddb_handshaking(int s);
55/* s: socket handle */
56extern int cddb_setting_proto(int s);
57/* This is called if the CDDB database has got several matches for our
58 discid. We take all matches and decide later, which to use. */
59extern cddb * query_get_all_matches(int s);
60/* Query some data */
61/* With the data given we later query the
62 tracknames */
63extern cddb * cddb_query(int s, CDDBINFO *cddbInfo);
64/* Reads the CDDB banner from the server after connecting */
65/* We don't really need it so it is only shown on stderr */
66extern int cddb_banner(int s);
67/* Ask for the information about our CD. Parse it and
68 save it in the data file. */
69extern int read_and_parse(int s,cddb * Cddb);
70extern int cddb_read(int s,cddb * Cddb);
71extern int cddbConnectToHost(int * skt);
72
73extern "C" LONG CDDBDiscID(char * drive,CDDBINFO *cddbInfo);
74void extern printError(char* errorString);
75void extern printErrorCR(char* errorString);
76void extern printData(char* outString);
77
78extern "C" void removeLog(void);
79extern "C" void writeLog(char* logText);
80extern "C" ULONG messageBox( char* text, ULONG ulTextID , LONG lSizeText,
81 char* title, ULONG ulTitleID, LONG lSizeTitle,
82 HMODULE hResource, HWND hwnd, ULONG ulFlags);
83extern "C" void getMessage(char* text,ULONG ulID, LONG lSizeText, HMODULE hResource,HWND hwnd);
84extern "C" HMODULE queryResModuleHandle2(char *installDir, char * chrBaseName);
85extern "C" void freeResHandle();
86extern void pmUsage();
87extern "C" void HlpSendCommandToObject(char* chrObject, char* command);
88extern "C" ULONG cwQueryOSRelease(void);
89void HlpSendCommandToObject(char* chrObject, char* command);
90
91MRESULT EXPENTRY cddbDialogProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2) ;
92
93//#define DEBUG
94
95char chrCDDBDir[CCHMAXPATH];
96char chrInstallDir[CCHMAXPATH];
97char chrBinDir[CCHMAXPATH];
98char chrCDDrive[3]="N:";
99char *chrRexxFile="";
100char *chrFolder="";
101
102int numArgs;
103char* params[4]={"","","",""};
104
105HMODULE RESSOURCEHANDLE=0;
106
107char logName[CCHMAXPATH]=PMCDDB_LOGFILENAME;
108char logNameFullPath[CCHMAXPATH];
109
110#define QUERYCDDB_VERSION "0.1"
111
112int port=8880;
113char host[1000]="gnudb.gnudb.org";
114char username[1000]={0};
115char hostname[1000]={0};
116char clientname[100]="Audio-CD-Creator";
117char version[100];
118int s; /* Socket */
119#define MAXSERVERS 10
120char cddbServer[MAXSERVERS][100];
121int NUMSERVERS= 3;
122
123cddb * Cddb;
124char cddbDataFile[CCHMAXPATH]="";
125
126HWND hwndError;
127HWND hwndDialog;
128HWND hwndNotify;
129
130ULONG launchRexx( char* pszTitle, char* rexxFile, char* parameters)
131{
132 STARTDATA startData={0};
133 APIRET rc;
134 PID pid;
135 ULONG ulSessionID=0;
136 char chrLoadError[CCHMAXPATH];
137 char startParams[CCHMAXPATH*4];
138 char tempText[CCHMAXPATH]= {0};
139 char *charPtr;
140 char trackname[CCHMAXPATH];
141
142 memset(&startData,0,sizeof(startData));
143 startData.Length=sizeof(startData);
144 startData.Related=SSF_RELATED_INDEPENDENT;
145 startData.FgBg=SSF_FGBG_BACK;
146 startData.TraceOpt=SSF_TRACEOPT_NONE;
147 startData.PgmTitle=(char*)pszTitle;
148
149 startData.PgmName=(char*)"cmd.exe";
150 startData.InheritOpt=SSF_INHERTOPT_SHELL;
151 startData.SessionType=SSF_TYPE_WINDOWABLEVIO;
152 startData.PgmControl|=SSF_CONTROL_INVISIBLE;//|SSF_CONTROL_MAXIMIZE|SSF_CONTROL_NOAUTOCLOSE;
153 startData.InitXPos=30;
154 startData.InitYPos=30;
155 startData.InitXSize=500;
156 startData.InitYSize=400;
157 startData.ObjectBuffer=(char*)chrLoadError;
158 startData.ObjectBuffLen=(ULONG)sizeof(chrLoadError);
159
160 sprintf(startParams," /C \" \"%s\" %s \"", rexxFile, parameters);
161 startData.PgmInputs=(CHAR*)startParams;
162
163 writeLog("Trying to start ");
164 writeLog(rexxFile);
165 writeLog("\n");
166 rc=DosStartSession(&startData,&ulSessionID,&pid);
167 return rc;
168}
169
170BOOL readCDDBIni()
171{
172 ULONG keyLength;
173 char profileName[CCHMAXPATH];
174 char moduleName[CCHMAXPATH];
175 char *chrPtr;
176 char *chrPtr2;
177 HINI hini=0;
178 char text[200];
179 ULONG ulSize;
180 int a;
181 char chrCD[4];
182 BOOL bError=FALSE;
183 HWND hwnd;
184
185 hwnd=HWND_DESKTOP;
186
187 /* Insert message in Logfile */
188 writeLog("Reading values from cddb.ini\n");
189
190 /* Build full path for cddb.ini file */
191 sprintf(profileName,"%s\\cddb.ini", chrInstallDir);
192 /* Open ini-file */
193 hini=PrfOpenProfile(WinQueryAnchorBlock(HWND_DESKTOP),(char *)profileName);
194 do{
195 if(!hini) {
196 writeLog("Can't open INI file.\n");
197 /* profileName: "Warning! Cannot open Ini-file!"
198 moduleName: "Data-CD-Creator"
199 */
200 messageBox( profileName, IDSTR_INIFILEOPENWARNING , sizeof(profileName),
201 moduleName, IDSTR_PMCDDBTITLE, sizeof(moduleName),
202 RESSOURCEHANDLE, HWND_DESKTOP, MB_OK | MB_ICONEXCLAMATION|MB_MOVEABLE);
203 break;
204 }/* end of if(!hini) */
205
206 NUMSERVERS=PrfQueryProfileInt(hini,(char*)"cddb",(char*)"numservers",0);
207 PrfQueryProfileString(hini,(char*)"cddb",(char*)"cddbuser",(char*) "guest",username,sizeof(username));
208 PrfQueryProfileString(hini,(char*)"cddb",(char*)"cddbuserhost",(char*) "",hostname,sizeof(hostname));
209
210 strncpy(version,QUERYCDDB_VERSION,sizeof(version));
211
212 if(NUMSERVERS==0) {
213 strncpy(cddbServer[0],"gnudb.gnudb.org:8880",sizeof(cddbServer[0]));
214 NUMSERVERS=1;
215 }
216 else {
217 if(NUMSERVERS>MAXSERVERS)
218 NUMSERVERS=MAXSERVERS;
219 /* Read the servers from ini */
220 for(a=0;a<NUMSERVERS;a++) {
221 sprintf(text,"cddbserver%d",a+1);
222 PrfQueryProfileString(hini,(CHAR*)"cddb",(CHAR*)text,(CHAR*)"",cddbServer[a],sizeof(cddbServer[0]));
223 }
224 }
225 if(hini)
226 PrfCloseProfile(hini);
227
228 if(strlen(username)==0)
229 break;
230 if(strlen(hostname)==0)
231 break;
232
233 return TRUE;
234 }while(TRUE);
235 writeLog("\nError while reading values from cddb.ini.\n");
236 writeLog("Make sure your username and your host are set.\n");
237
238 messageBox( profileName, IDSTR_SETUPERROR , sizeof(profileName),
239 moduleName, IDSTR_PMCDDBTITLE, sizeof(moduleName),
240 RESSOURCEHANDLE, HWND_DESKTOP, MB_OK | MB_ICONEXCLAMATION|MB_MOVEABLE);
241
242 HlpSendCommandToObject("<CWFREEDB_CLIENT_CONFIG>", "OPEN=DEFAULT;");
243
244 return FALSE;
245}
246
247void printCddbList(cddb * Cddb)
248{
249 cddb * tmpCddb;
250 char text[400];
251 int iNum;
252
253 tmpCddb=Cddb;
254 iNum=0;
255
256 printError("\n-------------------\n");
257 printError("CDDB database returned the following match(es):\n");
258
259 while (tmpCddb) {/* Print data of every match */
260 /* Print our data */
261 iNum++;
262 /* Print it to log */
263 sprintf(text,"%d: Title: %s Artist: %s"
264 ,iNum,tmpCddb->title,tmpCddb->artist);
265 printError(text);
266 printError("\n");
267 /* Insert into Listbox */
268 WinSendMsg(WinWindowFromID(hwndDialog, IDLB_CDDBCHOOSE), LM_INSERTITEM,MPFROMSHORT(LIT_END),text);
269 tmpCddb=tmpCddb->getNextCddb();
270 }/* while */
271 /* Preselect the first item */
272 WinSendMsg(WinWindowFromID(hwndDialog, IDLB_CDDBCHOOSE), LM_SELECTITEM,MPFROMSHORT(LIT_FIRST),MPFROMSHORT(TRUE));
273
274 printError("-------------------\n");
275
276}
277
278/* Return the chosen cddb data set from the list of cddb data sets */
279cddb* choseCddb(cddb* Cddb, SHORT a)
280{
281 int iNum;
282 cddb * tmpCddb;
283 char buffer[10]={0};
284 char * rc;
285
286 iNum=0;
287 tmpCddb=Cddb;
288 /* Count the matches */
289 while (tmpCddb) {
290 iNum++;
291 tmpCddb=tmpCddb->getNextCddb();
292 }/* while */
293
294
295 iNum=1;
296 tmpCddb=Cddb;
297 /* Get the cddb */
298 while (iNum!=a) {
299 iNum++;
300 tmpCddb=tmpCddb->getNextCddb();
301 }/* while */
302
303 return tmpCddb;
304}
305
306int queryServer()
307{
308 CDDBINFO cddbInfo;
309 char text[100];
310 SHORT a;
311 int b;
312 char *chrPtr;
313 struct stat statBuf;
314
315 Cddb=NULL;
316
317 /* Get track data for CDDB query.
318 This function calculates the diskID and the
319 length of the tracks of the inserted CD.
320 We use the data to perform the database query. */
321
322 if(!CDDBDiscID(chrCDDrive, &cddbInfo)) {
323 printError("Cannot query track data for calculating diskID.\nMake sure an audio CD is inserted." );
324 writeLog("Cannot query track data for calculating diskID.\nMake sure an audio CD is inserted.\n");
325 /* WinPostMsg(hwndNotify,WM_APPTERMINATENOTIFY,MPFROMLONG(ACKEY_CDDBQUERY),MPFROMLONG(0)); */
326 return -1;
327 }
328
329 /* Tell the caller, that we start a CDDB query. The caller may go on in the meantime */
330 /*WinPostMsg(hwndNotify, WM_APPTERMINATENOTIFY,MPFROMLONG(ACKEY_CDDBQUERY),MPFROMLONG(0));*/
331 sprintf(text,"%08x",cddbInfo.discid);
332 strcat(cddbDataFile,text);/* Build the name of the cddb data file */
333 writeLog("CDDB datafile name is: ");
334 writeLog(cddbDataFile);
335 writeLog("\n");
336 if(stat(cddbDataFile , &statBuf)!=-1) {
337 writeLog("Found CDDB data in cache directory. DB query finished.\n");
338 /* WinPostMsg(hwndNotify,WM_APPTERMINATENOTIFY,MPFROMLONG(ACKEY_CDDBQUERY),MPFROMLONG(1)); */
339 return 0;/* We have already a cddb data file from a previous query, so we are ready. */
340 }
341
342 for(b=0;b<NUMSERVERS;b++) {/* Query the whole list of servers if necessary */
343 strncpy(host,cddbServer[b],sizeof(host) - 1);
344 chrPtr=strrchr(host,':');
345 if(chrPtr) {
346 *chrPtr=0;
347 chrPtr++;
348 port=atoi(chrPtr);
349 }
350 /* Report what we're doing */
351 sprintf(text,"SETSTATUSTEXT=Trying %s:%d...",host,port);
352 /* Set statusline of folder */
353 HlpSendCommandToObject(chrFolder, text);
354 sprintf(text,"\nTrying %s:%d...",host,port);
355 printErrorCR(text);
356
357 /* Connect to cddb-host */
358 if(!cddbConnectToHost(&s)) {
359 /* Query the database */
360 do {
361 /* Getting CDDB banner */
362 if(cddb_banner(s))
363 break; /* Error */
364
365 /* Setting protocol level */
366 if(cddb_setting_proto(s))
367 break;
368
369 /* Handshaking */
370 if(cddb_handshaking(s))
371 break;
372
373 /* Query disc */
374 /* If there're several matches this call returns
375 a linked list of all matches. We let the user
376 decide later, which match to use. */
377 Cddb=cddb_query(s, &cddbInfo);
378
379 if(!Cddb)
380 break; /* no list, so break */
381
382 /* Let the user decide which match to use */
383 /* If the head of the list has iFuzzy set
384 to one we have to choose. */
385 if(Cddb->getFuzzyOrN()) {
386 /* Show the dialog with the list of matches */
387 a=(SHORT)WinDlgBox( HWND_DESKTOP, NULLHANDLE, cddbDialogProc, RESSOURCEHANDLE, IDDLG_CDDBCHOOSE , 0 );
388 sprintf(text,"Selection: %d",a);
389 /* WinMessageBox( HWND_DESKTOP, HWND_DESKTOP, text, "Debug", 0UL, MB_OK | MB_ICONEXCLAMATION|MB_MOVEABLE ); */
390 if(a==LIT_NONE) {
391 /* User pressed cancel */
392 if(Cddb)
393 delete(Cddb);
394 write(s,"QUIT\r\n",6);
395 close(s);
396 return -1;
397 }
398 Cddb=choseCddb(Cddb,a);
399 }
400
401 if(!Cddb)
402 break; /* no choice, so break */
403
404 /* Query tracks of match 'Cddb' */
405 /* The track names are put into a linked
406 list in Cddb. */
407 if(cddb_read(s,Cddb)==CDDB_ERROR)
408 break;
409
410 /* Print the queried data */
411 /* The data is already printed in cddb.cpp to the given datafile */
412 // printQueriedData(Cddb, &cddbInfo);
413
414
415 /* everything's ok */
416 write(s,"QUIT\r\n",6);
417 close(s);
418 delete(Cddb);
419 /* WinPostMsg(hwndNotify,WM_APPTERMINATENOTIFY,MPFROMLONG(ACKEY_CDDBQUERY),MPFROMLONG(1)); */
420 sprintf(text,"SETSTATUSTEXT=CDDB data found.");
421 return 0;
422 } while(TRUE);
423 if(Cddb)
424 delete(Cddb);
425 /* Error */
426 write(s,"QUIT\r\n",6);
427 close(s);
428 }
429 }/* for */
430 /* WinPostMsg(hwndNotify,WM_APPTERMINATENOTIFY,MPFROMLONG(ACKEY_CDDBQUERY),MPFROMLONG(1)); */
431 printError("Can't get data...");
432 HlpSendCommandToObject(chrFolder, "SETSTATUSTEXT=Can't get CDDB data...");
433 return -1;
434}
435
436MRESULT EXPENTRY cddbObjectProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
437{
438 switch(msg)
439 {
440 case WM_APPTERMINATENOTIFY:
441 /* This queue is blocked until the query is over. This is the reason we've chosen an object window. */
442 if(!queryServer()) {
443 char rexxParams[CCHMAXPATH*3];
444 sprintf(rexxParams, /*sizeof(rexxParams),*/ "\"%s\" \"%s\" \"%s\"", chrCDDrive, cddbDataFile, params[3]);
445 launchRexx( "Set tracknames", chrRexxFile, rexxParams);
446 }
447 WinPostMsg(hwnd,WM_QUIT,(MPARAM)0,(MPARAM)0);
448 return FALSE;
449 default:
450 break;
451 }
452 return WinDefWindowProc( hwnd, msg, mp1, mp2);
453}
454
455MRESULT EXPENTRY cddbDialogProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
456{
457
458 char text[CCHMAXPATH];
459 char statusText[CCHMAXPATH];
460 short a;
461 ULONG rc;
462 SWCNTRL swctl;
463 PID pid;
464
465 switch(msg)
466 {
467 case WM_INITDLG:
468
469#ifdef DEBUG
470 sprintf(text,"Params:\n");
471 for(a=0;a<numArgs;a++) {
472 strcat(text,params[a]);
473 strcat(text,"\n");
474 }
475 WinMessageBox( HWND_DESKTOP, HWND_DESKTOP, text, "Debug", 0UL, MB_OK | MB_ICONEXCLAMATION|MB_MOVEABLE );
476#endif
477
478 /* Add switch entry */
479 memset(&swctl,0,sizeof(swctl));
480 WinQueryWindowProcess(hwnd,&pid,NULL);
481 swctl.hwnd=hwnd;
482 swctl.uchVisibility=SWL_VISIBLE;
483 swctl.idProcess=pid;
484 swctl.bProgType=PROG_DEFAULT;
485 swctl.fbJump=SWL_JUMPABLE;
486 WinAddSwitchEntry(&swctl);
487
488 hwndError=WinWindowFromID(hwnd,3102);
489 hwndDialog=hwnd;
490
491 /* Set dialog font to WarpSans for Warp 4 and above */
492 if(cwQueryOSRelease()>=40) {
493 WinSetPresParam(hwnd,
494 PP_FONTNAMESIZE,(ULONG)sizeof(DEFAULT_DIALOG_FONT),
495 (PVOID) DEFAULT_DIALOG_FONT );
496 }
497
498 /* sprintf(text,"1.Eintrag");
499 WinSendMsg(WinWindowFromID(hwndDialog,3101), LM_INSERTITEM,MPFROMSHORT(LIT_END),text);
500 sprintf(text,"2.Eintrag");
501 WinSendMsg(WinWindowFromID(hwndDialog,3101), LM_INSERTITEM,MPFROMSHORT(LIT_END),text);
502 WinShowWindow(hwndDialog,TRUE);
503 for(a=0;a<4;a++) {
504 sprintf(text,cddbServer[a]);
505 WinSendMsg(WinWindowFromID(hwndDialog,3101), LM_INSERTITEM,MPFROMSHORT(LIT_END),text);
506 }*/
507 printCddbList(Cddb);
508 return (MRESULT) TRUE;
509 case WM_CLOSE:
510 WinPostMsg(hwnd,WM_QUIT,0,0);
511 return 0;
512 case WM_DESTROY:
513 /* The dialog closes and gets destroyed */
514 break;
515 case WM_COMMAND:
516 switch(SHORT1FROMMP(mp1))
517 {
518 case IDPB_OK:
519 /* Query selection */
520 a=SHORT1FROMMR(WinSendMsg(WinWindowFromID(hwnd, IDLB_CDDBCHOOSE),LM_QUERYSELECTION,MPFROMSHORT(LIT_FIRST),0));
521 if(a==LIT_NONE)
522 break;
523 WinDismissDlg(hwnd,a+1);
524 break;
525 case IDPB_CANCEL:
526 WinDismissDlg(hwnd, (ULONG)LIT_NONE);
527 break;
528 default:
529 break;
530 }
531 return (MRESULT) TRUE;
532 default:
533 break;
534 }
535 return WinDefDlgProc(hwnd, msg, mp1, mp2);
536}
537
538void config(char * theAddress)
539{
540 char *chrPtr;
541 char profileName[CCHMAXPATH];
542 HINI hini=0;
543
544 if((chrPtr=strchr(theAddress,'@'))==NULLHANDLE)
545 return;
546
547 *chrPtr=0;
548 chrPtr++;
549 strncpy(username, theAddress, sizeof(username)-1);
550 strncpy(hostname, chrPtr, sizeof(hostname)-1);
551 /* Save it to ini */
552
553 /* Insert message in Logfile */
554 writeLog("Reading values from cddb.ini\n");
555
556 /* Build full path for cddb.ini file */
557 sprintf(profileName,"%s\\cddb.ini", chrInstallDir);
558 /* Open ini-file */
559 hini=PrfOpenProfile(WinQueryAnchorBlock(HWND_DESKTOP),(char *)profileName);
560 if(hini) {
561 writeLog("INI file opened.\n");
562 PrfWriteProfileString(hini,(CHAR*)"cddb",(CHAR*)"cddbuserhost", (CHAR*)hostname);
563 PrfWriteProfileString(hini,(CHAR*)"cddb",(CHAR*)"cddbuser",(CHAR*) username);
564 PrfCloseProfile(hini);
565 }/* end of if(hini) */
566 else {
567 writeLog("Can't open INI file to save address.\n");
568 }
569}
570
571void usage(char * chrProgName)
572{
573 HAB hab;
574 HMQ hmq;
575 QMSG qmsg;
576
577 hab=WinInitialize(0);
578 if(hab) {
579 hmq=WinCreateMsgQueue(hab,0);
580 if(hmq) {
581 /* We need a message queue for dialog boxes */
582 char title[100];
583 char text[500];
584
585 RESSOURCEHANDLE=queryResModuleHandle2(chrInstallDir, RESDLL_BASENAME);
586
587 messageBox( text, IDSTR_USAGE , sizeof(text),
588 title, IDSTR_PMCDDBTITLE, sizeof(title),
589 RESSOURCEHANDLE, HWND_DESKTOP, MB_OK | MB_MOVEABLE);
590
591 freeResHandle();
592
593 WinDestroyMsgQueue(hmq);
594 }
595 WinTerminate(hab);
596 }
597
598}
599
600int main (int argc, char *argv[])
601{
602 HAB hab;
603 HMQ hmq;
604 QMSG qmsg;
605 char *chrPtr;
606 short a;
607
608 ULONG fl;
609 HWND hwndClient;
610
611 /* Create a copy of the args */
612 /* argv[0]: progname
613 * argv[1]: cd drive or /C for configuring
614 * argv[2]: REXX file. This file is used to parse the queried data file and
615 * set all the info of the CD track objects.
616 * When configuring argv[2] is the email address.
617 * argv[3]: folder path
618 */
619
620 numArgs=argc;
621
622 for(a=0;a<argc;a++)
623 {
624 params[a]=argv[a];
625 }
626
627 strncpy(chrBinDir, argv[0], sizeof(chrBinDir)-1);
628 if((chrPtr=strrchr(chrBinDir, '\\'))!=NULLHANDLE)
629 *chrPtr=0;
630 strncpy(chrInstallDir, chrBinDir, sizeof(chrInstallDir)-1);
631
632 if(numArgs<3) {
633 usage(argv[0]);
634 exit(1);
635 }
636
637 /* Build the cache directory location */
638 strncpy(chrCDDBDir, chrInstallDir, sizeof(chrCDDBDir)-1);
639 sprintf(chrCDDBDir, "%s\\cddbdata",chrInstallDir);
640 sprintf(cddbDataFile, "%s\\",chrCDDBDir);
641
642 strncpy(chrCDDrive, argv[1],sizeof(chrCDDrive)-1);
643 params[1]=chrInstallDir; /* For writeLog */
644 if(!stricmp(argv[1],"/c")) /* Configure E-Mail address */
645 {
646 config(argv[2]);
647 exit(0);
648 }
649 chrRexxFile=argv[2];
650 chrFolder=argv[3];
651
652 hab=WinInitialize(0);
653 if(hab) {
654 hmq=WinCreateMsgQueue(hab,0);
655 if(hmq) {
656 removeLog();
657
658 /*WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, chrInstallDir, "", 123, MB_MOVEABLE);*/
659 writeLog(argv[0]);
660 writeLog(" started with the following parameters:\n\n");
661 for(a=0;a<argc;a++)
662 {
663 writeLog(argv[a]);
664 writeLog("\n");
665 }
666 writeLog("\n");
667
668 /* Check if user started prog by hand */
669 if(!(argc<5))
670 {/*pmUsage();*/
671 }
672 else {
673 /* The window we notify after getting the cddb data */
674 /* hwndNotify=atol(params[3]);*/
675 /* Get our ressource dll */
676 RESSOURCEHANDLE=queryResModuleHandle2(chrInstallDir, RESDLL_BASENAME);
677 /* Load options from cdrecord.ini */
678 if(readCDDBIni()) {
679 /* sprintf(cddbDataFile,"%s\\cddbdata\\",params[1]); */
680 writeLog("\nCache directory is: ");
681 writeLog(cddbDataFile);
682 writeLog("\n\n");
683 /* Object window creation */
684 hwndClient=WinCreateWindow(HWND_OBJECT,WC_STATIC,(CHAR*)"cddbObject",0,0,0,0,0,NULL,HWND_BOTTOM,12343,NULL,NULL);
685 if(hwndClient) {
686 WinSubclassWindow(hwndClient,&cddbObjectProc);
687 /* Window created. */
688 WinPostMsg(hwndClient,WM_APPTERMINATENOTIFY,NULL,NULL); /* Let's start */
689 while(WinGetMsg(hab,&qmsg,(HWND)NULL,0,0))
690 WinDispatchMsg(hab,&qmsg);
691 WinDestroyWindow(hwndClient);
692 }
693 freeResHandle();
694 }
695 }
696 WinDestroyMsgQueue(hmq);
697 }
698 WinTerminate(hab);
699 }
700 return 0;
701}
702
703
704
705
706
707
708
709
710
Note: See TracBrowser for help on using the repository browser.