bsnes/icarus/core/game-boy-advance.cpp

45 lines
1.6 KiB
C++
Raw Normal View History

2015-08-21 11:29:53 +00:00
auto Icarus::gameBoyAdvanceManifest(const string& location) -> string {
vector<uint8_t> buffer;
concatenate(buffer, {location, "program.rom"});
return gameBoyAdvanceManifest(buffer, location);
}
auto Icarus::gameBoyAdvanceManifest(vector<uint8_t>& buffer, const string& location) -> string {
GameBoyAdvanceCartridge cartridge{buffer.data(), buffer.size()};
if(auto markup = cartridge.markup) {
markup.append("\n");
markup.append("information\n");
markup.append(" sha256: ", Hash::SHA256(buffer.data(), buffer.size()).digest(), "\n");
markup.append(" title: ", prefixname(location), "\n");
2015-08-21 11:29:53 +00:00
markup.append(" note: ", "heuristically generated by icarus\n");
return markup;
}
return "";
}
auto Icarus::gameBoyAdvanceImport(vector<uint8_t>& buffer, const string& location) -> bool {
auto name = prefixname(location);
auto source = pathname(location);
2015-08-21 11:29:53 +00:00
string target{settings.libraryPath, "Game Boy Advance/", name, ".gba/"};
//if(directory::exists(target)) return failure("game already exists");
string markup;
2015-08-21 11:29:53 +00:00
if(settings.useHeuristics && !markup) {
GameBoyAdvanceCartridge cartridge{buffer.data(), buffer.size()};
if(markup = cartridge.markup) {
markup.append("\n");
markup.append("information\n");
markup.append(" title: ", name, "\n");
markup.append(" note: heuristically generated by icarus\n");
}
}
2015-08-21 11:29:53 +00:00
if(!markup) return failure("failed to parse ROM image");
2015-08-21 11:29:53 +00:00
if(!directory::create(target)) return failure("library path unwritable");
if(settings.createManifests) file::write({target, "manifest.bml"}, markup);
file::write({target, "program.rom"}, buffer);
return success();
}