mirror of
https://github.com/ksherlock/mpw.git
synced 2024-11-25 04:31:52 +00:00
use common code for opening resource file.
This commit is contained in:
parent
8257050afc
commit
1a70abf995
@ -449,8 +449,8 @@ namespace RM
|
|||||||
}
|
}
|
||||||
if (fd >= 0) close(fd);
|
if (fd >= 0) close(fd);
|
||||||
|
|
||||||
HFSUniStr255 fork = {0,{0}};
|
HFSUniStr255 fork = {0,{0}};
|
||||||
::FSGetResourceForkName(&fork);
|
::FSGetResourceForkName(&fork);
|
||||||
|
|
||||||
error = ::FSCreateResourceFork(&ref, fork.length, fork.unicode, 0);
|
error = ::FSCreateResourceFork(&ref, fork.length, fork.unicode, 0);
|
||||||
|
|
||||||
@ -468,17 +468,17 @@ namespace RM
|
|||||||
if (error != noErr)
|
if (error != noErr)
|
||||||
return (MacOS::macos_error)error;
|
return (MacOS::macos_error)error;
|
||||||
|
|
||||||
HFSUniStr255 fork = {0,{0}};
|
HFSUniStr255 fork = {0,{0}};
|
||||||
::FSGetResourceForkName(&fork);
|
::FSGetResourceForkName(&fork);
|
||||||
|
|
||||||
refNum = -1;
|
refNum = -1;
|
||||||
error = ::FSOpenResourceFile(&ref,
|
error = ::FSOpenResourceFile(&ref,
|
||||||
fork.length,
|
fork.length,
|
||||||
fork.unicode,
|
fork.unicode,
|
||||||
permission,
|
permission,
|
||||||
&refNum);
|
&refNum);
|
||||||
|
|
||||||
if (error != noErr)
|
if (error != noErr)
|
||||||
return (MacOS::macos_error)error;
|
return (MacOS::macos_error)error;
|
||||||
|
|
||||||
return refNum;
|
return refNum;
|
||||||
@ -488,13 +488,8 @@ namespace RM
|
|||||||
{
|
{
|
||||||
// OpenResFile (fileName: Str255) : INTEGER;
|
// OpenResFile (fileName: Str255) : INTEGER;
|
||||||
|
|
||||||
ResFileRefNum refNum;
|
|
||||||
FSRef ref;
|
|
||||||
|
|
||||||
uint32_t sp;
|
uint32_t sp;
|
||||||
uint32_t fileName;
|
uint32_t fileName;
|
||||||
uint16_t permission;
|
|
||||||
OSErr error;
|
|
||||||
|
|
||||||
sp = StackFrame<4>(fileName);
|
sp = StackFrame<4>(fileName);
|
||||||
|
|
||||||
@ -502,27 +497,11 @@ namespace RM
|
|||||||
|
|
||||||
Log("%04x OpenResFile(%s)\n", trap, sname.c_str());
|
Log("%04x OpenResFile(%s)\n", trap, sname.c_str());
|
||||||
|
|
||||||
error = ::FSPathMakeRef( (const UInt8 *)sname.c_str(), &ref, NULL);
|
auto rv = OpenResCommon(sname);
|
||||||
if (error != noErr)
|
|
||||||
{
|
|
||||||
ToolReturn<2>(sp, (uint16_t)-1);
|
|
||||||
return SetResError(error);
|
|
||||||
}
|
|
||||||
|
|
||||||
HFSUniStr255 fork = {0,{0}};
|
ToolReturn<2>(sp, rv.value_or(-1));
|
||||||
::FSGetResourceForkName(&fork);
|
|
||||||
|
|
||||||
refNum = -1;
|
return SetResError(rv.error());
|
||||||
permission = 0; // whatever is allowed.
|
|
||||||
error = ::FSOpenResourceFile(&ref,
|
|
||||||
fork.length,
|
|
||||||
fork.unicode,
|
|
||||||
permission,
|
|
||||||
&refNum);
|
|
||||||
|
|
||||||
ToolReturn<2>(sp, (uint16_t)refNum);
|
|
||||||
|
|
||||||
return SetResError(error);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t HOpenResFile(uint16_t trap)
|
uint16_t HOpenResFile(uint16_t trap)
|
||||||
@ -530,10 +509,6 @@ namespace RM
|
|||||||
// FUNCTION HOpenResFile (vRefNum: Integer; dirID: LongInt;
|
// FUNCTION HOpenResFile (vRefNum: Integer; dirID: LongInt;
|
||||||
// fileName: Str255; permission: SignedByte): Integer;
|
// fileName: Str255; permission: SignedByte): Integer;
|
||||||
|
|
||||||
ResFileRefNum refNum;
|
|
||||||
FSRef ref;
|
|
||||||
OSErr error;
|
|
||||||
|
|
||||||
uint32_t sp;
|
uint32_t sp;
|
||||||
|
|
||||||
uint16_t vRefNum;
|
uint16_t vRefNum;
|
||||||
@ -556,31 +531,15 @@ namespace RM
|
|||||||
sname = OS::FSSpecManager::ExpandPath(sname, dirID);
|
sname = OS::FSSpecManager::ExpandPath(sname, dirID);
|
||||||
if (sname.empty())
|
if (sname.empty())
|
||||||
{
|
{
|
||||||
error = MacOS::dirNFErr;
|
|
||||||
ToolReturn<2>(sp, (uint16_t)-1);
|
ToolReturn<2>(sp, (uint16_t)-1);
|
||||||
return SetResError(error);
|
return SetResError(MacOS::dirNFErr);
|
||||||
}
|
}
|
||||||
|
|
||||||
error = ::FSPathMakeRef( (const UInt8 *)sname.c_str(), &ref, NULL);
|
auto rv = OpenResCommon(sname, permission);
|
||||||
if (error != noErr)
|
|
||||||
{
|
|
||||||
ToolReturn<2>(sp, (uint16_t)-1);
|
|
||||||
return SetResError(error);
|
|
||||||
}
|
|
||||||
|
|
||||||
HFSUniStr255 fork = {0,{0}};
|
ToolReturn<2>(sp, rv.value_or(-1));
|
||||||
::FSGetResourceForkName(&fork);
|
|
||||||
|
|
||||||
refNum = -1;
|
return SetResError(rv.error());
|
||||||
error = ::FSOpenResourceFile(&ref,
|
|
||||||
fork.length,
|
|
||||||
fork.unicode,
|
|
||||||
permission,
|
|
||||||
&refNum);
|
|
||||||
|
|
||||||
ToolReturn<2>(sp, (uint16_t)refNum);
|
|
||||||
|
|
||||||
return SetResError(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t FSpOpenResFile(void)
|
uint16_t FSpOpenResFile(void)
|
||||||
@ -597,11 +556,17 @@ namespace RM
|
|||||||
int parentID = memoryReadLong(spec + 2);
|
int parentID = memoryReadLong(spec + 2);
|
||||||
|
|
||||||
std::string sname = ToolBox::ReadPString(spec + 6, false);
|
std::string sname = ToolBox::ReadPString(spec + 6, false);
|
||||||
sname = OS::FSSpecManager::ExpandPath(sname, parentID);
|
|
||||||
|
|
||||||
Log(" FSpOpenResFile(%s, %04x)\n", sname.c_str(), permission);
|
Log(" FSpOpenResFile(%s, %04x)\n", sname.c_str(), permission);
|
||||||
|
|
||||||
|
|
||||||
|
sname = OS::FSSpecManager::ExpandPath(sname, parentID);
|
||||||
|
if (sname.empty())
|
||||||
|
{
|
||||||
|
ToolReturn<2>(sp, (uint16_t)-1);
|
||||||
|
return SetResError(MacOS::dirNFErr);
|
||||||
|
}
|
||||||
|
|
||||||
auto rv = OpenResCommon(sname, permission);
|
auto rv = OpenResCommon(sname, permission);
|
||||||
|
|
||||||
ToolReturn<2>(sp, rv.value_or(-1));
|
ToolReturn<2>(sp, rv.value_or(-1));
|
||||||
|
Loading…
Reference in New Issue
Block a user