mirror of https://github.com/bsnes-emu/bsnes.git
46 lines
1.6 KiB
C++
46 lines
1.6 KiB
C++
auto Icarus::superGrafxManifest(string location) -> string {
|
|
vector<uint8_t> buffer;
|
|
concatenate(buffer, {location, "program.rom"});
|
|
return superGrafxManifest(buffer, location);
|
|
}
|
|
|
|
auto Icarus::superGrafxManifest(vector<uint8_t>& buffer, string location) -> string {
|
|
string manifest;
|
|
|
|
if(settings["icarus/UseDatabase"].boolean() && !manifest) {
|
|
string digest = Hash::SHA256(buffer.data(), buffer.size()).digest();
|
|
for(auto node : database.superGrafx) {
|
|
if(node["sha256"].text() == digest) {
|
|
manifest.append(node.text(), "\n sha256: ", digest, "\n");
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
if(settings["icarus/UseHeuristics"].boolean() && !manifest) {
|
|
SuperGrafxCartridge cartridge{location, buffer.data(), buffer.size()};
|
|
manifest = cartridge.manifest;
|
|
}
|
|
|
|
return manifest;
|
|
}
|
|
|
|
auto Icarus::superGrafxImport(vector<uint8_t>& buffer, string location) -> string {
|
|
auto name = Location::prefix(location);
|
|
auto source = Location::path(location);
|
|
string target{settings["Library/Location"].text(), "SuperGrafx/", name, ".sg/"};
|
|
//if(directory::exists(target)) return failure("game already exists");
|
|
|
|
auto manifest = superGrafxManifest(buffer, location);
|
|
if(!manifest) return failure("failed to parse ROM image");
|
|
|
|
if(!directory::create(target)) return failure("library path unwritable");
|
|
if(file::exists({source, name, ".sav"}) && !file::exists({target, "save.ram"})) {
|
|
file::copy({source, name, ".sav"}, {target, "save.ram"});
|
|
}
|
|
|
|
if(settings["icarus/CreateManifests"].boolean()) file::write({target, "manifest.bml"}, manifest);
|
|
file::write({target, "program.rom"}, buffer);
|
|
return success(target);
|
|
}
|