ResourceFiles: read-only AppleDouble support (._filename convention)

This commit is contained in:
Wolfgang Thaller 2017-04-25 01:17:45 +02:00
parent d55bee477e
commit 3c4350b435
2 changed files with 71 additions and 13 deletions

View File

@ -142,7 +142,24 @@ bool ResourceFile::assign(std::string pathstring, ResourceFile::Format f)
format = Format::diskimage;
//else if(fs::exists(rsrcPath))
// format = Format::basilisk;
else
}
if(format == Format::autodetect)
{
fs::path adPath = path.parent_path() / ("._" + path.filename().string());
fs::ifstream in(adPath);
if(in)
{
int magic1 = longword(in);
if(in && magic1 == 0x00051607)
{
int magic2 = longword(in);
if(in && magic2 == 0x00020000)
format = Format::underscore_appledouble;
}
}
}
if(format == Format::autodetect)
{
fs::ifstream in(path);
if(in)
@ -156,7 +173,6 @@ bool ResourceFile::assign(std::string pathstring, ResourceFile::Format f)
}
}
}
}
if(format == Format::autodetect)
{
#ifdef __APPLE__
@ -186,9 +202,12 @@ bool ResourceFile::read()
fs::ifstream rsrcIn(path.parent_path() / ".rsrc" / path.filename());
resources = Resources(rsrcIn);
fs::ifstream finfIn(path.parent_path() / ".finf" / path.filename());
if(finfIn)
{
type = ostype(finfIn);
creator = ostype(finfIn);
}
}
break;
#ifdef __APPLE__
case Format::real:
@ -231,6 +250,7 @@ bool ResourceFile::read()
{
case 1:
// ###
// FIXME: read data fork
break;
case 2:
resources = Resources(in);
@ -243,6 +263,40 @@ bool ResourceFile::read()
}
}
break;
case Format::underscore_appledouble:
{
fs::ifstream dataIn(path);
data = std::string(std::istreambuf_iterator<char>(dataIn),
std::istreambuf_iterator<char>());
fs::path adPath = path.parent_path() / ("._" + path.filename().string());
fs::ifstream in(adPath);
if(longword(in) != 0x00051607)
return false;
if(longword(in) != 0x00020000)
return false;
in.seekg(24);
int n = word(in);
for(int i = 0; i < n; i++)
{
in.seekg(26 + i * 12);
int what = longword(in);
int off = longword(in);
//int len = longword(in);
in.seekg(off);
switch(what)
{
case 2:
resources = Resources(in);
break;
case 9:
type = ostype(in);
creator = ostype(in);
break;
}
}
}
break;
case Format::macbin:
{
fs::ifstream in(path);
@ -263,6 +317,7 @@ bool ResourceFile::read()
unsigned short crc = CalculateCRC(0,header,124);
if(word(in) != crc)
return false;
// FIXME: read data fork
in.seekg(128 + datasize);
resources = Resources(in);
}
@ -354,6 +409,9 @@ bool ResourceFile::write()
longword(out, 32);
}
break;
// TODO: case Format::underscore_appledouble
case Format::diskimage:
{
std::ostringstream rsrcOut;

View File

@ -18,7 +18,7 @@ public:
diskimage,
basilisk,
applesingle,
//underscore_ad,
underscore_appledouble,
//appledouble
};