From 6197910e3e141323c5ca7c34a7bfcb061add66a6 Mon Sep 17 00:00:00 2001 From: Kelvin Sherlock Date: Sat, 7 Feb 2015 12:30:30 -0500 Subject: [PATCH] RM::ChangedResource --- toolbox/rm.cpp | 54 +++++++++++++++++++++++++++++++++++++++++++++ toolbox/rm.h | 2 +- toolbox/toolbox.cpp | 4 ++++ 3 files changed, 59 insertions(+), 1 deletion(-) diff --git a/toolbox/rm.cpp b/toolbox/rm.cpp index 402207f..72722b5 100644 --- a/toolbox/rm.cpp +++ b/toolbox/rm.cpp @@ -780,6 +780,60 @@ namespace RM return SetResError(::ResError()); } + + uint16_t ChangedResource(uint16_t trap) + { + // PROCEDURE ChangedResource (theResource: Handle); + + uint32_t theResource; + + StackFrame<4>(theResource); + + Log("%04x ChangedResource(%04x)\n", trap, theResource); + + + // set the resChanged attribute so when UpdateResFile() is called + // (or the app exits) + // also needs to update the carbon handle/data with the mpw handle + // since the data has changed.... + + + auto iter = rhandle_map.find(theResource); + if (iter == rhandle_map.end()) + { + return SetResError(MacOS::resNotFound); + } + + Handle nativeHandle = iter->second; + + // check if handle size changed, resync data + + auto info = MM::GetHandleInfo(theResource); + if (!info.error()) return SetResError(info.error()); + + + uint32_t nativeSize = ::GetHandleSize(nativeHandle); + + if (nativeSize != info->size) { + // resize... + // chould get state / unlock / set state ... but that does nothing in OS X. + + ::SetHandleSize(nativeHandle, info->size); + OSErr err = MemError(); + if (err) return SetResError(err); + } + + std::memcpy(*nativeHandle, memoryPointer(info->address), info->size); + + ::ChangedResource(nativeHandle); + + return SetResError(::ResError()); + } + + + + + uint16_t GetResFileAttrs(uint16_t trap) { // FUNCTION GetResFileAttrs (refNum: Integer): Integer; diff --git a/toolbox/rm.h b/toolbox/rm.h index 6148545..af0cfb5 100644 --- a/toolbox/rm.h +++ b/toolbox/rm.h @@ -45,7 +45,7 @@ namespace RM uint16_t SetResAttrs(uint16_t trap); uint16_t WriteResource(uint16_t trap); uint16_t DetachResource(uint16_t trap); - + uint16_t ChangedResource(uint16_t trap); uint16_t RemoveResource(uint16_t trap); uint16_t GetResourceSizeOnDisk(uint16_t trap); diff --git a/toolbox/toolbox.cpp b/toolbox/toolbox.cpp index f53ec3f..b763772 100644 --- a/toolbox/toolbox.cpp +++ b/toolbox/toolbox.cpp @@ -549,6 +549,10 @@ namespace ToolBox { d0 = RM::AddResource(trap); break; + case 0xa9aa: + d0 = RM::ChangedResource(trap); + break; + case 0xa9ad: d0 = RM::RemoveResource(trap); break;