2015-08-21 11:29:53 +00:00
|
|
|
auto Icarus::sufamiTurboManifest(const string& location) -> string {
|
|
|
|
vector<uint8_t> buffer;
|
|
|
|
concatenate(buffer, {location, "program.rom"});
|
|
|
|
return sufamiTurboManifest(buffer, location);
|
|
|
|
}
|
|
|
|
|
|
|
|
auto Icarus::sufamiTurboManifest(vector<uint8_t>& buffer, const string& location) -> string {
|
|
|
|
SufamiTurboCartridge 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::sufamiTurboImport(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(), "Sufami Turbo/", name, ".st/"};
|
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-11-19 09:27:56 +00:00
|
|
|
if(settings["icarus/UseDatabase"].boolean() && !markup) {
|
2015-09-28 11:56:46 +00:00
|
|
|
auto digest = Hash::SHA256(buffer.data(), buffer.size()).digest();
|
|
|
|
for(auto node : database.sufamiTurbo) {
|
|
|
|
if(node.name() != "release") continue;
|
|
|
|
if(node["information/sha256"].text() == digest) {
|
|
|
|
markup.append(BML::serialize(node["cartridge"]), "\n");
|
|
|
|
markup.append(BML::serialize(node["information"]));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
SufamiTurboCartridge 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, "program.rom"}, buffer);
|
|
|
|
return success();
|
|
|
|
}
|