2015-08-21 11:29:53 +00:00
|
|
|
auto Icarus::famicomManifest(const string& location) -> string {
|
|
|
|
vector<uint8_t> buffer;
|
|
|
|
concatenate(buffer, {location, "ines.rom"});
|
|
|
|
concatenate(buffer, {location, "program.rom"});
|
|
|
|
concatenate(buffer, {location, "character.rom"});
|
|
|
|
return famicomManifest(buffer, location);
|
|
|
|
}
|
|
|
|
|
|
|
|
auto Icarus::famicomManifest(vector<uint8_t>& buffer, const string& location) -> string {
|
|
|
|
FamicomCartridge 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");
|
2015-09-28 11:56:46 +00:00
|
|
|
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::famicomImport(vector<uint8_t>& buffer, const string& location) -> bool {
|
2015-09-28 11:56:46 +00:00
|
|
|
auto name = prefixname(location);
|
|
|
|
auto source = pathname(location);
|
2015-11-19 09:27:56 +00:00
|
|
|
string target{settings["Library/Location"].text(), "Famicom/", name, ".fc/"};
|
2015-08-21 11:29:53 +00:00
|
|
|
//if(directory::exists(target)) return failure("game already exists");
|
|
|
|
|
2015-09-28 11:56:46 +00:00
|
|
|
string markup;
|
2015-08-21 11:29:53 +00:00
|
|
|
|
2015-11-19 09:27:56 +00:00
|
|
|
//if(settings["icarus/UseHeuristics"].boolean() && !markup) {
|
2015-09-28 11:56:46 +00:00
|
|
|
FamicomCartridge 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
|
|
|
|
2015-09-28 11:56:46 +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");
|
|
|
|
|
2015-11-19 09:27:56 +00:00
|
|
|
if(settings["icarus/CreateManifests"].boolean()) file::write({target, "manifest.bml"}, markup);
|
2015-08-21 11:29:53 +00:00
|
|
|
file::write({target, "ines.rom"}, buffer.data(), 16);
|
|
|
|
file::write({target, "program.rom"}, buffer.data() + 16, cartridge.prgrom);
|
|
|
|
if(!cartridge.chrrom) return success();
|
|
|
|
file::write({target, "character.rom"}, buffer.data() + 16 + cartridge.prgrom, cartridge.chrrom);
|
|
|
|
return success();
|
|
|
|
}
|