home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 1 / FFMCD01.bin / bbs / libdisks / d700t799 / disk751.lha / PPMC / Source / PPMC_Main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-11-05  |  17.4 KB  |  665 lines

  1. /*
  2.                             -----------------------
  3.                                   PPMC_Main.c
  4.                                 © 1992 REELSOFT
  5.                             -----------------------
  6. */
  7.  
  8. #include    "PPMC_Main.h"
  9. #include    "PPMC_Proto.h"
  10. #include    "PPMC.h"
  11.  
  12. VOID    main ( int argc, char *argv[] )
  13. {
  14.     Setup () ;
  15.     MainLoop () ;
  16.     Cleanup ( argc ? FROM_CLI : FROM_WB, RETURN_OK ) ;
  17. }
  18. #ifdef    _DCC
  19. VOID    wbmain ( struct WBStartup * wbmsg )
  20. {
  21.     main ( 01, ( long * )wbmsg ) ;
  22. }
  23. #endif
  24.  
  25. //    »»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  26. VOID    About (VOID)
  27. {
  28.     rtEZRequestTags (    PPMC_TITLE" "PPMC_VER"\n"PPMC_CPRIGHT"\n\n"
  29.                         "Written by Reza ELGHAZI\nUsing...\n\n"
  30.                         "SAS/C Compiler v5.10b\n\n"
  31.                         "GadToolsBox v1.4\nCopyright Jaba Development\n\n"
  32.                         "powerpacker.library v35\n& reqtools.library v38\n"
  33.                         "Copyright Nico Francois\n\n"
  34.                         "This program is FREEWARE",
  35.                         "_Continue", NULL, NULL,
  36.                         RT_Window,        PPMCWnd,
  37.                         RT_ReqPos,        REQPOS_CENTERSCR,
  38.                         RT_LockWindow,    TRUE,
  39.                         RT_ShareIDCMP,    TRUE,
  40.                         RT_Underscore,    '_',
  41.                         RT_TextAttr,    &PPMCFnt,
  42.                         RTEZ_ReqTitle,    "About PPMC...",
  43.                         RTEZ_Flags,        EZREQF_CENTERTEXT,
  44.                         TAG_END    ) ;
  45. }
  46.  
  47. //    »»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  48. BOOL    Quit ( VOID )
  49. {
  50.     BOOL    exit ;    
  51.  
  52.     exit = (BOOL)rtEZRequestTags (    "Do you really\n""want to quit ?",
  53.                                     "_Ok|_Cancel",
  54.                                     NULL, NULL,
  55.                                     RT_Window,        PPMCWnd,
  56.                                     RT_ReqPos,        REQPOS_TOPLEFTWIN,
  57.                                     RT_LockWindow,    TRUE,
  58.                                     RT_ShareIDCMP,    TRUE,
  59.                                     RT_Underscore,    '_',
  60.     //                                RT_TextAttr,    &PPMCFnt,
  61.                                     RTEZ_ReqTitle,    PPMC_NAME,
  62.                                     RTEZ_Flags,        EZREQF_CENTERTEXT,
  63.                                     TAG_END    ) ;
  64.     FreeCrMem () ;
  65.     return ( exit ) ;
  66. }
  67.  
  68. //    »»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»» Choosing the File to crunch..
  69. BOOL    Load ( BOOL choose )
  70. {
  71.     struct    rtFileRequester    *filereq ;
  72.     APTR    fr ;
  73.  
  74.     if ( choose ) {
  75.         filereq = rtAllocRequestA ( RT_FILEREQ, NULL ) ;
  76.         if ( filereq == NULL ) {
  77.             DisplayWarning ( "Out of memory !" ) ;
  78.             Cleanup ( 99, RETURN_WARN ) ;
  79.         }
  80.  
  81.         fr = rtFileRequest (    filereq, oldname,
  82.                                 "Select a file to powerpack..",
  83.                                 RT_Window,        PPMCWnd,
  84.                                 RT_ReqPos,        REQPOS_CENTERWIN,
  85.                                 RT_LockWindow,    TRUE,
  86.                                 RT_ShareIDCMP,    TRUE,
  87.                                 RT_Underscore,    '_',
  88.                                 RTFI_OkText,    "_Load",
  89.                                 TAG_END
  90.         ) ;
  91.         if ( fr == FALSE ) {
  92.             rtFreeRequest ( filereq ) ;
  93.             return FALSE ;
  94.         }
  95.         chdir ( filereq->Dir ) ;
  96.         rtFreeRequest ( filereq ) ;
  97.     }
  98.  
  99.     if ( AnalyseFile () == FALSE )
  100.         return FALSE ;
  101.     else
  102.         sprintf ( newname, oldname ) ;
  103.  
  104.     //    ...
  105.     GT_SetGadgetAttrs ( PPMCGadgets [GD_Save],   PPMCWnd, NULL, GA_Disabled, TRUE,  TAG_DONE ) ;
  106.     GT_SetGadgetAttrs ( PPMCGadgets [GD_Start],  PPMCWnd, NULL, GA_Disabled, FALSE, TAG_DONE ) ;
  107.     GT_SetGadgetAttrs ( PPMCGadgets [GD_Crunch], PPMCWnd, NULL, GTNM_Number, 0L, TAG_DONE ) ;
  108.     GT_SetGadgetAttrs ( PPMCGadgets [GD_Gained], PPMCWnd, NULL, GTNM_Number, 0L, TAG_DONE ) ;
  109.  
  110.     ClearMenus () ;
  111.     PPMCNewMenu [NM_Save].nm_Flags        = NM_ITEMDISABLED ;
  112.     PPMCNewMenu [NM_SaveAs].nm_Flags    = NM_ITEMDISABLED ;
  113.     PPMCNewMenu [NM_Start].nm_Flags        = 0 ;
  114.     SetupMenus () ;
  115.  
  116.     FillGauge (0) ;
  117.     FreeCrMem () ;
  118.  
  119.     return TRUE ;
  120. }
  121.  
  122. //    »»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»» Analyse File to Load..
  123. BOOL    AnalyseFile ( VOID )
  124. {
  125.     APTR    *fname = (APTR)&oldname ;
  126.     BPTR    flock ;
  127.     UBYTE    buffer [9] ;
  128.  
  129.     flock = Open ( oldname, MODE_OLDFILE ) ;
  130.     if ( flock == NULL ) {
  131.         rtEZRequestTags    (    "Unable to open \"%s\" !",
  132.                             "_Abort",
  133.                             NULL, &fname,
  134.                             RT_Window,        PPMCWnd,
  135.                             RT_ReqPos,        REQPOS_CENTERWIN,
  136.                             RT_LockWindow,    TRUE,
  137.                             RT_ShareIDCMP,    TRUE,
  138.                             RT_Underscore,    '_',
  139.         //                    RT_TextAttr,    &PPMCFnt,
  140.                             RTEZ_ReqTitle,    PPMC_WARN,
  141.                             RTEZ_Flags,        EZREQF_CENTERTEXT,
  142.                             TAG_END    ) ;
  143.         return FALSE ;
  144.     }
  145.     Read ( flock, buffer, 8 ) ;
  146.     Close ( flock ) ;
  147.  
  148.     //    Check if oldname is an executable file...
  149.     if (    buffer [0] == 0x00 && buffer [1] == 0x00 && buffer [2] == 0x03
  150.         &&    buffer [3] == 0xf3 && buffer [4] == 0x00 && buffer [5] == 0x00
  151.         &&    buffer [6] == 0x00 && buffer [7] == 0x00
  152.         &&    rtEZRequestTags    (    "\"%s\"\nis an Executable File\nLoad it anyway ?",
  153.                                 "_Ok|_Cancel",
  154.                                 NULL, &fname,
  155.                                 RT_Window,        PPMCWnd,
  156.                                 RT_ReqPos,        REQPOS_CENTERWIN,
  157.                                 RT_LockWindow,    TRUE,
  158.                                 RT_ShareIDCMP,    TRUE,
  159.                                 RT_Underscore,    '_',
  160.             //                    RT_TextAttr,    &PPMCFnt,
  161.                                 RTEZ_ReqTitle,    PPMC_WARN,
  162.                                 RTEZ_Flags,        EZREQF_CENTERTEXT,
  163.                                 TAG_END ) == FALSE
  164.     )
  165.         return FALSE ;
  166.  
  167.     buffer [4] = 0x00 ;
  168.     sprintf ( stmsg, "%s", oldname ) ;
  169.     if ( !strcmp ( buffer, "PP20" ) )
  170.         strcat ( stmsg, " (ppacked)" ) ;
  171.     else if ( !strcmp ( buffer, "PX20" ) )
  172.         strcat ( stmsg, " (ppacked & crypted)" ) ;
  173.     strcat ( stmsg, " will be crunched..." ) ;
  174.     GT_SetGadgetAttrs ( PPMCGadgets [GD_Status], PPMCWnd, NULL, GTTX_Text, stmsg, TAG_DONE ) ;
  175.  
  176.     return TRUE ;
  177. }
  178.  
  179. //    »»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»» Choosing a Save File..
  180. BOOL    Save ( ULONG cruneff, BOOL crypt, ULONG checksum, BOOL choose )
  181. {
  182.     struct    rtFileRequester    *filereq ;
  183.     APTR    *fname, fr ;
  184.     BPTR    flock ;
  185.  
  186. #ifdef    LATTICE
  187.     strmfe ( newname, newname, "pp" ) ;
  188. #else
  189.     strcat ( newname, ".pp" ) ;
  190. #endif
  191.     
  192.     fname = (APTR)&newname ;
  193.  
  194.     if ( choose ) {
  195.         filereq = rtAllocRequestA ( RT_FILEREQ, NULL ) ;
  196.         if ( filereq == NULL ) {
  197.             DisplayWarning ( "Out of memory !" ) ;
  198.             return FALSE ;
  199.         }
  200.         fr = rtFileRequest (    filereq, newname,
  201.                                 "Select a file to save..",
  202.                                 RT_Window,        PPMCWnd,
  203.                                 RT_ReqPos,        REQPOS_CENTERWIN,
  204.                                 RT_LockWindow,    TRUE,
  205.                                 RT_ShareIDCMP,    TRUE,
  206.                                 RT_Underscore,    '_',
  207.                                 RTFI_OkText,    "_Save",
  208.                                 RTFI_Flags,        FREQF_SAVE,
  209.                                 TAG_END    ) ;
  210.  
  211.         if ( fr == FALSE ) {
  212.             rtFreeRequest ( filereq ) ;
  213.             return FALSE ;
  214.         }
  215.         chdir ( filereq->Dir ) ;
  216.         rtFreeRequest ( filereq ) ;
  217.     }
  218.  
  219. //    Creating the Save File...
  220.     flock = Open ( newname, MODE_NEWFILE ) ;
  221.     if ( flock == NULL ) {
  222.         rtEZRequestTags    (    "Unable to open \"%s\" !",
  223.                             "_Abort",
  224.                             NULL, &fname,
  225.                             RT_Window,        PPMCWnd,
  226.                             RT_ReqPos,        REQPOS_CENTERWIN,
  227.                             RT_LockWindow,    TRUE,
  228.                             RT_ShareIDCMP,    TRUE,
  229.                             RT_Underscore,    '_',
  230.         //                    RT_TextAttr,    &PPMCFnt,
  231.                             RTEZ_ReqTitle,    PPMC_WARN,
  232.                             RTEZ_Flags,        EZREQF_CENTERTEXT,
  233.                             TAG_END    ) ;
  234.         return FALSE ;
  235.     }
  236.  
  237. //    Writing the Crunch Data Header...
  238.     if ( ppWriteDataHeader ( flock, cruneff, crypt, checksum ) ) {
  239.         //    Writing the Crunched File..
  240.         if ( Write ( flock, cdata, clen ) != clen )
  241.             DisplayWarning ( "Write Error !" ) ;
  242.     }
  243.     else
  244.         DisplayWarning ( "Error writing data header !" ) ;
  245.  
  246.     Close ( flock ) ;
  247.  
  248.     sprintf ( stmsg, "%s is saved.", newname ) ;
  249.     GT_SetGadgetAttrs ( PPMCGadgets [GD_Status], PPMCWnd, NULL, GTTX_Text, stmsg, TAG_DONE ) ;
  250.  
  251. //    ...
  252.     GT_SetGadgetAttrs ( PPMCGadgets [GD_Save],  PPMCWnd, NULL, GA_Disabled, TRUE, TAG_DONE ) ;
  253.     GT_SetGadgetAttrs ( PPMCGadgets [GD_Start], PPMCWnd, NULL, GA_Disabled, TRUE, TAG_DONE ) ;
  254.  
  255.     ClearMenus () ;
  256.     PPMCNewMenu [NM_Save].nm_Flags        = NM_ITEMDISABLED ;
  257.     PPMCNewMenu [NM_SaveAs].nm_Flags    = NM_ITEMDISABLED ;
  258.     PPMCNewMenu [NM_Start].nm_Flags        = NM_ITEMDISABLED ;
  259.     SetupMenus () ;
  260.  
  261.     FillGauge (0) ;
  262.     FreeCrMem () ;
  263.  
  264.     return TRUE ;
  265. }
  266.  
  267. //    »»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  268. BOOL    Crunch ( ULONG cruneff, ULONG bufsize, ULONG decrcol, UBYTE *password  )
  269. {
  270.     WORD    err ;
  271.     ULONG    errtags [] = {    RT_ShareIDCMP,    TRUE,
  272.                             RT_Underscore,    '_',
  273.                             RT_TextAttr,    &PPMCFnt,
  274.                             RTEZ_ReqTitle,    (UBYTE *)"PPMC Error",
  275.                             TAG_END
  276.             } ;
  277.  
  278.     GT_SetGadgetAttrs ( PPMCGadgets [GD_Save],   PPMCWnd, NULL, GA_Disabled, TRUE,  TAG_DONE ) ;
  279.  
  280.     FillGauge (0) ;
  281.     FreeCrMem () ;
  282.  
  283. //    Allocating the Crunching Informations...
  284.     crin = ppAllocCrunchInfo ( cruneff, bufsize, CrStatus, NULL ) ;
  285.     if ( crin == NULL )
  286.         Cleanup ( 99, RETURN_WARN ) ;
  287.  
  288. //    Loading the File to Crunch...
  289.     sprintf ( stmsg, "Loading %s...", newname ) ;
  290.     GT_SetGadgetAttrs ( PPMCGadgets [GD_Status], PPMCWnd, NULL, GTTX_Text, stmsg, TAG_DONE ) ;
  291.  
  292.     err = ppLoadData ( newname, decrcol, NULL, &cdata, &csize, NULL ) ;
  293.     if ( err ) {
  294.         rtEZRequest ( "%s !", "_Abort", NULL, (struct TagItem *)errtags, ppErrorMessage (err) ) ;
  295.         ppFreeCrunchInfo ( crin ) ;
  296.         strcpy ( stmsg, "Load or Drop another file to crunch..." ) ;
  297.         GT_SetGadgetAttrs ( PPMCGadgets [GD_Status], PPMCWnd, NULL, GTTX_Text, stmsg, TAG_DONE ) ;
  298.         return FALSE ;
  299.     }
  300.  
  301. //    Crunching...
  302.     crunched = TRUE ;
  303.     sprintf ( stmsg, "Crunching %s...", newname ) ;
  304.     GT_SetGadgetAttrs ( PPMCGadgets [GD_Status], PPMCWnd, NULL, GTTX_Text, stmsg, TAG_DONE ) ;
  305.  
  306. //    Enable the Abort gadget...
  307.     GT_SetGadgetAttrs ( PPMCGadgets [GD_Abort], PPMCWnd, NULL, GA_Disabled, FALSE, TAG_DONE ) ;
  308.  
  309.     SetAPen ( ppmcRP, 3 ) ;
  310.     clen = ppCrunchBuffer ( crin, cdata, csize ) ;
  311.  
  312. //    Checking wether or not to crypt the file...
  313.     if ( PPMCGadgets [GD_Crypt]->Flags & GFLG_SELECTED )
  314.         ppDecrypt ( cdata, clen - 4, ppCalcPasskey ( password ) ) ;
  315.  
  316. //    Disable the Abort gadget...
  317.     GT_SetGadgetAttrs ( PPMCGadgets [GD_Abort], PPMCWnd, NULL, GA_Disabled, TRUE, TAG_DONE ) ;
  318.  
  319.     switch ( clen ) {
  320.         default :
  321.                 GT_SetGadgetAttrs ( PPMCGadgets [GD_Save],  PPMCWnd, NULL, GA_Disabled, FALSE,  TAG_DONE ) ;
  322.                 sprintf ( stmsg, "%s crunched.", newname ) ;
  323.                 GT_SetGadgetAttrs ( PPMCGadgets [GD_Status], PPMCWnd, NULL, GTTX_Text, stmsg, TAG_DONE ) ;
  324.                 FillGauge (3) ;
  325.                 GT_SetGadgetAttrs ( PPMCGadgets [GD_Crunch], PPMCWnd, NULL, GTNM_Number, 100L, TAG_DONE ) ;
  326.  
  327.                 ClearMenus () ;
  328.                 PPMCNewMenu [NM_Save].nm_Flags        = 0 ;
  329.                 PPMCNewMenu [NM_SaveAs].nm_Flags    = 0 ;
  330.                 SetupMenus () ;
  331.  
  332.                 DisplayBeep (Scr) ;
  333.  
  334.                 return TRUE ;
  335.  
  336.         case PP_CRUNCHABORTED :
  337.                 rtEZRequestTags    (    "Crunching aborted...",
  338.                                     "_Resume",
  339.                                     NULL, NULL,
  340.                                     RT_Window,        PPMCWnd,
  341.                                     RT_ReqPos,        REQPOS_POINTER,
  342.                                     RT_LockWindow,    TRUE,
  343.                                     RT_ShareIDCMP,    TRUE,
  344.                                     RT_Underscore,    '_',
  345.                 //                    RT_TextAttr,    &PPMCFnt,
  346.                                     RTEZ_ReqTitle,    PPMC_WARN,
  347.                                     TAG_END    ) ;
  348.                 break ;
  349.  
  350.         case PP_BUFFEROVERFLOW :
  351.                 DisplayWarning ( "Buffer Overflow !" ) ;
  352.                 break ;
  353.     }
  354.     sprintf ( stmsg, "%s will be crunched...", newname ) ;
  355.     GT_SetGadgetAttrs ( PPMCGadgets [GD_Status], PPMCWnd, NULL, GTTX_Text, stmsg, TAG_DONE ) ;
  356.  
  357.     FillGauge (0) ;
  358.     FreeCrMem () ;
  359.  
  360.     return FALSE ;
  361. }
  362.  
  363. //    »»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  364. BOOL    __stdargs __saveds CrStatus ( ULONG sofar, ULONG crunlen, ULONG totlen, APTR userdata )
  365. {
  366.     struct    IntuiMessage    *imsg ;
  367.     ULONG    crunch, gained ;
  368.  
  369.     if ( sofar ) {
  370.         crunch = ( sofar * 100L ) / totlen ;
  371.         gained = 100L - ( 100L * crunlen) / sofar ;
  372.  
  373.         RectFill ( ppmcRP, 14, PPMCWnd->BorderTop + 85, 14 + 197 * sofar / totlen, PPMCWnd->BorderTop + 98 ) ;
  374.         GT_SetGadgetAttrs ( PPMCGadgets [GD_Crunch], PPMCWnd, NULL, GTNM_Number, crunch, TAG_DONE ) ;
  375.         GT_SetGadgetAttrs ( PPMCGadgets [GD_Gained], PPMCWnd, NULL, GTNM_Number, gained, TAG_DONE ) ;
  376.     }
  377. //    ...
  378.     if ( imsg = GT_GetIMsg ( PPMCWnd->UserPort ) ) {
  379.         if ( imsg->Class == GADGETUP
  380.             && ((struct Gadget *)(imsg->IAddress))->GadgetID == GD_Abort )
  381.             return FALSE ;
  382.         else
  383.             GT_ReplyIMsg ( imsg ) ;
  384.     }
  385.  
  386.     return TRUE ;
  387. }
  388.  
  389. //    »»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  390. VOID    FillGauge ( UBYTE pen )
  391. {
  392.     SetAPen ( ppmcRP, pen ) ;
  393.     RectFill ( ppmcRP, 14,PPMCWnd->BorderTop + 85,210,PPMCWnd->BorderTop + 98 ) ;
  394. }
  395.  
  396. VOID    FreeCrMem ( VOID )
  397. {
  398.     if ( crunched == TRUE ) {
  399.         FreeMem ( cdata, csize ) ;
  400.         ppFreeCrunchInfo (crin) ;
  401.         crunched = FALSE ;
  402.     }
  403. }
  404.  
  405. //    »»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  406. VOID    MainLoop (VOID)
  407. {
  408. #ifdef    PPMC_CX
  409.     ULONG    cxsig ;
  410. #endif
  411.     ULONG    globalsig, winsig, appwinsig,
  412.             cruneff        = 4L,    bufsize        = 0L,
  413.             decrcol        = 4L,    checksum    = 0L ;
  414.     UBYTE    password [17] ;
  415.     BOOL    quit    = FALSE,
  416.             crypt    = FALSE ;
  417.  
  418.     password [0] = newname [0] = oldname [0] = 0x00 ;
  419.  
  420.     appwinsig    = 1L << msgport->mp_SigBit ;
  421.     winsig        = 1L << PPMCWnd->UserPort->mp_SigBit ;
  422. #ifdef    PPMC_CX
  423.     cxsig        = 1L << BrokerMP->mp_SigBit ;
  424. #endif
  425.  
  426.     globalsig    = (    appwinsig | winsig
  427. #ifdef    PPMC_CX
  428.                     | SIGBREAKF_CTRL_C | cxsig
  429. #endif
  430.     ) ;
  431.  
  432.     do {
  433.         if ( Wait (globalsig) ) {
  434.             if ( msgport && appwinsig ) {
  435.                 struct    AppMessage    *amsg ;
  436.                 UBYTE    filepath [256] ;
  437.  
  438.                 while ( amsg = (struct AppMessage *)GetMsg (msgport) ) {
  439. #ifdef    LATTICE
  440.                     getpath ( amsg->am_ArgList->wa_Lock, filepath ) ;
  441. #else
  442.                     NameFromLock ( amsg->am_ArgList->wa_Lock, filepath, 256 ) ;
  443. #endif
  444.                     chdir ( filepath ) ;
  445.                     strcpy ( oldname, amsg->am_ArgList->wa_Name ) ;
  446.                     Load ( FALSE ) ;
  447.  
  448.                     ReplyMsg ( (struct Message *)amsg ) ;
  449.                 }
  450.             }
  451.             //    ...
  452.             if ( winsig ) {
  453.                 struct    IntuiMessage    *imsg ;
  454.                 struct    Gadget            *object ;
  455.                 struct    MenuItem        *item ;
  456.                 UWORD    code ;
  457.                 BOOL    loop ;
  458.  
  459.                 while ( imsg = GT_GetIMsg ( PPMCWnd->UserPort ) ) {
  460.                     object    = imsg->IAddress;
  461.                     code    = imsg->Code ;
  462.                     loop    = TRUE ;
  463.  
  464.                     switch ( imsg->Class ) {
  465.                         case REFRESHWINDOW :
  466.                             GT_BeginRefresh ( PPMCWnd ) ;
  467.                             PPMCRender () ;
  468.                             if ( crunched == TRUE )
  469.                                 FillGauge (3) ;
  470.                             GT_EndRefresh ( PPMCWnd, TRUE ) ;
  471.                             break ;
  472.  
  473.                         case CLOSEWINDOW :
  474.                             quit = Quit () ;
  475.                             break ;
  476.  
  477.                         case GADGETUP :
  478.                             switch ( object->GadgetID ) {
  479.                                 case GD_About :
  480.                                     About () ;
  481.                                     break ;
  482.  
  483.                                 case GD_Load :
  484.                                     Load ( TRUE ) ;
  485.                                     break ;
  486.  
  487.                                 case GD_Save :
  488.                                     Save ( cruneff, crypt, checksum, TRUE ) ;
  489.                                     break ;
  490.  
  491.                                 case GD_Start :
  492.                                     if ( crypt == TRUE && ppEnterPassword ( Scr, password ) == TRUE )
  493.                                         checksum = ppCalcChecksum ( password ) ;
  494.                                     Crunch ( cruneff, bufsize, decrcol, password ) ;
  495.                                     break ;
  496.  
  497.                                 case GD_Crypt :
  498.                                     crypt = !crypt ;
  499.  
  500.                                     ClearMenus () ;
  501.                                     if ( crypt == TRUE )
  502.                                         PPMCNewMenu [NM_Password].nm_Flags = CHECKIT|CHECKED|MENUTOGGLE ;
  503.                                     else
  504.                                         PPMCNewMenu [NM_Password].nm_Flags = CHECKIT|MENUTOGGLE ;
  505.                                     SetupMenus () ;
  506.  
  507.                                     break ;
  508.                             }
  509.                             break ;
  510.  
  511.                         case GADGETDOWN :
  512.                             switch ( object->GadgetID ) {
  513.                                 case GD_CrunEff :
  514.                                     cruneff = code ;
  515.                                     break ;
  516.  
  517.                                 case GD_BufSize :
  518.                                     bufsize = code ;
  519.                                     break ;
  520.  
  521.                                 case GD_DecrCol :
  522.                                     decrcol = code ;
  523.                                     break ;
  524.                             }
  525.                             break ;
  526.  
  527.                         case MENUPICK :
  528.                             while ( loop == TRUE && code != MENUNULL ) {
  529.                                 item = ItemAddress ( PPMCMenus, code ) ;
  530.  
  531.                                 switch ( MENUNUM (code) ) {
  532.                                     case 0 :        //    Project Menu
  533.                                         switch ( ITEMNUM (code) ) {
  534.                                             case 0 :    //    About...
  535.                                                 About () ;
  536.                                                 break ;
  537.  
  538.                                             case 2 :    //    Load...
  539.                                                 Load ( TRUE ) == TRUE ;
  540.                                                 loop = FALSE ;
  541.                                                 break ;
  542.  
  543.                                             case 3 :    //    Save
  544.                                             case 4 :    //    Save As...
  545.                                                 loop = !Save ( cruneff, crypt, checksum, (BOOL)(ITEMNUM(code)-3) ) ;
  546.                                                 break ;
  547.  
  548.                                             case 6 :    //    Quit...
  549.                                                 quit = Quit () ;
  550.                                                 break ;
  551.                                         }
  552.                                         break ;
  553.  
  554.                                     case 1 :        //    Parameters Menu
  555.                                         switch ( ITEMNUM (code) ) {
  556.                                             case 0 :    //    Efficiency
  557.                                                 cruneff = SUBNUM (code) ;
  558.                                                 GT_SetGadgetAttrs ( PPMCGadgets [GD_CrunEff], PPMCWnd, NULL, GTMX_Active, cruneff, TAG_DONE ) ;
  559.                                                 break ;
  560.  
  561.                                             case 1 :    //    Speedup Buffer
  562.                                                 bufsize = SUBNUM (code) ;
  563.                                                 GT_SetGadgetAttrs ( PPMCGadgets [GD_BufSize], PPMCWnd, NULL, GTMX_Active, bufsize, TAG_DONE ) ;
  564.                                                 break ;
  565.  
  566.                                             case 2 :    //    Decrunching Effect
  567.                                                 decrcol = SUBNUM (code) ;
  568.                                                 GT_SetGadgetAttrs ( PPMCGadgets [GD_DecrCol], PPMCWnd, NULL, GTMX_Active, decrcol, TAG_DONE ) ;
  569.                                                 break ;
  570.  
  571.                                             case 3 :    //    Password
  572.                                                 crypt = !crypt ;
  573.                                                 GT_SetGadgetAttrs ( PPMCGadgets [GD_Crypt], PPMCWnd, NULL, GTCB_Checked, crypt, TAG_DONE ) ;
  574.                                                 break ;
  575.                                         }
  576.                                         break ;
  577.  
  578.                                     case 2 :    //    Crunching Menu
  579.                                         if ( ITEMNUM (code) == 0 ) {    //    Start
  580.                                             if ( crypt == TRUE && ppEnterPassword ( Scr, password ) == TRUE )
  581.                                                 checksum = ppCalcChecksum ( password ) ;
  582.                                             Crunch ( cruneff, bufsize, decrcol, password ) ;
  583.                                             loop = FALSE ;
  584.                                         }
  585.                                         break ;
  586.                                 }
  587.                                 code = item->NextSelect ;
  588.                             }
  589.                             break ;
  590.                     }
  591.                     GT_ReplyIMsg (imsg) ;
  592.                 }
  593.             }
  594. #ifdef    PPMC_CX
  595.             if ( SIGBREAKF_CTRL_C ) {
  596.                 FreeCrMem () ;
  597.                 quit = TRUE ;
  598.             }
  599.             if ( msgport && cxsig ) {
  600.                 CxMsg    *cxmsg ;
  601.                 ULONG    msgid, msgtype ;
  602.  
  603.                 while ( cxmsg = (CxMsg *)GetMsg ( BrokerMP ) ) {
  604.                     msgid    = CxMsgID    (cxmsg) ;
  605.                     msgtype    = CxMsgType    (cxmsg) ;
  606.                     ReplyMsg ( (struct Message *)cxmsg ) ;
  607.  
  608.                     switch ( msgtype ) {
  609.                         case CXM_IEVENT :
  610.                             break ;
  611.  
  612.                         case CXM_COMMAND :
  613.                             switch ( msgid ) {
  614.                                 case CXCMD_ENABLE :
  615.                                     ActivateCxObj ( broker, 0L ) ;
  616.                                     if ( OpenPPMCWindow () ) {
  617.                                         DisplayWarning ( "Unable to reopen PPMC Window !" ) ;
  618.                                         quit = TRUE ;
  619.                                         break ;
  620.                                     }
  621.                                     appwin = AddAppWindow ( 1,0, PPMCWnd, msgport, NULL ) ;
  622.                                     if ( appwin == NULL ) {
  623.                                         DisplayWarning ( "Unable to add an AppWindow !" ) ;
  624.                                         quit = TRUE ;
  625.                                     }
  626.                                     break ;
  627.  
  628.                                 case CXCMD_DISABLE :
  629.                                     ActivateCxObj ( broker, 1L ) ;
  630.                                     FreeCrMem () ;
  631.                                     ClosePPMCWindow () ;
  632.                                     if (appwin)
  633.                                         RemoveAppWindow (appwin) ;
  634.                                     break ;
  635.  
  636.                                 case CXCMD_KILL :
  637.                                     FreeCrMem () ;
  638.                                     quit = TRUE ;
  639.                                     break ;
  640.                             }
  641.                             break ;
  642.                     }
  643.                 }
  644.             }
  645. #endif
  646.         }
  647.     } while ( quit == FALSE ) ;
  648. }
  649.  
  650. VOID    DisplayWarning ( UBYTE *message )
  651. {
  652.     rtEZRequestTags    (    message,
  653.                         "_Abort",
  654.                         NULL, NULL,
  655.                         RT_Window,        PPMCWnd,
  656.                         RT_ReqPos,        REQPOS_CENTERWIN,
  657.                         RT_LockWindow,    TRUE,
  658.                         RT_ShareIDCMP,    TRUE,
  659.                         RT_Underscore,    '_',
  660.                         RT_TextAttr,    &PPMCFnt,
  661.                         RTEZ_ReqTitle,    PPMC_WARN,
  662.                         TAG_END    ) ;
  663. }
  664.  
  665. //    ...