From 66d16a928b3e06324a3ad3ad339cf9fd41f842a6 Mon Sep 17 00:00:00 2001 From: kreatordxx <> Date: Sat, 28 Aug 2010 02:46:54 +0000 Subject: [PATCH] In select_file_recursive handle paths relative to the current write directory correctly --- CHANGELOG.txt | 1 + main/menu.c | 27 ++++++++++++++++++++++++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index eb3ca45dc..5bcbe69dd 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -4,6 +4,7 @@ D2X-Rebirth Changelog -------- main/menu.c: In list_dir_el make sure PHYSFS_getRealDir won't give NULL to strcmp which will happen for files located in a Windows root directory include/u_mem.h: Make define of MEM_K apply to non-debug builds as well (whoops) +main/menu.c: In select_file_recursive handle paths relative to the current write directory correctly 20100827 -------- diff --git a/main/menu.c b/main/menu.c index 4be45cf42..ac47208f5 100644 --- a/main/menu.c +++ b/main/menu.c @@ -1402,10 +1402,31 @@ int select_file_recursive(char *title, const char *orig_path, char **ext_list, i b->new_path = 1; // Set the viewing directory to orig_path, or some parent of it - if (orig_path && *orig_path) + if (orig_path) { - strncpy(b->view_path, orig_path, PATH_MAX - 1); - b->view_path[PATH_MAX - 1] = '\0'; + // Must make this an absolute path for directory browsing to work properly +#ifdef __WIN32 + if (!(isalpha(orig_path[0]) && (orig_path[1] == ':'))) // drive letter prompt (e.g. "C:" +#elif defined(macintosh) + if (orig_path[0] == ':') +#else + if (orig_path[0] != '/') +#endif + { + strncpy(b->view_path, PHYSFS_getBaseDir(), PATH_MAX - 1); // current write directory must be set to base directory + b->view_path[PATH_MAX - 1] = '\0'; +#ifdef macintosh + orig_path++; // go past ':' +#endif + strncat(b->view_path, orig_path, PATH_MAX - 1 - strlen(b->view_path)); + b->view_path[PATH_MAX - 1] = '\0'; + } + else + { + strncpy(b->view_path, orig_path, PATH_MAX - 1); + b->view_path[PATH_MAX - 1] = '\0'; + } + p = b->view_path + strlen(b->view_path) - 1; PHYSFS_getSearchPathCallback((PHYSFS_StringCallback) searchpath_matches, b);