--- hatari/src/gui-sdl/dlgFileSelect.c 2019/04/09 08:47:27 1.1.1.7 +++ hatari/src/gui-sdl/dlgFileSelect.c 2019/04/09 08:48:52 1.1.1.8 @@ -16,6 +16,7 @@ const char DlgFileSelect_fileid[] = "Hat #include "scandir.h" #include "sdlgui.h" #include "file.h" +#include "paths.h" #include "zip.h" @@ -89,10 +90,10 @@ static int entries; /*-----------------------------------------------------------------------*/ -/* - Update the file name strings in the dialog. - Returns false if it failed, true on success. -*/ +/** + * Update the file name strings in the dialog. + * Returns false if it failed, true on success. + */ static int DlgFileSelect_RefreshEntries(struct dirent **files, char *path, bool browsingzip) { int i; @@ -141,10 +142,10 @@ static int DlgFileSelect_RefreshEntries( /*-----------------------------------------------------------------------*/ -/* - Remove all hidden files (files with file names that begin with a dot) from - the list. -*/ +/** + * Remove all hidden files (files with file names that begin with a dot) from + * the list. + */ static void DlgFileSelect_RemoveHiddenFiles(struct dirent **files) { int i; @@ -186,9 +187,9 @@ static void DlgFileSelect_RemoveHiddenFi /*-----------------------------------------------------------------------*/ -/* - Prepare to scroll up one entry. -*/ +/** + * Prepare to scroll up one entry. + */ static void DlgFileSelect_ScrollUp(void) { if (ypos > 0) @@ -200,9 +201,9 @@ static void DlgFileSelect_ScrollUp(void) /*-----------------------------------------------------------------------*/ -/* - Prepare to scroll down one entry. -*/ +/** + * Prepare to scroll down one entry. + */ static void DlgFileSelect_ScrollDown(void) { if (ypos+SGFS_NUMENTRIES < entries) @@ -214,9 +215,9 @@ static void DlgFileSelect_ScrollDown(voi /*-----------------------------------------------------------------------*/ -/* - Handle SDL events. -*/ +/** + * Handle SDL events. + */ static void DlgFileSelect_HandleSdlEvents(SDL_Event *pEvent) { int oldypos = ypos; @@ -257,9 +258,9 @@ static void DlgFileSelect_HandleSdlEvent /*-----------------------------------------------------------------------*/ -/* - Free file entries -*/ +/** + * Free file entries + */ static struct dirent **files_free(struct dirent **files) { int i; @@ -276,10 +277,10 @@ static struct dirent **files_free(struct /*-----------------------------------------------------------------------*/ -/* - Copy to dst src+add if they are below maxlen and return true, - otherwise return false -*/ +/** + * Copy to dst src+add if they are below maxlen and return true, + * otherwise return false + */ static int strcat_maxlen(char *dst, int maxlen, const char *src, const char *add) { int slen, alen; @@ -295,9 +296,9 @@ static int strcat_maxlen(char *dst, int } /*-----------------------------------------------------------------------*/ -/* - Create and return suitable path into zip file -*/ +/** + * Create and return suitable path into zip file + */ static char* zip_get_path(const char *zipdir, const char *zipfilename, int browsingzip) { if (browsingzip) @@ -311,7 +312,9 @@ static char* zip_get_path(const char *zi return strdup(""); } -/* string for zip root needs to be empty, check and correct if needed */ +/** + * string for zip root needs to be empty, check and correct if needed + */ static void correct_zip_root(char *zippath) { if (zippath[0] == PATHSEP && !zippath[1]) @@ -321,19 +324,20 @@ static void correct_zip_root(char *zippa } /*-----------------------------------------------------------------------*/ -/* - Show and process a file selection dialog. - Returns path/name user selected or NULL if user canceled - input: zip_path = pointer's pointer to buffer to contain file path - within a selected zip file, or NULL if browsing zip files is disallowed. - bAllowNew: true if the user is allowed to insert new file names. -*/ +/** + * Show and process a file selection dialog. + * Returns path/name user selected or NULL if user canceled + * input: zip_path = pointer's pointer to buffer to contain file path + * within a selected zip file, or NULL if browsing zip files is disallowed. + * bAllowNew: true if the user is allowed to insert new file names. + */ char* SDLGui_FileSelect(const char *path_and_name, char **zip_path, bool bAllowNew) { struct dirent **files = NULL; char *pStringMem; char *retpath; - char *home, *path, *fname; /* The actual file and path names */ + const char *home; + char *path, *fname; /* The actual file and path names */ bool reloaddir = true; /* Do we have to reload the directory file list? */ int retbut; int oldcursorstate; @@ -382,6 +386,7 @@ char* SDLGui_FileSelect(const char *path if (!(File_DirExists(path) || getcwd(path, FILENAME_MAX))) { perror("SDLGui_FileSelect: non-existing path and CWD failed"); + free(pStringMem); return NULL; } } @@ -405,6 +410,12 @@ char* SDLGui_FileSelect(const char *path if (browsingzip) { files = ZIP_GetFilesDir(zipfiles, zipdir, &entries); + if(!files) + { + fprintf(stderr, "SDLGui_FileSelect: ZIP_GetFilesDir error!\n"); + free(pStringMem); + return NULL; + } } else { @@ -597,8 +608,8 @@ char* SDLGui_FileSelect(const char *path break; case SGFSDLG_HOMEDIR: /* Change to home directory */ - home = getenv("HOME"); - if (home == NULL) + home = Paths_GetUserHome(); + if (home == NULL || !*home) break; if (browsingzip) { @@ -686,7 +697,8 @@ char* SDLGui_FileSelect(const char *path /*-----------------------------------------------------------------------*/ -/* Let user browse for a file, confname is used as default. +/** + * Let user browse for a file, confname is used as default. * If bAllowNew is true, user can select new files also. * * If no file is selected, or there's some problem with the file,