mirror of
https://github.com/autc04/Retro68.git
synced 2024-12-22 19:30:36 +00:00
slight cleanup in class ResourceFile
This commit is contained in:
parent
57d99dfbed
commit
4e7e895782
@ -51,8 +51,8 @@ int main(int argc, char* argv[])
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResourceFile file(argv[1]);
|
ResourceFile file;
|
||||||
if(!file.read())
|
if(!file.read(argv[1]))
|
||||||
{
|
{
|
||||||
std::cerr << "Couldn't read input.\n";
|
std::cerr << "Couldn't read input.\n";
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -194,7 +194,7 @@ std::string fromhex(std::string hex)
|
|||||||
|
|
||||||
void Object::SingleSegmentApp(string output)
|
void Object::SingleSegmentApp(string output)
|
||||||
{
|
{
|
||||||
ResourceFile file(output);
|
ResourceFile file;
|
||||||
Resources& rsrc = file.resources;
|
Resources& rsrc = file.resources;
|
||||||
|
|
||||||
rsrc.addResource(Resource(ResType("CODE"), 0,
|
rsrc.addResource(Resource(ResType("CODE"), 0,
|
||||||
@ -218,7 +218,7 @@ void Object::SingleSegmentApp(string output)
|
|||||||
file.creator = ResType("????");
|
file.creator = ResType("????");
|
||||||
file.type = ResType("APPL");
|
file.type = ResType("APPL");
|
||||||
|
|
||||||
file.write();
|
file.write(output);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -227,7 +227,7 @@ void Object::MultiSegmentApp(string output, SegmentMap& segmentMap)
|
|||||||
{
|
{
|
||||||
bool noisy = false;
|
bool noisy = false;
|
||||||
|
|
||||||
ResourceFile file(output);
|
ResourceFile file;
|
||||||
Resources& rsrc = file.resources;
|
Resources& rsrc = file.resources;
|
||||||
|
|
||||||
for(auto namedSec : sections)
|
for(auto namedSec : sections)
|
||||||
@ -396,5 +396,5 @@ void Object::MultiSegmentApp(string output, SegmentMap& segmentMap)
|
|||||||
file.creator = ResType("????");
|
file.creator = ResType("????");
|
||||||
file.type = ResType("APPL");
|
file.type = ResType("APPL");
|
||||||
|
|
||||||
file.write();
|
file.write(output);
|
||||||
}
|
}
|
||||||
|
@ -22,8 +22,7 @@ Launcher::Launcher(boost::program_options::variables_map &options)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
app.assign(fn);
|
if(!app.read(fn))
|
||||||
if(!app.read())
|
|
||||||
throw std::runtime_error("Could not load application file.");
|
throw std::runtime_error("Could not load application file.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,8 +38,7 @@ Launcher::Launcher(boost::program_options::variables_map &options)
|
|||||||
Launcher::Launcher(boost::program_options::variables_map &options, ResourceFile::Format f)
|
Launcher::Launcher(boost::program_options::variables_map &options, ResourceFile::Format f)
|
||||||
: Launcher(options)
|
: Launcher(options)
|
||||||
{
|
{
|
||||||
app.assign(appPath.string(), f);
|
app.write(appPath.string(), f);
|
||||||
app.write();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Launcher::DumpOutput()
|
void Launcher::DumpOutput()
|
||||||
|
@ -11,8 +11,8 @@ namespace fs = boost::filesystem;
|
|||||||
|
|
||||||
void MakeExecutable(string fn)
|
void MakeExecutable(string fn)
|
||||||
{
|
{
|
||||||
ResourceFile rsrcFile(fn);
|
ResourceFile rsrcFile;
|
||||||
if(!rsrcFile.read())
|
if(!rsrcFile.read(fn))
|
||||||
{
|
{
|
||||||
std::cerr << "Cannot read application file: " << fn << std::endl;
|
std::cerr << "Cannot read application file: " << fn << std::endl;
|
||||||
exit(1);
|
exit(1);
|
||||||
|
@ -214,8 +214,8 @@ void MakeImportLibrary(char *pefptr, size_t pefsize, fs::path dest, fs::path tmp
|
|||||||
|
|
||||||
bool MakeImportLibraryMulti(fs::path path, fs::path libname)
|
bool MakeImportLibraryMulti(fs::path path, fs::path libname)
|
||||||
{
|
{
|
||||||
ResourceFile resFile(path.string());
|
ResourceFile resFile;
|
||||||
assert(resFile.read());
|
assert(resFile.read(path.string()));
|
||||||
|
|
||||||
std::vector<char> data(resFile.data.begin(), resFile.data.end());
|
std::vector<char> data(resFile.data.begin(), resFile.data.end());
|
||||||
|
|
||||||
|
@ -106,9 +106,9 @@ int main(int argc, char *argv[])
|
|||||||
if(options.count("input"))
|
if(options.count("input"))
|
||||||
for(std::string fn : options["input"].as<std::vector<std::string>>())
|
for(std::string fn : options["input"].as<std::vector<std::string>>())
|
||||||
{
|
{
|
||||||
ResourceFile rsrcFile(fn, format);
|
ResourceFile rsrcFile;
|
||||||
|
|
||||||
if(!rsrcFile.read())
|
if(!rsrcFile.read(fn, format))
|
||||||
{
|
{
|
||||||
std::cerr << "Can't read file.\n";
|
std::cerr << "Can't read file.\n";
|
||||||
return 1;
|
return 1;
|
||||||
@ -120,7 +120,7 @@ int main(int argc, char *argv[])
|
|||||||
if(showCreator)
|
if(showCreator)
|
||||||
out << " " << rsrcFile.creator;
|
out << " " << rsrcFile.creator;
|
||||||
if(showFormat)
|
if(showFormat)
|
||||||
out << " " << reverseFormats[rsrcFile.format];
|
out << " " << reverseFormats[rsrcFile.getFormat()];
|
||||||
if(showCount)
|
if(showCount)
|
||||||
out << " " << rsrcFile.resources.resources.size();
|
out << " " << rsrcFile.resources.resources.size();
|
||||||
if(showSize)
|
if(showSize)
|
||||||
|
@ -107,20 +107,18 @@ static void writeMacBinary(std::ostream& out, std::string filename,
|
|||||||
byte(out,0);
|
byte(out,0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ResourceFile::read(std::string path, Format f)
|
||||||
|
|
||||||
ResourceFile::ResourceFile()
|
|
||||||
{
|
{
|
||||||
|
if(!assign(path, f))
|
||||||
|
return false;
|
||||||
|
return read();
|
||||||
}
|
}
|
||||||
|
|
||||||
ResourceFile::ResourceFile(std::string path, ResourceFile::Format f)
|
bool ResourceFile::write(std::string path, Format f)
|
||||||
{
|
{
|
||||||
assign(path, f);
|
if(!assign(path, f))
|
||||||
}
|
return false;
|
||||||
|
return write();
|
||||||
ResourceFile::~ResourceFile()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool CheckAppleDouble(fs::path path, std::string prefix)
|
static bool CheckAppleDouble(fs::path path, std::string prefix)
|
||||||
@ -157,7 +155,7 @@ bool ResourceFile::assign(std::string pathstring, ResourceFile::Format f)
|
|||||||
format = Format::macbin;
|
format = Format::macbin;
|
||||||
else if(path.extension() == ".as")
|
else if(path.extension() == ".as")
|
||||||
format = Format::applesingle;
|
format = Format::applesingle;
|
||||||
else if(path.extension() == ".dsk" || path.extension() == ".img")
|
else if(path.extension() == ".dsk")
|
||||||
format = Format::diskimage;
|
format = Format::diskimage;
|
||||||
else if(path.filename().string().substr(0,2) == "._")
|
else if(path.filename().string().substr(0,2) == "._")
|
||||||
{
|
{
|
||||||
|
@ -25,30 +25,29 @@ public:
|
|||||||
percent_appledouble
|
percent_appledouble
|
||||||
};
|
};
|
||||||
|
|
||||||
ResourceFile();
|
bool read(std::string path, Format f = Format::autodetect);
|
||||||
ResourceFile(std::string path, Format f = Format::autodetect);
|
bool write(std::string path, Format f = Format::autodetect);
|
||||||
~ResourceFile();
|
|
||||||
|
|
||||||
bool assign(std::string path, Format f = Format::autodetect);
|
|
||||||
|
|
||||||
bool read(std::istream& in, Format f);
|
bool read(std::istream& in, Format f);
|
||||||
bool write(std::ostream& in, Format f);
|
bool write(std::ostream& in, Format f);
|
||||||
|
|
||||||
bool read();
|
|
||||||
bool write();
|
|
||||||
|
|
||||||
static bool hasPlainDataFork(Format f);
|
static bool hasPlainDataFork(Format f);
|
||||||
bool hasPlainDataFork();
|
bool hasPlainDataFork();
|
||||||
|
Format getFormat() { return format; }
|
||||||
|
|
||||||
static bool isSingleFork(Format f);
|
static bool isSingleFork(Format f);
|
||||||
|
|
||||||
std::string pathstring;
|
|
||||||
std::string filename;
|
|
||||||
Format format;
|
|
||||||
ResType type;
|
ResType type;
|
||||||
ResType creator;
|
ResType creator;
|
||||||
Resources resources;
|
Resources resources;
|
||||||
std::string data;
|
std::string data;
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool assign(std::string path, Format f = Format::autodetect);
|
||||||
|
bool read();
|
||||||
|
bool write();
|
||||||
|
|
||||||
|
std::string pathstring;
|
||||||
|
std::string filename;
|
||||||
|
Format format = Format::autodetect;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // RESOURCEFILE_H
|
#endif // RESOURCEFILE_H
|
||||||
|
17
Rez/Rez.cc
17
Rez/Rez.cc
@ -25,8 +25,8 @@ static void usage()
|
|||||||
|
|
||||||
static void CopyBinaryResources(RezWorld& world, const std::string& fn)
|
static void CopyBinaryResources(RezWorld& world, const std::string& fn)
|
||||||
{
|
{
|
||||||
ResourceFile copyRsrc(fn);
|
ResourceFile copyRsrc;
|
||||||
if(!copyRsrc.read())
|
if(!copyRsrc.read(fn))
|
||||||
{
|
{
|
||||||
world.problem(Diagnostic(Diagnostic::error, "Could not read binary resource file " + fn, yy::location()));
|
world.problem(Diagnostic(Diagnostic::error, "Could not read binary resource file " + fn, yy::location()));
|
||||||
}
|
}
|
||||||
@ -93,11 +93,11 @@ int main(int argc, const char *argv[])
|
|||||||
world.verboseFlag = true;
|
world.verboseFlag = true;
|
||||||
|
|
||||||
std::string outfile = options["output"].as<std::string>();
|
std::string outfile = options["output"].as<std::string>();
|
||||||
ResourceFile rsrcFile(outfile);
|
ResourceFile rsrcFile;
|
||||||
|
|
||||||
if(options.count("append"))
|
if(options.count("append"))
|
||||||
{
|
{
|
||||||
rsrcFile.read();
|
rsrcFile.read(outfile);
|
||||||
|
|
||||||
world.getResources().addResources(rsrcFile.resources);
|
world.getResources().addResources(rsrcFile.resources);
|
||||||
}
|
}
|
||||||
@ -105,8 +105,8 @@ int main(int argc, const char *argv[])
|
|||||||
if(options.count("data"))
|
if(options.count("data"))
|
||||||
{
|
{
|
||||||
std::string fn = options["data"].as<std::string>();
|
std::string fn = options["data"].as<std::string>();
|
||||||
ResourceFile dataFile(fn);
|
ResourceFile dataFile;
|
||||||
if(!dataFile.read())
|
if(!dataFile.read(fn))
|
||||||
world.problem(Diagnostic(Diagnostic::error, "Could not read dataresource file " + fn, yy::location()));
|
world.problem(Diagnostic(Diagnostic::error, "Could not read dataresource file " + fn, yy::location()));
|
||||||
rsrcFile.data = dataFile.data;
|
rsrcFile.data = dataFile.data;
|
||||||
}
|
}
|
||||||
@ -162,13 +162,12 @@ int main(int argc, const char *argv[])
|
|||||||
{
|
{
|
||||||
std::cerr << "Writing " << rsrcFile.resources.countResources() << " resources.\n";
|
std::cerr << "Writing " << rsrcFile.resources.countResources() << " resources.\n";
|
||||||
}
|
}
|
||||||
rsrcFile.write();
|
rsrcFile.write(outfile);
|
||||||
|
|
||||||
if(options.count("cc"))
|
if(options.count("cc"))
|
||||||
for(std::string ccFile : options["cc"].as<std::vector<std::string>>())
|
for(std::string ccFile : options["cc"].as<std::vector<std::string>>())
|
||||||
{
|
{
|
||||||
rsrcFile.assign(ccFile);
|
rsrcFile.write(ccFile);
|
||||||
rsrcFile.write();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user