NOT STABLE: attempting to write functions that copy themePath to and from settings.cfg file, keeps crashing rn for some reason though

This commit is contained in:
NightlyFox 2018-09-26 00:25:25 -05:00
parent e60156c34f
commit 5621fb460b
3 changed files with 40 additions and 36 deletions

View File

@ -55,25 +55,7 @@ void launchMenuBackTask() {
}
void launchApplyThemeTask(menuEntry_s* arg) {
config_t cfg = {0};
config_init(&cfg);
if(!config_read_file(&cfg, arg->path)) {
menuCreateMsgBox(780, 300, "Something went wrong, and the theme could not be loaded!");
return;
}
char tmp_path[PATH_MAX] = {0};
#ifdef __SWITCH__
tmp_path[0] = '/';
#endif
strncat(tmp_path, "config/nx-hbmenu/theme.cfg", sizeof(tmp_path)-2);
if(!config_write_file(&cfg, tmp_path)) {
menuCreateMsgBox(780, 300, "Something went wrong, and the theme could not be applied!");
return;
}
config_destroy(&cfg);
//SetThemePathToConfig(arg->path);
themeStartup(themeGlobalPreset);
computeFrontGradient(themeCurrent.frontWaveColor, 280);
}

View File

@ -54,16 +54,12 @@ void themeStartup(ThemePreset preset) {
.hbmenuLogoImage = hbmenu_logo_dark_bin
};
char tmp_path[PATH_MAX] = {0};
#ifdef __SWITCH__
tmp_path[0] = '/';
#endif
config_t themeCfg = {0};
config_setting_t *setting;
config_init(&themeCfg);
const char* themePath = "";
config_t thmPthCfg = {0};
config_init(&thmPthCfg);
GetThemePathFromConfig(thmPthCfg, themePath);
strncat(tmp_path, "config/nx-hbmenu/theme.cfg", sizeof(tmp_path)-2);
//GetThemePathFromConfig(themeCfg, setting, themePath);
theme_t *themeDefault;
config_t cfg = {0};
@ -72,7 +68,8 @@ void themeStartup(ThemePreset preset) {
color_t text, frontWave, middleWave, backWave, background, highlight, separator, borderColor, borderTextColor;
int waveBlending;
const char *AText, *BText;
bool good_cfg = config_read_file(&cfg, tmp_path);
bool good_cfg = config_read_file(&cfg, themePath);
config_destroy(&themeCfg);
switch (preset) {
case THEME_PRESET_LIGHT:
@ -141,18 +138,42 @@ void themeStartup(ThemePreset preset) {
config_destroy(&cfg);
}
void GetThemePathFromConfig(config_t cfg, const char* path){
void GetThemePathFromConfig(config_t cfg, config_setting_t *setting, const char* themePath) {
char tmp_path[PATH_MAX] = {0};
config_setting_t *setting;
#ifdef __SWITCH__
tmp_path[0] = '/';
#endif
strncat(tmp_path, "config/nx-hbmenu/setting.cfg", sizeof(tmp_path)-2);
bool good_cfg = config_read_file(&cfg, tmp_path);
if(good_cfg) {
config_setting_lookup_string(theme, "themePath", &path);
setting = config_lookup(&cfg, "themePath");
config_setting_lookup_string(setting, "themePath", &themePath);
}
}
void SetThemePathToConfig(const char* themePath) {
config_t cfg = {0};
config_init(&cfg);
char tmp_path[PATH_MAX] = {0};
config_setting_t *root,*group, *setting;
#ifdef __SWITCH__
tmp_path[0] = '/';
#endif
strncat(tmp_path, "config/nx-hbmenu/setting.cfg", sizeof(tmp_path)-2);
root = config_root_setting(&cfg);
group = config_setting_add(root, "hbmenuConfig", CONFIG_TYPE_GROUP);
setting = config_setting_add(group, "themePath", CONFIG_TYPE_STRING);
config_setting_set_string(setting, themePath);
if(!config_write_file(&cfg, tmp_path)) {
menuCreateMsgBox(780, 300, "Something went wrong, and the theme could not be applied!");
}
config_destroy(&cfg);
}

View File

@ -29,8 +29,9 @@ typedef enum
} ThemePreset;
bool colorFromSetting(config_setting_t *rgba, color_t *col);
void themeStartup(ThemePreset preset);
void GetThemePathFromConfig(config_t cfg, config_setting_t *setting, const char* themePath);
void SetThemePathToConfig(const char* themePath);
extern theme_t themeCurrent;