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();
|
Config();
|
||||||
void save();
|
void save();
|
||||||
void initialize();
|
void initialize();
|
||||||
|
void addMissingThings();
|
||||||
|
|
||||||
// Bar Color.
|
// Bar Color.
|
||||||
u32 barColor() { return this->v_barColor; }
|
u32 barColor() { return this->v_barColor; }
|
||||||
@@ -116,7 +117,10 @@ public:
|
|||||||
// First startup.
|
// First startup.
|
||||||
bool firstStartup() { return this->v_firstStartup; }
|
bool firstStartup() { return this->v_firstStartup; }
|
||||||
void firstStartup(bool v) { this->v_firstStartup = v; if (!this->changesMade) this->changesMade = true; }
|
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.
|
// Mainly helper.
|
||||||
bool getBool(const std::string &key);
|
bool getBool(const std::string &key);
|
||||||
void setBool(const std::string &key, bool v);
|
void setBool(const std::string &key, bool v);
|
||||||
@@ -126,14 +130,15 @@ public:
|
|||||||
void setString(const std::string &key, const std::string &v);
|
void setString(const std::string &key, const std::string &v);
|
||||||
private:
|
private:
|
||||||
nlohmann::json json; // Our private JSON file.
|
nlohmann::json json; // Our private JSON file.
|
||||||
bool changesMade = false;
|
bool changesMade = false, initialChanges = false;
|
||||||
|
int configVersion = 1;
|
||||||
|
|
||||||
// Color variables and more.
|
// Color variables and more.
|
||||||
u32 v_barColor, v_topBG, v_bottomBG, v_textColor, v_buttonColor, v_selectedColor, v_unselectedColor, v_progressbarColor,
|
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;
|
v_outdatedColor, v_uptodateColor, v_notfoundColor, v_futureColor;
|
||||||
std::string v_scriptPath, v_musicPath, v_storePath, v_autobootFile, v_language;
|
std::string v_scriptPath, v_musicPath, v_storePath, v_autobootFile, v_language;
|
||||||
int v_langPath, v_viewMode, v_autoboot, v_keyDelay;
|
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
|
#endif
|
||||||
@@ -71,6 +71,7 @@ const std::vector<std::string> Languages = {
|
|||||||
const std::vector<std::string> UniversalTeam = {
|
const std::vector<std::string> UniversalTeam = {
|
||||||
"DeadPhoenix",
|
"DeadPhoenix",
|
||||||
"FlameKat53",
|
"FlameKat53",
|
||||||
|
"NightScript",
|
||||||
"Pk11",
|
"Pk11",
|
||||||
"RocketRobz",
|
"RocketRobz",
|
||||||
"SuperSaiyajinStackZ",
|
"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> 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 {
|
void Credits::Draw(void) const {
|
||||||
std::string title = "Universal-Updater - ";
|
std::string title = "Universal-Updater - ";
|
||||||
title += Lang::get("CREDITS");
|
title += Lang::get("CREDITS");
|
||||||
GFX::DrawTop();
|
GFX::DrawTop();
|
||||||
if (creditsPage != 3) {
|
if (creditsPage != 4) {
|
||||||
Gui::DrawStringCentered(0, config->useBars() ? 0 : 2, 0.7f, config->textColor(), title, 400);
|
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, 30, 0.7f, config->textColor(), Lang::get("DEVELOPED_BY"), 390);
|
||||||
Gui::DrawStringCentered(0, 60, 0.7f, config->textColor(), Lang::get("MAIN_DEV"), 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, 38+(i*57), 0.7f, config->textColor(), line1, 320);
|
||||||
Gui::DrawStringCentered(0, 62+(i*57), 0.7f, config->textColor(), line2, 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 {
|
} else {
|
||||||
Gui::DrawStringCentered(0, -2, 0.55f, config->textColor(), Lang::get("LINK"), 320);
|
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;
|
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();
|
keyRepeatDelay = config->keyDelay();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -196,8 +227,11 @@ void Credits::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
|
|||||||
Selection = (int)UniversalTeam.size()-1;
|
Selection = (int)UniversalTeam.size()-1;
|
||||||
} else if (creditsPage == 2) {
|
} else if (creditsPage == 2) {
|
||||||
Selection = (int)ScriptCreators.size()-1;
|
Selection = (int)ScriptCreators.size()-1;
|
||||||
|
} else if (creditsPage == 3) {
|
||||||
|
Selection = (int)specialNames.size()-1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
keyRepeatDelay = config->keyDelay();
|
keyRepeatDelay = config->keyDelay();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -210,7 +244,7 @@ void Credits::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ((hDown & KEY_R || hDown & KEY_RIGHT)) {
|
if ((hDown & KEY_R || hDown & KEY_RIGHT)) {
|
||||||
if (creditsPage < 3) {
|
if (creditsPage < 4) {
|
||||||
Selection = 0;
|
Selection = 0;
|
||||||
creditsPage++;
|
creditsPage++;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -128,27 +128,37 @@ u32 barColor, bgTopColor, bgBottomColor, TextColor, selected, unselected, progre
|
|||||||
|
|
||||||
// Load the colors from the script.
|
// Load the colors from the script.
|
||||||
void loadColors(nlohmann::json &json) {
|
void loadColors(nlohmann::json &json) {
|
||||||
u32 colorTemp;
|
if (config->useScriptColor()) {
|
||||||
colorTemp = getColor(ScriptHelper::getString(json, "info", "barColor"));
|
u32 colorTemp;
|
||||||
barColor = colorTemp == 0 ? config->barColor() : colorTemp;
|
colorTemp = getColor(ScriptHelper::getString(json, "info", "barColor"));
|
||||||
|
barColor = colorTemp == 0 ? config->barColor() : colorTemp;
|
||||||
|
|
||||||
colorTemp = getColor(ScriptHelper::getString(json, "info", "bgTopColor"));
|
colorTemp = getColor(ScriptHelper::getString(json, "info", "bgTopColor"));
|
||||||
bgTopColor = colorTemp == 0 ? config->topBG() : colorTemp;
|
bgTopColor = colorTemp == 0 ? config->topBG() : colorTemp;
|
||||||
|
|
||||||
colorTemp = getColor(ScriptHelper::getString(json, "info", "bgBottomColor"));
|
colorTemp = getColor(ScriptHelper::getString(json, "info", "bgBottomColor"));
|
||||||
bgBottomColor = colorTemp == 0 ? config->bottomBG() : colorTemp;
|
bgBottomColor = colorTemp == 0 ? config->bottomBG() : colorTemp;
|
||||||
|
|
||||||
colorTemp = getColor(ScriptHelper::getString(json, "info", "textColor"));
|
colorTemp = getColor(ScriptHelper::getString(json, "info", "textColor"));
|
||||||
TextColor = colorTemp == 0 ? config->textColor() : colorTemp;
|
TextColor = colorTemp == 0 ? config->textColor() : colorTemp;
|
||||||
|
|
||||||
colorTemp = getColor(ScriptHelper::getString(json, "info", "selectedColor"));
|
colorTemp = getColor(ScriptHelper::getString(json, "info", "selectedColor"));
|
||||||
selected = colorTemp == 0 ? config->selectedColor() : colorTemp;
|
selected = colorTemp == 0 ? config->selectedColor() : colorTemp;
|
||||||
|
|
||||||
colorTemp = getColor(ScriptHelper::getString(json, "info", "unselectedColor"));
|
colorTemp = getColor(ScriptHelper::getString(json, "info", "unselectedColor"));
|
||||||
unselected = colorTemp == 0 ? config->unselectedColor() : colorTemp;
|
unselected = colorTemp == 0 ? config->unselectedColor() : colorTemp;
|
||||||
|
|
||||||
colorTemp = getColor(ScriptHelper::getString(json, "info", "progressbarColor"));
|
colorTemp = getColor(ScriptHelper::getString(json, "info", "progressbarColor"));
|
||||||
progressBar = colorTemp == 0 ? config->progressbarColor() : colorTemp;
|
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 {
|
void ScriptList::DrawSubMenu(void) const {
|
||||||
|
|||||||
@@ -50,26 +50,36 @@ UniStoreV1::UniStoreV1(nlohmann::json &JSON, const std::string sheetPath, bool d
|
|||||||
}
|
}
|
||||||
|
|
||||||
u32 colorTemp;
|
u32 colorTemp;
|
||||||
colorTemp = getColor(ScriptHelper::getString(this->storeJson, "storeInfo", "barColor"));
|
if (config->useScriptColor()) {
|
||||||
barColor = colorTemp == 0 ? config->barColor() : colorTemp;
|
colorTemp = getColor(ScriptHelper::getString(this->storeJson, "storeInfo", "barColor"));
|
||||||
|
barColor = colorTemp == 0 ? config->barColor() : colorTemp;
|
||||||
|
|
||||||
colorTemp = getColor(ScriptHelper::getString(this->storeJson, "storeInfo", "bgTopColor"));
|
colorTemp = getColor(ScriptHelper::getString(this->storeJson, "storeInfo", "bgTopColor"));
|
||||||
bgTopColor = colorTemp == 0 ? config->topBG() : colorTemp;
|
bgTopColor = colorTemp == 0 ? config->topBG() : colorTemp;
|
||||||
|
|
||||||
colorTemp = getColor(ScriptHelper::getString(this->storeJson, "storeInfo", "bgBottomColor"));
|
colorTemp = getColor(ScriptHelper::getString(this->storeJson, "storeInfo", "bgBottomColor"));
|
||||||
bgBottomColor = colorTemp == 0 ? config->bottomBG() : colorTemp;
|
bgBottomColor = colorTemp == 0 ? config->bottomBG() : colorTemp;
|
||||||
|
|
||||||
colorTemp = getColor(ScriptHelper::getString(this->storeJson, "storeInfo", "textColor"));
|
colorTemp = getColor(ScriptHelper::getString(this->storeJson, "storeInfo", "textColor"));
|
||||||
TextColor = colorTemp == 0 ? config->textColor() : colorTemp;
|
TextColor = colorTemp == 0 ? config->textColor() : colorTemp;
|
||||||
|
|
||||||
colorTemp = getColor(ScriptHelper::getString(this->storeJson, "storeInfo", "selectedColor"));
|
colorTemp = getColor(ScriptHelper::getString(this->storeJson, "storeInfo", "selectedColor"));
|
||||||
selected = colorTemp == 0 ? config->selectedColor() : colorTemp;
|
selected = colorTemp == 0 ? config->selectedColor() : colorTemp;
|
||||||
|
|
||||||
colorTemp = getColor(ScriptHelper::getString(this->storeJson, "storeInfo", "unselectedColor"));
|
colorTemp = getColor(ScriptHelper::getString(this->storeJson, "storeInfo", "unselectedColor"));
|
||||||
unselected = colorTemp == 0 ? config->unselectedColor() : colorTemp;
|
unselected = colorTemp == 0 ? config->unselectedColor() : colorTemp;
|
||||||
|
|
||||||
colorTemp = getColor(ScriptHelper::getString(this->storeJson, "storeInfo", "progressbarColor"));
|
colorTemp = getColor(ScriptHelper::getString(this->storeJson, "storeInfo", "progressbarColor"));
|
||||||
progressBar = colorTemp == 0 ? config->progressbarColor() : colorTemp;
|
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 {
|
void UniStoreV1::drawBlend(int key, int x, int y) const {
|
||||||
|
|||||||
+27
-2
@@ -30,6 +30,11 @@
|
|||||||
#include <citro2d.h>
|
#include <citro2d.h>
|
||||||
#include <unistd.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.
|
// In case it doesn't exist.
|
||||||
void Config::initialize() {
|
void Config::initialize() {
|
||||||
// Create through fopen "Write".
|
// Create through fopen "Write".
|
||||||
@@ -62,6 +67,8 @@ void Config::initialize() {
|
|||||||
this->setBool("PROGRESS_DISPLAY", true);
|
this->setBool("PROGRESS_DISPLAY", true);
|
||||||
this->setString("LANGUAGE", "en");
|
this->setString("LANGUAGE", "en");
|
||||||
this->setBool("FIRST_STARTUP", true);
|
this->setBool("FIRST_STARTUP", true);
|
||||||
|
this->setBool("USE_SCRIPT_COLORS", true);
|
||||||
|
this->setInt("VERSION", this->configVersion);
|
||||||
|
|
||||||
// Write to file.
|
// Write to file.
|
||||||
fwrite(this->json.dump(1, '\t').c_str(), 1, this->json.dump(1, '\t').size(), 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);
|
this->json = nlohmann::json::parse(file, nullptr, false);
|
||||||
fclose(file);
|
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")) {
|
if (!this->json.contains("BARCOLOR")) {
|
||||||
this->barColor(BarColor);
|
this->barColor(BarColor);
|
||||||
@@ -223,8 +239,9 @@ Config::Config() {
|
|||||||
this->progressDisplay(this->getBool("PROGRESS_DISPLAY"));
|
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->language("en");
|
||||||
|
this->initialChanges = true;
|
||||||
} else {
|
} else {
|
||||||
this->language(this->getString("LANGUAGE"));
|
this->language(this->getString("LANGUAGE"));
|
||||||
}
|
}
|
||||||
@@ -235,12 +252,19 @@ Config::Config() {
|
|||||||
this->firstStartup(this->getBool("FIRST_STARTUP"));
|
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.
|
this->changesMade = false; // No changes made yet.
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write to config if changesMade.
|
// Write to config if changesMade.
|
||||||
void Config::save() {
|
void Config::save() {
|
||||||
if (this->changesMade) {
|
if (this->changesMade) {
|
||||||
|
this->changesMade = false;
|
||||||
FILE *file = fopen("sdmc:/3ds/Universal-Updater/Settings.json", "w");
|
FILE *file = fopen("sdmc:/3ds/Universal-Updater/Settings.json", "w");
|
||||||
// Set values.
|
// Set values.
|
||||||
this->setInt("BARCOLOR", this->barColor());
|
this->setInt("BARCOLOR", this->barColor());
|
||||||
@@ -269,6 +293,7 @@ void Config::save() {
|
|||||||
this->setBool("PROGRESS_DISPLAY", this->progressDisplay());
|
this->setBool("PROGRESS_DISPLAY", this->progressDisplay());
|
||||||
this->setString("LANGUAGE", this->language());
|
this->setString("LANGUAGE", this->language());
|
||||||
this->setBool("FIRST_STARTUP", this->firstStartup());
|
this->setBool("FIRST_STARTUP", this->firstStartup());
|
||||||
|
this->setBool("USE_SCRIPT_COLORS", this->useScriptColor());
|
||||||
// Write changes to file.
|
// Write changes to file.
|
||||||
fwrite(this->json.dump(1, '\t').c_str(), 1, this->json.dump(1, '\t').size(), file);
|
fwrite(this->json.dump(1, '\t').c_str(), 1, this->json.dump(1, '\t').size(), file);
|
||||||
fclose(file);
|
fclose(file);
|
||||||
|
|||||||
Reference in New Issue
Block a user