home *** CD-ROM | disk | FTP | other *** search
- #define VERSION 4
- #define REVISION 0
-
- // Hotkey - screen to front
-
- #define PATCHVER="4.0"
-
- UBYTE SemName = "ModePro";
-
- UBYTE Version[] ="$VER: ModePro_Daemon "PATCHVER" "__AMIGADATE__;
- UBYTE ModeProPatch[]="ModePro Daemon "PATCHVER;
-
- void ShowGUI(void);
- void HideGUI(void);
- LONG SendPrefsMsg(ULONG Command, ULONG Code, APTR Data);
-
- /* Patch
- create struct.
- Load lists.
- InitSem(all sems);
- AddSem()
- ...
- quit:
- RemoveSem()
- ObtainSemaphore(SharedSem)
-
- ReplyMsgs
- */
-
- /* Prefs program:
- Forbid();
- if(Ms=FindSem("ModePro"))
- x=AttemptSemShared(SharedSem);
- Permit();
-
- if(x)
- {
- if(ver & rev)
- {
- ObtainSem(PortSem))
- Ms->PrefsPort=port;
- ReleaseSem(PortSem);
-
- PI()
-
- ObtainSem(PortSem)
- Ms->PrefsPort=NULL;
- ReleaseSem(PortSem);
- }
- else
- {
- wrong ver & rev
- }
-
- ReleaseSem(SharedSem)
- }
- else
- {
- print error
- }
- */
-
-
- struct IntuitionBase *IntuitionBase;
- struct Library *AslBase,
- *CxBase,
- *DiskfontBase,
- *GadToolsBase,
- *IconBase,
- *IFFParseBase,
- *LocaleBase,
- *UtilityBase;
-
- struct Libs MP_PatchLibs[]=
- {
- (APTR *)&AslBase, "asl.library", 38,
- (APTR *)&CxBase, "commodities.library",36,
- (APTR *)&DiskfontBase, "diskfont.library", 36,
- (APTR *)&GadToolsBase, "gadtools.library", 36,
- (APTR *)&IconBase, "icon.library", 36,
- (APTR *)&IFFParseBase, "iffparse.library", 36,
- (APTR *)&IntuitionBase,"intuition.library", 36,
- (APTR *)&UtilityBase, "utility.library", 36,
- 0,0,0
- };
-
- struct MPSem MPSem;
- struct MsgPort *CommodityPort,*ReplyPort;
-
- ULONG PublicSignal;
-
- void main(int argc, char **argv)
- {
-
- if(LocaleBase=OpenLibrary("locale.library",38))
- Catalog=OpenCatalog(NULL,(STRPTR)"modepro.catalog", TAG_DONE);
- else
- Catalog=NULL;
-
- if(OpenLibs(modepropatch,MP_PatchLibs))
- {
- if(GetArgs(argc,argv))
- {
- if(MPSem.PatchPort=CreateMsgPort())
- {
- InitSemaphore(&MPSem.PrefsSem);
- MPSem.PrefsSem.ss_Link.ln_Name = SemName;
- MPSem.PrefsSem.ss_Link.ln_Pri = 0;
-
- InitSemaphore(&MPSem.ListSem);
- MPSem.Version = VERSION;
- MPSem.Revision = REVISION;
-
- MPSem.PrefsPort=0;
- NewList(&MPSem.PromotionList[0]);
- NewList(&MPSem.PromotionList[1]);
- NewList(&MPSem.OpenList);
-
- if(CommodityPort=CreateMsgPort())
- {
- newbroker.nb_Pri=priority;
- newbroker.nb_Port=CommodityPort;
- if(broker=CxBroker(&newbroker,NULL))
- {
- filter=AddHotKey(broker,CommodityPort,hotkey,EVT_HOTKEY);
- if(CatchPort=CreateMsgPort())
- {
- if(PublicSignal=AllocSignal(-1))
- {
- MPTask=(struct Process *)FindTask(0);
- cxsig=1L<<CommodityPort->mp_SigBit;
- ActivateCxObj(broker,1);
-
- if(!LoadFile(EnvFile))
- LoadFile(EnvArcFile);
-
- Forbid();
- OldCloseScreen =SetFunction((struct Library *)IntuitionBase,-(0x42) ,(FUNCCAST)NewCloseScreen);
- OldOpenScreenTagList =SetFunction((struct Library *)IntuitionBase,-(0x264),(FUNCCAST)NewOpenScreenTagList);
- OldOpenScreen =SetFunction((struct Library *)IntuitionBase,-(0xc6) ,(FUNCCAST)NewOpenScreen);
- OldOpenWindowTagList =SetFunction((struct Library *)IntuitionBase,-(0x25e),(FUNCCAST)NewOpenWindowTagList);
- OldOpenWindow =SetFunction((struct Library *)IntuitionBase,-(0xcc) ,(FUNCCAST)NewOpenWindow);
- OldLayoutMenusA =SetFunction((struct Library *)GadToolsBase ,-(0x42) ,(FUNCCAST)NewLayoutMenusA);
- Permit();
-
- AddSemaphore(&MPSem.PrefsSem);
- ProcessInput();
- RemoveSemaphore(&MPSem.PrefsSem);
- ObtainSemaphore(&sem);
- ReleaseSemaphore(&sem);
- FreeDefList(&list[0]);
- FreeDefList(&list[1]);
- DeleteMsgPort(CatchPort);
- }
- }
- DeleteCxObjAll(broker);
- while(cxmsg=(CxMsg *)GetMsg(CommodityPort))
- ReplyMsg((struct Message *)cxmsg);
- }/* if CxBroker() */
- DeleteMsgPort(CommodityPort);
- }
- DeleteMsgPort(MPSem.PatchPort);
- }
- ArgArrayDone();
- FreeVec(winadd);
-
- }
- CloseLibs(MP_Libs);
- if(LocaleBase)
- {
- CloseCatalog(Catalog);
- CloseLibrary(LocaleBase);
- }
- }
-
- void ProcessInput(void)
- {
- struct DefaultNode *catdnode;
- struct MPMessage *mpmes;
- ULONG replysig,portsig,catchsig,signal,msgtype,pubsig,allsigs;
- LONG msgid;
-
- catchsig=1 << CatchPort->mp_SigBit;
- portsig =1 << CommodityPort->mp_SigBit;
- pubsig =1 << PublicSignal;
- replysig=1 << ReplyPort->mp_SigBit;
-
- allsigs=replysig | pubsig | catchsig | portsig | SIGBREAKF_CTRL_C;
-
- while (!deinstall)
- {
- signal=Wait (allsigs);
-
- if(replysig & signal)
- {
- while(mpmes=(struct MPMessage *)GetMsg(ReplyPort))
- {
- FreeVec(mpmes);
- }
- }
-
- if(pubsig & signal)
- {
- SetSignal(0,pubsig);
- ClosePubScreens();
- }
-
- if(catchsig & signal)
- {
- while(catdnode=(struct DefaultNode *)GetMsg(CatchPort))
- {
- AddDNode(catdnode->Type,catdnode);
- }
- if(CatPop)
- ShowGUI();
- }
-
- if(portsig & signal)
- {
- while(cxmsg=(CxMsg *)GetMsg(mp))
- {
- msgid=CxMsgID(cxmsg);
- msgtype=CxMsgType(cxmsg);
- ReplyMsg((struct Message *)cxmsg);
- switch(msgtype)
- {
- case CXM_IEVENT:
- switch(msgid)
- {
- case EVT_HOTKEY:
- ShowGUI();
- }
- break;
- case CXM_COMMAND:
- switch(msgid)
- {
- case CXCMD_DISABLE:
- if(menustrip && w)
- if(mi=ItemAddress(menustrip,FULLMENUNUM(0,6,NOSUB)))
- {
- mi->Flags&=(~CHECKED);
- ResetMenuStrip(w,menustrip);
- }
- active=FALSE;
- break;
- case CXCMD_ENABLE:
- if(menustrip && w)
- if(mi=ItemAddress(menustrip,FULLMENUNUM(0,6,NOSUB)))
- {
- mi->Flags|=CHECKED;
- ResetMenuStrip(w,menustrip);
- }
- active=TRUE;
- break;
- case CXCMD_KILL:
- CheckToQuit();
- break;
- case CXCMD_UNIQUE:
- case CXCMD_APPEAR:
- ShowGUI();
- closewindow=FALSE;
- break;
- case CXCMD_DISAPPEAR:
- if(w)
- HideGUI();
- closewindow=TRUE;
- break;
- }
- break;
- }
- }
- }
-
- }
- HideGUI();
- }
-
- void ShowGUI(void)
- {
- if(SendPrefsMsg(MP_PREFSTOFRONT,0,0)<0)
- Execute("run sys:prefs/ModePro");
- }
-
- void HideGUI(void)
- {
- SendPrefsMsg(MP_PREFSCLOSE,0,0);
- }
-
- /* returns -1 if prefs isn't running
- 0 if prefs is running but couldn't alloc mem
- 1 is message was sent */
- LONG SendPrefsMsg(ULONG Command, ULONG Code, APTR Data)
- {
- LONG rv=-1;
- struct MPMessage *mpm;
-
- ObtainSemaphore(&MPSem.PortSem);
- if(MPSem.PrefsPort)
- {
- rv=0;
- if(mpm=AllocVec(sizeof(struct MPMessage),MEMF_PUBLIC|MEMF_CLEAR))
- {
- PutMsg(MPSem.PrefsPort,(struct Message *)mpm);
- rv=1;
- }
- }
- ReleaseSemaphore(&MPSem.PortSem);
- return(rv);
- }
-