Fork handle remembers the FSSpec it originated from

This commit is contained in:
Iliyas Jorio 2020-12-01 17:35:56 +01:00
parent ffc5a80b9c
commit 3ee40824cc
4 changed files with 18 additions and 5 deletions

View File

@ -45,6 +45,15 @@ std::iostream& Pomme::Files::GetStream(short refNum)
return openFiles[refNum]->GetStream();
}
const FSSpec& Pomme::Files::GetSpec(short refNum)
{
if (!IsRefNumLegal(refNum))
{
throw std::runtime_error("illegal refNum");
}
return openFiles[refNum]->spec;
}
void Pomme::Files::CloseStream(short refNum)
{
if (!IsRefNumLegal(refNum))

View File

@ -18,8 +18,8 @@ struct HostForkHandle : public ForkHandle
std::fstream backingStream;
public:
HostForkHandle(ForkType theForkType, char perm, fs::path& path)
: ForkHandle(theForkType, perm)
HostForkHandle(ForkType theForkType, char perm, fs::path& path, const FSSpec& theSpec)
: ForkHandle(theForkType, perm, theSpec)
{
std::ios::openmode openmode = std::ios::binary;
if (permission & fsWrPerm) openmode |= std::ios::out;
@ -135,7 +135,7 @@ OSErr HostVolume::OpenFork(const FSSpec* spec, ForkType forkType, char permissio
{
return fnfErr;
}
handle = std::make_unique<HostForkHandle>(DataFork, permission, path);
handle = std::make_unique<HostForkHandle>(DataFork, permission, path, *spec);
return noErr;
}
else
@ -173,7 +173,7 @@ OSErr HostVolume::OpenFork(const FSSpec* spec, ForkType forkType, char permissio
continue;
}
path = candidatePath;
handle = std::make_unique<HostForkHandle>(ResourceFork, permission, path);
handle = std::make_unique<HostForkHandle>(ResourceFork, permission, path, *spec);
if (c.isAppleDoubleFile)
{
ADFJumpToResourceFork(handle->GetStream());

View File

@ -15,11 +15,13 @@ namespace Pomme::Files
public:
ForkType forkType;
char permission;
FSSpec spec;
protected:
ForkHandle(ForkType _forkType, char _permission)
ForkHandle(ForkType _forkType, char _permission, const FSSpec& _spec)
: forkType(_forkType)
, permission(_permission)
, spec(_spec)
{}
public:

View File

@ -35,6 +35,8 @@ namespace Pomme::Files
std::iostream& GetStream(short refNum);
const FSSpec& GetSpec(short refNum);
void CloseStream(short refNum);
FSSpec HostPathToFSSpec(const fs::path& fullPath);