[comp.sys.mac.programmer] Purge or Revert Resource?

holland@m2.csc.ti.com (Fred Hollander) (06/26/89)

I want to revert a resource that is already loaded into memory by
reading the resource from the resource file and discarding any
changes.  I also want to keep the same handle to the resource.  Can
this be done?  LoadResource won't do anything if it's already loaded.
I can't find a PurgeResource procedure.  Is there any way to force a
resource to be purged or to force a resource to be reloaded?

Thanks,
Fred
______________________________________________________________________________
| Fred Hollander                 |                                           |
| Computer Science Center        |     "Ha ha ha ha ha ha, Ah what a day!"   |
| Texas Instruments, Inc.        |             -- Joker                      |
| Internet:    hollander@ti.com  |                                           |
| Telnet:      214/995-0696      |  The above statements are my own and not  |
| AppleLink:   D1392             |  representative of Texas Instruments.     |
______________________________________________________________________________

trebor@biar.UUCP (Robert J Woodhead) (06/26/89)

In article <82203@ti-csl.csc.ti.com> holland@m2.csc.ti.com (Fred Hollander) writes:
>I want to revert a resource that is already loaded into memory by
>reading the resource from the resource file and discarding any
>changes.  I also want to keep the same handle to the resource.  Can
>this be done?  LoadResource won't do anything if it's already loaded.
>I can't find a PurgeResource procedure.  Is there any way to force a
>resource to be purged or to force a resource to be reloaded?

Check out DetachResource.  Assuming H is a handle to a resource such as
returned by GetResource, DetachResource(H) ``unlinks'' the handle so
the resource manager no longer recognises it as a handle to a resource.

So you can do something like this:

	DetachResource(H);
	DisposHandle(H);
	H:=GetResource('DERF',0);

to do your reversion.  I'm pretty sure that H will point to the same master
pointer after the GetResource call.  IM-I has some diagrams in the Resource
Manager chapter that explain DetachResource quite well.

-- 
(^;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-;^)
Robert J Woodhead, Biar Games, Inc.   !uunet!biar!trebor | trebor@biar.UUCP
  ``I can read your mind - right now, you're thinking I'm full of it...''

al@inebriae.UUCP (Al Evans) (06/26/89)

In article <82203@ti-csl.csc.ti.com> holland@m2.csc.ti.com (Fred Hollander) writes:
>I want to revert a resource that is already loaded into memory by
>reading the resource from the resource file and discarding any
>changes.  I also want to keep the same handle to the resource.  Can
>this be done?  LoadResource won't do anything if it's already loaded.
>I can't find a PurgeResource procedure.  Is there any way to force a
>resource to be purged or to force a resource to be reloaded?

I can't, offhand, think of any real clean way to do this and keep the same
handle. Probably, you should be making "provisional" changes on a COPY
of the original resource, anyway. That way you'd have your OWN handle, you
could revert at will, and only if you wanted to KEEP the changes would you
copy the resource back to the RM's handle and call ChangedResource on it.

                                             --Al Evans--
-- 
Al Evans    {tndev,texbell,ssbn}!inebriae!al
            al@inebriae.WLK.COM

al@inebriae.UUCP (Al Evans) (06/27/89)

In (some lost attribution line), Robert writes....

>Check out DetachResource.  Assuming H is a handle to a resource such as
>returned by GetResource, DetachResource(H) ``unlinks'' the handle so
>the resource manager no longer recognises it as a handle to a resource.
>
>So you can do something like this:
>
>	DetachResource(H);
>	DisposHandle(H);
>	H:=GetResource('DERF',0);
>
>to do your reversion.  I'm pretty sure that H will point to the same master
>pointer after the GetResource call.  IM-I has some diagrams in the Resource
>Manager chapter that explain DetachResource quite well.

I could be wrong, but I see nothing in IM which would imply this is true.
Seems to me it would be equivalent to saying:

	DisposHandle(H);
	H:= NewHandle(someSize);

and expecting H to be the same before and after. Though this may effectively
be the case, I don't think anything in IM *guarantees* it.

                                              --Al Evans--

-- 
Al Evans    {tndev,texbell,ssbn}!inebriae!al
            al@inebriae.WLK.COM

