summaryrefslogtreecommitdiffstats
path: root/src/mac/SAP/macSAPglue.c
blob: 11d3ff7206185a985ae73f5f239a2318da91e66c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include <CodeFragments.h>
#include <Processes.h>

#define TBALERTID	135
#define TB30ALERTID	136

OSErr __initializeSAPglue(InitBlockPtr ibp);

OSErr __initializeSAPglue(InitBlockPtr ibp)
{
	OSErr					err = noErr;
	short					fileRefNum, theCurrentRes;
	DateTimeRec				goalTimeBomb;
	long					currentTime, goalTimeBombInSecs;
	ProcessSerialNumber		thePSN;
	ProcessInfoRec			thePIR;
	
	/* Do normal init of the shared library */
	__initialize();
	
	/* Start our hack by saving the current resource ref*/
	
	theCurrentRes = CurResFile();
	
	if (ibp->fragLocator.where == kDataForkCFragLocator)
	{ 
		fileRefNum = FSpOpenResFile(ibp->fragLocator.u.onDisk.fileSpec, fsRdPerm);
	
		if ( fileRefNum == -1 )
			err = ResError();
	}
	
	/* We assume that the current process is the one calling us. Good bet */
	err = GetCurrentProcess( &thePSN );
	
	if ( err == noErr )
	{
		GetProcessInformation( &thePSN, &thePIR );
		
		if ( thePIR.processType == 'APPL' )
		{
			switch ( thePIR.processSignature )
			{
				/* Here we case off each application based on its type code */
				case 'MIDA':
					/* This is SAP (supposedly) */
			
					goalTimeBomb.year = 1997;
					goalTimeBomb.month = 6;
					goalTimeBomb.day = 1;
					goalTimeBomb.hour = 0; /* Let's use midnight for simplicity */
					goalTimeBomb.minute = 0;
					goalTimeBomb.second = 0;
					
					DateToSeconds( &goalTimeBomb, &goalTimeBombInSecs );
					
					GetDateTime(&currentTime);
					
					if ( (goalTimeBombInSecs - currentTime) <= 0 )
					{
						StopAlert(TBALERTID, NULL);
						/* if we just reported an error, then the SAP client would continue running. We
							don't want that so instead we'll just call ExitToShell and hope it doesn't
							leave anything hangin. If we just wanted the error, report non-zero */
						//err = -1;
						ExitToShell();
				    }
				    else 
				    	if ( (goalTimeBombInSecs - currentTime) < 1209600 )
						{ /* num seconds in 14 days */
							NoteAlert(TB30ALERTID, NULL);
						}
					break;
				default:
					break;
			}
		}
	}
	if ( fileRefNum != -1 )
		CloseResFile( fileRefNum );
		
	UseResFile( theCurrentRes );
	
	return err;
}