home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-01-11 | 3.7 KB | 128 lines | [TEXT/KAHL] |
- // File "contexts.c" -
- // This source file is Copyright Matt Slot & Slot-Machines Ltd., © 1994
-
- #include <Folders.h>
- #include <Processes.h>
-
- #include "main.h"
- #include "contexts.h"
-
- // * ****************************************************************************** *
- // Global Vars
-
- extern GlobalsRec glob;
-
- // * ****************************************************************************** *
- // * ****************************************************************************** *
-
- short CloneResFile() {
- short err, i, j, makeInvis;
- short rID, appFile, cloneFile;
- long rType;
- Handle rsrc;
- Str63 textBuff;
- FInfo fInfo;
- ProcessSerialNumber psn;
- ProcessInfoRec pInfo;
-
- if (FindFolder(kOnSystemDisk, kTemporaryFolderType, -1, &glob.cloneSpec.vRefNum,
- &glob.cloneSpec.parID) && FindFolder(kOnSystemDisk, kSystemFolderType,
- -1, &glob.cloneSpec.vRefNum ,&glob.cloneSpec.parID)) {
- GetCurrentProcess(&psn);
- pInfo.processInfoLength = sizeof(pInfo);
- pInfo.processName = textBuff;
- pInfo.processAppSpec = &glob.cloneSpec;
- GetProcessInformation(&psn, &pInfo);
- makeInvis = -1;
- }
- else makeInvis = 0;
-
- BlockMove((Ptr) 0x910, glob.cloneSpec.name, sizeof(glob.cloneSpec.name));
- if (glob.cloneSpec.name[0] > 25) glob.cloneSpec.name[0] = 25;
- NumToString(TickCount() % 10000, textBuff);
- BlockMove(textBuff, glob.cloneSpec.name + glob.cloneSpec.name[0] + 1, textBuff[0]+1);
- glob.cloneSpec.name[glob.cloneSpec.name[0] + 1] = '\r';
- glob.cloneSpec.name[0] += textBuff[0] + 1;
-
- FSpCreateResFile(&glob.cloneSpec, kCreatorType, '????', 0);
- if ((err = ResError()) == dupFNErr) {
- FSpDelete(&glob.cloneSpec);
- FSpCreateResFile(&glob.cloneSpec, kCreatorType, '????', 0);
- }
- if (err = ResError()) return(err);
-
- // Only make it invisible if it *had* to be put in the same folder
- if (makeInvis) {
- FSpGetFInfo(&glob.cloneSpec, &fInfo);
- fInfo.fdFlags |= fInvisible;
- FSpSetFInfo(&glob.cloneSpec, &fInfo);
- }
-
- glob.appFile = appFile = CurResFile();
- cloneFile = FSpOpenResFile(&glob.cloneSpec, fsRdWrPerm);
- UseResFile(appFile);
- for(i=Count1Types(); i; i--) {
- Get1IndType((ResType *) &rType, i);
- if (rType == 'CODE') continue;
- for(j=Count1Resources(rType); j; j--) {
- rsrc = Get1IndResource(rType, j);
- GetResInfo(rsrc, &rID, (ResType *) &rType, textBuff);
- DetachResource(rsrc);
- UseResFile(cloneFile);
- AddResource(rsrc, rType, rID, textBuff);
- WriteResource(rsrc);
- if (ResError()) return(err);
- UseResFile(appFile);
- }
- }
- CloseResFile(cloneFile);
- return(err = ResError());
- }
-
- // * ****************************************************************************** *
- // * ****************************************************************************** *
-
- ContextPtr SaveContext(short homeContext) {
- ContextPtr context;
-
- context = (ContextPtr) NewPtrClear(sizeof(*context));
- if (!context) return;
-
- asm {
- move.l context, a0
- move.l a5, (a0)
- }
-
- GetPort(&context->savePort);
- context->heapZone = GetZone();
- context->curResFile = (homeContext) ? 0 : CurResFile();
-
- return(context);
- }
-
- // * ****************************************************************************** *
- // * ****************************************************************************** *
-
- void RestoreContext(ContextPtr context) {
- if (!context) return;
-
- asm {
- move.l context, a0
- move.l (a0), a5
- }
-
- SetPort(context->savePort);
- SetZone(context->heapZone);
- if (context->curResFile) UseResFile(context->curResFile);
- }
-
-
- // * ****************************************************************************** *
- // * ****************************************************************************** *
-
- void DisposeContext(ContextPtr context) {
- if (! context) return;
-
- DisposePtr((Ptr) context);
- }
-