holland@m2.csc.ti.com (Fred Hollander) (06/27/89)

In article <689@biar.UUCP> trebor@biar.UUCP (Robert J Woodhead) writes:
>In article <82203@ti-csl.csc.ti.com> holland@m2.csc.ti.com (Fred Hollander) writes:
>>I want to revert a resource that is already loaded into memory by
>>reading the resource from the resource file and discarding any
>>changes.  I also want to keep the same handle to the resource.  Can
>
>So you can do something like this:
>
>	DetachResource(H);
>	DisposHandle(H);
>	H:=GetResource('DERF',0);
>
>to do your reversion.  I'm pretty sure that H will point to the same master
>pointer after the GetResource call.  IM-I has some diagrams in the Resource
>Manager chapter that explain DetachResource quite well.

It would be nice if it kept the same handle but, IM says (about
DetachResource) that a subsequent call to GetResource will cause a new
handle to be allocated.  Am I misunderstanding this?  Does it allocate
a new block (new pointer) but, actually keep the same handle?

Fred

______________________________________________________________________________
| Fred Hollander                 |                                           |
| Computer Science Center        |     "Ha ha ha ha ha ha, Ah what a day!"   |
| Texas Instruments, Inc.        |             -- Joker                      |
| Internet:    hollander@ti.com  |                                           |
| Telnet:      214/995-0696      |  The above statements are my own and not  |
| AppleLink:   D1392             |  representative of Texas Instruments.     |
______________________________________________________________________________

trebor@biar.UUCP (Robert J Woodhead) (06/27/89)

In article <376@inebriae.UUCP> al@inebriae.UUCP (Al Evans) writes:
>Seems to me it would be equivalent to saying:
>
>	DisposHandle(H);
>	H:= NewHandle(someSize);
>
>and expecting H to be the same before and after. Though this may effectively
>be the case, I don't think anything in IM *guarantees* it.

	You are right.  I misunderstood the original question slightly.

	Ok, the real need here is to purge the relocatable block and
	set the master pointer to nil.  This should be possible as
	follows:

		HUnlock(H);		{ can't be locked		}
		EmptyHandle(H);		{ IM II-40			}
		LoadResource(H);	{ gets it back from disk	}

-- 
(^;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-;^)
Robert J Woodhead, Biar Games, Inc.   !uunet!biar!trebor | trebor@biar.UUCP
  ``I can read your mind - right now, you're thinking I'm full of it...''

holland@m2.csc.ti.com (Fred Hollander) (06/28/89)

In article <693@biar.UUCP> trebor@biar.UUCP (Robert J Woodhead) writes:
>	Ok, the real need here is to purge the relocatable block and
>	set the master pointer to nil.  This should be possible as
>	follows:
>
>		HUnlock(H);		{ can't be locked		}
>		EmptyHandle(H);		{ IM II-40			}
>		LoadResource(H);	{ gets it back from disk	}

Just what I was looking for.  Thanks.

-Fred

______________________________________________________________________________
| Fred Hollander                 |                                           |
| Computer Science Center        |     "Ha ha ha ha ha ha, Ah what a day!"   |
| Texas Instruments, Inc.        |             -- Joker                      |
| Internet:    hollander@ti.com  |                                           |
| Telnet:      214/995-0696      |  The above statements are my own and not  |
| AppleLink:   D1392             |  representative of Texas Instruments.     |
______________________________________________________________________________

brecher@well.UUCP (Steve Brecher) (06/28/89)

In article <82203@ti-csl.csc.ti.com>, holland@m2.csc.ti.com (Fred Hollander)
writes:

> I want to revert a resource that is already loaded into memory by reading the
> resource from the resource file and discarding any changes.  I also want to
> keep the same handle to the resource.  Can this be done?  LoadResource won't
> do anything if it's already loaded. I can't find a PurgeResource procedure.
> Is there any way to force a resource to be purged or to force a resource to
> be reloaded?

        HUnlock(RsrcHandle);     {if it might have been locked}
        EmptyHandle(RsrcHandle); {this is the "PurgeResource" you sought}
        LoadResource(RsrcHandle);
-- 

brecher@well.UUCP (Steve Brecher)