mirror of
https://github.com/DarkStore-3DS/DarkStore.git
synced 2026-07-03 00:39:02 +00:00
In hope to fix the config crashes.
This commit is contained in:
@@ -37,6 +37,7 @@ public:
|
||||
Config();
|
||||
void save();
|
||||
void initialize();
|
||||
void addMissingThings();
|
||||
|
||||
// Bar Color.
|
||||
u32 barColor() { return this->v_barColor; }
|
||||
@@ -116,7 +117,10 @@ public:
|
||||
// First startup.
|
||||
bool firstStartup() { return this->v_firstStartup; }
|
||||
void firstStartup(bool v) { this->v_firstStartup = v; if (!this->changesMade) this->changesMade = true; }
|
||||
|
||||
// Use ScriptColors.
|
||||
bool useScriptColor() { return this->v_useScriptColor; }
|
||||
void useScriptColor(bool v) { this->v_useScriptColor = v; if (!this->changesMade) this->changesMade = true; }
|
||||
|
||||
// Mainly helper.
|
||||
bool getBool(const std::string &key);
|
||||
void setBool(const std::string &key, bool v);
|
||||
@@ -126,14 +130,15 @@ public:
|
||||
void setString(const std::string &key, const std::string &v);
|
||||
private:
|
||||
nlohmann::json json; // Our private JSON file.
|
||||
bool changesMade = false;
|
||||
bool changesMade = false, initialChanges = false;
|
||||
int configVersion = 1;
|
||||
|
||||
// Color variables and more.
|
||||
u32 v_barColor, v_topBG, v_bottomBG, v_textColor, v_buttonColor, v_selectedColor, v_unselectedColor, v_progressbarColor,
|
||||
v_outdatedColor, v_uptodateColor, v_notfoundColor, v_futureColor;
|
||||
std::string v_scriptPath, v_musicPath, v_storePath, v_autobootFile, v_language;
|
||||
int v_langPath, v_viewMode, v_autoboot, v_keyDelay;
|
||||
bool v_logging, v_useBars, v_screenFade, v_progressDisplay, v_firstStartup;
|
||||
bool v_logging, v_useBars, v_screenFade, v_progressDisplay, v_firstStartup, v_useScriptColor;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -71,6 +71,7 @@ const std::vector<std::string> Languages = {
|
||||
const std::vector<std::string> UniversalTeam = {
|
||||
"DeadPhoenix",
|
||||
"FlameKat53",
|
||||
"NightScript",
|
||||
"Pk11",
|
||||
"RocketRobz",
|
||||
"SuperSaiyajinStackZ",
|
||||
@@ -83,11 +84,19 @@ const std::vector<std::string> ScriptCreators = {
|
||||
};
|
||||
const std::vector<std::string> ScriptAmount = {"1", "1", "1", "1", "5", "10", "1 | 2"};
|
||||
|
||||
const std::vector<std::string> specialNames = {
|
||||
"devkitPro", "NightScript"
|
||||
};
|
||||
const std::vector<std::string> specialDescriptions = {
|
||||
"For devkitARM, Libctru, Citro2D, Citro3D and the portlibs.",
|
||||
"For posting updates on Reddit."
|
||||
};
|
||||
|
||||
void Credits::Draw(void) const {
|
||||
std::string title = "Universal-Updater - ";
|
||||
title += Lang::get("CREDITS");
|
||||
GFX::DrawTop();
|
||||
if (creditsPage != 3) {
|
||||
if (creditsPage != 4) {
|
||||
Gui::DrawStringCentered(0, config->useBars() ? 0 : 2, 0.7f, config->textColor(), title, 400);
|
||||
Gui::DrawStringCentered(0, 30, 0.7f, config->textColor(), Lang::get("DEVELOPED_BY"), 390);
|
||||
Gui::DrawStringCentered(0, 60, 0.7f, config->textColor(), Lang::get("MAIN_DEV"), 390);
|
||||
@@ -145,6 +154,18 @@ void Credits::DrawBottom(void) const {
|
||||
Gui::DrawStringCentered(0, 38+(i*57), 0.7f, config->textColor(), line1, 320);
|
||||
Gui::DrawStringCentered(0, 62+(i*57), 0.7f, config->textColor(), line2, 320);
|
||||
}
|
||||
} else if (creditsPage == 3) {
|
||||
Gui::DrawStringCentered(0, -2, 0.7f, config->textColor(), "Special Thanks", 320);
|
||||
for(int i = 0; i < ENTRIES_PER_SCREEN && i < (int)specialNames.size(); i++) {
|
||||
Gui::Draw_Rect(0, 40+(i*57), 320, 45, config->unselectedColor());
|
||||
line1 = specialNames[screenPos + i];
|
||||
line2 = specialDescriptions[screenPos + i];
|
||||
if (screenPos + i == Selection) {
|
||||
Gui::drawAnimatedSelector(0, 40+(i*57), 320, 45, .060, TRANSPARENT, config->selectedColor());
|
||||
}
|
||||
Gui::DrawStringCentered(0, 38+(i*57), 0.7f, config->textColor(), line1, 320);
|
||||
Gui::DrawStringCentered(0, 62+(i*57), 0.7f, config->textColor(), line2, 320);
|
||||
}
|
||||
} else {
|
||||
Gui::DrawStringCentered(0, -2, 0.55f, config->textColor(), Lang::get("LINK"), 320);
|
||||
}
|
||||
@@ -182,6 +203,16 @@ void Credits::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
|
||||
Selection = 0;
|
||||
}
|
||||
|
||||
keyRepeatDelay = config->keyDelay();
|
||||
}
|
||||
} else if (creditsPage == 3) {
|
||||
if ((hHeld & KEY_DOWN && !keyRepeatDelay)) {
|
||||
if (Selection < (int)specialNames.size()-1) {
|
||||
Selection++;
|
||||
} else {
|
||||
Selection = 0;
|
||||
}
|
||||
|
||||
keyRepeatDelay = config->keyDelay();
|
||||
}
|
||||
}
|
||||
@@ -196,8 +227,11 @@ void Credits::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
|
||||
Selection = (int)UniversalTeam.size()-1;
|
||||
} else if (creditsPage == 2) {
|
||||
Selection = (int)ScriptCreators.size()-1;
|
||||
} else if (creditsPage == 3) {
|
||||
Selection = (int)specialNames.size()-1;
|
||||
}
|
||||
}
|
||||
|
||||
keyRepeatDelay = config->keyDelay();
|
||||
}
|
||||
|
||||
@@ -210,7 +244,7 @@ void Credits::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
|
||||
}
|
||||
|
||||
if ((hDown & KEY_R || hDown & KEY_RIGHT)) {
|
||||
if (creditsPage < 3) {
|
||||
if (creditsPage < 4) {
|
||||
Selection = 0;
|
||||
creditsPage++;
|
||||
}
|
||||
|
||||
@@ -128,27 +128,37 @@ u32 barColor, bgTopColor, bgBottomColor, TextColor, selected, unselected, progre
|
||||
|
||||
// Load the colors from the script.
|
||||
void loadColors(nlohmann::json &json) {
|
||||
u32 colorTemp;
|
||||
colorTemp = getColor(ScriptHelper::getString(json, "info", "barColor"));
|
||||
barColor = colorTemp == 0 ? config->barColor() : colorTemp;
|
||||
if (config->useScriptColor()) {
|
||||
u32 colorTemp;
|
||||
colorTemp = getColor(ScriptHelper::getString(json, "info", "barColor"));
|
||||
barColor = colorTemp == 0 ? config->barColor() : colorTemp;
|
||||
|
||||
colorTemp = getColor(ScriptHelper::getString(json, "info", "bgTopColor"));
|
||||
bgTopColor = colorTemp == 0 ? config->topBG() : colorTemp;
|
||||
colorTemp = getColor(ScriptHelper::getString(json, "info", "bgTopColor"));
|
||||
bgTopColor = colorTemp == 0 ? config->topBG() : colorTemp;
|
||||
|
||||
colorTemp = getColor(ScriptHelper::getString(json, "info", "bgBottomColor"));
|
||||
bgBottomColor = colorTemp == 0 ? config->bottomBG() : colorTemp;
|
||||
colorTemp = getColor(ScriptHelper::getString(json, "info", "bgBottomColor"));
|
||||
bgBottomColor = colorTemp == 0 ? config->bottomBG() : colorTemp;
|
||||
|
||||
colorTemp = getColor(ScriptHelper::getString(json, "info", "textColor"));
|
||||
TextColor = colorTemp == 0 ? config->textColor() : colorTemp;
|
||||
colorTemp = getColor(ScriptHelper::getString(json, "info", "textColor"));
|
||||
TextColor = colorTemp == 0 ? config->textColor() : colorTemp;
|
||||
|
||||
colorTemp = getColor(ScriptHelper::getString(json, "info", "selectedColor"));
|
||||
selected = colorTemp == 0 ? config->selectedColor() : colorTemp;
|
||||
colorTemp = getColor(ScriptHelper::getString(json, "info", "selectedColor"));
|
||||
selected = colorTemp == 0 ? config->selectedColor() : colorTemp;
|
||||
|
||||
colorTemp = getColor(ScriptHelper::getString(json, "info", "unselectedColor"));
|
||||
unselected = colorTemp == 0 ? config->unselectedColor() : colorTemp;
|
||||
colorTemp = getColor(ScriptHelper::getString(json, "info", "unselectedColor"));
|
||||
unselected = colorTemp == 0 ? config->unselectedColor() : colorTemp;
|
||||
|
||||
colorTemp = getColor(ScriptHelper::getString(json, "info", "progressbarColor"));
|
||||
progressBar = colorTemp == 0 ? config->progressbarColor() : colorTemp;
|
||||
colorTemp = getColor(ScriptHelper::getString(json, "info", "progressbarColor"));
|
||||
progressBar = colorTemp == 0 ? config->progressbarColor() : colorTemp;
|
||||
} else {
|
||||
barColor = config->barColor();
|
||||
bgTopColor = config->topBG();
|
||||
bgBottomColor = config->bottomBG();
|
||||
TextColor = config->textColor();
|
||||
selected = config->selectedColor();
|
||||
unselected = config->unselectedColor();
|
||||
progressBar = config->progressbarColor();
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptList::DrawSubMenu(void) const {
|
||||
|
||||
@@ -50,26 +50,36 @@ UniStoreV1::UniStoreV1(nlohmann::json &JSON, const std::string sheetPath, bool d
|
||||
}
|
||||
|
||||
u32 colorTemp;
|
||||
colorTemp = getColor(ScriptHelper::getString(this->storeJson, "storeInfo", "barColor"));
|
||||
barColor = colorTemp == 0 ? config->barColor() : colorTemp;
|
||||
if (config->useScriptColor()) {
|
||||
colorTemp = getColor(ScriptHelper::getString(this->storeJson, "storeInfo", "barColor"));
|
||||
barColor = colorTemp == 0 ? config->barColor() : colorTemp;
|
||||
|
||||
colorTemp = getColor(ScriptHelper::getString(this->storeJson, "storeInfo", "bgTopColor"));
|
||||
bgTopColor = colorTemp == 0 ? config->topBG() : colorTemp;
|
||||
colorTemp = getColor(ScriptHelper::getString(this->storeJson, "storeInfo", "bgTopColor"));
|
||||
bgTopColor = colorTemp == 0 ? config->topBG() : colorTemp;
|
||||
|
||||
colorTemp = getColor(ScriptHelper::getString(this->storeJson, "storeInfo", "bgBottomColor"));
|
||||
bgBottomColor = colorTemp == 0 ? config->bottomBG() : colorTemp;
|
||||
colorTemp = getColor(ScriptHelper::getString(this->storeJson, "storeInfo", "bgBottomColor"));
|
||||
bgBottomColor = colorTemp == 0 ? config->bottomBG() : colorTemp;
|
||||
|
||||
colorTemp = getColor(ScriptHelper::getString(this->storeJson, "storeInfo", "textColor"));
|
||||
TextColor = colorTemp == 0 ? config->textColor() : colorTemp;
|
||||
colorTemp = getColor(ScriptHelper::getString(this->storeJson, "storeInfo", "textColor"));
|
||||
TextColor = colorTemp == 0 ? config->textColor() : colorTemp;
|
||||
|
||||
colorTemp = getColor(ScriptHelper::getString(this->storeJson, "storeInfo", "selectedColor"));
|
||||
selected = colorTemp == 0 ? config->selectedColor() : colorTemp;
|
||||
colorTemp = getColor(ScriptHelper::getString(this->storeJson, "storeInfo", "selectedColor"));
|
||||
selected = colorTemp == 0 ? config->selectedColor() : colorTemp;
|
||||
|
||||
colorTemp = getColor(ScriptHelper::getString(this->storeJson, "storeInfo", "unselectedColor"));
|
||||
unselected = colorTemp == 0 ? config->unselectedColor() : colorTemp;
|
||||
colorTemp = getColor(ScriptHelper::getString(this->storeJson, "storeInfo", "unselectedColor"));
|
||||
unselected = colorTemp == 0 ? config->unselectedColor() : colorTemp;
|
||||
|
||||
colorTemp = getColor(ScriptHelper::getString(this->storeJson, "storeInfo", "progressbarColor"));
|
||||
progressBar = colorTemp == 0 ? config->progressbarColor() : colorTemp;
|
||||
colorTemp = getColor(ScriptHelper::getString(this->storeJson, "storeInfo", "progressbarColor"));
|
||||
progressBar = colorTemp == 0 ? config->progressbarColor() : colorTemp;
|
||||
} else {
|
||||
barColor = config->barColor();
|
||||
bgTopColor = config->topBG();
|
||||
bgBottomColor = config->bottomBG();
|
||||
TextColor = config->textColor();
|
||||
selected = config->selectedColor();
|
||||
unselected = config->unselectedColor();
|
||||
progressBar = config->progressbarColor();
|
||||
}
|
||||
}
|
||||
|
||||
void UniStoreV1::drawBlend(int key, int x, int y) const {
|
||||
|
||||
+27
-2
@@ -30,6 +30,11 @@
|
||||
#include <citro2d.h>
|
||||
#include <unistd.h>
|
||||
|
||||
// Used to add missing stuff for the JSON. No new things for now.
|
||||
void Config::addMissingThings() {
|
||||
|
||||
}
|
||||
|
||||
// In case it doesn't exist.
|
||||
void Config::initialize() {
|
||||
// Create through fopen "Write".
|
||||
@@ -62,6 +67,8 @@ void Config::initialize() {
|
||||
this->setBool("PROGRESS_DISPLAY", true);
|
||||
this->setString("LANGUAGE", "en");
|
||||
this->setBool("FIRST_STARTUP", true);
|
||||
this->setBool("USE_SCRIPT_COLORS", true);
|
||||
this->setInt("VERSION", this->configVersion);
|
||||
|
||||
// Write to file.
|
||||
fwrite(this->json.dump(1, '\t').c_str(), 1, this->json.dump(1, '\t').size(), file);
|
||||
@@ -77,7 +84,16 @@ Config::Config() {
|
||||
this->json = nlohmann::json::parse(file, nullptr, false);
|
||||
fclose(file);
|
||||
|
||||
// Here we get the initial settings.
|
||||
if (!this->json.contains("VERSION")) {
|
||||
// Let us create a new one.
|
||||
this->initialize();
|
||||
}
|
||||
|
||||
// Here we add the missing things.
|
||||
if (this->json["VERSION"] < this->configVersion) {
|
||||
this->addMissingThings();
|
||||
this->save();
|
||||
}
|
||||
|
||||
if (!this->json.contains("BARCOLOR")) {
|
||||
this->barColor(BarColor);
|
||||
@@ -223,8 +239,9 @@ Config::Config() {
|
||||
this->progressDisplay(this->getBool("PROGRESS_DISPLAY"));
|
||||
}
|
||||
|
||||
if (!this->json.contains("LANGUAGE")) {
|
||||
if (!this->json.contains("LANGUAGE") || this->json.at("LANGUAGE").is_number()) {
|
||||
this->language("en");
|
||||
this->initialChanges = true;
|
||||
} else {
|
||||
this->language(this->getString("LANGUAGE"));
|
||||
}
|
||||
@@ -235,12 +252,19 @@ Config::Config() {
|
||||
this->firstStartup(this->getBool("FIRST_STARTUP"));
|
||||
}
|
||||
|
||||
if (!this->json.contains("USE_SCRIPT_COLORS")) {
|
||||
this->useScriptColor(true);
|
||||
} else {
|
||||
this->useScriptColor(this->getBool("USE_SCRIPT_COLORS"));
|
||||
}
|
||||
|
||||
this->changesMade = false; // No changes made yet.
|
||||
}
|
||||
|
||||
// Write to config if changesMade.
|
||||
void Config::save() {
|
||||
if (this->changesMade) {
|
||||
this->changesMade = false;
|
||||
FILE *file = fopen("sdmc:/3ds/Universal-Updater/Settings.json", "w");
|
||||
// Set values.
|
||||
this->setInt("BARCOLOR", this->barColor());
|
||||
@@ -269,6 +293,7 @@ void Config::save() {
|
||||
this->setBool("PROGRESS_DISPLAY", this->progressDisplay());
|
||||
this->setString("LANGUAGE", this->language());
|
||||
this->setBool("FIRST_STARTUP", this->firstStartup());
|
||||
this->setBool("USE_SCRIPT_COLORS", this->useScriptColor());
|
||||
// Write changes to file.
|
||||
fwrite(this->json.dump(1, '\t').c_str(), 1, this->json.dump(1, '\t').size(), file);
|
||||
fclose(file);
|
||||
|
||||
Reference in New Issue
Block a user