Slight fixups with FATStorage (#1934)

* Reload the SD card for `CartSD` and all subclasses

* Make `ROMManager::LoadDLDISDCard` delegate to `GetDLDISDCardArgs`

* Add a method overload for `CartSD::SetSDCard`

* Initialize new SD card images with the correct size

* Sync the old card to the host (if applicable) when move-assigning a new one

* Only sync the old card to the host if it's not read-only

* Remove static state in `FATStorage`

- Replace `FF_ReadStorage` and `FF_WriteStorage` with lambda functions
- Keep open and use the single `File` handle throughout the `FATStorage`'s life
This commit is contained in:
Jesse Talavera
2024-01-03 07:32:17 -05:00
committed by GitHub
parent 8bfc6df8de
commit d1cbc41115
5 changed files with 51 additions and 60 deletions

View File

@ -759,7 +759,12 @@ std::optional<DSi_NAND::NANDImage> LoadNAND(const std::array<u8, DSiBIOSSize>& a
return nandImage;
}
constexpr u64 imgsizes[] = {0, 256, 512, 1024, 2048, 4096};
constexpr u64 MB(u64 i)
{
return i * 1024 * 1024;
}
constexpr u64 imgsizes[] = {0, MB(256), MB(512), MB(1024), MB(2048), MB(4096)};
std::optional<FATStorageArgs> GetDSiSDCardArgs() noexcept
{
if (!Config::DSiSDEnable)
@ -804,12 +809,7 @@ std::optional<FATStorage> LoadDLDISDCard() noexcept
if (!Config::DLDIEnable)
return std::nullopt;
return FATStorage(
Config::DLDISDPath,
imgsizes[Config::DLDISize],
Config::DLDIReadOnly,
Config::DLDIFolderSync ? std::make_optional(Config::DLDIFolderPath) : std::nullopt
);
return FATStorage(*GetDLDISDCardArgs());
}
void EnableCheats(NDS& nds, bool enable)