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 >
Wrap
C/C++ Source or Header
|
1993-12-31
|
24KB
|
1,030 lines
/*
Auto: smake ForceIcon
*/
/* $Revision Header built automatically *************** (do not edit) ************
**
** © Copyright by GuntherSoft
**
** File : SnakeSYS:CPrgs/Utils/ForceIcon.c
** Created on : Wednesday, 20.10.93 15:55:50
** Created by : Kai Iske
** Current revision : V1.0
**
**
** Purpose
** -------
** - Forces Disk Icons to a specified position.
** Usefull for CD-Rom users
**
** Revision V1.0
** --------------
** created on Wednesday, 20.10.93 15:55:50 by Kai Iske. LogMessage :
** --- Initial release ---
**
*********************************************************************************/
/**********************************************************************/
/* External references */
/**********************************************************************/
extern struct Window *MainWinHandle; // Window handles
extern struct Window *EditWinHandle;
extern struct Window *PosWinHandle;
extern struct Window *ManWinHandle;
/**********************************************************************/
/* Library bases */
/**********************************************************************/
struct ExecBase *SysBase;
struct IntuitionBase *IntuitionBase = NULL;
struct Library *DiskfontBase = NULL;
struct GfxBase *GfxBase = NULL;
struct Library *GadToolsBase = NULL;
struct DosLibrary *DOSBase = NULL;
struct Library *IconBase = NULL;
struct Library *UtilityBase = NULL;
struct Library *CxBase = NULL;
struct Library *IFFParseBase = NULL;
struct Library *AslBase = NULL;
/**********************************************************************/
/* Broker Definition */
/**********************************************************************/
struct NewBroker BrokerDef =
{
NB_VERSION,
"ForceIcon",
"ForceIcon v"REVISION,
"Forces icons to abolute position",
NBU_NOTIFY|NBU_UNIQUE,
COF_SHOW_HIDE,
0,
NULL,
0
};
/**********************************************************************/
/* Commandline template */
/**********************************************************************/
static const char *Template = "CX_PRIORITY/K/N,CX_POPUP/K,CX_POPKEY/K";
enum {PRI_ARG, POP_ARG, KEY_ARG, LAST_ARG};
/**********************************************************************/
/* "No-StartUp vars" */
/**********************************************************************/
static const char _VER[] = "\0$VER: ForceIcon "REVISION" ("REVDATE")\0";
char _ProgramName[] = "ForceIcon";
LONG _OSERR = 0;
/**********************************************************************/
/* Global variables */
/**********************************************************************/
static ULONG __asm (*OldGetIcon)(register __a0 UBYTE *, register __a1 struct DiskObject *, register __a2 struct FreeList *, register __a6 struct Library *);
static ULONG __asm (*OldLock)(register __d1 UBYTE *, register __d2 ULONG, register __a6 struct DosLibrary *);
struct List VolumeList; // List of patched volumes
struct SignalSemaphore MySemaphore; // My beautiful semaphore
struct WBStartup *_WBenchMsg = NULL; // StartUp message
struct IClass *GetFileClass; // ImageClass for GetFile
static UWORD Active = TRUE; // State of Broker
/**********************************************************************/
/* This is our main program */
/**********************************************************************/
ULONG __saveds main(void)
{
struct Class *InitGetFile(void);
struct Process *MyProc;
struct MsgPort *BrokerPort;
CxObj *InputBroker;
CxObj *InputKey;
ULONG Error, Pri = 0;
char HotKeyDef[128];
BOOL PopUp = TRUE;
// Get SysBase
SysBase = *((struct ExecBase **)0x4L);
// Get address of our process
MyProc = (struct Process *)FindTask(NULL);
// Determine where we were started from
if(!MyProc->pr_CLI)
_WBenchMsg = (struct WBStartup *)GetMsg(&MyProc->pr_MsgPort);
// Initialize our semaphore
InitSemaphore(&MySemaphore);
// Open libraries
if(OpenAll())
{
// Check for tooltypes or Commandline args
if(CheckToolTypes(HotKeyDef, &Pri, &PopUp))
{
if((GetFileClass = (struct IClass *)InitGetFile()))
{
// Load in preferences
LoadPrefs();
// Create our Message Port for the Broker
if((BrokerPort = CreateMsgPort()))
{
// Set up additional fields within broker structure
BrokerDef.nb_Port = BrokerPort;
BrokerDef.nb_Pri = Pri;
// Create broker
if((InputBroker = CxBroker(&BrokerDef, (LONG *)&Error)))
{
// Create HotKey
if((InputKey = HotKey(HotKeyDef, BrokerPort, POPKEY)))
{
// Attach HotKey to Broker
AttachCxObj(InputBroker, InputKey);
// Activate Broker
ActivateCxObj(InputBroker, TRUE);
Forbid();
// Patch icon.library functions
OldGetIcon = (ULONG *)SetFunction(IconBase, -0x0000002a, &MyGetIcon);
// Patch dos.library functions
OldLock = (ULONG *)SetFunction(DOSBase, -0x00000054, &MyLock);
Permit();
// PopUp main window ???
if(PopUp)
OpenMainWin();
// Handle all inputs
HandleInput(BrokerPort, InputBroker);
Forbid();
// Reinstall old icon.library functions
SetFunction(IconBase, -0x0000002a, OldGetIcon);
// Restore DOS-Library functions
SetFunction(DOSBase, -0x00000054, OldLock);
Permit();
}
// Dispose Broker
DeleteCxObjAll(InputBroker);
}
// Remove Msg-Port
DeleteMsgPort(BrokerPort);
}
// Free list of patches
FreeDevVolList(&VolumeList);
// Dispose GetFile class
FreeClass(GetFileClass);
}
else
DisplayError(ERR_NOFILE, NULL);
}
}
// Close libs
CloseAll();
// Send back WBStartUp Message
if(_WBenchMsg)
{
Forbid();
ReplyMsg((struct Message *)_WBenchMsg);
}
return(0);
}
/**********************************************************************/
/* Functionreplacements */
/**********************************************************************/
void chkabort(void){;}
void __stdargs _XCEXIT(LONG Val){;}
/**********************************************************************/
/* Check for ToolTypes */
/**********************************************************************/
BOOL CheckToolTypes(char *HotKeyDef, ULONG *Pri, BOOL *PopUp)
{
// set default PopUp HotKey
strcpy(HotKeyDef, "lalt lshift i");
// Did we come from WB ???
if(_WBenchMsg)
{
struct WBArg *MyArg = _WBenchMsg->sm_ArgList;
struct DiskObject *MyObj;
char **ToolTypes, *ThisTool;
// Switch to currentdir
CurrentDir(MyArg->wa_Lock);
// Try to get our icon
if((MyObj = GetDiskObjectNew(MyArg->wa_Name)))
{
// Get tooltypes
if((ToolTypes = MyObj->do_ToolTypes))
{
// Parse ToolTypes
if((ThisTool = FindToolType(ToolTypes, "CX_PRIORITY")))
{
char *Dummy;
*Pri = strtol(ThisTool, &Dummy, 10);
}
if((ThisTool = FindToolType(ToolTypes, "CX_POPUP")))
*PopUp = !(MatchToolValue(ThisTool, "NO"));
if((ThisTool = FindToolType(ToolTypes, "CX_POPKEY")))
strncpy(HotKeyDef, ThisTool, 127);
}
// Free our DiskObject again
FreeDiskObject(MyObj);
}
return(TRUE);
}
else
{
APTR *Args;
struct RDArgs *MyRDArgs;
BOOL GoOn = FALSE;
// Try to allocate buffer for ReadArgs
if((Args = AllocVec((sizeof(ULONG) * LAST_ARG), MEMF_CLEAR)))
{
// Parse commandline
if((MyRDArgs = ReadArgs((char *)Template, (LONG *)Args, NULL)))
{
GoOn = TRUE;
if(Args[PRI_ARG])
*Pri = *(ULONG *)Args[PRI_ARG];
if(Args[POP_ARG])
{
if(!stricmp(Args[POP_ARG], "NO"))
*PopUp = FALSE;
}
if(Args[KEY_ARG])
strncpy(HotKeyDef, Args[KEY_