From 5426b3a741f79f2cfa42f2dde2235f4acfb3564c Mon Sep 17 00:00:00 2001 From: Wolfgang Thaller Date: Sat, 1 Nov 2014 01:58:18 +0100 Subject: [PATCH] fix reading/writing of real resource files on the mac --- ResourceFiles/ResourceFile.cc | 36 +++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/ResourceFiles/ResourceFile.cc b/ResourceFiles/ResourceFile.cc index a8d57575a2..46c3d51777 100644 --- a/ResourceFiles/ResourceFile.cc +++ b/ResourceFiles/ResourceFile.cc @@ -161,19 +161,36 @@ bool ResourceFile::read() { case Format::basilisk: { - fs::path rsrcPath = path.parent_path() / ".rsrc" / path.filename(); - fs::path finfPath = path.parent_path() / ".finf" / path.filename(); - - fs::ifstream rsrcIn(rsrcPath); - resources.addResources(Resources(rsrcIn)); - fs::ifstream finfIn(finfPath); - type = ostype(finfIn); - creator = ostype(finfIn); fs::ifstream dataIn(path); data = std::string(std::istreambuf_iterator(dataIn), std::istreambuf_iterator()); + + fs::ifstream rsrcIn(path.parent_path() / ".rsrc" / path.filename()); + resources.addResources(Resources(rsrcIn)); + fs::ifstream finfIn(path.parent_path() / ".finf" / path.filename()); + type = ostype(finfIn); + creator = ostype(finfIn); } break; +#ifdef __APPLE__ + case Format::real: + { + fs::ifstream dataIn(path); + data = std::string(std::istreambuf_iterator(dataIn), + std::istreambuf_iterator()); + fs::ifstream rsrcIn(path / "..namedfork" / "rsrc"); + resources.addResources(Resources(rsrcIn)); + + char finf[32]; + int n = getxattr(path.c_str(), XATTR_FINDERINFO_NAME, + finf, 32, 0, 0); + + std::istringstream finfIn(std::string(finf, finf+n)); + type = ostype(finfIn); + creator = ostype(finfIn); + } + break; +#endif default: return false; } @@ -202,7 +219,6 @@ bool ResourceFile::write() ostype(finfOut, creator); for(int i = 8; i < 32; i++) byte(finfOut, 0); - } break; #ifdef __APPLE__ @@ -213,7 +229,7 @@ bool ResourceFile::write() std::ostringstream finfOut; dataOut << data; - rsrc.writeFork(rsrcOut); + resources.writeFork(rsrcOut); ostype(finfOut, type); ostype(finfOut, creator);