From e01ca3150e7c024831779936c888dc6b2885a5ef Mon Sep 17 00:00:00 2001 From: yellows8 Date: Mon, 1 Oct 2018 12:53:08 -0400 Subject: [PATCH] Moved path init code from menuStartup() into new func menuStartupPath(), which now creates the config dirs if needed. Added menuGetRootBasePath(), which is now used for config paths and pc-build fonts. Changed some funcs from () to (void). Fixed broken button handling in pc_main for theme-menu. This fixes pc-build support for config/theme-menu. --- common/common.h | 7 ++++--- common/font.c | 2 +- common/menu.c | 39 +++++++++++++++++++++++++++++---------- common/menu.h | 3 ++- common/theme.c | 15 +++++---------- nx_main/main.c | 2 ++ pc_main/main.cpp | 4 +++- 7 files changed, 46 insertions(+), 26 deletions(-) diff --git a/common/common.h b/common/common.h index 35bcbfa..fa11c5e 100644 --- a/common/common.h +++ b/common/common.h @@ -59,9 +59,10 @@ typedef union { #include "theme.h" #include "message-box.h" -void menuStartup(); -void themeMenuStartup(); -void menuLoop(); +void menuStartupPath(void); +void menuStartup(void); +void themeMenuStartup(void); +void menuLoop(void); static inline uint8_t BlendColor(uint32_t src, uint32_t dst, uint8_t alpha) { diff --git a/common/font.c b/common/font.c index 75e94e3..29184e9 100644 --- a/common/font.c +++ b/common/font.c @@ -349,7 +349,7 @@ bool fontInitialize(void) for (i=0; itype == ENTRY_TYPE_FOLDER) @@ -286,15 +291,15 @@ void computeFrontGradient(color_t baseColor, int height) { } } -void menuStartup() { - char tmp_path[PATH_MAX]; +void menuStartupPath(void) { + char tmp_path[PATH_MAX+25]; #ifdef __SWITCH__ - strcpy(tmp_path,"sdmc:"); + strncpy(rootPathBase, "sdmc:", sizeof(rootPathBase)-1); #else - getcwd(tmp_path, PATH_MAX); + getcwd(rootPathBase, sizeof(rootPathBase)); #endif - snprintf(rootPath, sizeof(rootPath)-1, "%s%s%s", tmp_path, DIRECTORY_SEPARATOR, "switch"); + snprintf(rootPath, sizeof(rootPath)-1, "%s%s%s", rootPathBase, DIRECTORY_SEPARATOR, "switch"); struct stat st = {0}; @@ -302,6 +307,20 @@ void menuStartup() { mkdir(rootPath, 0755); } + snprintf(tmp_path, sizeof(tmp_path)-1, "%s/config/nx-hbmenu/themes", rootPathBase); + if (stat(tmp_path, &st) == -1) { + snprintf(tmp_path, sizeof(tmp_path)-1, "%s/config", rootPathBase); + mkdir(tmp_path, 0755); + + snprintf(tmp_path, sizeof(tmp_path)-1, "%s/config/nx-hbmenu", rootPathBase); + mkdir(tmp_path, 0755); + + snprintf(tmp_path, sizeof(tmp_path)-1, "%s/config/nx-hbmenu/themes", rootPathBase); + mkdir(tmp_path, 0755); + } +} + +void menuStartup(void) { menuScan(rootPath); folder_icon_small = downscaleImg(folder_icon_bin, 256, 256, 140, 140, IMAGE_MODE_RGB24); @@ -314,12 +333,12 @@ void menuStartup() { //menuCreateMsgBox(780, 300, "This is a test"); } -void themeMenuStartup() { +void themeMenuStartup(void) { if(hbmenu_state != HBMENU_DEFAULT) return; hbmenu_state = HBMENU_THEME_MENU; - char tmp_path[PATH_MAX]; + char tmp_path[PATH_MAX+25]; - snprintf(tmp_path, sizeof(tmp_path)-1, "%s%s%s%s%s%s",DIRECTORY_SEPARATOR, "config", DIRECTORY_SEPARATOR, "nx-hbmenu" , DIRECTORY_SEPARATOR, "themes"); + snprintf(tmp_path, sizeof(tmp_path)-1, "%s%s%s%s%s%s%s", rootPathBase, DIRECTORY_SEPARATOR, "config", DIRECTORY_SEPARATOR, "nx-hbmenu" , DIRECTORY_SEPARATOR, "themes"); themeMenuScan(tmp_path); } @@ -406,7 +425,7 @@ void drawBackBtn(menu_s* menu, bool emptyDir) { } } -void menuLoop() { +void menuLoop(void) { menuEntry_s* me; menu_s* menu = menuGetCurrent(); int i; diff --git a/common/menu.h b/common/menu.h index 7e6811c..f7fac55 100644 --- a/common/menu.h +++ b/common/menu.h @@ -91,7 +91,8 @@ void launchMenuEntryTask(menuEntry_s* arg); void launchApplyThemeTask(menuEntry_s* arg); void launchMenuBackTask(); void launchMenuNetloaderTask(); -char *menuGetRootPath(); +char *menuGetRootPath(void); +char *menuGetRootBasePath(void); void menuHandleAButton(void); diff --git a/common/theme.c b/common/theme.c index bbcbaca..671f0f6 100644 --- a/common/theme.c +++ b/common/theme.c @@ -144,16 +144,11 @@ void GetThemePathFromConfig(char* themePath, size_t size) { const char* tmpThemePath = ""; config_t cfg = {0}; config_setting_t *settings = NULL; - char tmp_path[PATH_MAX] = {0}; - char tmp_path_theme[PATH_MAX] = {0}; + char tmp_path[PATH_MAX+1] = {0}; + char tmp_path_theme[PATH_MAX+1] = {0}; - #ifdef __SWITCH__ - tmp_path[0] = '/'; - tmp_path_theme[0] = '/'; - #endif - - strncat(tmp_path, "config/nx-hbmenu/settings.cfg", sizeof(tmp_path)-2); - strncat(tmp_path_theme, "config/nx-hbmenu/themes/", sizeof(tmp_path_theme)-2); + snprintf(tmp_path, sizeof(tmp_path)-1, "%s/config/nx-hbmenu/settings.cfg", menuGetRootBasePath()); + snprintf(tmp_path_theme, sizeof(tmp_path_theme)-1, "%s/config/nx-hbmenu/themes/", menuGetRootBasePath()); bool good_cfg = config_read_file(&cfg, tmp_path); if(good_cfg) { @@ -183,7 +178,7 @@ void SetThemePathToConfig(const char* themePath) { settingPath[0] = '/'; #endif - strncat(settingPath, "config/nx-hbmenu/settings.cfg", sizeof(settingPath)-2); + snprintf(settingPath, sizeof(settingPath)-1, "%s/config/nx-hbmenu/settings.cfg", menuGetRootBasePath()); bool good_cfg = config_read_file(&cfg, settingPath); if(good_cfg) { diff --git a/nx_main/main.c b/nx_main/main.c index 351e5b7..0ccbd42 100644 --- a/nx_main/main.c +++ b/nx_main/main.c @@ -41,6 +41,8 @@ int main(int argc, char **argv) rc = plInitialize(); if (R_FAILED(rc)) fatalSimple(-6); + menuStartupPath(); + themeStartup((ThemePreset)theme); textInit(); menuStartup(); diff --git a/pc_main/main.cpp b/pc_main/main.cpp index 90fd5ea..6019d09 100644 --- a/pc_main/main.cpp +++ b/pc_main/main.cpp @@ -15,9 +15,10 @@ int main() sf::RenderWindow window(sf::VideoMode(1280, 720), "Test"); window.setFramerateLimit(60); + menuStartupPath(); themeStartup(THEME_PRESET_LIGHT); textInit(); - fontInitialize();//Must be called before menuStartup() due to cwd. + fontInitialize(); menuStartup(); while (window.isOpen()) @@ -111,6 +112,7 @@ extern "C" bool menuUpdate(void) { esc_state = new_esc_state; return_state = new_return_state; y_state = new_y_state; + t_state = new_t_state; return 0; }