-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
plus some fixes commit f1e7153 Author: Ash Logan <ash@heyquark.com> Date: Sat Dec 10 14:00:43 2022 +1100 config: move to own file get it outta here! I don't wanna see it! commit 386874e Author: scatterbrain <119330240+kurbus@users.noreply.github.com> Date: Fri Dec 9 21:19:28 2022 -0500 skipPatches to connect_to_network (#6) * baseline for fix Make config more readable * change skip patches to connect to network for clarity. Nice C code, by the way. * scratch that number 15, diarrhea
- Loading branch information
Showing
4 changed files
with
108 additions
and
76 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// | ||
// Created by ash on 10/12/22. | ||
// | ||
|
||
#include "config.h" | ||
|
||
#include "utils/logger.h" | ||
#include <wups.h> | ||
#include <wups/config/WUPSConfigItemBoolean.h> | ||
|
||
#include <coreinit/launch.h> | ||
#include <sysapp/launch.h> | ||
|
||
bool Config::connect_to_network = true; | ||
bool Config::need_relaunch = false; | ||
|
||
void Config::Init() { | ||
WUPSStorageError storageRes = WUPS_OpenStorage(); | ||
if (storageRes != WUPS_STORAGE_ERROR_SUCCESS) { | ||
DEBUG_FUNCTION_LINE("Failed to open storage %s (%d)", WUPS_GetStorageStatusStr(storageRes), storageRes); | ||
} | ||
else { | ||
// Try to get value from storage | ||
if ((storageRes = WUPS_GetBool(nullptr, "connect_to_network", &connect_to_network)) == WUPS_STORAGE_ERROR_NOT_FOUND) { | ||
bool skipPatches = false; | ||
if ((storageRes = WUPS_GetBool(nullptr, "skipPatches", &skipPatches)) != WUPS_STORAGE_ERROR_NOT_FOUND) { | ||
// Migrate old config value | ||
connect_to_network = !skipPatches; | ||
} | ||
// Add the value to the storage if it's missing. | ||
if (WUPS_StoreBool(nullptr, "connect_to_network", connect_to_network) != WUPS_STORAGE_ERROR_SUCCESS) { | ||
DEBUG_FUNCTION_LINE("Failed to store bool"); | ||
} | ||
} | ||
else if (storageRes != WUPS_STORAGE_ERROR_SUCCESS) { | ||
DEBUG_FUNCTION_LINE("Failed to get bool %s (%d)", WUPS_GetStorageStatusStr(storageRes), storageRes); | ||
} | ||
|
||
// Close storage | ||
if (WUPS_CloseStorage() != WUPS_STORAGE_ERROR_SUCCESS) { | ||
DEBUG_FUNCTION_LINE("Failed to close storage"); | ||
} | ||
} | ||
} | ||
|
||
static void connect_to_network_changed(ConfigItemBoolean* item, bool new_value) { | ||
DEBUG_FUNCTION_LINE("New value in skipPatchesChanged: %d", new_value); | ||
if (new_value != Config::connect_to_network) { | ||
Config::need_relaunch = true; | ||
} | ||
Config::connect_to_network = new_value; | ||
WUPS_StoreInt(nullptr, "connect_to_network", Config::connect_to_network); | ||
} | ||
|
||
WUPS_GET_CONFIG() { | ||
// We open the storage so we can persist the configuration the user did. | ||
if (WUPS_OpenStorage() != WUPS_STORAGE_ERROR_SUCCESS) { | ||
DEBUG_FUNCTION_LINE("Failed to open storage"); | ||
return 0; | ||
} | ||
|
||
WUPSConfigHandle config; | ||
WUPSConfig_CreateHandled(&config, "Inkay"); | ||
|
||
WUPSConfigCategoryHandle cat; | ||
WUPSConfig_AddCategoryByNameHandled(config, "Patching", &cat); | ||
|
||
WUPSConfigItemBoolean_AddToCategoryHandled(config, cat, "connect_to_network", "Connect to the Pretendo network", Config::connect_to_network, &connect_to_network_changed); | ||
|
||
return config; | ||
} | ||
|
||
WUPS_CONFIG_CLOSED() { | ||
// Save all changes | ||
if (WUPS_CloseStorage() != WUPS_STORAGE_ERROR_SUCCESS) { | ||
DEBUG_FUNCTION_LINE("Failed to close storage"); | ||
} | ||
|
||
if (Config::need_relaunch) { | ||
// Need to reload the console so the patches reset | ||
OSForceFullRelaunch(); | ||
SYSLaunchMenu(); | ||
Config::need_relaunch = false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// | ||
// Created by ash on 10/12/22. | ||
// | ||
|
||
#ifndef INKAY_CONFIG_H | ||
#define INKAY_CONFIG_H | ||
|
||
class Config { | ||
public: | ||
static void Init(); | ||
|
||
// wups config items | ||
static bool connect_to_network; | ||
|
||
// private stuff | ||
static bool need_relaunch; | ||
}; | ||
|
||
#endif //INKAY_CONFIG_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters