From a25b4549a2dd0fdeb009ae0ee7094ba835ae74f1 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Sat, 2 Oct 2021 03:47:42 +0200 Subject: [PATCH] BAHAHAHAHAAHAHAHhh --- src/FATStorage.cpp | 43 ++++++++++++++++++++++++++++++++++++++++--- src/FATStorage.h | 2 ++ src/NDSCart.cpp | 5 ++++- 3 files changed, 46 insertions(+), 4 deletions(-) diff --git a/src/FATStorage.cpp b/src/FATStorage.cpp index 388f8e45..11789741 100644 --- a/src/FATStorage.cpp +++ b/src/FATStorage.cpp @@ -56,7 +56,8 @@ FATStorage::FATStorage() FATStorage::~FATStorage() { - // + printf("SAVING DLDI SHIT\n"); + Save("dldi"); } @@ -298,7 +299,7 @@ void FATStorage::ExportDirectory(std::string path, std::string outbase, int leve fDIR dir; FILINFO info; FRESULT res; - +printf("EXPORTING DIRECTORY %s (base %s level %d)\n", path.c_str(), outbase.c_str(), level); std::string fullpath = "0:/" + path; res = f_opendir(&dir, fullpath.c_str()); if (res != FR_OK) return; @@ -332,7 +333,7 @@ void FATStorage::ExportDirectory(std::string path, std::string outbase, int leve else { bool doexport = false; - +printf("- FILE %s\n", fullpath.c_str()); if (FileIndex.count(fullpath) < 1) { doexport = true; @@ -866,3 +867,39 @@ bool FATStorage::Build(const char* sourcedir, u64 size, const char* filename) return true; } + +bool FATStorage::Save(std::string sourcedir) +{ + FF_File = Platform::OpenLocalFile(FilePath.c_str(), "r+b"); + if (!FF_File) + { + return false; + } + + FF_FileSize = FileSize; + ff_disk_open(FF_ReadStorage, FF_WriteStorage, (LBA_t)(FileSize>>9)); + + FRESULT res; + FATFS fs; + + res = f_mount(&fs, "0:", 1); + if (res != FR_OK) + { + ff_disk_close(); + fclose(FF_File); + FF_File = nullptr; + return false; + } + + ExportChanges("dldi"); + + SaveIndex(); + + f_unmount("0:"); + + ff_disk_close(); + fclose(FF_File); + FF_File = nullptr; + + return true; +} diff --git a/src/FATStorage.h b/src/FATStorage.h index 9e09a0d0..be3ab5a6 100644 --- a/src/FATStorage.h +++ b/src/FATStorage.h @@ -58,7 +58,9 @@ private: void CleanupDirectory(std::string path, int level); bool ImportFile(std::string path, std::string in); bool BuildSubdirectory(const char* sourcedir, const char* path, int level); + bool Build(const char* sourcedir, u64 size, const char* filename); + bool Save(std::string sourcedir); typedef struct { diff --git a/src/NDSCart.cpp b/src/NDSCart.cpp index e614bfcf..33ec5bf2 100644 --- a/src/NDSCart.cpp +++ b/src/NDSCart.cpp @@ -1178,7 +1178,10 @@ CartHomebrew::CartHomebrew(u8* rom, u32 len, u32 chipid) : CartCommon(rom, len, CartHomebrew::~CartHomebrew() { if (SDFile) fclose(SDFile); - if (test) delete test; + if (test) + { + delete test; + } } void CartHomebrew::Reset()