Only update the card optionally

This commit is contained in:
BernardoGiordano 2019-07-08 22:22:38 +02:00
parent a54fcb8834
commit 1cba69344e
5 changed files with 86 additions and 13 deletions

View file

@ -12,5 +12,7 @@
},
"nand_saves": false,
"version": 2
"scan_cart": false,
"ftp-enabled": false,
"version": 3
}

View file

@ -34,7 +34,7 @@
#include <unordered_set>
#include <vector>
#define CONFIG_VERSION 2
#define CONFIG_VERSION 3
class Configuration {
public:
@ -47,6 +47,8 @@ public:
bool filter(u64 id);
bool favorite(u64 id);
bool nandSaves(void);
bool shouldScanCard(void);
bool isFTPEnabled(void);
std::vector<std::u16string> additionalSaveFolders(u64 id);
std::vector<std::u16string> additionalExtdataFolders(u64 id);
@ -64,7 +66,7 @@ private:
nlohmann::json mJson;
std::unordered_set<u64> mFilterIds, mFavoriteIds;
std::unordered_map<u64, std::vector<std::u16string>> mAdditionalSaveFolders, mAdditionalExtdataFolders;
bool mNandSaves;
bool mNandSaves, mScanCard, mFTPEnabled;
std::string BASEPATH = "/3ds/Checkpoint/config.json";
};

View file

@ -29,7 +29,7 @@
Configuration::Configuration(void)
{
// check for existing config.json files on the sd card, BASEPATH
if (!io::fileExists(Archive::sdmc(), StringUtils::UTF8toUTF16(BASEPATH.c_str()))) {
if (!mJson.is_object() || mJson.find("version") == mJson.end() || !mJson["version"].is_number_integer()) {
store();
}
@ -41,11 +41,67 @@ Configuration::Configuration(void)
store();
}
else {
// 3.4.2 -> 3.5.0
if (mJson["version"] < 2) {
if (mJson["version"] < CONFIG_VERSION) {
mJson["version"] = CONFIG_VERSION;
updateJson = true;
}
if (!(mJson.contains("nand_saves") && mJson["nand_saves"].is_boolean())) {
mJson["nand_saves"] = false;
updateJson = true;
}
if (!(mJson.contains("ftp-enabled") && mJson["ftp-enabled"].is_boolean())) {
mJson["ftp-enabled"] = false;
updateJson = true;
}
if (!(mJson.contains("scan_cart") && mJson["scan_cart"].is_boolean())) {
mJson["scan_cart"] = false;
updateJson = true;
}
if (!(mJson.contains("filter") && mJson["filter"].is_array())) {
mJson["filter"] = nlohmann::json::array();
updateJson = true;
}
if (!(mJson.contains("favorites") && mJson["favorites"].is_array())) {
mJson["favorites"] = nlohmann::json::array();
updateJson = true;
}
if (!(mJson.contains("additional_save_folders") && mJson["additional_save_folders"].is_array())) {
mJson["additional_save_folders"] = nlohmann::json::array();
updateJson = true;
}
if (!(mJson.contains("additional_extdata_folders") && mJson["additional_extdata_folders"].is_array())) {
mJson["additional_extdata_folders"] = nlohmann::json::array();
updateJson = true;
}
// check every single entry in the arrays...
for (auto& obj : mJson["filter"]) {
if (!obj.is_string()) {
mJson["filter"] = nlohmann::json::array();
updateJson = true;
break;
}
}
for (auto& obj : mJson["favorites"]) {
if (!obj.is_string()) {
mJson["favorites"] = nlohmann::json::array();
updateJson = true;
break;
}
}
for (auto& obj : mJson["additional_save_folders"]) {
if (!obj.is_string()) {
mJson["additional_save_folders"] = nlohmann::json::array();
updateJson = true;
break;
}
}
for (auto& obj : mJson["additional_extdata_folders"]) {
if (!obj.is_string()) {
mJson["additional_extdata_folders"] = nlohmann::json::array();
updateJson = true;
break;
}
}
}
if (updateJson) {
@ -65,8 +121,9 @@ Configuration::Configuration(void)
mFavoriteIds.emplace(strtoull(id.c_str(), NULL, 16));
}
// parse nand saves
mNandSaves = mJson["nand_saves"];
mScanCard = mJson["scan_cart"];
mFTPEnabled = mJson["ftp-enabled"];
// parse additional save folders
auto js = mJson["additional_save_folders"];
@ -149,3 +206,13 @@ std::vector<std::u16string> Configuration::additionalExtdataFolders(u64 id)
auto folders = mAdditionalExtdataFolders.find(id);
return folders == mAdditionalExtdataFolders.end() ? emptyvec : folders->second;
}
bool Configuration::shouldScanCard(void)
{
return mScanCard;
}
bool Configuration::isFTPEnabled(void)
{
return mFTPEnabled;
}

View file

@ -45,7 +45,9 @@ int main()
hidScanInput();
hidTouchRead(&touch);
if (Configuration::getInstance().shouldScanCard()) {
updateCard();
}
C3D_FrameBegin(C3D_FRAME_SYNCDRAW);
g_screen->doDrawTop();

View file

@ -946,8 +946,8 @@ void updateCard(void)
FSUSER_CardSlotIsInserted(&cardIn);
if (cardIn != oldCardIn) {
bool power;
if (cardIn) {
bool power;
FSUSER_CardSlotPowerOn(&power);
while (!power) {
FSUSER_CardSlotGetCardIFPowerStatus(&power);