mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-02-15 08:49:20 +01:00
Core: In deterministic mode, build SD cards with a consistent filename order and dummy timestamps.
This commit is contained in:
parent
1d12e95404
commit
a621fdf857
@ -30,6 +30,7 @@ enum : u32
|
|||||||
|
|
||||||
static std::mutex s_fatfs_mutex;
|
static std::mutex s_fatfs_mutex;
|
||||||
static File::IOFile s_image;
|
static File::IOFile s_image;
|
||||||
|
static bool s_deterministic;
|
||||||
|
|
||||||
extern "C" DSTATUS disk_status(BYTE pdrv)
|
extern "C" DSTATUS disk_status(BYTE pdrv)
|
||||||
{
|
{
|
||||||
@ -96,6 +97,9 @@ extern "C" DRESULT disk_ioctl(BYTE pdrv, BYTE cmd, void* buff)
|
|||||||
|
|
||||||
extern "C" DWORD get_fattime(void)
|
extern "C" DWORD get_fattime(void)
|
||||||
{
|
{
|
||||||
|
if (s_deterministic)
|
||||||
|
return 0;
|
||||||
|
|
||||||
const std::time_t time = std::time(nullptr);
|
const std::time_t time = std::time(nullptr);
|
||||||
std::tm tm;
|
std::tm tm;
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
@ -286,13 +290,26 @@ static bool Pack(const File::FSTEntry& entry, bool is_root, std::vector<u8>& tmp
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SyncSDFolderToSDImage()
|
static void SortFST(File::FSTEntry* root)
|
||||||
{
|
{
|
||||||
|
std::sort(root->children.begin(), root->children.end(),
|
||||||
|
[](const File::FSTEntry& lhs, const File::FSTEntry& rhs) {
|
||||||
|
return lhs.virtualName < rhs.virtualName;
|
||||||
|
});
|
||||||
|
for (auto& child : root->children)
|
||||||
|
SortFST(&child);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SyncSDFolderToSDImage(bool deterministic)
|
||||||
|
{
|
||||||
|
deterministic = true;
|
||||||
const std::string root_path = File::GetUserPath(D_WIISDCARDSYNCFOLDER_IDX);
|
const std::string root_path = File::GetUserPath(D_WIISDCARDSYNCFOLDER_IDX);
|
||||||
if (!File::IsDirectory(root_path))
|
if (!File::IsDirectory(root_path))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
const File::FSTEntry root = File::ScanDirectoryTree(root_path, true);
|
File::FSTEntry root = File::ScanDirectoryTree(root_path, true);
|
||||||
|
if (deterministic)
|
||||||
|
SortFST(&root);
|
||||||
if (!CheckIfFATCompatible(root))
|
if (!CheckIfFATCompatible(root))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@ -302,6 +319,7 @@ bool SyncSDFolderToSDImage()
|
|||||||
size = AlignUp(size, MAX_CLUSTER_SIZE);
|
size = AlignUp(size, MAX_CLUSTER_SIZE);
|
||||||
|
|
||||||
std::lock_guard lk(s_fatfs_mutex);
|
std::lock_guard lk(s_fatfs_mutex);
|
||||||
|
s_deterministic = deterministic;
|
||||||
|
|
||||||
const std::string image_path = File::GetUserPath(F_WIISDCARDIMAGE_IDX);
|
const std::string image_path = File::GetUserPath(F_WIISDCARDIMAGE_IDX);
|
||||||
const std::string temp_image_path = File::GetTempFilenameForAtomicWrite(image_path);
|
const std::string temp_image_path = File::GetTempFilenameForAtomicWrite(image_path);
|
||||||
|
@ -7,6 +7,6 @@
|
|||||||
|
|
||||||
namespace Common
|
namespace Common
|
||||||
{
|
{
|
||||||
bool SyncSDFolderToSDImage();
|
bool SyncSDFolderToSDImage(bool deterministic);
|
||||||
bool SyncSDImageToSDFolder();
|
bool SyncSDImageToSDFolder();
|
||||||
} // namespace Common
|
} // namespace Common
|
||||||
|
@ -499,7 +499,7 @@ static void EmuThread(std::unique_ptr<BootParameters> boot, WindowSystemInfo wsi
|
|||||||
bool sync_sd_folder = core_parameter.bWii && Config::Get(Config::MAIN_WII_SD_CARD) &&
|
bool sync_sd_folder = core_parameter.bWii && Config::Get(Config::MAIN_WII_SD_CARD) &&
|
||||||
Config::Get(Config::MAIN_WII_SD_CARD_ENABLE_FOLDER_SYNC);
|
Config::Get(Config::MAIN_WII_SD_CARD_ENABLE_FOLDER_SYNC);
|
||||||
if (sync_sd_folder)
|
if (sync_sd_folder)
|
||||||
sync_sd_folder = Common::SyncSDFolderToSDImage();
|
sync_sd_folder = Common::SyncSDFolderToSDImage(Core::WantsDeterminism());
|
||||||
|
|
||||||
Common::ScopeGuard sd_folder_sync_guard{[sync_sd_folder] {
|
Common::ScopeGuard sd_folder_sync_guard{[sync_sd_folder] {
|
||||||
if (sync_sd_folder && Config::Get(Config::MAIN_ALLOW_SD_WRITES))
|
if (sync_sd_folder && Config::Get(Config::MAIN_ALLOW_SD_WRITES))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user