MCPcopy Create free account
hub / github.com/PCSX2/pcsx2 / cdvdSaveNVRAM

Function cdvdSaveNVRAM

pcsx2/CDVD/CDVD.cpp:207–239  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

205}
206
207void 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
241static void cdvdReadNVM(u8* dst, int offset, int bytes)
242{

Callers 1

ShutdownMethod · 0.85

Calls 4

cdvdGetNVRAMPathFunction · 0.85
GetDescriptionMethod · 0.80
c_strMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected