mirror of https://github.com/bsnes-emu/bsnes.git
57 lines
2.0 KiB
C++
57 lines
2.0 KiB
C++
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");
|
|
markup.append(" title: ", prefixname(location), "\n");
|
|
markup.append(" note: ", "heuristically generated by icarus\n");
|
|
return markup;
|
|
}
|
|
return "";
|
|
}
|
|
|
|
auto Icarus::sufamiTurboImport(vector<uint8_t>& buffer, const string& location) -> bool {
|
|
auto name = prefixname(location);
|
|
auto source = pathname(location);
|
|
string target{settings.libraryPath, "Sufami Turbo/", name, ".st/"};
|
|
//if(directory::exists(target)) return failure("game already exists");
|
|
|
|
string markup;
|
|
|
|
if(settings.useDatabase && !markup) {
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
|
|
if(settings.useHeuristics && !markup) {
|
|
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");
|
|
}
|
|
}
|
|
|
|
if(!markup) return failure("failed to parse ROM image");
|
|
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();
|
|
}
|