Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.milw.wisc.edu!cs.utexas.edu!uunet!uvm-gen!chaffee From: chaffee@uvm-gen.UUCP (Alex D. Chaffee,231 Votey,,6581273) Newsgroups: comp.sys.mac.programmer Subject: Moving resources into the system file Summary: Under MultiFinder, moving resources into the system file corrupts it Keywords: frustrating resources technical system MultiFinder Message-ID: <1230@uvm-gen.UUCP> Date: 18 Jul 89 23:42:29 GMT Sender: nobody@uvm-gen.UUCP Distribution: na Organization: EMBA Computer Facility, Univ. of Vermont, Burlington. Lines: 68 I am writing a utility, called Valet, whose purpose in life is to move resources from one file to another. With the exception of one small flaw, it is ready to be posted into the public domain. This flaw concerns the system file: I "pack" a resource from another file into the (open) System file. Using my "Get info" command assures me that it is intact. I quit the program and immediately restart it. I open the System file again, do a get info, and bang! The resource is corrupt. The name and ID are fine, but SizeResource() returns -113. Yes, negative 113, or -111, or some arbitrarily huge number. ResEdit doesn't like it either. But if I open ResEdit after "packing" but before quitting (I'm using MultiFinder) and open the resource, it looks fine; then if I quit both and rerun Valet, _the resource _is_ fine_. Apparently ResEdit knows how to save the resource, but I don't. This only happens under MultiFinder. Under Finder, packing, quitting and restarting works perfectly. Before I order the Programmer's Guide to MultiFinder (which I somehow doubt would be much help, since I have done nothing even remotely sneaky or Finder-dependent), could someone tell me what, if anything, I can do to ensure that a resource I write to the system file stays healthy? The Fine Print: I am using a Mac SE, 2.5 megs, LightspeedC C v3.0. The problem occurs with or without the symbolic debugger, and from a standalone app; under Finder, it works when Run or launched. I have trashed and rebuilt my project, reinstalled LSC, reinstalled the System (dozens of times :-), and run under an INIT-free system. The program flow of "Packing" consists of: SetResLoad(FALSE); UseResFile(fileToPack); count = Count1Resources(type); for (i = 1; i <= count; ++i) { Hand = Get1IndResource(type, i); /* read the next resource */ [error checking] [ add resource data to an internal data structure ] } SetResLoad(TRUE); for ( [every resource] ) { [check if it exists] UseResFile(fileToPack); SetResLoad(TRUE); LoadResource(theItem->H); if (ResError()) ... DetachResource(theItem->H); if (ResError()) ... HNoPurge(theItem->H); UseResFile(masterFile); AddResource(theItem->H, theItem->species, newID, newName); if (ResError()) ... WriteResource(theItem->H); if (ResError()) ... } [erase internal data structure, without touching the resource handles] CloseResFile(fileToPack); UpdateResFile(masterFile); "Quitting" is: if ([the system file is open]) UpdateResFile(...); else CloseResFile(...); [dispose of all data -- but don't touch the resource handles] I have avoided (I believe) all the obvious pitfalls, like calling CloseResFile on the system file. I have error-checked beyond the limits of sanity. And IT WORKS UNDER UNIFINDER. Please, somebody... help... Alex Chaffee chaffee@emily.uvm.edu ____________________________