/* Watchdog - Überwacht einzelne dateien und gibt bei Veränderung einen
   Alert aus. Speziell für Christian "CTAF" Lemiesz...                  */

#include <dos/notify.h>
#include <exec/libraries.h>
#include <exec/memory.h>
#include <intuition/intuition.h>
#include <libraries/dos.h>
#include <libraries/dosextens.h>
#include <workbench/startup.h>
#include <workbench/workbench.h>


extern struct DosLibrary *DOSBase;
struct Library *CxBase;
struct MsgPort *myport=NULL;
struct NotifyMessage *msg;

UBYTE *aMsg=
	"\x00\xE0\x10" "*** Dumm-User-Alarm  #1 ***" "\x00\x01"
	"\x00\xE0\x1A" "Finger weg von dieser Datei" "\x00\x01"
	"\x00\xD8\x2A" "PRESS MOUSEBUTTON TO CONTINUE" "\x00";

WatchdogRequest(TEXT *name)
{
	DisplayAlert(DEADEND_ALERT, aMsg, 55);
}

main(int argc, char *argv[])
{
	long Version;
	char name[256];
	char *watch;
	UBYTE **ttypes;
	BOOL quit=FALSE;
	struct NotifyRequest *nreq;
	
	if((Version=DOSBase->dl_lib.lib_Version) > 36)
	{
		if(CxBase=(struct Library *) OpenLibrary("commodities.library",37))
		{
			myport=(struct MsgPort *) CreatePort(0,0);

			ttypes =(UBYTE **) ArgArrayInit(argc, &argv[0]);
		
			watch=(UBYTE *)ArgString(ttypes, "WATCH", ":disk.info");

			if(nreq=(struct NotifyRequest *)AllocVec(sizeof(struct NotifyRequest), MEMF_CLEAR|MEMF_PUBLIC))
			{
				nreq->nr_Name=watch;
				nreq->nr_Flags=NRF_SEND_MESSAGE;
				nreq->nr_stuff.nr_Msg.nr_Port=myport;
				
				if(StartNotify(nreq))
				{
					WaitPort(myport);
					msg=(struct NotifyMessage *)GetMsg(myport);
					strncpy(name, msg->nm_NReq->nr_Name, 255);
					ReplyMsg(msg);
					WatchdogRequest(name);
				}
				EndNotify(nreq);
				FreeVec(nreq);
			}
			DeletePort(myport);
			ArgArrayDone(); 
		}
		CloseLibrary(CxBase);
	}
}
			
void wbmain(wbs)
struct WBStartup *wbs;
{
	main(0 , (LONG *) wbs);
}
