home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1999 November / PCONLINE_11_99.ISO / filesbbs / OS2 / ACDCR032.ZIP / source / audiofolder.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1999-08-07  |  28.0 KB  |  796 lines

  1. /*
  2.  * This file is (C) Chris Wohlgemuth 1999
  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. #define INCL_DOSQUEUES
  21. #include "audiofolder.hh"
  22. #include "audiofolderhelp.h"
  23. #include <stdio.h>
  24. #include <stdlib.h>
  25. #include <wpshadow.hh>
  26. #include <string.h>
  27.  
  28. extern BOOL setupDone;
  29. extern BOOL GrabberSetupDone;
  30.  
  31. extern int iNumCD;
  32. extern char cFirstCD;
  33. extern char chosenCD[3];
  34. extern char chrGrabberPath[CCHMAXPATH];
  35. extern char chrGrabberOptions[CCHMAXPATH];
  36. extern int bTrackNumbers;
  37.  
  38.  
  39. extern char chrCDRecord[CCHMAXPATH];/* Path to cdrecord */
  40. extern char chrCDROptions[CCHMAXPATH];
  41.  
  42.  
  43. extern ATOM atomUpdateStatusbar;
  44. extern ATOM atomStartGrab;
  45. extern ATOM atomStartWrite;
  46.  
  47. typedef struct
  48. {
  49.   USHORT cb;
  50.   CWAudioFolder* thisPtr;
  51. }WCNTRLDATA;
  52.  
  53.  
  54.  
  55. HFILE openDrive(char * drive);
  56. void closeDrive(HFILE hfDrive);
  57. ULONG queryAudioCDTracks(HFILE hfDrive);
  58. MRESULT EXPENTRY CDToolsDlgProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 );
  59. MRESULT EXPENTRY trackDialogProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2);
  60. LONG queryFreeDriveSpace(ULONG diskNum);
  61. LONG CDQueryTrackSize(ULONG numTrack, char * drive);
  62. PSZ buildWrapperName();
  63. ULONG launchGrabber(PSZ parameter, PSZ folderPath,HWND hwnd);
  64. MRESULT EXPENTRY grabberOptionDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2) ;
  65. MRESULT EXPENTRY cdrecordOptionDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2) ;
  66.  
  67. /* Local */
  68. HMODULE queryModuleHandle(void);
  69. PSZ buildGrabberParam(int numTrack,PSZ trackname);
  70. MRESULT EXPENTRY grabStatusDialogProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2);
  71. MRESULT EXPENTRY grabObjectProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2);
  72.  
  73. /* This function returns the module handle of our class-dll */
  74. HMODULE queryModuleHandle(void)
  75. {
  76.   static HMODULE hmod=0;
  77.   
  78.   if(!hmod) {
  79.     PSZ pathname=SOMClassMgrObject  //Query Pathname of class file
  80.       ->somLocateClassFile(somIdFromString("CWAudioFolder"),1,2);
  81.     DosQueryModuleHandle(pathname,&hmod);  //Query module handle
  82.   }
  83.   return hmod;
  84. }
  85.  
  86. PSZ buildGrabberParam(int numTrack,PSZ trackname)
  87. {
  88.   char parameter[CCHMAXPATH*2];
  89.   char *charPtr;
  90.   char *charPtr2;
  91.  
  92.   //      sprintf(statusText,"Grab tracks message");  
  93.   //  WinMessageBox(  HWND_DESKTOP,   HWND_DESKTOP,   chrGrabberPath, chrGrabberOptions, 0UL, MB_OK | MB_ICONEXCLAMATION|MB_MOVEABLE );
  94.   //  return "";
  95.     
  96.   /* Build commandline */
  97.   charPtr=strchr(chrGrabberOptions,'%');
  98.   if(charPtr) {
  99.     /* There is a var */
  100.     *charPtr=0;/* String splitten */
  101.     sprintf(parameter,"%s",chrGrabberOptions);
  102.         
  103.     *charPtr='%';
  104.     charPtr++;/* Parameter */ 
  105.     if(*charPtr=='1')
  106.       /* replace var with cd-drive letter */
  107.       sprintf(parameter,"%s%c",parameter,chosenCD[0]);
  108.     else
  109.       /* replace var with tracknum */
  110.       sprintf(parameter,"%s%d",parameter,numTrack);
  111.     /* check rest of line */
  112.     charPtr++;
  113.     /* find second var */
  114.     charPtr2=strchr(charPtr,'%');
  115.     if(!charPtr2)
  116.       /* No second parameter */
  117.       sprintf(parameter,"%s%s",parameter,charPtr);
  118.     else {
  119.       *charPtr2=0;/* String splitten */
  120.       sprintf(parameter,"%s%s",parameter,charPtr);
  121.       *charPtr2='%';
  122.       charPtr2++;
  123.       if(*charPtr2=='1')
  124.         /* replace var with cd-drive letter */
  125.         sprintf(parameter,"%s%c",parameter,chosenCD[0]);
  126.       else
  127.         /* replace var with tracknum */
  128.         sprintf(parameter,"%s%d",parameter,numTrack);
  129.       charPtr2++;
  130.       sprintf(parameter,"%s%s",parameter,charPtr2);
  131.     }
  132.   }
  133.  
  134.   /* append filename */
  135.   /* check trackname for extension */
  136.   if(bTrackNumbers) {
  137.     /* Find last dot */                 
  138.     charPtr=strrchr(trackname,'.');
  139.     if(charPtr) {
  140.       /* We have an extension */
  141.       *charPtr=0;     /* split string */
  142.       charPtr++;
  143.       if(numTrack<10)
  144.         sprintf(parameter,"%s %s0%d.%s",parameter,trackname,numTrack,charPtr);/* insert tracknum */
  145.       else
  146.         sprintf(parameter,"%s %s%d.%s",parameter,trackname,numTrack,charPtr);/* insert tracknum */
  147.     }
  148.     else {
  149.       /* No extension */                      
  150.       if(numTrack<10)
  151.         sprintf(parameter,"%s %s0%d",parameter,trackname,numTrack);/* append trackname */
  152.       else
  153.         sprintf(parameter,"%s %s%d",parameter,trackname,numTrack);/* append trackname */
  154.     }
  155.   }
  156.   else {
  157.     /* No tracknumbers */   
  158.     sprintf(parameter,"%s %s",parameter,trackname);
  159.   }
  160.   /* commandline is ready */                      
  161.   return parameter;   
  162. }
  163.  
  164.  
  165.  
  166. MRESULT EXPENTRY grabStatusDialogProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2) 
  167. {
  168.   CWAudioFolder * thisPtr;
  169.     
  170.   switch(msg)
  171.     {
  172.     case WM_INITDLG :   
  173.       WinSetWindowULong(hwnd,QWL_USER,(ULONG)PVOIDFROMMP(mp2));//Save object ptr.
  174.       thisPtr=(CWAudioFolder*) PVOIDFROMMP(mp2);
  175.       return (MRESULT) TRUE;
  176.     case WM_HELP:
  177.       thisPtr=(CWAudioFolder*) WinQueryWindowULong(hwnd,QWL_USER);
  178.       thisPtr->wpDisplayHelp(IDDLG_GRABSTATUS, AFHELPLIBRARY);
  179.             
  180.       break;
  181.     case WM_CLOSE:
  182.       thisPtr=(CWAudioFolder*) WinQueryWindowULong(hwnd,QWL_USER);
  183.       if(thisPtr->tid)
  184.         /* We are currently grabbing, so hide the window */
  185.         WinShowWindow(hwnd,FALSE);
  186.       else
  187.         WinPostMsg(hwnd,WM_QUIT,0,0);
  188.       return 0;
  189.     case WM_DESTROY:
  190.       /* The dialog closes and gets destroyed */     
  191.       thisPtr=(CWAudioFolder*) WinQueryWindowULong(hwnd,QWL_USER);
  192.       if(thisPtr){
  193.         //thisPtr->wpSaveDeferred();
  194.       }
  195.       break;    
  196.     case WM_COMMAND:    
  197.       switch(SHORT1FROMMP(mp1))
  198.         {
  199.         case IDPB_BREAK:
  200.           DosBeep(1000,100);
  201.           thisPtr=(CWAudioFolder*) WinQueryWindowULong(hwnd,QWL_USER);
  202.           thisPtr->cwEnableGrab(FALSE);
  203.           WinEnableWindow(WinWindowFromID(hwnd,IDPB_BREAK),FALSE);
  204.           break;
  205.         case IDPB_ABORT:
  206.           DosBeep(5000,300);
  207.           break;                  
  208.         default:
  209.           break;
  210.         }
  211.       return (MRESULT) TRUE;
  212.     default:
  213.       break;
  214.     }
  215.   return WinDefDlgProc(hwnd, msg, mp1, mp2);    
  216. }
  217.  
  218. MRESULT EXPENTRY grabObjectProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  219. {
  220.   CWAudioFolder * thisPtr;
  221.   SHORT a;
  222.   SIZEL sizel;
  223.   ULONG ulFlags;
  224.   HWND hwndGrab;
  225.   char text[CCHMAXPATH];
  226.   char parameter[CCHMAXPATH*2];
  227.   char folderName[CCHMAXPATH];
  228.   HWND hwndTemp;
  229.   ULONG ulSize;
  230.   ULONG rc;
  231.   char statusText[100];
  232.   ULONG ulDrive;
  233.     
  234.   switch (msg)
  235.     {
  236.     case WM_APPTERMINATENOTIFY:
  237.       rc=MBID_YES;
  238.       if(LONGFROMMP(mp2)!=0) {
  239.         if(!WinLoadString(WinQueryAnchorBlock(hwnd),queryModuleHandle(),IDSTR_GRABBERERRORTEXT,sizeof(text),text))
  240.           sprintf(text,"Grabber returned a Non-zero resultcode. The grabbed track is probably corrupted. \
  241. Do you want to continue grabbing?");
  242.         if(!WinLoadString(WinQueryAnchorBlock(hwnd),queryModuleHandle(),IDSTR_GRABBERERRORTITLE, sizeof(statusText),
  243.                           statusText))
  244.           sprintf(statusText,"Grabber error!");               
  245.         rc=WinMessageBox(  HWND_DESKTOP,    hwnd,   text,   statusText, 0UL, MB_YESNO | MB_ICONEXCLAMATION|MB_MOVEABLE );
  246.       }
  247.       thisPtr=(CWAudioFolder*) WinQueryWindowULong(hwnd,QWL_USER);
  248.       /* Update statusbar */
  249.       if(thisPtr)
  250.         thisPtr->cwForceStatusUpdate();
  251.       if(thisPtr && rc==MBID_YES) {
  252.         /* Continue Grabbing */
  253.         hwndGrab=thisPtr->hwndGrab;/* Get grab dialog hwnd */
  254.         if(thisPtr->cwQueryGrabEnabled()) {
  255.           thisPtr->a=(int)WinSendMsg(WinWindowFromID(hwndGrab,IDLB_GRABTRACKS),LM_QUERYSELECTION,MPFROMSHORT(thisPtr->a),0);
  256.           if(thisPtr->a!=LIT_NONE) {
  257.             hwndTemp=thisPtr->cwQueryFrameCtl(WinQueryWindow(hwndGrab,QW_PARENT), &sizel,FCTL_TOP, &ulFlags);           
  258.             thisPtr->b++;
  259.             /*********** Build commandline ******************/
  260.             /* Get trackname */
  261.             WinQueryWindowText( WinWindowFromID(hwndTemp,IDEF_TRACKNAME),sizeof(parameter),parameter);
  262.                         
  263.             /* Get folder name */
  264.             ulSize=sizeof(folderName);
  265.             thisPtr->wpQueryRealName(folderName,&ulSize,TRUE);
  266.             ulDrive=folderName[0]-'A'+1;/* Build drive num */ 
  267.                         
  268.             /* Build full trackname */                  
  269.             sprintf(text,"%s\\%s",folderName,parameter);
  270.                         
  271.             /* Build grabber param line */
  272.             sprintf(parameter,"%s",buildGrabberParam(thisPtr->a+1,text));
  273.                         
  274.                         
  275.             /*************** Start the grabber here ****************/
  276.                         
  277.             /* Build status window */
  278.             sprintf(statusText,"Grabbing track %d of %d     ",thisPtr->b,thisPtr->numTracks);
  279.             WinSetWindowText(WinWindowFromID(thisPtr->hwndStatus,IDST_GRABSTATUS),statusText);
  280.                         
  281.                         
  282.             if(CDQueryTrackSize(thisPtr->a+1,chosenCD)+44 > queryFreeDriveSpace(ulDrive)){/* 44 bytes for waveheader */
  283.               if(!WinLoadString(WinQueryAnchorBlock(hwnd),queryModuleHandle(),IDSTR_NOGRABSPACETEXT,sizeof(text),text))
  284.                 sprintf(text,"Not enough free space on destination drive.");
  285.               if(!WinLoadString(WinQueryAnchorBlock(hwnd),queryModuleHandle(),IDSTR_NOTRACKSSELECTEDTITLE, sizeof(statusText),
  286.                                 statusText))
  287.                 sprintf(statusText,"Grab tracks message");  
  288.               WinMessageBox(  HWND_DESKTOP,   hwnd,   text,   statusText, 0UL,    MB_OK | MB_ICONEXCLAMATION|MB_MOVEABLE );
  289.             }
  290.             else {
  291.               launchGrabber(parameter,folderName,hwnd);
  292.               return (MRESULT)TRUE;
  293.             }
  294.           }
  295.         }/* thisPtr->cwQueryGrabEnabled() */
  296.       }/* end of if(thisPtr) */
  297.       if(thisPtr) {
  298.         //        WinSendMsg(thisPtr->hwndStatus,WM_CLOSE,0,0);
  299.           WinDestroyWindow(thisPtr->hwndStatus);
  300.  
  301.         /* Enable windows in grab dialog */
  302.         thisPtr->cwEnableGrabControls(TRUE);
  303.                 
  304.         /* Enable windows in selection dialog */
  305.         thisPtr->cwEnableSelectControls(TRUE);
  306.       }
  307.       WinPostMsg(hwnd,WM_QUIT,(MPARAM)0,(MPARAM)0);
  308.       return 0;
  309.     default:
  310.       if(msg == atomStartGrab) {
  311.         /* Start grab message */
  312.         thisPtr=(CWAudioFolder*)PVOIDFROMMP(mp1);
  313.         WinSetWindowULong(hwnd,QWL_USER,(ULONG)thisPtr);/* Save object ptr */
  314.         if(!thisPtr) {
  315.           /* Error: quit */
  316.           WinPostMsg(hwnd,WM_QUIT,(MPARAM)0,(MPARAM)0);
  317.           return 0;
  318.         }   
  319.                 
  320.         hwndGrab=thisPtr->hwndGrab;         
  321.         thisPtr->a=SHORT1FROMMR(WinSendMsg(WinWindowFromID(hwndGrab,IDLB_GRABTRACKS),LM_QUERYSELECTION,MPFROMSHORT(LIT_FIRST),0));
  322.         if(thisPtr->a==LIT_NONE) {
  323.           WinPostMsg(hwnd,WM_QUIT,(MPARAM)0,(MPARAM)0);
  324.           return 0;
  325.         }           
  326.         /*      sprintf(text,"hwndGrab=%x",hwndGrab);
  327.                 WinMessageBox(  HWND_DESKTOP,   hwnd,   text,   "Debug", 0UL,   MB_OK | MB_ICONEXCLAMATION|MB_MOVEABLE );*/
  328.         if(!hwndGrab) {
  329.           WinPostMsg(hwnd,WM_QUIT,(MPARAM)0,(MPARAM)0);
  330.           return 0;
  331.         }
  332.                                 
  333.         hwndTemp=thisPtr->cwQueryFrameCtl(WinQueryWindow(hwndGrab,QW_PARENT), &sizel,FCTL_TOP, &ulFlags);           
  334.         thisPtr->cwEnableGrab(TRUE);
  335.                 
  336.         /* Count selected files */
  337.         a=SHORT1FROMMR(WinSendMsg(WinWindowFromID(hwndGrab,IDLB_GRABTRACKS),LM_QUERYSELECTION,MPFROMSHORT(LIT_FIRST),0));
  338.         thisPtr->numTracks=0;
  339.         do {
  340.           if(a!=LIT_NONE) {
  341.             thisPtr->numTracks++;
  342.             a=SHORT1FROMMR(WinSendMsg(WinWindowFromID(hwndGrab,IDLB_GRABTRACKS),LM_QUERYSELECTION,MPFROMSHORT(a),0));
  343.             /*  sprintf(text,"numTracks=%x  a=%x",thisPtr->numTracks,a);
  344.                 WinMessageBox(  HWND_DESKTOP,   hwnd,   text,   "Debug", 0UL,   MB_OK | MB_ICONEXCLAMATION|MB_MOVEABLE );
  345.                 if(thisPtr->numTracks==10) {
  346.                 WinPostMsg(hwnd,WM_QUIT,(MPARAM)0,(MPARAM)0);
  347.                 return 0;
  348.                 }*/
  349.           }
  350.         }
  351.         while(a!=LIT_NONE);
  352.         /*  sprintf(text,"numTracks=%x",thisPtr->numTracks);
  353.             WinMessageBox(  HWND_DESKTOP,   hwnd,   text,   "Debug", 0UL,   MB_OK | MB_ICONEXCLAMATION|MB_MOVEABLE );
  354.             WinPostMsg(hwnd,WM_QUIT,(MPARAM)0,(MPARAM)0);
  355.             return 0;*/
  356.                 
  357.         thisPtr->b=1;
  358.                 
  359.         /*********** Build commandline ******************/
  360.         /* Get trackname */
  361.         WinQueryWindowText( WinWindowFromID(hwndTemp,IDEF_TRACKNAME),sizeof(parameter),parameter);          
  362.         /* Get folder name */
  363.         ulSize=sizeof(folderName);
  364.         thisPtr->wpQueryRealName(folderName,&ulSize,TRUE);
  365.         ulDrive=folderName[0]-'A'+1;/* Build drive num */           
  366.         /* Build full trackname */                  
  367.         sprintf(text,"%s\\%s",folderName,parameter);
  368.         /* Build grabber param line */
  369.         sprintf(parameter,"%s",buildGrabberParam(thisPtr->a+1,text));           
  370.  
  371.         /* Add redirection of stdout, stderr.*/
  372.         //sprintf(parameter,"%s 2>>%s\\grab.log 1>>&2",parameter,folderName);
  373.  
  374.         /*************** Start the grabber here ****************/
  375.         /* Build status window */
  376.  
  377.         thisPtr->hwndStatus=WinLoadDlg(HWND_DESKTOP,HWND_DESKTOP,
  378.                                        grabStatusDialogProc,queryModuleHandle(),IDDLG_GRABSTATUS,thisPtr);            
  379.  
  380.         sprintf(statusText,"Grabbing track %d of %d     ",thisPtr->b,thisPtr->numTracks);
  381.         WinSetWindowText(WinWindowFromID(thisPtr->hwndStatus,IDST_GRABSTATUS),statusText);
  382.             
  383.             
  384.         if(CDQueryTrackSize(thisPtr->a+1,chosenCD)+44 > queryFreeDriveSpace(ulDrive)){/* 44 bytes for waveheader */
  385.           if(!WinLoadString(WinQueryAnchorBlock(hwnd),queryModuleHandle(),IDSTR_NOGRABSPACETEXT,sizeof(text),text))
  386.             sprintf(text,"Not enough free space on destination drive.");
  387.           if(!WinLoadString(WinQueryAnchorBlock(hwnd),queryModuleHandle(),IDSTR_NOTRACKSSELECTEDTITLE, sizeof(statusText),
  388.                             statusText))
  389.             sprintf(statusText,"Grab tracks message");  
  390.           WinMessageBox(  HWND_DESKTOP,   hwnd,   text,   statusText, 0UL,    MB_OK | MB_ICONEXCLAMATION|MB_MOVEABLE );
  391.       
  392.  
  393.           WinDestroyWindow(thisPtr->hwndStatus);
  394.           /* Enable windows in grab dialog */
  395.           thisPtr->cwEnableGrabControls(TRUE);
  396.           /* Enable windows in selection dialog */
  397.           thisPtr->cwEnableSelectControls(TRUE);
  398.           WinPostMsg(hwnd,WM_QUIT,(MPARAM)0,(MPARAM)0);
  399.           return 0;
  400.         }
  401.         launchGrabber(parameter,folderName,hwnd);
  402.         /* end of grabber start */
  403.         return 0;               
  404.       }
  405.       break;
  406.     }
  407.   return WinDefWindowProc( hwnd, msg, mp1, mp2);
  408. }
  409.  
  410. /* This thread handles the audio grabbing */
  411. void _Optlink grabThreadFunc (void *arg)
  412. {
  413.   HWND hwndGrab;
  414.   HAB  hab;
  415.   HMQ  hmq;
  416.   QMSG qmsg;
  417.   //HWND hwnd;
  418.   CWAudioFolder * thisPtr;
  419.  
  420.   thisPtr=(CWAudioFolder*)arg;
  421.   thisPtr->wpLockObject();
  422.     
  423.   hab=WinInitialize(0);
  424.   if(hab) {
  425.     hmq=WinCreateMsgQueue(hab,0);
  426.     if(hmq) {
  427.       hwndGrab=WinCreateWindow(HWND_OBJECT,WC_STATIC,"myObj",0,0,0,0,0,NULL,HWND_BOTTOM,1234,NULL,NULL);
  428.       if(hwndGrab) {
  429.         WinSubclassWindow(hwndGrab,&grabObjectProc);
  430.         /* audio grab window created. Start grabbing */             
  431.         WinPostMsg(hwndGrab,atomStartGrab,MPFROMP(thisPtr),0);
  432.         while(WinGetMsg(hab,&qmsg,(HWND)NULL,0,0))
  433.           WinDispatchMsg(hab,&qmsg);
  434.         WinDestroyWindow(hwndGrab);
  435.       }
  436.       WinDestroyMsgQueue(hmq);
  437.     }
  438.     WinTerminate(hab);
  439.   }
  440.   thisPtr->wpUnlockObject();
  441.   thisPtr->tid=0;
  442.   //  DosBeep(100,2000);
  443. }
  444.  
  445.  
  446. /******************************************************/
  447. /* This function checks if the object is a wave file. */
  448. /* It only checks the extension because cdrecord      */
  449. /* doesn't know types and needs the extension to      */
  450. /* distinguish between wavefiles and raw data files.  */
  451. /******************************************************/
  452. BOOL CWAudioFolder::cwIsWaveFile(WPObject* wpObject)
  453. {
  454.   char objectName[CCHMAXPATH];
  455.   ULONG ulNameSize;
  456.   char* chrExtension;
  457.  
  458.   if(!somResolveByName(wpObject,"wpQueryRealName"))
  459.     /* It's not a file system object */
  460.     return FALSE;
  461.  
  462.   /* Check if it's folder */
  463.   if(somResolveByName(wpObject,"wpQueryContent"))
  464.     /* It's a folder */
  465.     return FALSE;
  466.  
  467.   /* Check the extension */
  468.   ulNameSize=sizeof(objectName);
  469.   ((WPFileSystem*)wpObject)->wpQueryRealName(objectName,&ulNameSize,FALSE);
  470.   chrExtension=strstr(strlwr(objectName),".wav");
  471.   if(chrExtension)
  472.     if(*(chrExtension+4)==0)return TRUE;//It's a wavefile
  473.   
  474.   return FALSE;
  475. }
  476.  
  477. /* This thread handles the CDTools-dialog */
  478. void _Optlink toolsThreadFunc (void *arg)
  479. {
  480.   HWND hwndTools;
  481.   HAB  hab;
  482.   HMQ  hmq;
  483.   QMSG qmsg;
  484.   CWAudioFolder *thisPtr;
  485.   
  486.   thisPtr=(CWAudioFolder*)arg;    //Pointer auf CWAudioFolder-Object
  487.   hab=WinInitialize(0);
  488.   if(hab) {
  489.     hmq=WinCreateMsgQueue(hab,0);
  490.     if(hmq) {
  491.       hwndTools=WinLoadDlg(HWND_DESKTOP,HWND_DESKTOP,CDToolsDlgProc,queryModuleHandle(),IDDLG_CDRTOOLS,thisPtr);
  492.       if(hwndTools) {
  493.         /* CDR tools window created */
  494.         while(WinGetMsg(hab,&qmsg,(HWND)NULL,0,0))
  495.           WinDispatchMsg(hab,&qmsg);
  496.         WinDestroyWindow(hwndTools);
  497.       }
  498.       WinDestroyMsgQueue(hmq);
  499.     }
  500.     WinTerminate(hab);
  501.   }
  502.   // DosBeep(100,2000);
  503. }
  504.  
  505. /********************************************************/
  506. /* New class function which inserts the Cdrecord option */
  507. /* page into the settings notebook                      */
  508. /********************************************************/
  509. BOOL CWAudioFolder::AddCdrecordOptionPage(HWND hwndNotebook)
  510. {
  511.   PAGEINFO pageinfo;
  512.   
  513.   //Clear the pageinfo structure
  514.   memset((PCH)&pageinfo, 0, sizeof(PAGEINFO));
  515.   //Fill the pageinfo structure
  516.   pageinfo.cb = sizeof(PAGEINFO);
  517.   pageinfo.hwndPage = NULLHANDLE;
  518.   pageinfo.usPageStyleFlags = BKA_MAJOR | BKA_STATUSTEXTON;
  519.   pageinfo.usPageInsertFlags = BKA_FIRST;
  520.   //We want page numbers
  521.   pageinfo.usSettingsFlags = SETTINGS_PAGE_NUMBERS;
  522.   //The dialog procedure for this page
  523.   pageinfo.pfnwp = cdrecordOptionDlgProc;
  524.   //The resource is in the class file
  525.   pageinfo.resid = queryModuleHandle();
  526.   //The ID of the dialog template
  527.   pageinfo.dlgid = IDDLG_CDRECORDSETUP;
  528.   //We need a pointer to our WPS-object in the dialog procedure
  529.   //to call class functions
  530.   pageinfo.pCreateParams = this;
  531.   //The ID of the help panel for this page
  532.   pageinfo.idDefaultHelpPanel = IDDLG_CDRECORDSETUP;
  533.   //Tell the WPS the help library name
  534.   pageinfo.pszHelpLibraryName = AFHELPLIBRARY;
  535.   //We have a major tab so we need a name
  536.   pageinfo.pszName = "CDRecord/2 options";
  537.   
  538.   //Insert the page into the settings notebook
  539.   return wpInsertSettingsPage(hwndNotebook,&pageinfo);
  540. }
  541.   
  542. /********************************************************/
  543. /* New class function which inserts the Grabber option  */
  544. /* page into the settings notebook                      */
  545. /********************************************************/
  546. BOOL CWAudioFolder::AddGrabOptionPage(HWND hwndNotebook)
  547. {
  548.   PAGEINFO pageinfo;
  549.   
  550.   //Clear the pageinfo structure
  551.   memset((PCH)&pageinfo, 0, sizeof(PAGEINFO));
  552.   //Fill the pageinfo structure
  553.   pageinfo.cb = sizeof(PAGEINFO);
  554.   pageinfo.hwndPage = NULLHANDLE;
  555.   pageinfo.usPageStyleFlags = BKA_MAJOR | BKA_STATUSTEXTON;
  556.   pageinfo.usPageInsertFlags = BKA_FIRST;
  557.   //We want page numbers
  558.   pageinfo.usSettingsFlags = SETTINGS_PAGE_NUMBERS;
  559.   //The dialog procedure for this page
  560.   pageinfo.pfnwp = grabberOptionDlgProc;
  561.   //The resource is in the class file
  562.   pageinfo.resid = queryModuleHandle();
  563.   pageinfo.dlgid = IDDLG_GRABBERSETUP;
  564.   //We need a pointer to our WPS-object in the dialog procedure
  565.   //to call class functions
  566.   pageinfo.pCreateParams = this;
  567.   //The ID of the help panel for this page
  568.   pageinfo.idDefaultHelpPanel = IDDLG_GRABBERSETUP;
  569.   //Tell the WPS the help library name
  570.   pageinfo.pszHelpLibraryName = AFHELPLIBRARY;
  571.   //We have a major tab so we need a name
  572.   pageinfo.pszName = "Grabber options";
  573.   
  574.   //Insert the page into the settings notebook
  575.   return wpInsertSettingsPage(hwndNotebook,&pageinfo);
  576. }
  577.  
  578.  
  579. void CWAudioFolder::cwSetStatusTime(ULONG ulTrackSize)
  580. {
  581.   char text[200];
  582.   ULONG ulSize;
  583.     
  584.   ulSize=ulTrackSize;
  585.   ulSize/=(2*2*44100);/* Calculate seconds */
  586.   sprintf(text,"Total time: %d min %02d sec",ulSize/60 , (ulSize % 60));
  587.   WinSetWindowText(WinWindowFromID(hwndStatusFrameCtl,IDST_STATUSTOTALTIME),text);    
  588. }
  589.  
  590. void CWAudioFolder::cwLoadIniValues()
  591. {
  592.   ULONG keyLength;
  593.   char profileName[CCHMAXPATH];
  594.   char moduleName[CCHMAXPATH];
  595.   char *chrPtr;
  596.   HINI hini=0;
  597.  
  598.   /* Query the number of CD-drives */
  599.   cwQueryCDDrives(&iNumCD,&cFirstCD);
  600.  
  601.   if(!wpRestoreLong("CWAudioFolder",IDKEY_FDRWRITEFLAGS,&ulWriteFlags))
  602.     ulWriteFlags=IDWF_PAD|IDWF_NOFIX|IDWF_DUMMY;
  603.   /* Get folder of class-dll. */
  604.   DosQueryModuleName(queryModuleHandle(),sizeof(moduleName),moduleName);
  605.   chrPtr=strrchr(moduleName,'\\');
  606.   if(chrPtr)
  607.     *chrPtr=0;
  608.   /* Build full path for cdrecord.ini file */
  609.   sprintf(profileName,"%s\\cdrecord.ini",moduleName);       
  610.   hini=PrfOpenProfile(WinQueryAnchorBlock(HWND_DESKTOP),profileName);
  611.   do{
  612.     if(!hini) {
  613.       WinMessageBox(  HWND_DESKTOP,
  614.                       HWND_DESKTOP,
  615.                       "Warning! Cannot open Ini-file!",
  616.                       "Audio-CD-Creator",
  617.                       0UL,
  618.                       MB_OK | MB_ICONEXCLAMATION );
  619.       break;
  620.     }/* end of if(!hini) */
  621.  
  622.     keyLength=PrfQueryProfileString(hini,"CDWriter","cdrecord","",chrCDRecord,sizeof(chrCDRecord));
  623.     if(keyLength==1){
  624.       break;/* First opening. We havn't got entries yet */
  625.     }
  626.     PrfQueryProfileString(hini,"CDWriter","cdroptions","",chrCDROptions,sizeof(chrCDROptions));
  627.     setupDone=TRUE;
  628.  
  629.     keyLength=PrfQueryProfileString(hini,"CDGrabber","grabber","",chrGrabberPath,sizeof(chrGrabberPath));
  630.     if(keyLength==1){
  631.       break;/* We havn't got entries yet */
  632.     }
  633.     PrfQueryProfileString(hini,"CDGrabber","graboptions","",chrGrabberOptions,sizeof(chrGrabberOptions));
  634.     PrfQueryProfileString(hini,"CDGrabber","grabdrive","",chosenCD,sizeof(chosenCD));
  635.     bTrackNumbers=PrfQueryProfileInt(hini,"CDGrabber","tracknumbers",1);
  636.     GrabberSetupDone=TRUE;
  637.     break;
  638.   } while(TRUE);
  639.   if(hini)PrfCloseProfile(hini);        
  640. }
  641.  
  642. ULONG CWAudioFolder::cwQueryWriteFlags()
  643. {
  644.   return ulWriteFlags;
  645. }
  646.  
  647. ULONG CWAudioFolder::cwSetWriteFlags(ULONG ulNewWriteFlags,ULONG ulMask)
  648. {
  649.   ULONG rc;
  650.  
  651.   rc=cwQueryWriteFlags();
  652.   ulWriteFlags=((ulNewWriteFlags&ulMask) | (~ulMask & ulWriteFlags));
  653.  
  654.   return rc;/* return previous flags */
  655. }
  656.  
  657. void CWAudioFolder::cwEnableGrab(BOOL bEnable)
  658. {
  659.   bGrabEnabled=bEnable;
  660. }
  661.  
  662. BOOL CWAudioFolder::cwQueryGrabEnabled(void)
  663. {   
  664.   return bGrabEnabled;    
  665. }
  666.  
  667. void CWAudioFolder::cwEnableWrite(BOOL bEnable)
  668. {
  669.   bWriteEnabled=bEnable;
  670. }
  671.  
  672. BOOL CWAudioFolder::cwQueryWriteEnabled(void)
  673. {   
  674.   return bWriteEnabled;    
  675. }
  676.  
  677. void CWAudioFolder::cwEnableGrabControls(BOOL bEnable)
  678. {
  679.   if(!hwndGrab)
  680.     return;
  681.   WinEnableWindow(WinWindowFromID(hwndGrab,IDPB_SELECTALL) ,bEnable);
  682.   WinEnableWindow(WinWindowFromID(hwndGrab,IDLB_GRABTRACKS) ,bEnable);
  683.   WinEnableWindow(WinWindowFromID(hwndGrab,IDPB_GRAB) ,bEnable);
  684.   WinEnableWindow(WinWindowFromID(hwndGrab,IDPB_REFRESH) ,bEnable);
  685.     
  686. }
  687.  
  688. void CWAudioFolder::cwEnableSelectControls(BOOL bEnable)
  689. {
  690.   if(!hwndSelect)
  691.     return;
  692.   WinEnableWindow(WinWindowFromID(hwndSelect,IDRB_WRITE) ,bEnable);
  693.   WinEnableWindow(WinWindowFromID(hwndSelect,IDRB_GRAB) ,bEnable);
  694.   WinEnableWindow(WinWindowFromID(hwndSelect,IDEF_TRACKNAME) ,bEnable);
  695. }
  696.  
  697. void CWAudioFolder::cwForceStatusUpdate(void)
  698. {
  699.   if(atomUpdateStatusbar)
  700.     WinPostMsg(hwndStatusFrameCtl,atomUpdateStatusbar,0,MPFROMP(this));     
  701. }
  702.  
  703. void CWAudioFolder::cwEnableWriteControls(BOOL bEnable)
  704. {
  705.   if(!hwndWrite)
  706.     return;
  707.   WinEnableWindow(WinWindowFromID(hwndWrite,IDCB_PAD) ,bEnable);
  708.   WinEnableWindow(WinWindowFromID(hwndWrite,IDCB_NOFIX) ,bEnable);
  709.   WinEnableWindow(WinWindowFromID(hwndWrite,IDCB_PREEMP) ,bEnable);
  710.   WinEnableWindow(WinWindowFromID(hwndWrite,IDCB_DUMMY) ,bEnable);
  711.   WinEnableWindow(WinWindowFromID(hwndWrite,IDPB_BURN) ,bEnable);
  712. }
  713.  
  714. void CWAudioFolder::cwSetStatusText(char * text)
  715.   WinSetWindowText(WinWindowFromID(hwndStatusFrameCtl,IDST_STATUSTOTALTIME),text);    
  716. }
  717.  
  718. /*********************************************************************/
  719. /*                                                                   */
  720. /* This procedure fills the given listbox with all the tracks of the */
  721. /* given folder. If no listbox is given only the size is returned    */
  722. /*                                                                   */
  723. /* Parameters:                                                       */
  724. /*              hwndFrame:   frame handle of wpFolder window         */
  725. /*              hwndListBox: handle of listbox where to insert the   */
  726. /*                           wavefile names                          */
  727. /*                                                                   */
  728. /* Returns: Size of all tracks in byte                               */
  729. /*                                                                   */
  730. /*********************************************************************/
  731. ULONG CWAudioFolder::cwFillTrackList(HWND hwndFrame, HWND hwndListBox)
  732. {
  733.   HWND hwndCnr;
  734.   PMINIRECORDCORE mrc;   
  735.   WPObject * contentObject;
  736.   char name[CCHMAXPATH];
  737.   ULONG ulNameSize;
  738.   ULONG ulSize;
  739.     
  740.   ulSize=0;
  741.   /* Get hwnd of folder container */ 
  742.   hwndCnr=WinWindowFromID(hwndFrame,FID_CLIENT);
  743.   if(hwndCnr){ /* Catch error */
  744.     /* Get first container item of our folder */
  745.     mrc=(PMINIRECORDCORE)WinSendMsg(hwndCnr,CM_QUERYRECORD,NULL,
  746.                                     MPFROM2SHORT(CMA_FIRST,CMA_ITEMORDER));
  747.     if(mrc){ 
  748.       while(mrc) {
  749.         /* Get wps-object-ptr. from container item */
  750.         contentObject=(WPObject*)OBJECT_FROM_PREC(mrc);//Get object
  751.         ulNameSize=sizeof(name);
  752.         if(contentObject) {
  753.           /* Get file system object or NULL */
  754.           contentObject=cwGetFileSystemObject(contentObject);
  755.         }
  756.         if(contentObject){
  757.           /* It's a file system object */
  758.           /* Check, if it's a wave file */
  759.           if(cwIsWaveFile(contentObject)){
  760.             /* Yes, query the full path */
  761.             ((WPFileSystem*)contentObject)->wpQueryRealName(name,&ulNameSize,TRUE);
  762.             /* Add tracksize to totalsize */ 
  763.             ulSize+=((WPFileSystem*)contentObject)->wpQueryFileSize()-44;
  764.             /* Add 2 seconds for pause between tracks */
  765.             //ulSize+=8*44100;
  766.             /* insert the name into the listbox */ 
  767.             if(hwndListBox)
  768.               WinInsertLboxItem(hwndListBox,LIT_END,
  769.                                 name);
  770.                         
  771.           }           
  772.         }/* end of if(contentObject) */           
  773.         /* Get next container item */
  774.         mrc=(PMINIRECORDCORE)WinSendMsg(hwndCnr,CM_QUERYRECORD,MPFROMP(mrc),
  775.                                         MPFROM2SHORT(CMA_NEXT,CMA_ITEMORDER));
  776.       }// end of while(mrc)
  777.     }// end of if(mrc)
  778.   }
  779.   return ulSize;  
  780. }
  781.  
  782.  
  783.  
  784.  
  785.  
  786.  
  787.  
  788.  
  789.  
  790.  
  791.  
  792.  
  793.  
  794.  
  795.