From 58f5a78ceb679e92c69434b8687f9f5e682a859e Mon Sep 17 00:00:00 2001 From: NightlyFox Date: Wed, 26 Sep 2018 01:08:50 -0500 Subject: [PATCH] added removeDriveFromPath Function --- common/font.c | 24 +++++++++++------------- common/menu.c | 3 ++- common/menu.h | 7 +++++++ common/theme.c | 22 ++++++++++++---------- common/theme.h | 2 +- 5 files changed, 33 insertions(+), 25 deletions(-) diff --git a/common/font.c b/common/font.c index 9f96627..78a51b8 100644 --- a/common/font.c +++ b/common/font.c @@ -377,50 +377,48 @@ void fontExit() } /*Automatically gives you the desired x-coordinate - *based on the string length and desired alignment + *based on the string length and desired alignmenr *rY=reference point... where to align around - *align='t','b','c' translates to (top,bottom,center) + *align='t','b','c' translates too (top,bottom,center) *'t' aligned, top of text aligns with rY, *you get the rest.... */ -uint32_t GetTextYCoordinate(u32 font, uint32_t rY, const char* text, const char align) { +uint32_t getYCoordinate(u32 font,uint32_t rY,const char* text, const char align){ uint32_t height_o,width; GetTextDimensions(font,text,&width,&height_o); uint32_t height = (uint32_t)height_o; uint32_t fC = (rY-height); - switch(align){ case 't': default: return rY; case 'c': - return (rY+(height>>1));//>>1 is a bitwise shift for dividing by 2 + return (rY+(height/2U)); case 'b': - if(fC<=0) return 0; + if(fC<=0U) return 0U; else return fC; } } /*Automatically gives you the desired x-coordinate - *based on the string length and desired alignment + *based on the string length and desired alignmenr *rX=reference point... where to align around *text=string you want to display - *align='r','l','c' translates to (right,left,center) + *align='r','l','c' translates too (right,left,center) *'r' aligned, rX location = end of string, you get the rest... */ -uint32_t GetTextXCoordinate(u32 font, uint32_t rX, const char* text, const char align) { +uint32_t getXCoordinate(u32 font,uint32_t rX, const char* text ,const char align){ uint32_t height,width_o; GetTextDimensions(font,text,&width_o,&height); uint32_t fC = (rX-width_o); - switch(align){ case 'r': - if(fC<0) return 0; + if(fC<0U) return 0U; else return fC; case 'c': - return (rX+(width_o>>1));//>>1 is a bitwise shift for dividing by 2 + return (rX+(width_o/2U)); case 'l': default: return rX; } -} \ No newline at end of file +} diff --git a/common/menu.c b/common/menu.c index b762cdf..82e975e 100644 --- a/common/menu.c +++ b/common/menu.c @@ -55,7 +55,8 @@ void launchMenuBackTask() { } void launchApplyThemeTask(menuEntry_s* arg) { - //SetThemePathToConfig(arg->path); + const char* themePath = removeDriveFromPath(arg->path); + //SetThemePathToConfig(themePath); themeStartup(themeGlobalPreset); computeFrontGradient(themeCurrent.frontWaveColor, 280); } diff --git a/common/menu.h b/common/menu.h index d34d21e..a155814 100644 --- a/common/menu.h +++ b/common/menu.h @@ -111,3 +111,10 @@ static inline char* getSlash(const char* str) for (p = str+strlen(str); p >= str && *p != '/'; p--); return (char*)p; } + +static inline char* removeDriveFromPath(const char* str) { + const char* p; + for (p = str; p <= (str+strlen(str)) && *p != ':'; p++); + p++;//iterate one more time past ':' + return (char*)p; +} \ No newline at end of file diff --git a/common/theme.c b/common/theme.c index df4c837..b687063 100644 --- a/common/theme.c +++ b/common/theme.c @@ -54,11 +54,9 @@ void themeStartup(ThemePreset preset) { .hbmenuLogoImage = hbmenu_logo_dark_bin }; - config_t themeCfg = {0}; - config_setting_t *setting; - config_init(&themeCfg); + const char* themePath = ""; - //GetThemePathFromConfig(themeCfg, setting, themePath); + GetThemePathFromConfig(themePath); theme_t *themeDefault; @@ -69,7 +67,6 @@ void themeStartup(ThemePreset preset) { int waveBlending; const char *AText, *BText; bool good_cfg = config_read_file(&cfg, themePath); - config_destroy(&themeCfg); switch (preset) { case THEME_PRESET_LIGHT: @@ -138,7 +135,11 @@ void themeStartup(ThemePreset preset) { config_destroy(&cfg); } -void GetThemePathFromConfig(config_t cfg, config_setting_t *setting, const char* themePath) { +void GetThemePathFromConfig(const char* themePath) { + config_t cfg = {0}; + config_setting_t *setting; + config_init(&cfg); + char tmp_path[PATH_MAX] = {0}; #ifdef __SWITCH__ @@ -152,26 +153,27 @@ void GetThemePathFromConfig(config_t cfg, config_setting_t *setting, const char setting = config_lookup(&cfg, "themePath"); config_setting_lookup_string(setting, "themePath", &themePath); } + config_destroy(&cfg); } void SetThemePathToConfig(const char* themePath) { config_t cfg = {0}; config_init(&cfg); - char tmp_path[PATH_MAX] = {0}; + char settingPath[PATH_MAX] = {0}; config_setting_t *root,*group, *setting; #ifdef __SWITCH__ - tmp_path[0] = '/'; + settingPath[0] = '/'; #endif - strncat(tmp_path, "config/nx-hbmenu/setting.cfg", sizeof(tmp_path)-2); + strncat(settingPath, "config/nx-hbmenu/setting.cfg", sizeof(settingPath)-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)) { + if(!config_write_file(&cfg, settingPath)) { menuCreateMsgBox(780, 300, "Something went wrong, and the theme could not be applied!"); } diff --git a/common/theme.h b/common/theme.h index b95a419..a316863 100644 --- a/common/theme.h +++ b/common/theme.h @@ -30,7 +30,7 @@ typedef enum 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 GetThemePathFromConfig(const char* themePath); void SetThemePathToConfig(const char* themePath); extern theme_t themeCurrent;