source: trunk/mediafolder/c/cddb/pmcddb.cc@ 2

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

Import sources from cwmm-full.zip dated 2005-03-21

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