diff options
author | Arisotura <thetotalworm@gmail.com> | 2022-09-23 22:53:23 +0200 |
---|---|---|
committer | Arisotura <thetotalworm@gmail.com> | 2022-09-23 22:53:23 +0200 |
commit | 86786738cc91dbea5f9dcdf0e147bd6615e1ca46 (patch) | |
tree | 090abb961c3b990517a8b5d6c5018d7801c71202 /src/DSi_NAND.cpp | |
parent | fc112580710a1a96b38ded2481e54a1ba42a3e0d (diff) |
properly make the DSi NAND instance-unique
Diffstat (limited to 'src/DSi_NAND.cpp')
-rw-r--r-- | src/DSi_NAND.cpp | 49 |
1 files changed, 48 insertions, 1 deletions
diff --git a/src/DSi_NAND.cpp b/src/DSi_NAND.cpp index e24ed31..912fee4 100644 --- a/src/DSi_NAND.cpp +++ b/src/DSi_NAND.cpp @@ -49,8 +49,48 @@ UINT FF_ReadNAND(BYTE* buf, LBA_t sector, UINT num); UINT FF_WriteNAND(BYTE* buf, LBA_t sector, UINT num); -bool Init(FILE* nandfile, u8* es_keyY) +bool Init(u8* es_keyY) { + CurFile = nullptr; + + std::string nandpath = Platform::GetConfigString(Platform::DSi_NANDPath); + std::string instnand = nandpath + Platform::InstanceFileSuffix(); + + FILE* nandfile = Platform::OpenLocalFile(instnand, "r+b"); + if ((!nandfile) && (Platform::InstanceID() > 0)) + { + FILE* orig = Platform::OpenLocalFile(nandpath, "rb"); + if (!orig) + { + printf("Failed to open DSi NAND\n"); + return false; + } + + fseek(orig, 0, SEEK_END); + long len = ftell(orig); + fseek(orig, 0, SEEK_SET); + + nandfile = Platform::OpenLocalFile(instnand, "w+b"); + if (nandfile) + { + u8* tmpbuf = new u8[0x10000]; + for (long i = 0; i < len; i+=0x10000) + { + long blklen = 0x10000; + if ((i+blklen) > len) blklen = len-i; + + fread(tmpbuf, blklen, 1, orig); + fwrite(tmpbuf, blklen, 1, nandfile); + } + delete[] tmpbuf; + } + + fclose(orig); + fclose(nandfile); + + nandfile = Platform::OpenLocalFile(instnand, "r+b"); + } + if (!nandfile) return false; @@ -138,10 +178,17 @@ void DeInit() f_unmount("0:"); ff_disk_close(); + if (CurFile) fclose(CurFile); CurFile = nullptr; } +FILE* GetFile() +{ + return CurFile; +} + + void GetIDs(u8* emmc_cid, u64& consoleid) { memcpy(emmc_cid, eMMC_CID, 16); |