home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d8xx / d812 / ppmc.lha / PPMC / Source / PPMC1.2b_source.lha / setup.c < prev    next >
C/C++ Source or Header  |  1993-01-27  |  5KB  |  189 lines

  1. /*
  2.                             ----------------------
  3.                                     setup.c
  4.                              © 1992,1993 REELSOFT
  5.                             ----------------------
  6. */
  7.  
  8. #include    <proto/asl.h>
  9. #include    <proto/dos.h>
  10. #include    <proto/exec.h>
  11. #include    <proto/gadtools.h>
  12. #include    <proto/graphics.h>
  13. #include    <proto/powerpacker.h>
  14. #include    <proto/reqtools.h>
  15. #include    <proto/utility.h>
  16. #include    <proto/wb.h>
  17.  
  18. #include    <clib/locale_protos.h>
  19. #include    <pragmas/locale_pragmas.h>
  20.  
  21. #include    <libraries/dos.h>
  22. #include    <libraries/ppbase.h>
  23. #include    <libraries/reqtools.h>
  24. #include    <graphics/gfxbase.h>
  25.  
  26. #include    <stdlib.h>
  27.  
  28. #include    "protos.h"
  29. #include    "macros.h"
  30. #include    "debug.h"
  31.  
  32. #include    "ppmc.h"
  33. #include    "setup.h"
  34. #include    "locale.h"
  35.  
  36. //""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  37. VOID    __regargs _CXBRK (VOID)
  38. {
  39.     Printf("\n\033[32mPPMC:\033[31m \033[1m%s...\033[0m\n",LOC(MSG_CLI_BREAK)) ;
  40.     FreeCrMem() ;
  41.     Cleanup (EXIT_SUCCESS) ;
  42. }
  43. //""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  44. VOID    Setup (VOID)
  45. {
  46.     //    opening the locale.library if available,
  47.     //    and reading all the translated strings :
  48.     if (LocaleBase = (struct LocaleBase *)OpenLibrary ("locale.library",38L)) {
  49.         struct    Catalog    *catalog = OpenCatalog (NULL,"ppmc.catalog",OC_Language,sup.language,TAG_DONE) ;
  50.         if (catalog) {
  51.             UBYTE    n ;
  52.             for (n=0 ; n<=MSG_PER_PACKED ; n++)
  53.                 AppStrings[n].as_Str = GetCatalogStr (catalog,n,AppStrings[n].as_Str) ;
  54.             CloseCatalog (catalog) ;
  55.         }
  56.     }
  57.  
  58.     //    opening reqtools.library :
  59.     if (NOT sup.cli) {
  60.         if (NOT (ReqToolsBase = (struct ReqToolsBase *)OpenLibrary (REQTOOLSNAME,REQTOOLSVERSION)))
  61.             Cleanup (EXIT_FAILURE) ;
  62.         REQTITLE = (ULONG)LOC(MSG_TITLE_WARNING) ;
  63.     }
  64.  
  65.     //    opening the powerpacker.library :
  66.     if (NOT (PPBase = (struct PPBase *)OpenLibrary (PPNAME,PPVERSION))) {
  67.         if (sup.cli)
  68.             Printf ("\033[32mPPMC:\033[31m \033[1m%s !\033[0m\n",LOC(MSG_PPACKER_VER)) ;
  69.         else
  70.             rtEZRequest ("%s !",LOC(MSG_OK_ABORT),NULL,rttags,LOC(MSG_PPACKER_VER)) ;
  71.         Cleanup (EXIT_FAILURE) ;
  72.     }
  73.  
  74.     //    open the utility.library :
  75.     if (NOT (UtilityBase = OpenLibrary ("utility.library",37L))) {
  76.         if (sup.cli)
  77.             Printf ("\033[32mPPMC:\033[31m \033[1m%s !\033[0m\n",LOC(MSG_OS_VER)) ;
  78.         else
  79.             rtEZRequest ("%s !",LOC(MSG_OK_ABORT),NULL,rttags,LOC(MSG_OS_VER)) ;
  80.         Cleanup (EXIT_FAILURE) ;
  81.     }
  82.  
  83.     password[0] = 0x00 ;
  84.     pac.eff    = (pac.eff>0&&pac.eff<=5)?(pac.eff-1):4 ;
  85.     pac.buf    = (pac.buf>0&&pac.buf<=3)?(pac.buf-1):0 ;
  86.     pac.dec    = (pac.dec>0&&pac.dec<=5)?(pac.dec-1):4 ;
  87.  
  88.     //    invoked from CLI ? well, we have all we need, let's return to main()..
  89.     if (sup.cli)
  90.         return ;
  91.  
  92.     //    otherwise, we have to open several other libraries :
  93.     if (   NOT(IntuitionBase    = (struct IntuitionBase *)OpenLibrary ("intuition.library",37L))
  94.         || NOT(GfxBase            = (struct GfxBase *)OpenLibrary (GRAPHICSNAME,37L))
  95.         || NOT(WorkbenchBase    = OpenLibrary (WORKBENCH_NAME,37L))
  96.         || NOT(GadToolsBase        = OpenLibrary ("gadtools.library",37L)) )
  97.         Cleanup (RETURN_ERROR) ;
  98.  
  99.     //    try to open the asl.library for the file requester :
  100.     if (sup.asl)
  101.         AslBase = OpenLibrary (AslName,37L) ;
  102.  
  103.     //    initializing and Adding the custom font :
  104.     FontInit() ;
  105.     sup.font = TRUE ;
  106.  
  107.     //    locking the `sup.pubscreen' screen (Workbench by default) :
  108.     if (SetupScreen()) {
  109.         rtEZRequest ("%s !",LOC (MSG_OK_ABORT),NULL,rttags,LOC(MSG_LOCK_SCREEN)) ;
  110.         Cleanup (EXIT_FAILURE) ;
  111.     }
  112.  
  113.     //    opening PPMC Window :
  114.     if (SetupWindow()) {
  115.         rtEZRequest ("%s !",LOC(MSG_OK_ABORT),NULL,rttags,LOC(MSG_OPEN_WINDOW)) ;
  116.         Cleanup (EXIT_FAILURE) ;
  117.     }
  118.     else {
  119.         struct    Process    *process = (struct Process *) FindTask(0) ;
  120.         process->pr_WindowPtr = Wnd ;
  121.     }
  122.  
  123.     //    creating a Message Port :
  124.     MsgPort = CreateMsgPort() ;
  125.     if (NOT MsgPort) {
  126.         DEBUG_MSG (MSG_MSGPORT_DEBUG) ;
  127.         Cleanup (EXIT_FAILURE) ;
  128.     }
  129.     else {    //    adding an AppWindow :
  130.         AppWin = AddAppWindow (1,0,Wnd,MsgPort,NULL) ;
  131.         if (NOT AppWin) {
  132.             DEBUG_MSG (MSG_APPWIN_DEBUG) ;
  133.             DeleteMsgPort (MsgPort) ;
  134.             MsgPort = NULL ;
  135.         }
  136.     }
  137.  
  138.     //    getting the Gadgets short-cut key code :
  139.     key.save    = ShCutKey (MSG_SAVE_GAD,    'S') ;
  140.     key.pack    = ShCutKey (MSG_PACK_GAD,    'P') ;
  141.     key.unpack    = ShCutKey (MSG_UNPACK_GAD,    'U') ;
  142.     key.encrypt    = ShCutKey (MSG_ENCRYPT_GAD,'E') ;
  143.  
  144.     name.old[0] = name.new[0] = 0x00 ;
  145. }
  146. //""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  147. VOID    Cleanup (UBYTE errcode)
  148. {
  149.     FreeCrMem() ;
  150.  
  151.     if (NOT sup.cli) {
  152.         if (AppWin)
  153.             RemoveAppWindow (AppWin) ;
  154.         if (MsgPort)
  155.             DeleteMsgPort (MsgPort) ;
  156.  
  157.         CloseDownWindow() ;
  158.         CloseDownScreen() ;
  159.  
  160.         if (sup.font)
  161.             RemFont (&Font) ;
  162.  
  163.         //    closing opened libraries :
  164.         if (GadToolsBase)                                //    gadtools.library
  165.             CloseLibrary (GadToolsBase) ;
  166.         if (AslBase)                                    //    asl.library
  167.             CloseLibrary (AslBase) ;
  168.         if (WorkbenchBase)                                //    workbench.library
  169.             CloseLibrary (WorkbenchBase) ;
  170.         if (GfxBase)                                    //    graphics.library
  171.             CloseLibrary ((struct Library *)GfxBase) ;
  172.         if (IntuitionBase)                                //    intuition.library
  173.             CloseLibrary ((struct Library *)IntuitionBase) ;
  174.     }
  175.  
  176.     if (UtilityBase)                                    //    utility.library
  177.         CloseLibrary (UtilityBase) ;
  178.     if (PPBase)                                            //    powerpacker.library
  179.         CloseLibrary ((struct Library *)PPBase) ;
  180.     if (ReqToolsBase)                                    //    reqtools.library
  181.         CloseLibrary ((struct Library *)ReqToolsBase) ;
  182.  
  183.     if (LocaleBase)                                        //    locale.library
  184.         CloseLibrary ((struct Library *)LocaleBase) ;
  185.  
  186.     exit (errcode) ;
  187. }
  188.  
  189. //    ...