home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #1 / monster.zip / monster / WIN_BMP / FRCICN13.ZIP / FORCEICO.C < prev    next >
C/C++ Source or Header  |  1994-02-15  |  25KB  |  1,049 lines

  1. /*
  2. Auto:        smake    ForceIcon
  3. */
  4.  
  5. /* $Revision Header built automatically *************** (do not edit) ************
  6. **
  7. ** ⌐ Copyright by GuntherSoft
  8. **
  9. ** File             : SnakeSYS:CPrgs/Utils/ForceIcon.c
  10. ** Created on       : Wednesday, 20.10.93 15:55:50
  11. ** Created by       : Kai Iske
  12. ** Current revision : V1.0
  13. **
  14. **
  15. ** Purpose
  16. ** -------
  17. **   - Forces Disk Icons to a specified position.
  18. **     Usefull for CD-Rom users
  19. **
  20. ** Revision V1.0
  21. ** --------------
  22. ** created on Wednesday, 20.10.93 15:55:50  by  Kai Iske.   LogMessage :
  23. **     --- Initial release ---
  24. **
  25. *********************************************************************************/
  26.  
  27.  
  28.  
  29. /**********************************************************************/
  30. /*                        External references                         */
  31. /**********************************************************************/
  32. extern struct    Window        *MainWinHandle;        // Window handles
  33. extern struct    Window        *EditWinHandle;
  34. extern struct    Window        *PosWinHandle;
  35. extern struct    Window        *ManWinHandle;
  36.  
  37.  
  38.  
  39.  
  40.  
  41. /**********************************************************************/
  42. /*                      Routines for this module                      */
  43. /**********************************************************************/
  44. static BOOL CheckToolTypes(char *HotKeyDef, ULONG *Pri, BOOL *PopUp);
  45. static ULONG __saveds __asm MyGetIcon(register __a0 UBYTE *Name, register __a1 struct DiskObject *DObj, register __a2 struct FreeList *FList, register __a6 struct Library *IconBase);
  46. static ULONG __asm DoForce(register __a0 UBYTE *Name, register __a1 struct DiskObject *DObj, register __a2 struct FreeList *FList, register __a6 struct Library *IconBase);
  47. static ULONG __saveds __asm MyLock(register __d1 UBYTE *Name, register __d2 ULONG Mode, register __a6 struct DosLibrary *DOSBase);
  48. static BOOL OpenAll(void);
  49. static void CloseAll(void);
  50. static void HandleInput(struct MsgPort *BrokerPort, CxObj *InputBroker);
  51.  
  52.  
  53.  
  54.  
  55.  
  56. /**********************************************************************/
  57. /*                           Library bases                            */
  58. /**********************************************************************/
  59. struct    ExecBase    *SysBase;
  60. struct    IntuitionBase    *IntuitionBase    = NULL;
  61. struct    Library        *DiskfontBase    = NULL;
  62. struct    GfxBase        *GfxBase    = NULL;
  63. struct    Library        *GadToolsBase    = NULL;
  64. struct    DosLibrary    *DOSBase    = NULL;
  65. struct    Library        *IconBase    = NULL;
  66. struct    Library        *UtilityBase    = NULL;
  67. struct    Library        *CxBase        = NULL;
  68. struct    Library        *IFFParseBase    = NULL;
  69. struct    Library        *AslBase    = NULL;
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76. /**********************************************************************/
  77. /*                         Broker Definition                          */
  78. /**********************************************************************/
  79. struct NewBroker BrokerDef =
  80. {
  81.     NB_VERSION,
  82.     "ForceIcon",
  83.     "ForceIcon v"REVISION,
  84.     "Forces icons to abolute position",
  85.     NBU_NOTIFY|NBU_UNIQUE,
  86.     COF_SHOW_HIDE,
  87.     0,
  88.     NULL,
  89.     0
  90. };
  91.  
  92.  
  93.  
  94. /**********************************************************************/
  95. /*                        Commandline template                        */
  96. /**********************************************************************/
  97. static const char    *Template = "CX_PRIORITY/K/N,CX_POPUP/K,CX_POPKEY/K";
  98. enum    {PRI_ARG, POP_ARG, KEY_ARG, LAST_ARG};
  99.  
  100.  
  101. /**********************************************************************/
  102. /*                         "No-StartUp vars"                          */
  103. /**********************************************************************/
  104. static const char    _VER[] = "\0$VER: ForceIcon "REVISION" ("REVDATE")\0";
  105. char    _ProgramName[] = "ForceIcon";
  106. LONG    _OSERR = 0;
  107.  
  108. /**********************************************************************/
  109. /*                          Global variables                          */
  110. /**********************************************************************/
  111. static    ULONG    __asm (*OldGetIcon)(register __a0 UBYTE *, register __a1 struct DiskObject *, register __a2 struct FreeList *, register __a6 struct Library *);
  112. static    ULONG    __asm (*OldLock)(register __d1 UBYTE *, register __d2 ULONG, register __a6 struct DosLibrary *);
  113.  
  114. struct    List        VolumeList;            // List of patched volumes
  115. struct    SignalSemaphore    MySemaphore;            // My beautiful semaphore
  116. struct    WBStartup    *_WBenchMsg    = NULL;        // StartUp message
  117. struct    IClass        *GetFileClass;            // ImageClass for GetFile
  118. static    UWORD    Active = TRUE;                // State of Broker
  119.  
  120.  
  121.  
  122.  
  123.  
  124. /**********************************************************************/
  125. /*                      This is our main program                      */
  126. /**********************************************************************/
  127. ULONG __saveds main(void)
  128. {
  129.     struct    Class        *InitGetFile(void);
  130.     struct    Process        *MyProc;
  131.     struct    MsgPort        *BrokerPort;
  132.     CxObj            *InputBroker;
  133.     CxObj            *InputKey;
  134.     ULONG            Error, Pri = 0;
  135.     char            HotKeyDef[128];
  136.     BOOL            PopUp = TRUE;
  137.  
  138.         // Get SysBase
  139.  
  140.     SysBase    = *((struct ExecBase **)0x4L);
  141.  
  142.         // Get address of our process
  143.  
  144.     MyProc = (struct Process *)FindTask(NULL);
  145.  
  146.         // Determine where we were started from
  147.  
  148.     if(!MyProc->pr_CLI)
  149.         _WBenchMsg = (struct WBStartup *)GetMsg(&MyProc->pr_MsgPort);
  150.  
  151.         // Initialize our semaphore
  152.  
  153.     InitSemaphore(&MySemaphore);
  154.  
  155.         // Open libraries
  156.  
  157.     if(OpenAll())
  158.     {
  159.             // Check for tooltypes or Commandline args
  160.  
  161.         if(CheckToolTypes(HotKeyDef, &Pri, &PopUp))
  162.         {
  163.             if((GetFileClass = (struct IClass *)InitGetFile()))
  164.             {
  165.                     // Load in preferences
  166.  
  167.                 LoadPrefs();
  168.  
  169.                     // Create our Message Port for the Broker
  170.  
  171.                 if((BrokerPort = CreateMsgPort()))
  172.                 {
  173.                         // Set up additional fields within broker structure
  174.  
  175.                     BrokerDef.nb_Port    = BrokerPort;
  176.                     BrokerDef.nb_Pri    = Pri;
  177.  
  178.                         // Create broker
  179.  
  180.                     if((InputBroker = CxBroker(&BrokerDef, (LONG *)&Error)))
  181.                     {
  182.                             // Create HotKey
  183.  
  184.                         if((InputKey = HotKey(HotKeyDef, BrokerPort, POPKEY)))
  185.                         {
  186.                                 // Attach HotKey to Broker
  187.  
  188.                             AttachCxObj(InputBroker, InputKey);
  189.  
  190.                                 // Activate Broker
  191.  
  192.                             ActivateCxObj(InputBroker, TRUE);
  193.  
  194.                             Forbid();
  195.                                 // Patch icon.library functions
  196.  
  197.                             OldGetIcon        = (ULONG *)SetFunction(IconBase, -0x0000002a, &MyGetIcon);
  198.  
  199.                                 // Patch dos.library functions
  200.  
  201.                             OldLock            = (ULONG *)SetFunction(DOSBase, -0x00000054, &MyLock);
  202.                             Permit();
  203.  
  204.                                 // PopUp main window ???
  205.  
  206.                             if(PopUp)
  207.                                 OpenMainWin();
  208.  
  209.                                 // Handle all inputs
  210.  
  211.                             HandleInput(BrokerPort, InputBroker);
  212.  
  213.  
  214.                             Forbid();
  215.                                 // Reinstall old icon.library functions
  216.  
  217.                             SetFunction(IconBase, -0x0000002a, OldGetIcon);
  218.  
  219.                                 // Restore DOS-Library functions
  220.  
  221.                             SetFunction(DOSBase, -0x00000054, OldLock);
  222.                             Permit();
  223.                         }
  224.  
  225.                             // Dispose Broker
  226.  
  227.                         DeleteCxObjAll(InputBroker);
  228.                     }
  229.  
  230.                         // Remove Msg-Port
  231.  
  232.                     DeleteMsgPort(BrokerPort);
  233.                 }
  234.                     // Free list of patches
  235.  
  236.                 FreeDevVolList(&VolumeList);
  237.  
  238.                     // Dispose GetFile class
  239.  
  240.                 FreeClass(GetFileClass);
  241.             }
  242.             else
  243.                 DisplayError(ERR_NOFILE, NULL);
  244.         }
  245.     }
  246.  
  247.         // Close libs
  248.  
  249.     CloseAll();
  250.  
  251.         // Send back WBStartUp Message
  252.  
  253.     if(_WBenchMsg)
  254.     {
  255.         Forbid();
  256.         ReplyMsg((struct Message *)_WBenchMsg);
  257.     }
  258.     return(0);
  259. }
  260.  
  261.  
  262.  
  263.  
  264. /**********************************************************************/
  265. /*                        Functionreplacements                        */
  266. /**********************************************************************/
  267. void chkabort(void){;}
  268. void __stdargs _XCEXIT(LONG Val){;}
  269.  
  270.  
  271.  
  272.  
  273.  
  274.  
  275. /**********************************************************************/
  276. /*                        Check for ToolTypes                         */
  277. /**********************************************************************/
  278. static BOOL CheckToolTypes(char *HotKeyDef, ULONG *Pri, BOOL *PopUp)
  279. {
  280.         // set default PopUp HotKey
  281.  
  282.     strcpy(HotKeyDef, "lalt lshift i");
  283.  
  284.  
  285.         // Did we come from WB ???
  286.  
  287.     if(_WBenchMsg)
  288.     {
  289.         struct    WBArg        *MyArg = _WBenchMsg->sm_ArgList;
  290.         struct    DiskObject    *MyObj;
  291.         char    **ToolTypes, *ThisTool;
  292.  
  293.             // Switch to currentdir
  294.  
  295.         CurrentDir(MyArg->wa_Lock);
  296.  
  297.             // Try to get our icon
  298.  
  299.         if((MyObj = GetDiskObjectNew(MyArg->wa_Name)))
  300.         {
  301.                 // Get tooltypes
  302.  
  303.             if((ToolTypes = MyObj->do_ToolTypes))
  304.             {
  305.                     // Parse ToolTypes
  306.  
  307.                 if((ThisTool = FindToolType(ToolTypes, "CX_PRIORITY")))
  308.                 {
  309.                     char    *Dummy;
  310.  
  311.                     *Pri = strtol(ThisTool, &Dummy, 10);
  312.                 }
  313.  
  314.                 if((ThisTool = FindToolType(ToolTypes, "CX_POPUP")))
  315.                     *PopUp = !(MatchToolValue(ThisTool, "NO"));
  316.  
  317.                 if((ThisTool = FindToolType(ToolTypes, "CX_POPKEY")))
  318.                     strncpy(HotKeyDef, ThisTool, 127);
  319.             }
  320.  
  321.                 // Free our DiskObject again
  322.  
  323.             FreeDiskObject(MyObj);
  324.         }
  325.         return(TRUE);
  326.     }
  327.     else
  328.     {
  329.         APTR    *Args;
  330.         struct    RDArgs    *MyRDArgs;
  331.         BOOL    GoOn = FALSE;
  332.  
  333.             // Try to allocate buffer for ReadArgs
  334.  
  335.         if((Args = AllocVec((sizeof(ULONG) * LAST_ARG), MEMF_CLEAR)))
  336.         {
  337.                 // Parse commandline
  338.  
  339.             if((MyRDArgs = ReadArgs((char *)Template, (LONG *)Args, NULL)))
  340.             {
  341.                 GoOn = TRUE;
  342.  
  343.                 if(Args[PRI_ARG])
  344.                     *Pri = *(ULONG *)Args[PRI_ARG];
  345.  
  346.                 if(Args[POP_ARG])
  347.                 {
  348.                     if(!stricmp(Args[POP_ARG], "NO"))
  349.                         *PopUp = FALSE;
  350.                 }
  351.  
  352.                 if(Args[KEY_ARG])
  353.                     strncpy(HotKeyDef, Args[KEY_ARG], 127);
  354.  
  355.                 FreeArgs(MyRDArgs);
  356.             }
  357.             else
  358.                 PrintFault(IoErr(), "ForceIcon ");
  359.  
  360.             FreeVec(Args);
  361.         }
  362.         else
  363.             PrintFault(ERROR_NO_FREE_STORE, "ForceIcon ");
  364.  
  365.         return(GoOn);
  366.     }
  367. }
  368.  
  369.  
  370.  
  371.  
  372.  
  373.  
  374.  
  375. /**********************************************************************/
  376. /*                      My new GetIcon function                       */
  377. /**********************************************************************/
  378. static ULONG __saveds __asm MyGetIcon(register __a0 UBYTE *Name, register __a1 struct DiskObject *DObj, register __a2 struct FreeList *FList, register __a6 struct Library *IconBase)
  379. {
  380.     struct    Process        *MyProc = (struct Process *)FindTask(NULL);
  381.     ULONG    RetVal;
  382.  
  383.         // Calling process a real process and is it Workbench ?
  384.  
  385.     if((MyProc->pr_Task.tc_Node.ln_Type == NT_PROCESS) && !strcmp(MyProc->pr_Task.tc_Node.ln_Name, "Workbench"))
  386.     {
  387.             if(!stricmp(Name, "Disk"))
  388.                 RetVal = DoForce(Name, DObj, FList, IconBase);
  389.             else
  390.                 RetVal = OldGetIcon(Name, DObj, FList, IconBase);
  391.     }
  392.     else
  393.         RetVal = OldGetIcon(Name, DObj, FList, IconBase);
  394.  
  395.     return(RetVal);
  396. }
  397.  
  398.  
  399.  
  400.  
  401.  
  402.  
  403. /**********************************************************************/
  404. /*                       Main forcement routine                       */
  405. /**********************************************************************/
  406. static ULONG __asm DoForce(register __a0 UBYTE *Name, register __a1 struct DiskObject *DObj, register __a2 struct FreeList *FList, register __a6 struct Library *IconBase)
  407. {
  408.     struct    FileLock    *Dir;
  409.     struct    DosList        *DList;
  410.     char    VolName[130], DevName[130];
  411.     BPTR    MyLock, CheckLock;
  412.     ULONG    RetVal = 0;
  413.     BOOL    Found = FALSE;
  414.  
  415.         // Get our semaphore
  416.  
  417.     ObtainSemaphore(&MySemaphore);
  418.  
  419.         // Are we active ???
  420.  
  421.     if(Active)
  422.     {
  423.             // Switch to current dir
  424.  
  425.         MyLock    = CurrentDir(NULL);
  426.         Dir    = (struct FileLock *)BADDR(MyLock);
  427.         DList    = (struct DosList *)BADDR(Dir->fl_Volume);
  428.  
  429.             // Get name of volume inserted
  430.  
  431.         setmem(VolName, 130, 0);
  432.         setmem(DevName, 130, 0);
  433.         strncpy(VolName, ((char *)BADDR(DList->dol_Name) + 1), *((char *)BADDR(DList->dol_Name)));
  434.  
  435.             // Reset current dir
  436.  
  437.         CurrentDir(MyLock);
  438.  
  439.             // Get Name of Device
  440.  
  441.         if((DList = LockDosList(LDF_DEVICES|LDF_READ)))
  442.         {
  443.             while((DList = NextDosEntry(DList, LDF_DEVICES|LDF_READ)))
  444.             {
  445.                 if(Dir->fl_Task == DList->dol_Task)
  446.                     strncpy(DevName, ((char *)BADDR(DList->dol_Name) + 1), *((char *)BADDR(DList->dol_Name)));
  447.             }
  448.             UnLockDosList(LDF_DEVICES|LDF_READ);
  449.         }
  450.  
  451.             // Really to load from ROOT ???
  452.  
  453.         if(!(CheckLock = ParentDir(MyLock)))
  454.         {
  455.                 // Do we have patches waiting ???
  456.  
  457.             if(!IsListEmpty(&VolumeList))
  458.             {
  459.                 struct    VolEntry    *ThisEntry = (struct VolEntry *)VolumeList.lh_Head;
  460.  
  461.                 do
  462.                 {
  463.                         // This one to patch ???
  464.  
  465.                     if(ThisEntry->Link.ln_Type == LDF_DEVICES && !stricmp(ThisEntry->VolName, DevName))
  466.                         Found = TRUE;
  467.  
  468.                     else if(ThisEntry->Link.ln_Type == LDF_VOLUMES && !stricmp(ThisEntry->VolName, VolName))
  469.                         Found = TRUE;
  470.  
  471.                     else
  472.                         ThisEntry = (struct VolEntry *)ThisEntry->Link.ln_Succ;
  473.  
  474.                 } while(!Found && ThisEntry->Link.ln_Succ);
  475.  
  476.                     // Object to be patched ?
  477.  
  478.                 if(Found)
  479.                 {
  480.                         // Alternative icon ???
  481.  
  482.                     if(ThisEntry->UseAlt)
  483.                     {
  484.                         char    *End;
  485.  
  486.                             // Check for name and remove extension
  487.  
  488.                         strcpy(VolName, ThisEntry->IconName);
  489.                         strlwr(VolName);
  490.                         if((End = strstr(VolName, ".info")))
  491.                         {
  492.                             BPTR    TestLock;
  493.  
  494.                             setmem(VolName, 130, 0);
  495.                             strncpy(VolName, ThisEntry->IconName, (End - VolName));
  496.  
  497.                                 // Try to get supplied name
  498.  
  499.                             if((TestLock = Lock(ThisEntry->IconName, ACCESS_READ)))
  500.                             {
  501.                                 UnLock(TestLock);
  502.  
  503.                                     // Try to read in this icon
  504.  
  505.                                 if(!(RetVal = OldGetIcon(VolName, DObj, FList, IconBase)))
  506.                                     RetVal = OldGetIcon(Name, DObj, FList, IconBase);
  507.                                 else
  508.                                 {
  509.                                         // Ok, we`ve loaded a new icon, so set appropriate flags ;)
  510.  
  511.                                     if(DObj->do_Type == WBTOOL || DObj->do_Type == WBPROJECT)
  512.                                     {
  513.                                             // Try to set drawerdata for tool and project icons
  514.  
  515.                                         if((DObj->do_DrawerData = AllocMem(sizeof(struct DrawerData), MEMF_CLEAR|MEMF_PUBLIC)))
  516.                                         {
  517.                                             struct    DrawerData    *DDat = DObj->do_DrawerData;
  518.  
  519.                                                 // Fill in structure
  520.  
  521.                                             DDat->dd_NewWindow.LeftEdge    = ThisEntry->LeftEdge;
  522.                                             DDat->dd_NewWindow.TopEdge    = ThisEntry->TopEdge;
  523.                                             DDat->dd_NewWindow.Width    = ThisEntry->Width;
  524.                                             DDat->dd_NewWindow.Height    = ThisEntry->Height;
  525.                                             DDat->dd_NewWindow.DetailPen    = 255;
  526.                                             DDat->dd_NewWindow.BlockPen    = 255;
  527.                                             DDat->dd_NewWindow.Flags    = WFLG_HASZOOM|WFLG_WINDOWTICKED|WFLG_REPORTMOUSE|WFLG_SIMPLE_REFRESH|WFLG_SIZEBRIGHT|WFLG_SIZEBBOTTOM|WFLG_CLOSEGADGET|WFLG_DEPTHGADGET|WFLG_DRAGBAR|WFLG_SIZEGADGET;
  528.                                             DDat->dd_NewWindow.MinWidth    = 90;
  529.                                             DDat->dd_NewWindow.MinHeight    = 40;
  530.                                             DDat->dd_NewWindow.MaxWidth    = 0xffff;
  531.                                             DDat->dd_NewWindow.MaxHeight    = 0xffff;
  532.  
  533.                                                 // A Ok, set new type of icon
  534.  
  535.                                             DObj->do_Type = WBDISK;
  536.                                         }
  537.                                     }
  538.                                     else
  539.                                         DObj->do_Type = WBDISK;
  540.                                 }
  541.                             }
  542.                             else
  543.                                 RetVal = OldGetIcon(Name, DObj, FList, IconBase);
  544.                         }
  545.                         else
  546.                             RetVal = OldGetIcon(Name, DObj, FList, IconBase);
  547.                     }
  548.                     else
  549.                         RetVal = OldGetIcon(Name, DObj, FList, IconBase);
  550.  
  551.                         // Patch position ???
  552.  
  553.                     if(RetVal)
  554.                     {
  555.                         struct    Screen    *WBScreen    = LockPubScreen("Workbench");
  556.  
  557.                         if(WBScreen)
  558.                         {
  559.                                 // Do so
  560.  
  561.                             DObj->do_CurrentX = (ThisEntry->IconPos) ? ThisEntry->Left : NO_ICON_POSITION;
  562.                             DObj->do_CurrentY = (ThisEntry->IconPos) ? ThisEntry->Top - WBScreen->BarHeight - 1 : NO_ICON_POSITION;
  563.  
  564.                             UnlockPubScreen(NULL, WBScreen);
  565.                         }
  566.                     }
  567.                 }
  568.             }
  569.         }
  570.         else
  571.             UnLock(CheckLock);
  572.     }
  573.  
  574.         // No entry found and not the orig. icon read -> use supplied name
  575.  
  576.     if(!Found && !RetVal)
  577.         RetVal = OldGetIcon(Name, DObj, FList, IconBase);
  578.  
  579.         // Release that fine semaphore
  580.  
  581.     ReleaseSemaphore(&MySemaphore);
  582.  
  583.     return(RetVal);
  584. }
  585.  
  586.  
  587.  
  588.  
  589.  
  590. /**********************************************************************/
  591. /*                        My new Lock routine                         */
  592. /**********************************************************************/
  593. static ULONG __saveds __asm MyLock(register __d1 UBYTE *Name, register __d2 ULONG Mode, register __a6 struct DosLibrary *DOSBase)
  594. {
  595.     struct    Process        *MyProc = (struct Process *)FindTask(NULL);
  596.     struct    FileLock    *Dir;
  597.     struct    DosList        *DList;
  598.     char    VolName[130], DevName[130];
  599.     BPTR    MyLock, CheckLock;
  600.     ULONG    RetVal;
  601.     BOOL    Found = FALSE;
  602.  
  603.  
  604.         // Calling process a real process and is it Workbench ?
  605.  
  606.     if((MyProc->pr_Task.tc_Node.ln_Type == NT_PROCESS) && !strcmp(MyProc->pr_Task.tc_Node.ln_Name, "Workbench"))
  607.     {
  608.             // Trying to load a Disk.info ???
  609.  
  610.         if(!stricmp(Name, "Disk.info"))
  611.         {
  612.                 // Get my semaphore
  613.  
  614.             ObtainSemaphore(&MySemaphore);
  615.  
  616.                 // Broker active ???
  617.  
  618.             if(Active)
  619.             {
  620.                     // Switch to current dir
  621.  
  622.                 MyLock    = CurrentDir(NULL);
  623.                 Dir    = (struct FileLock *)BADDR(MyLock);
  624.                 DList    = (struct DosList *)BADDR(Dir->fl_Volume);
  625.  
  626.                     // Get name of volume inserted
  627.  
  628.                 setmem(VolName, 130, 0);
  629.                 setmem(DevName, 130, 0);
  630.                 strncpy(VolName, ((char *)BADDR(DList->dol_Name) + 1), *((char *)BADDR(DList->dol_Name)));
  631.  
  632.                     // Reset current dir
  633.  
  634.                 CurrentDir(MyLock);
  635.  
  636.                     // Get Name of Device
  637.  
  638.                 if((DList = LockDosList(LDF_DEVICES|LDF_READ)))
  639.                 {
  640.                     while((DList = NextDosEntry(DList, LDF_DEVICES|LDF_READ)))
  641.                     {
  642.                         if(Dir->fl_Task == DList->dol_Task)
  643.                             strncpy(DevName, ((char *)BADDR(DList->dol_Name) + 1), *((char *)BADDR(DList->dol_Name)));
  644.                     }
  645.                     UnLockDosList(LDF_DEVICES|LDF_READ);
  646.                 }
  647.  
  648.                     // Really load from ROOT ?
  649.  
  650.                 if(!(CheckLock = ParentDir(MyLock)))
  651.                 {
  652.                         // Do we have patches waiting ???
  653.  
  654.                     if(!IsListEmpty(&VolumeList))
  655.                     {
  656.                         struct    VolEntry    *ThisEntry = (struct VolEntry *)VolumeList.lh_Head;
  657.  
  658.                         do
  659.                         {
  660.                                 // This one to patch ???
  661.  
  662.                             if(ThisEntry->Link.ln_Type == LDF_DEVICES && !stricmp(ThisEntry->VolName, DevName))
  663.                                 Found = TRUE;
  664.  
  665.                             else if(ThisEntry->Link.ln_Type == LDF_VOLUMES && !stricmp(ThisEntry->VolName, VolName))
  666.                                 Found = TRUE;
  667.  
  668.                             else
  669.                                 ThisEntry = (struct VolEntry *)ThisEntry->Link.ln_Succ;
  670.  
  671.                         } while(!Found && ThisEntry->Link.ln_Succ);
  672.  
  673.                             // Object to be patched ?
  674.  
  675.                         if(Found)
  676.                         {
  677.                                 // If an alternative icon is to be used
  678.                                 // lock this one, otherwise lock Disk.info
  679.  
  680.                             if(ThisEntry->UseAlt)
  681.                             {
  682.                                 struct    DiskObject    *OldDiskObject;
  683.                                 WORD    OldLeft = 50, OldTop = 50, OldWidth = 400, OldHeight = 100;
  684.  
  685.                                 if(!(RetVal = OldLock(ThisEntry->IconName, Mode, DOSBase)))
  686.                                     RetVal = OldLock(Name, Mode, DOSBase);
  687.                                 else
  688.                                 {
  689.                                         // Get original Disk.info file, in order to obtain
  690.                                         // the correct window position and size
  691.  
  692.                                     strcat(DevName, ":Disk");
  693.                                     if(!(OldDiskObject = GetDiskObject(DevName)))
  694.                                     {
  695.                                         strcat(VolName, ":Disk");
  696.                                         OldDiskObject = GetDiskObject(VolName);
  697.                                     }
  698.  
  699.                                     if(OldDiskObject)
  700.                                     {
  701.                                         OldLeft        = OldDiskObject->do_DrawerData->dd_NewWindow.LeftEdge;
  702.                                         OldTop        = OldDiskObject->do_DrawerData->dd_NewWindow.TopEdge;
  703.                                         OldWidth    = OldDiskObject->do_DrawerData->dd_NewWindow.Width;
  704.                                         OldHeight    = OldDiskObject->do_DrawerData->dd_NewWindow.Height;
  705.  
  706.                                         FreeDiskObject(OldDiskObject);
  707.                                     }
  708.  
  709.                                     ThisEntry->LeftEdge    = OldLeft;
  710.                                     ThisEntry->TopEdge    = OldTop;
  711.                                     ThisEntry->Width    = OldWidth;
  712.                                     ThisEntry->Height    = OldHeight;
  713.                                 }
  714.                             }
  715.                             else
  716.                                 Found = FALSE;
  717.                         }
  718.                     }
  719.                 }
  720.                 else
  721.                     UnLock(CheckLock);
  722.             }
  723.  
  724.             ReleaseSemaphore(&MySemaphore);
  725.         }
  726.     }
  727.  
  728.     if(!Found)
  729.         RetVal = OldLock(Name, Mode, DOSBase);
  730.  
  731.     return(RetVal);
  732. }
  733.  
  734.  
  735.  
  736.  
  737.  
  738.  
  739. /**********************************************************************/
  740. /*                           Open libraries                           */
  741. /**********************************************************************/
  742. static BOOL OpenAll(void)
  743. {
  744.     if(!(IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library", 37)))
  745.     {
  746.         DisplayError(ERR_OPEN, (ULONG)"intuition.library");
  747.         return(FALSE);
  748.     }
  749.  
  750.     if(!(DOSBase = (struct DosLibrary *)OpenLibrary("dos.library", 37)))
  751.     {
  752.         DisplayError(ERR_OPEN, (ULONG)"dos.library");
  753.         return(FALSE);
  754.     }
  755.  
  756.     if(!(GfxBase = (struct GfxBase *)OpenLibrary("graphics.library", 37)))
  757.     {
  758.         DisplayError(ERR_OPEN, (ULONG)"graphics.library");
  759.         return(FALSE);
  760.     }
  761.  
  762.     if(!(GadToolsBase = OpenLibrary("gadtools.library", 37)))
  763.     {
  764.         DisplayError(ERR_OPEN, (ULONG)"gadtools.library");
  765.         return(FALSE);
  766.     }
  767.  
  768.     if(!(IconBase = OpenLibrary("icon.library", 37)))
  769.     {
  770.         DisplayError(ERR_OPEN, (ULONG)"icon.library");
  771.         return(FALSE);
  772.     }
  773.  
  774.     if(!(UtilityBase = OpenLibrary("utility.library", 37)))
  775.     {
  776.         DisplayError(ERR_OPEN, (ULONG)"utility.library");
  777.         return(FALSE);
  778.     }
  779.  
  780.     if(!(CxBase = OpenLibrary("commodities.library", 37)))
  781.     {
  782.         DisplayError(ERR_OPEN, (ULONG)"commodities.library");
  783.         return(FALSE);
  784.     }
  785.  
  786.     if(!(IFFParseBase = OpenLibrary("iffparse.library", 37)))
  787.     {
  788.         DisplayError(ERR_OPEN, (ULONG)"iffparse.library");
  789.         return(FALSE);
  790.     }
  791.  
  792.     if(!(DiskfontBase = OpenLibrary("diskfont.library", 36)))
  793.     {
  794.         DisplayError(ERR_OPEN, (ULONG)"diskfont.library");
  795.         return(FALSE);
  796.     }
  797.  
  798.     if(!(AslBase = OpenLibrary("asl.library", 36)))
  799.     {
  800.         DisplayError(ERR_OPEN, (ULONG)"asl.library");
  801.         return(FALSE);
  802.     }
  803.  
  804.     return(TRUE);
  805. }
  806.  
  807.  
  808.  
  809.  
  810.  
  811.  
  812.  
  813.  
  814. /**********************************************************************/
  815. /*                          Close libraries                           */
  816. /**********************************************************************/
  817. static void CloseAll(void)
  818. {
  819.     if(AslBase)
  820.         CloseLibrary(AslBase);
  821.  
  822.     if(DiskfontBase)
  823.         CloseLibrary(DiskfontBase);
  824.  
  825.     if(IFFParseBase)
  826.         CloseLibrary(IFFParseBase);
  827.  
  828.     if(CxBase)
  829.         CloseLibrary(CxBase);
  830.  
  831.     if(UtilityBase)
  832.         CloseLibrary(UtilityBase);
  833.  
  834.     if(IconBase)
  835.         CloseLibrary(IconBase);
  836.  
  837.     if(DOSBase)
  838.         CloseLibrary((struct Library *)DOSBase);
  839.  
  840.     if(GadToolsBase)
  841.         CloseLibrary(GadToolsBase);
  842.  
  843.     if(GfxBase)
  844.         CloseLibrary((struct Library *)GfxBase);
  845.  
  846.     if(IntuitionBase)
  847.         CloseLibrary((struct Library *)IntuitionBase);
  848. }
  849.  
  850.  
  851.  
  852.  
  853.  
  854.  
  855.  
  856. /**********************************************************************/
  857. /*                         Handle all inputs                          */
  858. /**********************************************************************/
  859. static void HandleInput(struct MsgPort *BrokerPort, CxObj *InputBroker)
  860. {
  861.     CxMsg            *MyMsg;
  862.     ULONG    BrokerSig    = (1L << BrokerPort->mp_SigBit),
  863.         MainSig, EditSig, PosSig, ManSig, MySig;
  864.     ULONG    MsgType, MsgID;
  865.     BOOL    QuitIT = FALSE;
  866.  
  867.  
  868.  
  869.     while(!QuitIT)
  870.     {
  871.             // Main window open ???
  872.  
  873.         if(MainWinHandle)
  874.             MainSig = (1L << MainWinHandle->UserPort->mp_SigBit);
  875.         else
  876.             MainSig = 0;
  877.  
  878.             // Edit window open ???
  879.  
  880.         if(EditWinHandle)
  881.             EditSig = (1L << EditWinHandle->UserPort->mp_SigBit);
  882.         else
  883.             EditSig = 0;
  884.  
  885.             // Position window open ???
  886.  
  887.         if(PosWinHandle)
  888.             PosSig = (1L << PosWinHandle->UserPort->mp_SigBit);
  889.         else
  890.             PosSig = 0;
  891.  
  892.             // Manual input window open ???
  893.  
  894.         if(ManWinHandle)
  895.             ManSig = (1L << ManWinHandle->UserPort->mp_SigBit);
  896.         else
  897.             ManSig = 0;
  898.  
  899.             // Wait for some signals
  900.  
  901.         MySig = Wait(BrokerSig | MainSig | EditSig | PosSig | ManSig | SIGBREAKF_CTRL_C);
  902.  
  903.  
  904.             // Go a CTRL-C ???
  905.  
  906.         if((MySig & SIGBREAKF_CTRL_C))
  907.             QuitIT = TRUE;
  908.  
  909.  
  910.             // Signal from Broker-Port ???
  911.  
  912.         if((MySig & BrokerSig))
  913.         {
  914.                 // Loop on all messages
  915.  
  916.             while((MyMsg = (CxMsg *)GetMsg(BrokerPort)))
  917.             {
  918.                 MsgType    = CxMsgType(MyMsg);
  919.                 MsgID    = CxMsgID(MyMsg);
  920.  
  921.                 ReplyMsg((struct Message *)MyMsg);
  922.  
  923.                 switch(MsgType)
  924.                 {
  925.                     case CXM_COMMAND :
  926.                     {
  927.                         switch(MsgID)
  928.                         {
  929.                                 // Remove...
  930.  
  931.                             case CXCMD_KILL :
  932.                             {
  933.                                 QuitIT = TRUE;
  934.                                 break;
  935.                             }
  936.                                 // On appear or unique, open main window
  937.  
  938.                             case CXCMD_APPEAR :
  939.                             case CXCMD_UNIQUE :
  940.                             {
  941.                                 if(!MainWinHandle)
  942.                                     OpenMainWin();
  943.                                 else
  944.                                     WindowToFront(MainWinHandle);
  945.                                 break;
  946.                             }
  947.                                 // Close all windows
  948.  
  949.                             case CXCMD_DISAPPEAR :
  950.                             {
  951.                                 CloseManWin();
  952.                                 CloseEditWin();
  953.                                 CloseMainWin();
  954.                                 break;
  955.                             }
  956.                                 // Disable ourself
  957.  
  958.                             case CXCMD_DISABLE :
  959.                             {
  960.                                     // Get semaphore, set state and flag
  961.  
  962.                                 ObtainSemaphore(&MySemaphore);
  963.                                 ActivateCxObj(InputBroker, FALSE);
  964.                                 Active = FALSE;
  965.                                 ReleaseSemaphore(&MySemaphore);
  966.                                 break;
  967.                             }
  968.                                 // Enable ourself
  969.  
  970.                             case CXCMD_ENABLE :
  971.                             {
  972.                                     // Get semaphore, set state and flag
  973.  
  974.                                 ObtainSemaphore(&MySemaphore);
  975.                                 ActivateCxObj(InputBroker, TRUE);
  976.                                 Active = TRUE;
  977.                                 ReleaseSemaphore(&MySemaphore);
  978.                                 break;
  979.                             }
  980.                         }
  981.                         break;
  982.                     }
  983.                         // Had a hotkey
  984.  
  985.                     case CXM_IEVENT :
  986.                     {
  987.                         switch(MsgID)
  988.                         {
  989.                                 // Open main window
  990.  
  991.                             case POPKEY :
  992.                             {
  993.                                 if(!MainWinHandle)
  994.                                     OpenMainWin();
  995.                                 else
  996.                                     WindowToFront(MainWinHandle);
  997.                                 break;
  998.                             }
  999.                         }
  1000.                         break;
  1001.                     }
  1002.                 }
  1003.             }
  1004.         }
  1005.  
  1006.             // Message from mainwindow
  1007.  
  1008.         if(MainWinHandle && (MySig & MainSig))
  1009.         {
  1010.                 // Handle inputs
  1011.  
  1012.             if(HandleMainWin(&QuitIT))
  1013.             {
  1014.                     // Quit ???
  1015.  
  1016.                 if(!QuitIT)
  1017.                     CloseMainWin();
  1018.             }
  1019.         }
  1020.  
  1021.             // Message from edit window
  1022.  
  1023.         if(EditWinHandle && (MySig & EditSig))
  1024.         {
  1025.             if(HandleEditWin())
  1026.                 CloseEditWin();
  1027.         }
  1028.  
  1029.             // Message from manual input window
  1030.  
  1031.         if(ManWinHandle && (MySig & ManSig))
  1032.         {
  1033.             if(HandleManWin())
  1034.                 CloseManWin();
  1035.         }
  1036.  
  1037.             // Message from position window
  1038.  
  1039.         if(PosWinHandle && (MySig & PosSig))
  1040.             HandlePosWin();
  1041.     }
  1042.  
  1043.         // Close all windows on exit
  1044.  
  1045.     CloseManWin();
  1046.     CloseEditWin();
  1047.     CloseMainWin();
  1048. }
  1049.