From 988f8b250a9f2a99bf7de01c7ef5a8dff685b179 Mon Sep 17 00:00:00 2001 From: dimok321 <15055714+dimok789@users.noreply.github.com> Date: Sun, 10 May 2009 10:47:15 +0000 Subject: [PATCH] *Fixed settings crash on too long paths *Added new directory creation function. Now you set unlimited subfolders for covers/discimages. The programm creates the subfolders automaticly on download now. --- source/cfg.c | 24 +++++++++++++++++++++ source/cfg.h | 1 + source/menu.cpp | 55 ++++++++++++++++++++++++++++++++++++------------- 3 files changed, 66 insertions(+), 14 deletions(-) diff --git a/source/cfg.c b/source/cfg.c index 7d32ac5c..fc8b1ac2 100644 --- a/source/cfg.c +++ b/source/cfg.c @@ -156,6 +156,30 @@ bool cfg_map(char *name, char *val, short *var, short id) return false; } +int subfoldercheck(char * dircovers) { + //check forsubfolders + char dircheck[100]; + char dirslash[100]; + int cnt = 0; + char * pch; + struct stat st; + + sprintf(dirslash, "%s/", dircovers); + + if(stat(dirslash, &st) != 0) { + pch = strrchr(dircovers, '/'); + cnt = pch-dircovers; + snprintf(dircheck, cnt+1, "%s", dircovers); + subfoldercheck(dircheck); + } + + if (mkdir(dircovers, 0777) == -1) { + return 0; + } + +return 1; +} + bool cfg_bool(char *name, short *var) { return (cfg_map(name, "0", var, 0) || cfg_map(name, "1", var, 1)); diff --git a/source/cfg.h b/source/cfg.h index b26ae597..9ee27d5e 100644 --- a/source/cfg.h +++ b/source/cfg.h @@ -156,6 +156,7 @@ void CFG_Load(int argc, char **argv); struct Game_CFG* CFG_get_game_opt(u8 *id); bool CFG_save_game_opt(u8 *id); bool CFG_forget_game_opt(u8 *id); +int subfoldercheck(char * directory); //Astidof - Begin of modification enum { diff --git a/source/menu.cpp b/source/menu.cpp index 4b72b1fc..0a0fe44a 100644 --- a/source/menu.cpp +++ b/source/menu.cpp @@ -1596,16 +1596,20 @@ ProgressDownloadWindow(int choice2) char dircovers[100]; snprintf(dircovers,strlen(CFG.covers_path),"%s",CFG.covers_path); if (mkdir(dircovers, 0777) == -1) { - WindowPrompt("Error:","Can't create directory","OK",0,0,0); - cntMissFiles = 0; + if(subfoldercheck(dircovers) != 1) { + WindowPrompt("Error:","Can't create directory","OK",0,0,0); + cntMissFiles = 0; + } } } if(stat(CFG.disc_path,&st) != 0) { char dirdiscs[100]; snprintf(dirdiscs,strlen(CFG.disc_path),"%s",CFG.disc_path); if (mkdir(dirdiscs, 0777) == -1) { - WindowPrompt("Error:","Can't create directory","OK",0,0,0); - cntMissFiles = 0; + if(subfoldercheck(dirdiscs) != 1) { + WindowPrompt("Error:","Can't create directory","OK",0,0,0); + cntMissFiles = 0; + } } } @@ -1855,7 +1859,7 @@ err: * Opens an on-screen keyboard window, with the data entered being stored * into the specified variable. ***************************************************************************/ -static int OnScreenKeyboard(char * var, u16 maxlen) +static int OnScreenKeyboard(char * var, u32 maxlen) { int save = -1; @@ -3242,6 +3246,7 @@ static int MenuSettings() { int menu = MENU_NONE; int ret; + char cfgtext[20]; GuiSound btnSoundOver(button_over_pcm, button_over_pcm_size, SOUND_PCM, vol); GuiSound btnClick(button_click2_pcm, button_click2_pcm_size, SOUND_PCM, vol); @@ -3579,11 +3584,33 @@ static int MenuSettings() else if(CFG.parentalcontrol == 2) sprintf(options2.value[5], "2"); else if(CFG.parentalcontrol == 3) sprintf(options2.value[5], "3"); - sprintf(options2.value[6], CFG.covers_path); - sprintf(options2.value[7], CFG.disc_path); + if (strlen(CFG.covers_path) < (9 + 3)) { + sprintf(cfgtext, "%s", CFG.covers_path); + } else { + strncpy(cfgtext, CFG.covers_path, 9); + cfgtext[9] = '\0'; + strncat(cfgtext, "...", 3); + } + sprintf(options2.value[6], "%s", cfgtext); - sprintf(options2.value[8], CFG.theme_path); + if (strlen(CFG.disc_path) < (9 + 3)) { + sprintf(cfgtext, "%s", CFG.disc_path); + } else { + strncpy(cfgtext, CFG.disc_path, 9); + cfgtext[9] = '\0'; + strncat(cfgtext, "...", 3); + } + sprintf(options2.value[7], "%s", cfgtext); + + if (strlen(CFG.theme_path) < (9 + 3)) { + sprintf(cfgtext, "%s", CFG.theme_path); + } else { + strncpy(cfgtext, CFG.theme_path, 9); + cfgtext[9] = '\0'; + strncat(cfgtext, "...", 3); + } + sprintf(options2.value[8], "%s", cfgtext); ret = optionBrowser2.GetClickedOption(); @@ -3643,9 +3670,9 @@ static int MenuSettings() mainWindow->Remove(&page2Btn); w.Remove(&backBtn); w.Remove(&lockBtn); - char entered[50] = ""; + char entered[43] = ""; strncpy(entered, CFG.covers_path, sizeof(entered)); - int result = OnScreenKeyboard(entered, 50); + int result = OnScreenKeyboard(entered,43); mainWindow->Append(&optionBrowser2); mainWindow->Append(&page1Btn); mainWindow->Append(&page2Btn); @@ -3671,9 +3698,9 @@ static int MenuSettings() mainWindow->Remove(&page2Btn); w.Remove(&backBtn); w.Remove(&lockBtn); - char entered[50] = ""; + char entered[43] = ""; strncpy(entered, CFG.disc_path, sizeof(entered)); - int result = OnScreenKeyboard(entered, 50); + int result = OnScreenKeyboard(entered, 43); mainWindow->Append(&optionBrowser2); mainWindow->Append(&page1Btn); mainWindow->Append(&page2Btn); @@ -3699,9 +3726,9 @@ static int MenuSettings() mainWindow->Remove(&page2Btn); w.Remove(&backBtn); w.Remove(&lockBtn); - char entered[50] = ""; + char entered[43] = ""; strncpy(entered, CFG.theme_path, sizeof(entered)); - int result = OnScreenKeyboard(entered, 50); + int result = OnScreenKeyboard(entered, 43); mainWindow->Append(&optionBrowser2); mainWindow->Append(&page1Btn); mainWindow->Append(&page2Btn);