added check for empty themePath, added check for existing settings config, changed ptr to char array and used strncpy
This commit is contained in:
parent
1d9ef3b9de
commit
624fbed1fd
@ -54,11 +54,8 @@ void themeStartup(ThemePreset preset) {
|
|||||||
.hbmenuLogoImage = hbmenu_logo_dark_bin
|
.hbmenuLogoImage = hbmenu_logo_dark_bin
|
||||||
};
|
};
|
||||||
|
|
||||||
const char* themePath = "";
|
char themePath[PATH_MAX] = {0};
|
||||||
config_t themeCfg = {0};
|
GetThemePathFromConfig(themePath);
|
||||||
config_setting_t *setting;
|
|
||||||
config_init(&themeCfg);
|
|
||||||
GetThemePathFromConfig(themeCfg, setting, &themePath);
|
|
||||||
|
|
||||||
theme_t *themeDefault;
|
theme_t *themeDefault;
|
||||||
config_t cfg = {0};
|
config_t cfg = {0};
|
||||||
@ -67,8 +64,10 @@ void themeStartup(ThemePreset preset) {
|
|||||||
color_t text, frontWave, middleWave, backWave, background, highlight, separator, borderColor, borderTextColor;
|
color_t text, frontWave, middleWave, backWave, background, highlight, separator, borderColor, borderTextColor;
|
||||||
int waveBlending;
|
int waveBlending;
|
||||||
const char *AText, *BText;
|
const char *AText, *BText;
|
||||||
bool good_cfg = config_read_file(&cfg, themePath);
|
bool good_cfg = false;
|
||||||
config_destroy(&themeCfg);
|
|
||||||
|
if(themePath[0]!=0)
|
||||||
|
good_cfg = config_read_file(&cfg, themePath);
|
||||||
|
|
||||||
switch (preset) {
|
switch (preset) {
|
||||||
case THEME_PRESET_LIGHT:
|
case THEME_PRESET_LIGHT:
|
||||||
@ -137,7 +136,10 @@ void themeStartup(ThemePreset preset) {
|
|||||||
config_destroy(&cfg);
|
config_destroy(&cfg);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GetThemePathFromConfig(config_t cfg, config_setting_t *setting, const char** themePath) {
|
void GetThemePathFromConfig(char* themePath) {
|
||||||
|
const char* tmpThemePath = "";
|
||||||
|
config_t cfg = {0};
|
||||||
|
config_setting_t *setting;
|
||||||
char tmp_path[PATH_MAX] = {0};
|
char tmp_path[PATH_MAX] = {0};
|
||||||
|
|
||||||
#ifdef __SWITCH__
|
#ifdef __SWITCH__
|
||||||
@ -150,9 +152,12 @@ void GetThemePathFromConfig(config_t cfg, config_setting_t *setting, const char*
|
|||||||
if(good_cfg) {
|
if(good_cfg) {
|
||||||
setting = config_lookup(&cfg, "hbmenuConfig");
|
setting = config_lookup(&cfg, "hbmenuConfig");
|
||||||
if(setting != NULL){
|
if(setting != NULL){
|
||||||
config_setting_lookup_string(setting, "themePath", themePath);
|
if(config_setting_lookup_string(setting, "themePath", &tmpThemePath))
|
||||||
|
strncpy(themePath, tmpThemePath, PATH_MAX-1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
config_destroy(&cfg);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetThemePathToConfig(const char* themePath) {
|
void SetThemePathToConfig(const char* themePath) {
|
||||||
@ -167,11 +172,18 @@ void SetThemePathToConfig(const char* themePath) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
strncat(settingPath, "config/nx-hbmenu/settings.cfg", sizeof(settingPath)-2);
|
strncat(settingPath, "config/nx-hbmenu/settings.cfg", sizeof(settingPath)-2);
|
||||||
|
bool good_cfg = config_read_file(&cfg, settingPath);
|
||||||
root = config_root_setting(&cfg);
|
|
||||||
group = config_setting_add(root, "hbmenuConfig", CONFIG_TYPE_GROUP);
|
if(good_cfg) {
|
||||||
setting = config_setting_add(group, "themePath", CONFIG_TYPE_STRING);
|
group = config_lookup(&cfg, "hbmenuConfig");
|
||||||
config_setting_set_string(setting, themePath);
|
setting = config_setting_lookup(group, "themePath");
|
||||||
|
config_setting_set_string(setting, themePath);
|
||||||
|
} else {
|
||||||
|
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, settingPath)) {
|
if(!config_write_file(&cfg, settingPath)) {
|
||||||
menuCreateMsgBox(780, 300, "Something went wrong, and the theme could not be applied!");
|
menuCreateMsgBox(780, 300, "Something went wrong, and the theme could not be applied!");
|
||||||
|
@ -30,7 +30,7 @@ typedef enum
|
|||||||
|
|
||||||
bool colorFromSetting(config_setting_t *rgba, color_t *col);
|
bool colorFromSetting(config_setting_t *rgba, color_t *col);
|
||||||
void themeStartup(ThemePreset preset);
|
void themeStartup(ThemePreset preset);
|
||||||
void GetThemePathFromConfig(config_t cfg, config_setting_t *setting, const char** themePath);
|
void GetThemePathFromConfig(char* themePath);
|
||||||
void SetThemePathToConfig(const char* themePath);
|
void SetThemePathToConfig(const char* themePath);
|
||||||
|
|
||||||
extern theme_t themeCurrent;
|
extern theme_t themeCurrent;
|
||||||
|
Loading…
Reference in New Issue
Block a user