--- hatari/src/gui-sdl/dlgFileSelect.c 2019/04/01 07:13:50 1.1.1.4 +++ hatari/src/gui-sdl/dlgFileSelect.c 2019/04/01 07:14:59 1.1.1.5 @@ -6,7 +6,7 @@ A file selection dialog for the graphical user interface for Hatari. */ -const char DlgFileSelect_rcsid[] = "Hatari $Id: dlgFileSelect.c,v 1.1.1.4 2019/04/01 07:13:50 root Exp $"; +const char DlgFileSelect_rcsid[] = "Hatari $Id: dlgFileSelect.c,v 1.1.1.5 2019/04/01 07:14:59 root Exp $"; #include #include @@ -76,7 +76,7 @@ static SGOBJ fsdlg[] = { SGTEXT, SG_EXIT, 0, 2,21, DLGFILENAMES_SIZE,1, dlgfilenames[15] }, { SGBUTTON, SG_TOUCHEXIT, 0, 62,6, 1,1, "\x01" }, /* Arrow up */ { SGBUTTON, SG_TOUCHEXIT, 0, 62,21, 1,1, "\x02" }, /* Arrow down */ - { SGCHECKBOX, SG_EXIT, SG_SELECTED, 2,23, 18,1, "Show hidden files" }, + { SGCHECKBOX, SG_EXIT, 0, 2,23, 18,1, "Show hidden files" }, { SGBUTTON, SG_DEFAULT, 0, 32,23, 8,1, "Okay" }, { SGBUTTON, SG_CANCEL, 0, 50,23, 8,1, "Cancel" }, { -1, 0, 0, 0,0, 0,0, NULL } @@ -84,7 +84,7 @@ static SGOBJ fsdlg[] = static int ypos; /* First entry number to be displayed */ -static BOOL refreshentries; /* Do we have to update the file names in the dialog? */ +static bool refreshentries; /* Do we have to update the file names in the dialog? */ static int entries; /* How many files are in the actual directory? */ @@ -93,7 +93,7 @@ static int entries; 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) +static int DlgFileSelect_RefreshEntries(struct dirent **files, char *path, bool browsingzip) { int i; char *tempstr = malloc(FILENAME_MAX); @@ -328,22 +328,21 @@ static void correct_zip_root(char *zippa 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) +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 */ - BOOL reloaddir = TRUE; /* Do we have to reload the directory file list? */ + bool reloaddir = TRUE; /* Do we have to reload the directory file list? */ int retbut; int oldcursorstate; int selection = -1; /* The actual selection, -1 if none selected */ char *zipfilename; /* Filename in zip file */ char *zipdir; - BOOL browsingzip = FALSE; /* Are we browsing an archive? */ + bool browsingzip = FALSE; /* Are we browsing an archive? */ zip_dir *zipfiles = NULL; SDL_Event sdlEvent; - struct stat filestat; ypos = 0; refreshentries = TRUE; @@ -356,6 +355,8 @@ char* SDLGui_FileSelect(const char *path zipdir = pStringMem + 2 * FILENAME_MAX; zipfilename = pStringMem + 3 * FILENAME_MAX; zipfilename[0] = 0; + fname[0] = 0; + path[0] = 0; SDLGui_CenterDlg(fsdlg); if (bAllowNew) @@ -375,21 +376,16 @@ char* SDLGui_FileSelect(const char *path strncpy(path, path_and_name, FILENAME_MAX); path[FILENAME_MAX-1] = '\0'; } - else + if (!File_DirExists(path)) { - if (!getcwd(path, FILENAME_MAX)) + File_SplitPath(path, path, fname, NULL); + if (!(File_DirExists(path) || getcwd(path, FILENAME_MAX))) { - perror("SDLGui_FileSelect"); + perror("SDLGui_FileSelect: non-existing path and CWD failed"); return NULL; } } - if (stat(path, &filestat) == 0 && S_ISDIR(filestat.st_mode)) - { - File_AddSlashToEndFileName(path); - fname[0] = 0; - } - else - File_SplitPath(path, path, fname, NULL); + File_MakeAbsoluteName(path); File_MakeValidPathName(path); File_ShrinkName(dlgpath, path, DLGPATH_SIZE); @@ -426,7 +422,7 @@ char* SDLGui_FileSelect(const char *path { fprintf(stderr, "SDLGui_FileSelect: Path not found.\n"); free(pStringMem); - return FALSE; + return NULL; } /* reload always implies refresh */ @@ -440,7 +436,7 @@ char* SDLGui_FileSelect(const char *path if (!DlgFileSelect_RefreshEntries(files, path, browsingzip)) { free(pStringMem); - return FALSE; + return NULL; } refreshentries = FALSE; } @@ -458,7 +454,7 @@ char* SDLGui_FileSelect(const char *path { perror("Error while allocating temporary memory in SDLGui_FileSelect()"); free(pStringMem); - return FALSE; + return NULL; } if (browsingzip == TRUE) @@ -468,7 +464,7 @@ char* SDLGui_FileSelect(const char *path { fprintf(stderr, "SDLGui_FileSelect: Path name too long!\n"); free(pStringMem); - return FALSE; + return NULL; } /* directory? */ if (File_DoesFileNameEndWithSlash(tempstr)) @@ -523,9 +519,9 @@ char* SDLGui_FileSelect(const char *path { fprintf(stderr, "SDLGui_FileSelect: Path name too long!\n"); free(pStringMem); - return FALSE; + return NULL; } - if (stat(tempstr, &filestat) == 0 && S_ISDIR(filestat.st_mode)) + if (File_DirExists(tempstr)) { File_HandleDotDirs(tempstr); File_AddSlashToEndFileName(tempstr); @@ -699,7 +695,7 @@ char* SDLGui_FileSelect(const char *path * (dlgname is shrinked & limited to maxlen and confname is assumed * to have FILENAME_MAX amount of space). */ -BOOL SDLGui_FileConfSelect(char *dlgname, char *confname, int maxlen, BOOL bAllowNew) +bool SDLGui_FileConfSelect(char *dlgname, char *confname, int maxlen, bool bAllowNew) { char *selname;