fix MakeAPPL again

This commit is contained in:
Wolfgang Thaller 2012-04-06 21:12:41 +02:00
parent 6b82186aad
commit 2ddb1c1849

View File

@ -36,16 +36,23 @@ public:
Resource(std::string type, int id, std::string data) Resource(std::string type, int id, std::string data)
: type(type), id(id), data(data) {} : type(type), id(id), data(data) {}
const std::string& getData() { return data; } const std::string& getData() const { return data; }
inline std::string getType() { return type; } inline std::string getType() const { return type; }
inline int getID() { return id; } inline int getID() const { return id; }
}; };
class Resources class Fork
{
public:
virtual void writeFork(std::ostream& out) const { }
virtual ~Fork() {}
};
class Resources : public Fork
{ {
std::vector<Resource> resources; std::vector<Resource> resources;
public: public:
void writeFork(std::ostream& out); void writeFork(std::ostream& out) const;
void addResource(Resource res) { resources.push_back(res); } void addResource(Resource res) { resources.push_back(res); }
}; };
@ -72,7 +79,7 @@ void longword(std::ostream& out, int longword)
} }
void Resources::writeFork(std::ostream& out) void Resources::writeFork(std::ostream& out) const
{ {
std::streampos start = out.tellp(); std::streampos start = out.tellp();
longword(out,0x100); longword(out,0x100);
@ -82,7 +89,7 @@ void Resources::writeFork(std::ostream& out)
out.seekp(start + std::streampos(0x100)); out.seekp(start + std::streampos(0x100));
std::map< std::string, std::map<int, int> > resourceInfos; std::map< std::string, std::map<int, int> > resourceInfos;
std::streampos datastart = out.tellp(); std::streampos datastart = out.tellp();
for(std::vector<Resource>::iterator p = resources.begin(); p != resources.end(); ++p) for(std::vector<Resource>::const_iterator p = resources.begin(); p != resources.end(); ++p)
{ {
const std::string& data = p->getData(); const std::string& data = p->getData();
resourceInfos[ p->getType() ][ p->getID() ] = out.tellp() - datastart; resourceInfos[ p->getType() ][ p->getID() ] = out.tellp() - datastart;
@ -193,13 +200,13 @@ static unsigned short CalculateCRC(unsigned short CRC, const char* dataBlock, in
void writeMacBinary(std::ostream& out, std::string filename, void writeMacBinary(std::ostream& out, std::string filename,
std::string type, std::string creator, std::string type, std::string creator,
std::string rsrc, std::string data) const Fork& rsrc, const Fork& data)
{ {
out.seekp(128); out.seekp(128);
out.write(&data[0], data.size()); data.writeFork(out);
std::streampos dataend = out.tellp(); std::streampos dataend = out.tellp();
std::streampos rsrcstart = ((int)dataend + 0x7F) & ~0x7F; std::streampos rsrcstart = ((int)dataend + 0x7F) & ~0x7F;
out.write(&rsrc[0], rsrc.size()); rsrc.writeFork(out);
std::streampos rsrcend = out.tellp(); std::streampos rsrcend = out.tellp();
while((int)out.tellp() % 128) while((int)out.tellp() % 128)
@ -366,12 +373,8 @@ int main(int argc, char *argv[])
{ {
std::ofstream out(binFileName.c_str()); std::ofstream out(binFileName.c_str());
std::ostringstream rsrcStream; writeMacBinary(out, outFileName, "APPL", "????",
rsrc.writeFork(rsrcStream); rsrc, Fork());
writeMacBinary(out, outFileName, "APPL", "????",
rsrcStream.str(),
std::string());
} }
wrapMacBinary(binFileName, dskFileName); wrapMacBinary(binFileName, dskFileName);
return 0; return 0;