| 205 | } |
| 206 | |
| 207 | void cdvdSaveNVRAM() |
| 208 | { |
| 209 | Error error; |
| 210 | const std::string nvmfile = cdvdGetNVRAMPath(); |
| 211 | auto fp = FileSystem::OpenManagedCFileTryIgnoreCase(nvmfile.c_str(), "r+b", &error); |
| 212 | if (!fp) |
| 213 | { |
| 214 | fp = FileSystem::OpenManagedCFileTryIgnoreCase(nvmfile.c_str(), "w+b", &error); |
| 215 | if (!fp) [[unlikely]] |
| 216 | { |
| 217 | ERROR_LOG("Failed to open NVRAM at {} for updating: {}", Path::GetFileName(nvmfile), error.GetDescription()); |
| 218 | return; |
| 219 | } |
| 220 | } |
| 221 | |
| 222 | u8 existing_nvram[NVRAM_SIZE]; |
| 223 | if (std::fread(existing_nvram, sizeof(existing_nvram), 1, fp.get()) == 1 && |
| 224 | std::memcmp(existing_nvram, s_nvram, NVRAM_SIZE) == 0) |
| 225 | { |
| 226 | DEV_LOG("NVRAM has not changed, not writing to disk."); |
| 227 | return; |
| 228 | } |
| 229 | |
| 230 | if (FileSystem::FSeek64(fp.get(), 0, SEEK_SET) == 0 && |
| 231 | std::fwrite(s_nvram, NVRAM_SIZE, 1, fp.get()) == 1) |
| 232 | { |
| 233 | INFO_LOG("NVRAM saved to {}.", Path::GetFileName(nvmfile)); |
| 234 | } |
| 235 | else |
| 236 | { |
| 237 | ERROR_LOG("Failed to save NVRAM to {}: {}", Path::GetFileName(nvmfile), Error::CreateErrno(errno).GetDescription()); |
| 238 | } |
| 239 | } |
| 240 | |
| 241 | static void cdvdReadNVM(u8* dst, int offset, int bytes) |
| 242 | { |
no test coverage detected