From 6c746f22813405543794fa983956854512521b6a Mon Sep 17 00:00:00 2001 From: Jesse Talavera-Greenberg Date: Tue, 26 Dec 2023 08:47:47 -0500 Subject: [PATCH 1/2] Apply some quick hotfixes - Set `NANDImage::Length` in the move constructor/assignment - Make `FATStorage`'s constructors `explicit` - Delegate to one of `FATStorage`'s constructors --- src/DSi_NAND.cpp | 4 +++- src/FATStorage.cpp | 7 ++----- src/FATStorage.h | 4 ++-- src/NDSCart.cpp | 10 ++++++++-- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/DSi_NAND.cpp b/src/DSi_NAND.cpp index 5f767142bd..8da02540e6 100644 --- a/src/DSi_NAND.cpp +++ b/src/DSi_NAND.cpp @@ -122,7 +122,8 @@ NANDImage::NANDImage(NANDImage&& other) noexcept : ConsoleID(other.ConsoleID), FATIV(other.FATIV), FATKey(other.FATKey), - ESKey(other.ESKey) + ESKey(other.ESKey), + Length(other.Length) { other.CurFile = nullptr; } @@ -140,6 +141,7 @@ NANDImage& NANDImage::operator=(NANDImage&& other) noexcept FATIV = other.FATIV; FATKey = other.FATKey; ESKey = other.ESKey; + Length = other.Length; other.CurFile = nullptr; } diff --git a/src/FATStorage.cpp b/src/FATStorage.cpp index 52011a8e72..bb470c5d1e 100644 --- a/src/FATStorage.cpp +++ b/src/FATStorage.cpp @@ -32,10 +32,7 @@ using namespace Platform; using std::string; FATStorage::FATStorage(const std::string& filename, u64 size, bool readonly, const std::optional& sourcedir) : - FilePath(filename), - FileSize(size), - ReadOnly(readonly), - SourceDir(sourcedir) + FATStorage(FATStorageArgs { filename, size, readonly, sourcedir }) { Load(filename, size, sourcedir); @@ -55,7 +52,7 @@ FATStorage::FATStorage(FATStorageArgs&& args) noexcept : { Load(FilePath, FileSize, SourceDir); - File = nullptr; + File = Platform::OpenLocalFile(FilePath, FileMode::ReadWriteExisting); } FATStorage::FATStorage(FATStorage&& other) noexcept diff --git a/src/FATStorage.h b/src/FATStorage.h index 1e89b764de..48a411b0c9 100644 --- a/src/FATStorage.h +++ b/src/FATStorage.h @@ -48,8 +48,8 @@ class FATStorage { public: FATStorage(const std::string& filename, u64 size, bool readonly, const std::optional& sourcedir = std::nullopt); - FATStorage(const FATStorageArgs& args) noexcept; - FATStorage(FATStorageArgs&& args) noexcept; + explicit FATStorage(const FATStorageArgs& args) noexcept; + explicit FATStorage(FATStorageArgs&& args) noexcept; FATStorage(FATStorage&& other) noexcept; FATStorage(const FATStorage& other) = delete; FATStorage& operator=(const FATStorage& other) = delete; diff --git a/src/NDSCart.cpp b/src/NDSCart.cpp index a5fe318098..a64d8a275f 100644 --- a/src/NDSCart.cpp +++ b/src/NDSCart.cpp @@ -1657,9 +1657,15 @@ std::unique_ptr ParseROM(std::unique_ptr&& romdata, u32 romlen std::unique_ptr sram = args ? std::move(args->SRAM) : nullptr; u32 sramlen = args ? args->SRAMLength : 0; if (homebrew) - cart = std::make_unique(std::move(cartrom), cartromsize, cartid, romparams, args ? std::move(args->SDCard) : std::nullopt); + { + std::optional sdcard = args && args->SDCard ? std::make_optional(std::move(*args->SDCard)) : std::nullopt; + cart = std::make_unique(std::move(cartrom), cartromsize, cartid, romparams, std::move(sdcard)); + } else if (gametitle[0] == 0 && !strncmp("SD/TF-NDS", gametitle + 1, 9) && gamecode == 0x414D5341) - cart = std::make_unique(std::move(cartrom), cartromsize, cartid, romparams, CartR4TypeR4, CartR4LanguageEnglish, args ? std::move(args->SDCard) : std::nullopt); + { + std::optional sdcard = args && args->SDCard ? std::make_optional(std::move(*args->SDCard)) : std::nullopt; + cart = std::make_unique(std::move(cartrom), cartromsize, cartid, romparams, CartR4TypeR4, CartR4LanguageEnglish, std::move(sdcard)); + } else if (cartid & 0x08000000) cart = std::make_unique(std::move(cartrom), cartromsize, cartid, romparams, std::move(sram), sramlen); else if (irversion != 0) From 31385b3aea50da8c6b182755306a0545b0460acb Mon Sep 17 00:00:00 2001 From: Jesse Talavera-Greenberg Date: Tue, 26 Dec 2023 10:30:06 -0500 Subject: [PATCH 2/2] Remove duplicated loading logic --- src/FATStorage.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/FATStorage.cpp b/src/FATStorage.cpp index bb470c5d1e..9a1a9ad478 100644 --- a/src/FATStorage.cpp +++ b/src/FATStorage.cpp @@ -34,9 +34,6 @@ using std::string; FATStorage::FATStorage(const std::string& filename, u64 size, bool readonly, const std::optional& sourcedir) : FATStorage(FATStorageArgs { filename, size, readonly, sourcedir }) { - Load(filename, size, sourcedir); - - File = Platform::OpenLocalFile(FilePath, FileMode::ReadWriteExisting); } FATStorage::FATStorage(const FATStorageArgs& args) noexcept :