home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1999 November / PCONLINE_11_99.ISO / filesbbs / OS2 / ACDCR032.ZIP / source / CDRTOOLS / SOURCE / cdrtools.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1999-01-08  |  10.4 KB  |  351 lines

  1. /*
  2.  * This program is free software; you can redistribute it and/or modify
  3.  * it under the terms of the GNU General Public License as published by
  4.  * the Free Software Foundation; either version 2, or (at your option)
  5.  * any later version.
  6.  *
  7.  * This program is distributed in the hope that it will be useful,
  8.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  10.  * GNU General Public License for more details.
  11.  *
  12.  * You should have received a copy of the GNU General Public License
  13.  * along with this program; see the file COPYING.  If not, write to
  14.  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  15.  */
  16. #define INCL_DOSSESMGR
  17. #define INCL_DOS
  18. #define INCL_DOSERRORS
  19. #define INCL_WIN
  20. #define INCL_WINDIALOGS
  21.  
  22. #include <os2.h>
  23. #include <stdio.h>
  24. #include <string.h>
  25.  
  26. #include "audiodialog.h"
  27.  
  28. MRESULT EXPENTRY CDToolsDlgProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 );
  29. MRESULT EXPENTRY CDSettingsDlgProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 );
  30.  
  31.  
  32. HINI hini;
  33. char chrCDRecord[CCHMAXPATH];
  34. char chrCDROptions[CCHMAXPATH];
  35.  
  36. main()
  37. {
  38.   HAB hab;
  39.   HMQ hmq;
  40.   ULONG keyLength;
  41.   char profileName[20];
  42.   
  43.   hab = WinInitialize( 0 );
  44.   if(hab) {
  45.     hmq = WinCreateMsgQueue( hab, 100UL );
  46.     if(hmq) {
  47.       sprintf(profileName,"cdrecord.ini");        
  48.       hini=PrfOpenProfile(WinQueryAnchorBlock(HWND_DESKTOP),profileName);
  49.       if(!hini) {
  50.     WinMessageBox(  HWND_DESKTOP,
  51.               HWND_DESKTOP,
  52.               "Warning! Cannot open Ini-file!",
  53.               "",
  54.               0UL,
  55.               MB_OK | MB_ICONEXCLAMATION );
  56.     WinDestroyMsgQueue( hmq );
  57.     WinTerminate( hab );
  58.     return( 1 );
  59.       }/* end of if(!hini) */
  60.       
  61.       keyLength=PrfQueryProfileString(hini,"CDWriter","cdrecord","",chrCDRecord,sizeof(chrCDRecord));
  62.       if(keyLength==1){
  63.     if( WinDlgBox( HWND_DESKTOP, NULLHANDLE, CDSettingsDlgProc, NULLHANDLE,DLGID_SETUP, 0 ) == DID_ERROR )
  64.       {
  65.         WinMessageBox(  HWND_DESKTOP,
  66.               HWND_DESKTOP,
  67.               "Warning! Cannot open Settings dialog!",
  68.               "",
  69.               0UL,
  70.               MB_OK | MB_ICONEXCLAMATION );
  71.         WinDestroyMsgQueue( hmq );
  72.         WinTerminate( hab );
  73.         if(hini)PrfCloseProfile(hini);
  74.         return( 1 );
  75.       }
  76.     if(!PrfWriteProfileString(hini,"CDWriter","cdrecord",chrCDRecord)){
  77.       WinMessageBox(  HWND_DESKTOP,
  78.             HWND_DESKTOP,
  79.             "Warning! Cannot write to Ini-file!",
  80.             "",
  81.             0UL,
  82.             MB_OK | MB_ICONEXCLAMATION );
  83.       WinDestroyMsgQueue( hmq );
  84.       WinTerminate( hab );
  85.       if(hini)PrfCloseProfile(hini);
  86.       return( 1 );
  87.     }
  88.     
  89.     if(!PrfWriteProfileString(hini,"CDWriter","cdroptions",chrCDROptions)){
  90.       WinMessageBox(  HWND_DESKTOP,
  91.             HWND_DESKTOP,
  92.             "Warning! Cannot write to Ini-file!",
  93.             "",
  94.             0UL,
  95.             MB_OK | MB_ICONEXCLAMATION );
  96.       WinDestroyMsgQueue( hmq );
  97.       WinTerminate( hab );
  98.       if(hini)PrfCloseProfile(hini);
  99.       return( 1 );
  100.     };
  101.       }
  102.       PrfQueryProfileString(hini,"CDWriter","cdroptions","",chrCDROptions,sizeof(chrCDROptions));
  103.       
  104.       if( WinDlgBox( HWND_DESKTOP, NULLHANDLE, CDToolsDlgProc, NULLHANDLE,DLGID_CDTOOLS, 0 ) == DID_ERROR )
  105.     {
  106.       WinDestroyMsgQueue( hmq );
  107.       WinTerminate( hab );
  108.       if(hini)PrfCloseProfile(hini);
  109.       DosBeep(100,600);
  110.       return( 1 );
  111.     }
  112.       if(hini)PrfCloseProfile(hini);
  113.       WinDestroyMsgQueue( hmq );
  114.     }
  115.     WinTerminate( hab );
  116.   }
  117.   return( 0 );    
  118. }
  119.  
  120. MRESULT EXPENTRY CDToolsDlgProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 )
  121. {
  122.   HAB hab;
  123.   char chrLoadError[CCHMAXPATH];
  124.   STARTDATA startData={0};
  125.   PSZ pszTitle="CDRecord/2";
  126.   APIRET rc;
  127.   PID pid;
  128.   ULONG ulSessionID=0;
  129.   char chrParams[CCHMAXPATH];
  130.   char chrParams2[20];
  131.   
  132.   switch( msg )
  133.     {
  134.     case WM_INITDLG:
  135.       {
  136.     WinCheckButton(hwnd,RBID_FAST,TRUE);
  137.     WinCheckButton(hwnd,RBID_LOADDISK,TRUE);
  138.     WinCheckButton(hwnd,CBID_DUMMY,TRUE);
  139.     WinCheckButton(hwnd,CBID_FIXDUMMY,TRUE);
  140.       }
  141.       return (MRESULT) TRUE;
  142.     case WM_DESTROY:
  143.       
  144.       break;
  145.     case WM_CLOSE:
  146.       if(WinMessageBox(  HWND_DESKTOP,
  147.                hwnd,
  148.                "Do you really want to quit?",
  149.                "Question",
  150.                0UL,
  151.                MB_OKCANCEL | MB_ICONQUESTION )==MBID_OK)
  152.     WinPostMsg(hwnd,WM_QUIT,(MPARAM)0,(MPARAM)0);
  153.       return 0;
  154.     case WM_COMMAND:
  155.       {
  156.     memset(&startData,0,sizeof(startData));
  157.     startData.Length=sizeof(startData);
  158.     startData.Related=SSF_RELATED_INDEPENDENT;
  159.     startData.FgBg=SSF_FGBG_FORE;
  160.     startData.TraceOpt=SSF_TRACEOPT_NONE;
  161.     startData.PgmTitle=pszTitle;
  162.     startData.PgmName=chrCDRecord;
  163.     startData.InheritOpt=SSF_INHERTOPT_SHELL;
  164.     startData.SessionType=SSF_TYPE_WINDOWABLEVIO;
  165.     startData.PgmControl=SSF_CONTROL_VISIBLE|SSF_CONTROL_MAXIMIZE|SSF_CONTROL_NOAUTOCLOSE;
  166.     startData.InitXPos=30;
  167.     startData.InitYPos=30;
  168.     startData.InitXSize=500;
  169.     startData.InitYSize=400;
  170.     startData.ObjectBuffer=chrLoadError;
  171.     startData.ObjectBuffLen=(ULONG)sizeof(chrLoadError);
  172.     switch( SHORT1FROMMP( mp1 ) )
  173.       {
  174.       case PBID_BLANK:
  175.         if(!WinQueryButtonCheckstate(hwnd,CBID_DUMMY)) {
  176.           if(WinMessageBox(  HWND_DESKTOP,
  177.                    hwnd,
  178.                    "Do you really want to perform a real write?",
  179.                    "Dummy is unchecked!",
  180.                    0UL,
  181.                    MB_OKCANCEL | MB_ICONEXCLAMATION )==MBID_CANCEL)break;
  182.           sprintf(chrParams2,"%s","");
  183.         }
  184.         else
  185.           sprintf(chrParams2,"%s","-dummy");
  186.         if(WinQueryButtonCheckstate(hwnd,RBID_FAST))
  187.           sprintf(chrParams,"%s %s %s",chrCDROptions,chrParams2,"-blank=fast");
  188.         if(WinQueryButtonCheckstate(hwnd,RBID_ALL))
  189.           sprintf(chrParams,"%s %s %s",chrCDROptions,chrParams2,"-blank=all");
  190.         if(WinQueryButtonCheckstate(hwnd,RBID_LASTSESSION))
  191.           sprintf(chrParams,"%s %s %s",chrCDROptions,chrParams2,"-blank=session");
  192.         if(WinQueryButtonCheckstate(hwnd,RBID_UNCLOSE))
  193.           sprintf(chrParams,"%s %s %s",chrCDROptions,chrParams2,"-blank=unclose");
  194.         startData.PgmInputs=chrParams;
  195.         rc=DosStartSession(&startData,&ulSessionID,&pid);                    
  196.         break;
  197.       case PBID_FIX:
  198.         if(!WinQueryButtonCheckstate(hwnd,CBID_FIXDUMMY)) {
  199.           if(WinMessageBox(  HWND_DESKTOP,
  200.                    hwnd,
  201.                    "Do you really want to perform a real write?",
  202.                    "Dummy is unchecked!",
  203.                    0UL,
  204.                    MB_OKCANCEL | MB_ICONEXCLAMATION )==MBID_CANCEL)break;
  205.           sprintf(chrParams,"%s %s",chrCDROptions," -fix");
  206.         }
  207.         else
  208.           sprintf(chrParams,"%s %s",chrCDROptions,"-dummy -fix");            
  209.         startData.PgmInputs=chrParams;
  210.         rc=DosStartSession(&startData,&ulSessionID,&pid);
  211.         break;
  212.       case PBID_MISC:
  213.         if(WinQueryButtonCheckstate(hwnd,RBID_UNLOADDISK))
  214.           sprintf(chrParams,"%s %s",chrCDROptions,"-eject");
  215.         if(WinQueryButtonCheckstate(hwnd,RBID_LOADDISK))
  216.           sprintf(chrParams,"%s %s",chrCDROptions,"-load");
  217.         if(WinQueryButtonCheckstate(hwnd,RBID_RESETDEVICE))
  218.           sprintf(chrParams,"%s %s",chrCDROptions,"-reset");
  219.         if(WinQueryButtonCheckstate(hwnd,RBID_SHOWTOC))
  220.           sprintf(chrParams,"%s %s",chrCDROptions,"-toc");
  221.         startData.PgmInputs=chrParams;
  222.         rc=DosStartSession(&startData,&ulSessionID,&pid);
  223.         break;
  224.       case PBID_EXIT:
  225.         WinPostMsg(hwnd,WM_CLOSE,(MPARAM)0,(MPARAM)0);
  226.         break;
  227.       case PBID_SETTINGS:
  228.         if( WinDlgBox( HWND_DESKTOP, hwnd, CDSettingsDlgProc, NULLHANDLE,DLGID_SETUP, 0 ) == DID_ERROR )
  229.           {
  230.         WinMessageBox(  HWND_DESKTOP,
  231.                   HWND_DESKTOP,
  232.                   "Warning! Cannot open Settings dialog!",
  233.                   "",
  234.                   0UL,
  235.                   MB_OK | MB_ICONEXCLAMATION );
  236.           }
  237.         break;
  238.       default:
  239.         break;
  240.       }
  241.       }
  242.       return (MRESULT) TRUE;
  243.       break;
  244.     }    
  245.   return( WinDefDlgProc( hwnd, msg, mp1, mp2 ) );    
  246. }
  247.  
  248. MRESULT EXPENTRY CDSettingsDlgProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 )
  249. {
  250.   FILEDLG fd = { 0 };
  251.   char profileName[20];
  252.   static HINI hini;
  253.   ULONG keyLength;
  254.   static  char chrPath[CCHMAXPATH];
  255.   static  char chrOptions[CCHMAXPATH];
  256.  
  257.   switch( msg )
  258.     {
  259.     case WM_INITDLG:
  260.       {
  261.     WinSendMsg(WinWindowFromID(hwnd,EFID_CDRECORDPATH),EM_SETTEXTLIMIT,MPFROMSHORT((SHORT)CCHMAXPATH),0);
  262.     WinSendMsg(WinWindowFromID(hwnd,EFID_CDRECORDOPTIONS),EM_SETTEXTLIMIT,MPFROMSHORT((SHORT)CCHMAXPATH),0);
  263.     WinSetWindowText( WinWindowFromID(hwnd,EFID_CDRECORDPATH),chrCDRecord);
  264.     WinSetWindowText( WinWindowFromID(hwnd,EFID_CDRECORDOPTIONS),chrCDROptions);
  265.     sprintf(chrPath,"%s",chrCDRecord);
  266.     sprintf(chrOptions,"%s",chrCDROptions);
  267.     sprintf(profileName,"cdrecord.ini");        
  268.     hini=PrfOpenProfile(WinQueryAnchorBlock(HWND_DESKTOP),profileName);
  269.     if(!hini) {
  270.       WinMessageBox(  HWND_DESKTOP,
  271.             HWND_DESKTOP,
  272.             "Warning! Cannot open Ini-file!",
  273.             "",
  274.             0UL,
  275.             MB_OK | MB_ICONEXCLAMATION );
  276.       WinDismissDlg(hwnd,DID_ERROR);
  277.     }/* end of if(!hini) */                
  278.       }
  279.       return (MRESULT) TRUE;
  280.     case WM_DESTROY:
  281.       if(hini)PrfCloseProfile(hini);
  282.       hini=NULLHANDLE;
  283.       break;
  284.     case WM_CLOSE:
  285.       WinDismissDlg(hwnd,DID_ERROR);
  286.       break;
  287.     case WM_COMMAND:
  288.       {            
  289.     switch( SHORT1FROMMP( mp1 ) )
  290.       {
  291.       case PBID_CDRECORDBROWSE:
  292.         fd.cbSize = sizeof( fd );
  293.         fd.fl = FDS_OPEN_DIALOG|FDS_CENTER;
  294.         fd.pszTitle = "Search CDRecord/2";
  295.         sprintf(fd.szFullFile,"%s","*.exe");
  296.         
  297.         if( WinFileDlg( HWND_DESKTOP, hwnd, &fd ) == NULLHANDLE )
  298.           {
  299.         break;
  300.           }
  301.         if( fd.lReturn == DID_OK )
  302.           {
  303.         WinSetWindowText( WinWindowFromID(hwnd,EFID_CDRECORDPATH), fd.szFullFile );
  304.         sprintf(chrCDRecord,"%s",fd.szFullFile);
  305.           }
  306.         break;
  307.       case DID_OK:
  308.         WinQueryWindowText(WinWindowFromID(hwnd,EFID_CDRECORDOPTIONS),sizeof(chrCDROptions),chrCDROptions);
  309.         if(!PrfWriteProfileString(hini,"CDWriter","cdrecord",chrCDRecord)){
  310.           WinMessageBox(  HWND_DESKTOP,
  311.                 HWND_DESKTOP,
  312.                 "Warning! Cannot write to Ini-file!",
  313.                 "",
  314.                 0UL,
  315.                 MB_OK | MB_ICONEXCLAMATION );
  316.           WinDismissDlg(hwnd,DID_ERROR);
  317.         }
  318.         
  319.         if(!PrfWriteProfileString(hini,"CDWriter","cdroptions",chrCDROptions)){
  320.           WinMessageBox(  HWND_DESKTOP,
  321.                 HWND_DESKTOP,
  322.                 "Warning! Cannot write to Ini-file!",
  323.                 "",
  324.                 0UL,
  325.                 MB_OK | MB_ICONEXCLAMATION );
  326.           WinDismissDlg(hwnd,DID_ERROR);
  327.         };
  328.         WinDismissDlg(hwnd,0);
  329.         break;
  330.       case DID_CANCEL:
  331.         sprintf(chrCDRecord,"%s",chrPath);
  332.         sprintf(chrCDROptions,"%s",chrOptions);
  333.         WinDismissDlg(hwnd,1);
  334.         break;
  335.         
  336.       default:
  337.         break;
  338.       }
  339.       }
  340.       return (MRESULT) TRUE;      
  341.     }    
  342.   return( WinDefDlgProc( hwnd, msg, mp1, mp2 ) );    
  343. }
  344.  
  345.  
  346.  
  347.  
  348.  
  349.  
  350.  
  351.