2015-04-21 11:51:57 +00:00
|
|
|
auto Program::stateName(unsigned slot, bool manager) -> string {
|
|
|
|
return {
|
|
|
|
folderPaths[0], "higan/states/",
|
|
|
|
manager ? "managed/" : "quick/",
|
2015-12-06 21:11:41 +00:00
|
|
|
"slot-", natural(slot, 2L), ".bst"
|
2015-04-21 11:51:57 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
auto Program::loadState(unsigned slot, bool manager) -> bool {
|
|
|
|
if(!emulator) return false;
|
|
|
|
auto location = stateName(slot, manager);
|
|
|
|
auto memory = file::read(location);
|
2015-04-13 11:16:33 +00:00
|
|
|
if(memory.size() == 0) return showMessage({"Slot ", slot, " does not exist"}), false;
|
|
|
|
serializer s(memory.data(), memory.size());
|
2015-04-21 11:51:57 +00:00
|
|
|
if(emulator->unserialize(s) == false) return showMessage({"Slot ", slot, " state incompatible"}), false;
|
2015-04-13 11:16:33 +00:00
|
|
|
return showMessage({"Loaded from slot ", slot}), true;
|
|
|
|
}
|
|
|
|
|
2015-04-21 11:51:57 +00:00
|
|
|
auto Program::saveState(unsigned slot, bool manager) -> bool {
|
|
|
|
if(!emulator) return false;
|
|
|
|
auto location = stateName(slot, manager);
|
|
|
|
serializer s = emulator->serialize();
|
2015-04-13 11:16:33 +00:00
|
|
|
if(s.size() == 0) return showMessage({"Failed to save state to slot ", slot}), false;
|
2015-09-28 11:56:46 +00:00
|
|
|
directory::create(pathname(location));
|
2015-04-21 11:51:57 +00:00
|
|
|
if(file::write(location, s.data(), s.size()) == false) {
|
2015-04-13 11:16:33 +00:00
|
|
|
return showMessage({"Unable to write to slot ", slot}), false;
|
|
|
|
}
|
|
|
|
return showMessage({"Saved to slot ", slot}), true;
|
|
|
|
}
|