home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Applications / NoEject 1.1 / NoEject.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-04-25  |  1.6 KB  |  100 lines  |  [TEXT/MPS ]

  1.  
  2. // (c) 1996 Dieter Spaar
  3. // Internet: spaar@mirider.augusta.de
  4.  
  5. // Wrapper to install assembler shutdown routine
  6. // The patch for SCSIDispatch is executed just before volumes are unmounted
  7.  
  8. #include <Quickdraw.h>
  9. #include <Events.h>
  10. #include <Traps.h>
  11. #include <Windows.h>
  12. #include <Dialogs.h>
  13. #include <Controls.h>
  14. #include <Menus.h>
  15. #include <TextEdit.h>
  16. #include <Memory.h>
  17. #include <Desk.h>
  18. #include <Fonts.h>
  19. #include <ToolUtils.h>
  20. #include <Files.h>
  21. #include <Shutdown.h>
  22.  
  23. // DLOG
  24.  
  25. #define About        128
  26. #define Splash        129
  27.  
  28. extern pascal long GetSize(void);
  29. extern pascal Ptr GetAddr(void);
  30.  
  31. void ShowSplashDialog(void)
  32. {
  33.     GrafPtr     savePort;
  34.     DialogPtr    theDialog;
  35.     long         time;
  36.     
  37.     GetPort(&savePort);
  38.     theDialog = GetNewDialog(Splash, nil, (WindowPtr) -1);
  39.     SetPort(theDialog);
  40.  
  41.     DrawDialog(theDialog);
  42.     
  43.     time = TickCount();
  44.     do 
  45.     {
  46.         SystemTask();
  47.     } while (TickCount() - time < 120L);
  48.  
  49.     DisposDialog(theDialog);
  50.     SetPort(savePort);
  51. }
  52.  
  53. // install shutdown routine in system heap
  54.  
  55. void InstallPatch(void)
  56. {
  57.     long size;
  58.     Ptr patchSysPtr;
  59.     
  60.     size = GetSize();
  61.     
  62.     SetZone(SystemZone());
  63.     patchSysPtr = NewPtr(size);
  64.     SetZone(ApplicZone());    
  65.  
  66.     if( patchSysPtr == nil )
  67.     {
  68.         SysBeep(60); // very simple error handling  ;-)
  69.         return;
  70.     }
  71.     
  72.     BlockMove(GetAddr(), patchSysPtr, size);
  73.  
  74.     ShutDwnInstall((ShutDwnUPP)patchSysPtr, sdOnUnmount);    
  75. }
  76.  
  77.  
  78. main()
  79. {
  80.     // initialisation
  81.     
  82.     MaxApplZone();    
  83.     InitGraf(&qd.thePort);
  84.     InitFonts();
  85.     FlushEvents(everyEvent, 0);
  86.     InitWindows();
  87.     InitMenus();
  88.     TEInit();
  89.     InitDialogs(nil);
  90.     InitCursor();
  91.  
  92. #if 0 // alert instead of splash screen
  93.     if( NoteAlert(About, nil) == 1)
  94.         InstallPatch();
  95. #else
  96.     ShowSplashDialog();
  97.     InstallPatch();
  98. #endif
  99. }
  100.