source: trunk/mediafolder/c/cddb/pmcddb.cc@ 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: 21.6 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]=PMCDDB_LOGFILENAME;
108char logNameFullPath[CCHMAXPATH];
109
110#define QUERYCDDB_VERSION "0.1"
111
112int port=888;
113char host[1000]="uk.freedb.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=(UCHAR*)pszTitle;
148
149 startData.PgmName=(UCHAR*)"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=(UCHAR*)chrLoadError;
158 startData.ObjectBuffLen=(ULONG)sizeof(chrLoadError);
159
160 sprintf(startParams," /C \" \"%s\" %s \"", rexxFile, parameters);
161 startData.PgmInputs=(UCHAR*)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),(unsigned 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,(UCHAR*)"cddb",(UCHAR*)"numservers",0);
207 PrfQueryProfileString(hini,(UCHAR*)"cddb",(UCHAR*)"cddbuser",(UCHAR*) "guest",username,sizeof(username));
208 PrfQueryProfileString(hini,(UCHAR*)"cddb",(UCHAR*)"cddbuserhost",(UCHAR*) "",hostname,sizeof(hostname));
209
210 strncpy(version,QUERYCDDB_VERSION,sizeof(version));
211
212 if(NUMSERVERS==0) {
213 strncpy(cddbServer[0],"de.freedb.org:888",sizeof(cddbServer[0]));
214 strncpy(cddbServer[1],"at.freedb.org:888",sizeof(cddbServer[0]));
215 strncpy(cddbServer[2],"ca.freedb.org:888",sizeof(cddbServer[0]));
216 strncpy(cddbServer[3],"uk.freedb.org:888",sizeof(cddbServer[0]));
217 strncpy(cddbServer[4],"freedb.freedb.org:888",sizeof(cddbServer[0]));
218 strncpy(cddbServer[5],"cz.freedb.org:888",sizeof(cddbServer[0]));
219 NUMSERVERS=6;
220 }
221 else {
222 if(NUMSERVERS>MAXSERVERS)
223 NUMSERVERS=MAXSERVERS;
224 /* Read the servers from ini */
225 for(a=0;a<NUMSERVERS;a++) {
226 sprintf(text,"cddbserver%d",a+1);
227 PrfQueryProfileString(hini,(UCHAR*)"cddb",(UCHAR*)text,(UCHAR*)"",cddbServer[a],sizeof(cddbServer[0]));
228 }
229 }
230 if(hini)
231 PrfCloseProfile(hini);
232
233 if(strlen(username)==0)
234 break;
235 if(strlen(hostname)==0)
236 break;
237
238 return TRUE;
239 }while(TRUE);
240 writeLog("\nError while reading values from cddb.ini.\n");
241 writeLog("Make sure your username and your host are set.\n");
242
243 messageBox( profileName, IDSTR_SETUPERROR , sizeof(profileName),
244 moduleName, IDSTR_PMCDDBTITLE, sizeof(moduleName),
245 RESSOURCEHANDLE, HWND_DESKTOP, MB_OK | MB_ICONEXCLAMATION|MB_MOVEABLE);
246
247 HlpSendCommandToObject("<CWFREEDB_CLIENT_CONFIG>", "OPEN=DEFAULT;");
248
249 return FALSE;
250}
251
252void printCddbList(cddb * Cddb)
253{
254 cddb * tmpCddb;
255 char text[400];
256 int iNum;
257
258 tmpCddb=Cddb;
259 iNum=0;
260
261 printError("\n-------------------\n");
262 printError("CDDB database returned the following match(es):\n");
263
264 while (tmpCddb) {/* Print data of every match */
265 /* Print our data */
266 iNum++;
267 /* Print it to log */
268 sprintf(text,"%d: Title: %s Artist: %s"
269 ,iNum,tmpCddb->title,tmpCddb->artist);
270 printError(text);
271 printError("\n");
272 /* Insert into Listbox */
273 WinSendMsg(WinWindowFromID(hwndDialog, IDLB_CDDBCHOOSE), LM_INSERTITEM,MPFROMSHORT(LIT_END),text);
274 tmpCddb=tmpCddb->getNextCddb();
275 }/* while */
276 /* Preselect the first item */
277 WinSendMsg(WinWindowFromID(hwndDialog, IDLB_CDDBCHOOSE), LM_SELECTITEM,MPFROMSHORT(LIT_FIRST),MPFROMSHORT(TRUE));
278
279 printError("-------------------\n");
280
281}
282
283/* Return the chosen cddb data set from the list of cddb data sets */
284cddb* choseCddb(cddb* Cddb, SHORT a)
285{
286 int iNum;
287 cddb * tmpCddb;
288 char buffer[10]={0};
289 char * rc;
290
291 iNum=0;
292 tmpCddb=Cddb;
293 /* Count the matches */
294 while (tmpCddb) {
295 iNum++;
296 tmpCddb=tmpCddb->getNextCddb();
297 }/* while */
298
299
300 iNum=1;
301 tmpCddb=Cddb;
302 /* Get the cddb */
303 while (iNum!=a) {
304 iNum++;
305 tmpCddb=tmpCddb->getNextCddb();
306 }/* while */
307
308 return tmpCddb;
309}
310
311int queryServer()
312{
313 CDDBINFO cddbInfo;
314 char text[100];
315 SHORT a;
316 int b;
317 char *chrPtr;
318 struct stat statBuf;
319
320 Cddb=NULL;
321
322 /* Get track data for CDDB query.
323 This function calculates the diskID and the
324 length of the tracks of the inserted CD.
325 We use the data to perform the database query. */
326
327 if(!CDDBDiscID(chrCDDrive, &cddbInfo)) {
328 printError("Cannot query track data for calculating diskID.\nMake sure an audio CD is inserted." );
329 writeLog("Cannot query track data for calculating diskID.\nMake sure an audio CD is inserted.\n");
330 /* WinPostMsg(hwndNotify,WM_APPTERMINATENOTIFY,MPFROMLONG(ACKEY_CDDBQUERY),MPFROMLONG(0)); */
331 return -1;
332 }
333
334 /* Tell the caller, that we start a CDDB query. The caller may go on in the meantime */
335 /*WinPostMsg(hwndNotify, WM_APPTERMINATENOTIFY,MPFROMLONG(ACKEY_CDDBQUERY),MPFROMLONG(0));*/
336 sprintf(text,"%08x",cddbInfo.discid);
337 strcat(cddbDataFile,text);/* Build the name of the cddb data file */
338 writeLog("CDDB datafile name is: ");
339 writeLog(cddbDataFile);
340 writeLog("\n");
341 if(stat(cddbDataFile , &statBuf)!=-1) {
342 writeLog("Found CDDB data in cache directory. DB query finished.\n");
343 /* WinPostMsg(hwndNotify,WM_APPTERMINATENOTIFY,MPFROMLONG(ACKEY_CDDBQUERY),MPFROMLONG(1)); */
344 return 0;/* We have already a cddb data file from a previous query, so we are ready. */
345 }
346
347 for(b=0;b<NUMSERVERS;b++) {/* Query the whole list of servers if necessary */
348 strncpy(host,cddbServer[b],sizeof(host));
349 chrPtr=strrchr(host,':');
350 if(chrPtr) {
351 *chrPtr=0;
352 chrPtr++;
353 port=atoi(chrPtr);
354 }
355 /* Report what we're doing */
356 sprintf(text,"SETSTATUSTEXT=Trying %s:%d...",host,port);
357 /* Set statusline of folder */
358 HlpSendCommandToObject(chrFolder, text);
359 sprintf(text,"\nTrying %s:%d...",host,port);
360 printErrorCR(text);
361
362 /* Connect to cddb-host */
363 if(!cddbConnectToHost(&s)) {
364 /* Query the database */
365 do {
366 /* Getting CDDB banner */
367 if(cddb_banner(s))
368 break; /* Error */
369
370 /* Setting protocol level */
371 if(cddb_setting_proto(s))
372 break;
373
374 /* Handshaking */
375 if(cddb_handshaking(s))
376 break;
377
378 /* Query disc */
379 /* If there're several matches this call returns
380 a linked list of all matches. We let the user
381 decide later, which match to use. */
382 Cddb=cddb_query(s, &cddbInfo);
383
384 if(!Cddb)
385 break; /* no list, so break */
386
387 /* Let the user decide which match to use */
388 /* If the head of the list has iFuzzy set
389 to one we have to choose. */
390 if(Cddb->getFuzzyOrN()) {
391 /* Show the dialog with the list of matches */
392 a=(SHORT)WinDlgBox( HWND_DESKTOP, NULLHANDLE, cddbDialogProc, RESSOURCEHANDLE, IDDLG_CDDBCHOOSE , 0 );
393 sprintf(text,"Selection: %d",a);
394 /* WinMessageBox( HWND_DESKTOP, HWND_DESKTOP, text, "Debug", 0UL, MB_OK | MB_ICONEXCLAMATION|MB_MOVEABLE ); */
395 if(a==LIT_NONE) {
396 /* User pressed cancel */
397 if(Cddb)
398 delete(Cddb);
399 write(s,"QUIT\r\n",6);
400 close(s);
401 return -1;
402 }
403 Cddb=choseCddb(Cddb,a);
404 }
405
406 if(!Cddb)
407 break; /* no choice, so break */
408
409 /* Query tracks of match 'Cddb' */
410 /* The track names are put into a linked
411 list in Cddb. */
412 if(cddb_read(s,Cddb)==CDDB_ERROR)
413 break;
414
415 /* Print the queried data */
416 /* The data is already printed in cddb.cpp to the given datafile */
417 // printQueriedData(Cddb, &cddbInfo);
418
419
420 /* everything's ok */
421 write(s,"QUIT\r\n",6);
422 close(s);
423 delete(Cddb);
424 /* WinPostMsg(hwndNotify,WM_APPTERMINATENOTIFY,MPFROMLONG(ACKEY_CDDBQUERY),MPFROMLONG(1)); */
425 sprintf(text,"SETSTATUSTEXT=CDDB data found.");
426 return 0;
427 } while(TRUE);
428 if(Cddb)
429 delete(Cddb);
430 /* Error */
431 write(s,"QUIT\r\n",6);
432 close(s);
433 }
434 }/* for */
435 /* WinPostMsg(hwndNotify,WM_APPTERMINATENOTIFY,MPFROMLONG(ACKEY_CDDBQUERY),MPFROMLONG(1)); */
436 printError("Can't get data...");
437 HlpSendCommandToObject(chrFolder, "SETSTATUSTEXT=Can't get CDDB data...");
438 return -1;
439}
440
441MRESULT EXPENTRY cddbObjectProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
442{
443 switch(msg)
444 {
445 case WM_APPTERMINATENOTIFY:
446 /* This queue is blocked until the query is over. This is the reason we've chosen an object window. */
447 if(!queryServer()) {
448 char rexxParams[CCHMAXPATH*3];
449 snprintf(rexxParams, sizeof(rexxParams), "\"%s\" \"%s\" \"%s\"", chrCDDrive, cddbDataFile, params[3]);
450 launchRexx( "Set tracknames", chrRexxFile, rexxParams);
451 }
452 WinPostMsg(hwnd,WM_QUIT,(MPARAM)0,(MPARAM)0);
453 return FALSE;
454 default:
455 break;
456 }
457 return WinDefWindowProc( hwnd, msg, mp1, mp2);
458}
459
460MRESULT EXPENTRY cddbDialogProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
461{
462
463 char text[CCHMAXPATH];
464 char statusText[CCHMAXPATH];
465 short a;
466 ULONG rc;
467 SWCNTRL swctl;
468 PID pid;
469
470 switch(msg)
471 {
472 case WM_INITDLG:
473
474#ifdef DEBUG
475 sprintf(text,"Params:\n");
476 for(a=0;a<numArgs;a++) {
477 strcat(text,params[a]);
478 strcat(text,"\n");
479 }
480 WinMessageBox( HWND_DESKTOP, HWND_DESKTOP, text, "Debug", 0UL, MB_OK | MB_ICONEXCLAMATION|MB_MOVEABLE );
481#endif
482
483 /* Add switch entry */
484 memset(&swctl,0,sizeof(swctl));
485 WinQueryWindowProcess(hwnd,&pid,NULL);
486 swctl.hwnd=hwnd;
487 swctl.uchVisibility=SWL_VISIBLE;
488 swctl.idProcess=pid;
489 swctl.bProgType=PROG_DEFAULT;
490 swctl.fbJump=SWL_JUMPABLE;
491 WinAddSwitchEntry(&swctl);
492
493 hwndError=WinWindowFromID(hwnd,3102);
494 hwndDialog=hwnd;
495
496 /* Set dialog font to WarpSans for Warp 4 and above */
497 if(cwQueryOSRelease()>=40) {
498 WinSetPresParam(hwnd,
499 PP_FONTNAMESIZE,(ULONG)sizeof(DEFAULT_DIALOG_FONT),
500 DEFAULT_DIALOG_FONT );
501 }
502
503 /* sprintf(text,"1.Eintrag");
504 WinSendMsg(WinWindowFromID(hwndDialog,3101), LM_INSERTITEM,MPFROMSHORT(LIT_END),text);
505 sprintf(text,"2.Eintrag");
506 WinSendMsg(WinWindowFromID(hwndDialog,3101), LM_INSERTITEM,MPFROMSHORT(LIT_END),text);
507 WinShowWindow(hwndDialog,TRUE);
508 for(a=0;a<4;a++) {
509 sprintf(text,cddbServer[a]);
510 WinSendMsg(WinWindowFromID(hwndDialog,3101), LM_INSERTITEM,MPFROMSHORT(LIT_END),text);
511 }*/
512 printCddbList(Cddb);
513 return (MRESULT) TRUE;
514 case WM_CLOSE:
515 WinPostMsg(hwnd,WM_QUIT,0,0);
516 return 0;
517 case WM_DESTROY:
518 /* The dialog closes and gets destroyed */
519 break;
520 case WM_COMMAND:
521 switch(SHORT1FROMMP(mp1))
522 {
523 case IDPB_OK:
524 /* Query selection */
525 a=SHORT1FROMMR(WinSendMsg(WinWindowFromID(hwnd, IDLB_CDDBCHOOSE),LM_QUERYSELECTION,MPFROMSHORT(LIT_FIRST),0));
526 if(a==LIT_NONE)
527 break;
528 WinDismissDlg(hwnd,a+1);
529 break;
530 case IDPB_CANCEL:
531 WinDismissDlg(hwnd, (ULONG)LIT_NONE);
532 break;
533 default:
534 break;
535 }
536 return (MRESULT) TRUE;
537 default:
538 break;
539 }
540 return WinDefDlgProc(hwnd, msg, mp1, mp2);
541}
542
543void config(char * theAddress)
544{
545 char *chrPtr;
546 char profileName[CCHMAXPATH];
547 HINI hini=0;
548
549 if((chrPtr=strchr(theAddress,'@'))==NULLHANDLE)
550 return;
551
552 *chrPtr=0;
553 chrPtr++;
554 strncpy(username, theAddress, sizeof(username)-1);
555 strncpy(hostname, chrPtr, sizeof(hostname)-1);
556 /* Save it to ini */
557
558 /* Insert message in Logfile */
559 writeLog("Reading values from cddb.ini\n");
560
561 /* Build full path for cddb.ini file */
562 sprintf(profileName,"%s\\cddb.ini", chrInstallDir);
563 /* Open ini-file */
564 hini=PrfOpenProfile(WinQueryAnchorBlock(HWND_DESKTOP),(unsigned char *)profileName);
565 if(hini) {
566 writeLog("INI file opened.\n");
567 PrfWriteProfileString(hini,(UCHAR*)"cddb",(UCHAR*)"cddbuserhost", (UCHAR*)hostname);
568 PrfWriteProfileString(hini,(UCHAR*)"cddb",(UCHAR*)"cddbuser",(UCHAR*) username);
569 PrfCloseProfile(hini);
570 }/* end of if(hini) */
571 else {
572 writeLog("Can't open INI file to save address.\n");
573 }
574}
575
576void usage(char * chrProgName)
577{
578 HAB hab;
579 HMQ hmq;
580 QMSG qmsg;
581
582 hab=WinInitialize(0);
583 if(hab) {
584 hmq=WinCreateMsgQueue(hab,0);
585 if(hmq) {
586 /* We need a message queue for dialog boxes */
587 char title[100];
588 char text[500];
589
590 RESSOURCEHANDLE=queryResModuleHandle2(chrInstallDir, RESDLL_BASENAME);
591
592 messageBox( text, IDSTR_USAGE , sizeof(text),
593 title, IDSTR_PMCDDBTITLE, sizeof(title),
594 RESSOURCEHANDLE, HWND_DESKTOP, MB_OK | MB_MOVEABLE);
595
596 freeResHandle();
597
598 WinDestroyMsgQueue(hmq);
599 }
600 WinTerminate(hab);
601 }
602
603}
604
605int main (int argc, char *argv[])
606{
607 HAB hab;
608 HMQ hmq;
609 QMSG qmsg;
610 char *chrPtr;
611 short a;
612
613 ULONG fl;
614 HWND hwndClient;
615
616 /* Create a copy of the args */
617 /* argv[0]: progname
618 * argv[1]: cd drive or /C for configuring
619 * argv[2]: REXX file. This file is used to parse the queried data file and
620 * set all the info of the CD track objects.
621 * When configuring argv[2] is the email address.
622 * argv[3]: folder path
623 */
624
625 numArgs=argc;
626
627 for(a=0;a<argc;a++)
628 {
629 params[a]=argv[a];
630 }
631
632 strncpy(chrBinDir, argv[0], sizeof(chrBinDir)-1);
633 if((chrPtr=strrchr(chrBinDir, '\\'))!=NULLHANDLE)
634 *chrPtr=0;
635 strncpy(chrInstallDir, chrBinDir, sizeof(chrInstallDir)-1);
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.