home *** CD-ROM | disk | FTP | other *** search
/ BMUG PD-ROM A / PD-ROM A.iso / Utility / Virus Checkers / Disinfectant 2.5.1 / Source Code for 2.4 / Source Code / init.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-10-02  |  6.0 KB  |  246 lines  |  [TEXT/MPS ]

  1. /*______________________________________________________________________
  2.  
  3.     init.c - Initialization Module
  4.     
  5.     Copyright © 1988, 1989, 1990 Northwestern University.  Permission is granted
  6.     to use this code in your own projects, provided you give credit to both
  7.     John Norstad and Northwestern University in your about box or document.
  8.     
  9.     This module takes care of program intialization.
  10. _____________________________________________________________________*/
  11.  
  12.  
  13. #pragma load "precompile"
  14. #include "utl.h"
  15. #include "rez.h"
  16. #include "glob.h"
  17. #include "misc.h"
  18. #include "main.h"
  19. #include "pref.h"
  20. #include "help.h"
  21. #include "abou.h"
  22. #include "init.h"
  23. #include "prog.h"
  24.  
  25. #pragma segment init
  26.  
  27. /*______________________________________________________________________
  28.  
  29.     MyGrowZone - Grow Zone Procedure.
  30.     
  31.     Entry:    cbNeeded = number of bytes needed.
  32. _____________________________________________________________________*/
  33.  
  34.  
  35. #pragma segment Main
  36.  
  37. static pascal long MyGrowZone (Size cbNeeded)
  38.  
  39. {
  40. #pragma unused (cbNeeded)
  41.  
  42.     if (NoMemFullAlert) return 0;
  43.     misc_Notify(requiresAttn, true);
  44.     (void) utl_StopAlert(noMemID, nil, 0);
  45.     ExitToShell();
  46. };
  47.  
  48. #pragma segment init
  49.  
  50. /*______________________________________________________________________
  51.  
  52.     init_InitMem - Initialize Memory.
  53. _____________________________________________________________________*/
  54.  
  55.  
  56. #pragma segment Main
  57.  
  58. void init_InitMem (void)
  59.  
  60. {
  61.     /* Increase stack space by 20,000 bytes */
  62.     
  63.     SetApplLimit(GetApplLimit() - 20000);
  64.     
  65.     /* Expand the application heap zone to the maximum. */
  66.     
  67.     MaxApplZone();
  68.     
  69.     /* Allocate a bunch of master pointers. */
  70.     
  71.     MoreMasters();
  72.     MoreMasters();
  73.     MoreMasters();
  74.     MoreMasters();
  75. };
  76.  
  77. #pragma segment init
  78.  
  79. /*______________________________________________________________________
  80.  
  81.     init_Initialize - Initialize the Program.
  82.     
  83.     Ths routine is put in its own segment, which is unloaded after
  84.     it's used.
  85. _____________________________________________________________________*/
  86.  
  87.  
  88. void init_Initialize (void)
  89.  
  90. {
  91.     Handle            rectHandle;            /* handle to rectangle list */
  92.     short                i;                        /* loop index */
  93.     FCBPBRec            fcbBlock;            /* file info param block */
  94.     EventRecord        event;                /* event record */
  95.     Str255            apName;                /* name of Disinfectant application file */
  96.     short                apRefNum;            /* refnum of Disinfectant applicaion file */
  97.     Handle            apParam;                /* application parameters */
  98.     FInfo                fndrInfo;            /* Finder info */
  99.     
  100.     /* Initialize all the managers. */
  101.  
  102.     InitGraf(&qd.thePort);
  103.     InitFonts();
  104.     FlushEvents(everyEvent, 0);
  105.     InitWindows();
  106.     InitMenus();
  107.     TEInit();
  108.     InitDialogs(nil);
  109.     
  110.     /* Establish a grow zone procedure to catch out of memory conditions. */ 
  111.     
  112.     CouldAlert(noMemID);
  113.     SetGrowZone(MyGrowZone);
  114.     
  115.     /* Call WaitNextEvent a few times to force our window to initially appear
  116.         in the foreground.  See TN 180. */
  117.         
  118.     utl_WaitNextEvent(everyEvent, &event, 0, nil);
  119.     utl_WaitNextEvent(everyEvent, &event, 0, nil);
  120.     
  121.     /* Check to make sure we have HFS. */
  122.     
  123.     if (*(short*)FSFCBLen <= 0) {
  124.         (void) utl_StopAlert(noHFSID, nil, 0);
  125.         ExitToShell();
  126.     };
  127.     
  128.     /* Get the ROM environment. */
  129.     
  130.     OldRom = utl_Rom64();
  131.     
  132.     /* Get the file ref nums of the system file and Sample. */
  133.     
  134.     SysRefNum = *((short*)SysMap);
  135.     DfectRefNum = *((short*)CurMap);
  136.     DfectVol = utl_GetApplVol();
  137.     
  138.     /* Get the system volume reference number and the directory id of
  139.         the blessed folder. */
  140.         
  141.     SysVol = utl_GetSysVol();
  142.     if (!utl_VolIsMFS(SysVol)) {
  143.         fcbBlock.ioNamePtr = nil;
  144.         fcbBlock.ioVRefNum = 0;
  145.         fcbBlock.ioRefNum = SysRefNum;
  146.         fcbBlock.ioFCBIndx = 0;
  147.         (void) PBGetFCBInfo(&fcbBlock, false);
  148.         SysDirID = fcbBlock.ioFCBParID;
  149.     };
  150.     
  151.     /* Check to make sure all the packages we need exist.  If they don't 
  152.         exist, put up an alert telling the user we require system 3.2 or 
  153.         later and exit to shell. */
  154.         
  155.     if (!utl_CheckPack(listMgr, false) || !utl_CheckPack(stdFile, false) || 
  156.         !utl_CheckPack(dskInit, false) || !utl_CheckPack(intUtil, false) || 
  157.         !utl_CheckPack(bdConv, false)) {
  158.         (void) utl_StopAlert(badSysID, nil, 0);
  159.         ExitToShell();
  160.     };
  161.     
  162.     /* Determine whether or not the system has the shutdown trap.
  163.         (See TN 156).*/
  164.     
  165.     SysHasShutDown = NGetTrapAddress(_ShutDown & 0x3ff, ToolTrap) !=
  166.         NGetTrapAddress(_Unimplemented & 0x3ff, ToolTrap);
  167.         
  168.     /* Get the long sleep time. */
  169.     
  170.     LongSleep = utl_GetLongSleep();
  171.     
  172.     /* Get the cursors. */
  173.     
  174.     Watch = GetCursor(watchCursor);
  175.     HelpCurs = GetCursor(helpCursID);
  176.     IBeamCurs = GetCursor(iBeamCursor);
  177.     
  178.     /* Initialize the menus. */
  179.  
  180.     SetMenuBar(GetNewMBar(mBarID));
  181.     AddResMenu(GetMHandle(appleMID), (ResType) 'DRVR');
  182.     DrawMenuBar();
  183.     
  184.     /* Initialize the drag rectangle. */
  185.     
  186.     DragRect = (***(RgnHandle*)GrayRgn).rgnBBox;
  187.     InsetRect(&DragRect, dragSlop, dragSlop);
  188.     
  189.     /* Get the rectangle list. */
  190.     
  191.     rectHandle = GetResource(rectType, rectID);
  192.     (void) memcpy(RectList, *rectHandle, sizeof(Rect)*numRects);
  193.     ReleaseResource(rectHandle);
  194.     
  195.     /* Check Disinfectant's bundle bit.  If it's not set, set the bundle bit
  196.         and clear the inited bit.  This tells the Finder to try again to read
  197.         the bundle.
  198.         
  199.         This code is present because with version 2.0 some users reported that
  200.         the Disinfectant file appeared on their desktop with no icon after being
  201.         unstuffed.
  202.         
  203.         We only do this if the file has type APPL, to avoid setting the bundle bit
  204.         on Think C project files in the Think C sample program.  (Thanks, Ephraim!) */
  205.     
  206.     GetAppParms(apName, &apRefNum, &apParam);
  207.     if (!GetFInfo(apName, 0, &fndrInfo) && !(fndrInfo.fdFlags & fHasBundle) &&
  208.         fndrInfo.fdType == 'APPL') {
  209.         fndrInfo.fdFlags |= fHasBundle;
  210.         fndrInfo.fdFlags &= ~fInited;
  211.         SetFInfo(apName, 0, &fndrInfo);
  212.     };
  213.     
  214.     /* Initialize the preferences. */
  215.     
  216.     misc_ReadPref();
  217.     
  218.     /* Reopen windows, in back-to-front order. */
  219.     
  220.     for (i = Prefs.numOpenWind-1; i >= 0; i--) {
  221.         switch (Prefs.openWind[i]) {
  222.             case mainWind:
  223.                 main_Open();
  224.                 break;
  225.             case helpWind:
  226.                 help_Open(0);
  227.                 break;
  228.             case prefWind:
  229.                 pref_Open();
  230.                 break;
  231.             case abouWind:
  232.                 abou_Open();
  233.                 break;
  234.         };
  235.         while (EventAvail(updateMask | activMask, &event)) prog_Event();
  236.     };
  237.     
  238.     /* Initialize the cursor. */
  239.  
  240.     InitCursor();
  241.     
  242.     /* Set initialization complete. */
  243.     
  244.     Initialized = true;
  245. }
  246.