Oops
This commit is contained in:
@@ -45,18 +45,16 @@ void Mem::LoadSRAM(SaveType save_type, fs::path path) {
|
||||
saveData.unmap();
|
||||
}
|
||||
|
||||
FILE *f = fopen(sramPath.c_str(), "rb");
|
||||
if (!f) {
|
||||
Util::panic("Could not open {}", sramPath);
|
||||
auto sramVec = Util::ReadFileBinary(sramPath);
|
||||
if(sramVec.empty()) {
|
||||
Util::WriteFileBinary(std::array<u8, SRAM_SIZE>{}, sramPath);
|
||||
sramVec = Util::ReadFileBinary(sramPath);
|
||||
}
|
||||
|
||||
fseek(f, 0, SEEK_END);
|
||||
size_t actualSize = ftell(f);
|
||||
fseek(f, 0, SEEK_SET);
|
||||
if (actualSize != SRAM_SIZE) {
|
||||
if (sramVec.size() != SRAM_SIZE) {
|
||||
Util::panic("Corrupt SRAM!");
|
||||
}
|
||||
fclose(f);
|
||||
|
||||
saveData = mio::make_mmap_sink(
|
||||
sramPath, 0, mio::map_entire_file, error);
|
||||
if (error) { Util::panic("Could not mmap {}", sramPath); }
|
||||
|
||||
@@ -20,18 +20,17 @@ void Flash::Load(SaveType saveType, const std::string& path) {
|
||||
saveData.unmap();
|
||||
}
|
||||
|
||||
FILE *f = fopen(flashPath.c_str(), "rb");
|
||||
if (!f) {
|
||||
Util::panic("Could not open {}", flashPath);
|
||||
auto flashVec = Util::ReadFileBinary(flashPath);
|
||||
if(flashVec.empty()) {
|
||||
std::vector<u8> dummy{};
|
||||
dummy.resize(FLASH_SIZE);
|
||||
Util::WriteFileBinary(dummy, flashPath);
|
||||
flashVec = Util::ReadFileBinary(flashPath);
|
||||
}
|
||||
|
||||
fseek(f, 0, SEEK_END);
|
||||
size_t actualSize = ftell(f);
|
||||
fseek(f, 0, SEEK_SET);
|
||||
if (actualSize != FLASH_SIZE) {
|
||||
Util::panic("Corrupt flash!");
|
||||
if (flashVec.size() != FLASH_SIZE) {
|
||||
Util::panic("Corrupt SRAM!");
|
||||
}
|
||||
fclose(f);
|
||||
|
||||
saveData = mio::make_mmap_sink(
|
||||
flashPath, 0, mio::map_entire_file, error);
|
||||
|
||||
@@ -39,8 +39,10 @@ void PIF::MaybeLoadMempak() {
|
||||
}
|
||||
|
||||
auto mempakVec = Util::ReadFileBinary(mempakPath);
|
||||
if(mempak.empty())
|
||||
if(mempak.empty()) {
|
||||
Util::WriteFileBinary(std::array<u8, MEMPAK_SIZE>{}, mempakPath);
|
||||
mempakVec = Util::ReadFileBinary(mempakPath);
|
||||
}
|
||||
|
||||
if (mempakVec.size() != MEMPAK_SIZE) {
|
||||
Util::panic("Corrupt mempak!");
|
||||
@@ -87,6 +89,7 @@ void PIF::LoadEeprom(SaveType saveType, const std::string& path) {
|
||||
std::vector<u8> dummy{};
|
||||
dummy.resize(GetSaveSize(saveType));
|
||||
Util::WriteFileBinary(dummy, eepromPath);
|
||||
eepromVec = Util::ReadFileBinary(eepromPath);
|
||||
}
|
||||
|
||||
if (eepromVec.size() != eepromSize) {
|
||||
|
||||
Reference in New Issue
Block a user