From 5d008fc95259eedd90b9124f6ae56230d7cc6709 Mon Sep 17 00:00:00 2001 From: zhupengfei Date: Fri, 15 May 2020 23:08:59 +0800 Subject: [PATCH] Add version check --- src/core/importer.cpp | 7 +++++++ src/core/importer.h | 5 +++++ src/frontend/main.cpp | 30 +++++++++++++++++++++++++----- 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/src/core/importer.cpp b/src/core/importer.cpp index 9df5a78..1f70e77 100644 --- a/src/core/importer.cpp +++ b/src/core/importer.cpp @@ -899,6 +899,13 @@ std::vector LoadPresetConfig(std::string mount_point) { LOAD_DATA(system_archives_path, "sysarchives/"); LOAD_DATA(system_titles_path, "title/"); #undef LOAD_DATA + + // Load version + if (FileUtil::Exists(mount_point + "threeSD/version.txt")) { + std::ifstream stream; + OpenFStream(stream, mount_point + "threeSD/version.txt", std::ios::in); + stream >> config_template.version; + } } // Regex for 3DS ID0 and ID1 diff --git a/src/core/importer.h b/src/core/importer.h index d1f0fc4..2c7cdc7 100644 --- a/src/core/importer.h +++ b/src/core/importer.h @@ -79,8 +79,13 @@ struct Config { std::string system_archives_path; ///< Path to system archives. std::string system_titles_path; ///< Path to system titles. + + int version = 0; ///< Version of the dumper used. }; +// Version of the current dumper. +constexpr int CurrentDumperVersion = 1; + class SDMCFile; template diff --git a/src/frontend/main.cpp b/src/frontend/main.cpp index bd27cc8..2d6c300 100644 --- a/src/frontend/main.cpp +++ b/src/frontend/main.cpp @@ -98,9 +98,6 @@ void MainDialog::LoadPresetConfig() { auto list = Core::LoadPresetConfig(storage.rootPath().toStdString()); for (std::size_t i = 0; i < list.size(); ++i) { - if (!IsConfigGood(list[i])) { - return; - } preset_config_list.emplace_back(list[i]); QString path = storage.rootPath(); @@ -119,8 +116,13 @@ void MainDialog::LoadPresetConfig() { // Get status QString status = tr("Good"); - if (list[i].safe_mode_firm_path.empty() || list[i].config_savegame_path.empty() || - list[i].system_archives_path.empty()) { + if (!IsConfigGood(list[i])) { + status = tr("No Configuration Found"); + } else if (list[i].version != Core::CurrentDumperVersion) { + status = tr("Version Dismatch"); + } else if (list[i].safe_mode_firm_path.empty() || + list[i].config_savegame_path.empty() || + list[i].system_archives_path.empty()) { status = tr("Missing System Files"); } else if (list[i].seed_db_path.empty()) { @@ -172,6 +174,24 @@ void MainDialog::LaunchImportDialog() { } // Check config integrity + if (!IsConfigGood(config)) { + QMessageBox::critical( + this, tr("Error"), + tr("Could not load configuration from this SD card. You need to prepare your SD card " + "before using threeSD.
Please check if you have followed the " + "guide correctly.")); + return; + } + + if (config.version != Core::CurrentDumperVersion) { + QMessageBox::critical(this, tr("Version Dismatch"), + tr("You are using an unsupported version of threeSDumper.
Please " + "ensure that you are using the most recent version of both " + "threeSD and threeSDumper and try again.")); + return; + } + if (config.safe_mode_firm_path.empty() || config.config_savegame_path.empty() || config.system_archives_path.empty()) { QMessageBox::warning(