home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 5 / FreshFish_July-August1994.bin / bbs / os20 / forceicon-1.2.lha / ForceIcon / Source / ForceIcon.c < prev    next >
C/C++ Source or Header  |  1993-12-31  |  24KB  |  1,030 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. /*                           Library bases                            */
  43. /**********************************************************************/
  44. struct    ExecBase    *SysBase;
  45. struct    IntuitionBase    *IntuitionBase    = NULL;
  46. struct    Library        *DiskfontBase    = NULL;
  47. struct    GfxBase        *GfxBase    = NULL;
  48. struct    Library        *GadToolsBase    = NULL;
  49. struct    DosLibrary    *DOSBase    = NULL;
  50. struct    Library        *IconBase    = NULL;
  51. struct    Library        *UtilityBase    = NULL;
  52. struct    Library        *CxBase        = NULL;
  53. struct    Library        *IFFParseBase    = NULL;
  54. struct    Library        *AslBase    = NULL;
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61. /**********************************************************************/
  62. /*                         Broker Definition                          */
  63. /**********************************************************************/
  64. struct NewBroker BrokerDef =
  65. {
  66.     NB_VERSION,
  67.     "ForceIcon",
  68.     "ForceIcon v"REVISION,
  69.     "Forces icons to abolute position",
  70.     NBU_NOTIFY|NBU_UNIQUE,
  71.     COF_SHOW_HIDE,
  72.     0,
  73.     NULL,
  74.     0
  75. };
  76.  
  77.  
  78.  
  79. /**********************************************************************/
  80. /*                        Commandline template                        */
  81. /**********************************************************************/
  82. static const char    *Template = "CX_PRIORITY/K/N,CX_POPUP/K,CX_POPKEY/K";
  83. enum    {PRI_ARG, POP_ARG, KEY_ARG, LAST_ARG};
  84.  
  85.  
  86. /**********************************************************************/
  87. /*                         "No-StartUp vars"                          */
  88. /**********************************************************************/
  89. static const char    _VER[] = "\0$VER: ForceIcon "REVISION" ("REVDATE")\0";
  90. char    _ProgramName[] = "ForceIcon";
  91. LONG    _OSERR = 0;
  92.  
  93. /**********************************************************************/
  94. /*                          Global variables                          */
  95. /**********************************************************************/
  96. static    ULONG    __asm (*OldGetIcon)(register __a0 UBYTE *, register __a1 struct DiskObject *, register __a2 struct FreeList *, register __a6 struct Library *);
  97. static    ULONG    __asm (*OldLock)(register __d1 UBYTE *, register __d2 ULONG, register __a6 struct DosLibrary *);
  98.  
  99. struct    List        VolumeList;            // List of patched volumes
  100. struct    SignalSemaphore    MySemaphore;            // My beautiful semaphore
  101. struct    WBStartup    *_WBenchMsg    = NULL;        // StartUp message
  102. struct    IClass        *GetFileClass;            // ImageClass for GetFile
  103. static    UWORD    Active = TRUE;                // State of Broker
  104.  
  105.  
  106.  
  107.  
  108.  
  109. /**********************************************************************/
  110. /*                      This is our main program                      */
  111. /**********************************************************************/
  112. ULONG __saveds main(void)
  113. {
  114.     struct    Class        *InitGetFile(void);
  115.     struct    Process        *MyProc;
  116.     struct    MsgPort        *BrokerPort;
  117.     CxObj            *InputBroker;
  118.     CxObj            *InputKey;
  119.     ULONG            Error, Pri = 0;
  120.     char            HotKeyDef[128];
  121.     BOOL            PopUp = TRUE;
  122.  
  123.         // Get SysBase
  124.  
  125.     SysBase    = *((struct ExecBase **)0x4L);
  126.  
  127.         // Get address of our process
  128.  
  129.     MyProc = (struct Process *)FindTask(NULL);
  130.  
  131.         // Determine where we were started from
  132.  
  133.     if(!MyProc->pr_CLI)
  134.         _WBenchMsg = (struct WBStartup *)GetMsg(&MyProc->pr_MsgPort);
  135.  
  136.         // Initialize our semaphore
  137.  
  138.     InitSemaphore(&MySemaphore);
  139.  
  140.         // Open libraries
  141.  
  142.     if(OpenAll())
  143.     {
  144.             // Check for tooltypes or Commandline args
  145.  
  146.         if(CheckToolTypes(HotKeyDef, &Pri, &PopUp))
  147.         {
  148.             if((GetFileClass = (struct IClass *)InitGetFile()))
  149.             {
  150.                     // Load in preferences
  151.  
  152.                 LoadPrefs();
  153.  
  154.                     // Create our Message Port for the Broker
  155.  
  156.                 if((BrokerPort = CreateMsgPort()))
  157.                 {
  158.                         // Set up additional fields within broker structure
  159.  
  160.                     BrokerDef.nb_Port    = BrokerPort;
  161.                     BrokerDef.nb_Pri    = Pri;
  162.  
  163.                         // Create broker
  164.  
  165.                     if((InputBroker = CxBroker(&BrokerDef, (LONG *)&Error)))
  166.                     {
  167.                             // Create HotKey
  168.  
  169.                         if((InputKey = HotKey(HotKeyDef, BrokerPort, POPKEY)))
  170.                         {
  171.                                 // Attach HotKey to Broker
  172.  
  173.                             AttachCxObj(InputBroker, InputKey);
  174.  
  175.                                 // Activate Broker
  176.  
  177.                             ActivateCxObj(InputBroker, TRUE);
  178.  
  179.                             Forbid();
  180.                                 // Patch icon.library functions
  181.  
  182.                             OldGetIcon        = (ULONG *)SetFunction(IconBase, -0x0000002a, &MyGetIcon);
  183.  
  184.                                 // Patch dos.library functions
  185.  
  186.                             OldLock            = (ULONG *)SetFunction(DOSBase, -0x00000054, &MyLock);
  187.                             Permit();
  188.  
  189.                                 // PopUp main window ???
  190.  
  191.                             if(PopUp)
  192.                                 OpenMainWin();
  193.  
  194.                                 // Handle all inputs
  195.  
  196.                             HandleInput(BrokerPort, InputBroker);
  197.  
  198.  
  199.                             Forbid();
  200.                                 // Reinstall old icon.library functions
  201.  
  202.                             SetFunction(IconBase, -0x0000002a, OldGetIcon);
  203.  
  204.                                 // Restore DOS-Library functions
  205.  
  206.                             SetFunction(DOSBase, -0x00000054, OldLock);
  207.                             Permit();
  208.                         }
  209.  
  210.                             // Dispose Broker
  211.  
  212.                         DeleteCxObjAll(InputBroker);
  213.                     }
  214.  
  215.                         // Remove Msg-Port
  216.  
  217.                     DeleteMsgPort(BrokerPort);
  218.                 }
  219.                     // Free list of patches
  220.  
  221.                 FreeDevVolList(&VolumeList);
  222.  
  223.                     // Dispose GetFile class
  224.  
  225.                 FreeClass(GetFileClass);
  226.             }
  227.             else
  228.                 DisplayError(ERR_NOFILE, NULL);
  229.         }
  230.     }
  231.  
  232.         // Close libs
  233.  
  234.     CloseAll();
  235.  
  236.         // Send back WBStartUp Message
  237.  
  238.     if(_WBenchMsg)
  239.     {
  240.         Forbid();
  241.         ReplyMsg((struct Message *)_WBenchMsg);
  242.     }
  243.     return(0);
  244. }
  245.  
  246.  
  247. /**********************************************************************/
  248. /*                        Functionreplacements                        */
  249. /**********************************************************************/
  250. void chkabort(void){;}
  251. void __stdargs _XCEXIT(LONG Val){;}
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258. /**********************************************************************/
  259. /*                        Check for ToolTypes                         */
  260. /**********************************************************************/
  261. BOOL CheckToolTypes(char *HotKeyDef, ULONG *Pri, BOOL *PopUp)
  262. {
  263.         // set default PopUp HotKey
  264.  
  265.     strcpy(HotKeyDef, "lalt lshift i");
  266.  
  267.  
  268.         // Did we come from WB ???
  269.  
  270.     if(_WBenchMsg)
  271.     {
  272.         struct    WBArg        *MyArg = _WBenchMsg->sm_ArgList;
  273.         struct    DiskObject    *MyObj;
  274.         char    **ToolTypes, *ThisTool;
  275.  
  276.             // Switch to currentdir
  277.  
  278.         CurrentDir(MyArg->wa_Lock);
  279.  
  280.             // Try to get our icon
  281.  
  282.         if((MyObj = GetDiskObjectNew(MyArg->wa_Name)))
  283.         {
  284.                 // Get tooltypes
  285.  
  286.             if((ToolTypes = MyObj->do_ToolTypes))
  287.             {
  288.                     // Parse ToolTypes
  289.  
  290.                 if((ThisTool = FindToolType(ToolTypes, "CX_PRIORITY")))
  291.                 {
  292.                     char    *Dummy;
  293.  
  294.                     *Pri = strtol(ThisTool, &Dummy, 10);
  295.                 }
  296.  
  297.                 if((ThisTool = FindToolType(ToolTypes, "CX_POPUP")))
  298.                     *PopUp = !(MatchToolValue(ThisTool, "NO"));
  299.  
  300.                 if((ThisTool = FindToolType(ToolTypes, "CX_POPKEY")))
  301.                     strncpy(HotKeyDef, ThisTool, 127);
  302.             }
  303.  
  304.                 // Free our DiskObject again
  305.  
  306.             FreeDiskObject(MyObj);
  307.         }
  308.         return(TRUE);
  309.     }
  310.     else
  311.     {
  312.         APTR    *Args;
  313.         struct    RDArgs    *MyRDArgs;
  314.         BOOL    GoOn = FALSE;
  315.  
  316.             // Try to allocate buffer for ReadArgs
  317.  
  318.         if((Args = AllocVec((sizeof(ULONG) * LAST_ARG), MEMF_CLEAR)))
  319.         {
  320.                 // Parse commandline
  321.  
  322.             if((MyRDArgs = ReadArgs((char *)Template, (LONG *)Args, NULL)))
  323.             {
  324.                 GoOn = TRUE;
  325.  
  326.                 if(Args[PRI_ARG])
  327.                     *Pri = *(ULONG *)Args[PRI_ARG];
  328.  
  329.                 if(Args[POP_ARG])
  330.                 {
  331.                     if(!stricmp(Args[POP_ARG], "NO"))
  332.                         *PopUp = FALSE;
  333.                 }
  334.  
  335.                 if(Args[KEY_ARG])
  336.                     strncpy(HotKeyDef, Args[KEY_