changeset 1674:c362f2c7766a

Moved fake virtual root stuff to get_dir_list from legacy menu so it can be used in new UI
author Michael Pavone <pavone@retrodev.com>
date Thu, 03 Jan 2019 23:30:17 -0800
parents ab3b465c052c
children 357b4951d9b2
files menu.c util.c
diffstat 2 files changed, 61 insertions(+), 49 deletions(-) [+]
line wrap: on
line diff
--- a/menu.c	Thu Jan 03 19:30:41 2019 -0800
+++ b/menu.c	Thu Jan 03 23:30:17 2019 -0800
@@ -134,24 +134,6 @@
 		switch (address >> 2)
 		{
 		case 0: {
-#if _WIN32
-			//handle virtual "drives" directory
-			if (menu->curpath[0] == PATH_SEP[0]) {
-				char drivestrings[4096];
-				if (sizeof(drivestrings) >= GetLogicalDriveStrings(sizeof(drivestrings), drivestrings)) {
-					for (char *cur = drivestrings; *cur; cur += strlen(cur) + 1)
-					{
-						dst = copy_dir_entry_to_guest(dst, m68k, cur, 1);
-					}
-				}
-				//terminate list
-				uint8_t *dest = get_native_pointer(dst, (void **)m68k->mem_pointers, &m68k->options->gen);
-				if (dest) {
-					*dest = dest[1] = 0;
-				}
-				break;
-			}
-#endif
 			size_t num_entries;
 			dir_entry *entries = get_dir_list(menu->curpath, &num_entries);
 			if (entries) {
@@ -163,12 +145,6 @@
 				entries->is_dir = 1;
 				num_entries = 1;
 			}
-#ifdef _WIN32
-			if (menu->curpath[1] == ':' && !menu->curpath[2]) {
-				//Add fake .. entry to allow navigation to virtual "drives" directory
-				dst = copy_dir_entry_to_guest(dst, m68k, "..", 1);
-			}
-#endif
 			uint32_t num_exts;
 			char **ext_list = get_extension_list(config, &num_exts);
 			for (size_t i = 0; dst && i < num_entries; i++)
--- a/util.c	Thu Jan 03 19:30:41 2019 -0800
+++ b/util.c	Thu Jan 03 23:30:17 2019 -0800
@@ -537,34 +537,70 @@
 
 dir_entry *get_dir_list(char *path, size_t *numret)
 {
-	HANDLE dir;
-	WIN32_FIND_DATA file;
-	char *pattern = alloc_concat(path, "/*.*");
-	dir = FindFirstFile(pattern, &file);
-	free(pattern);
-	if (dir == INVALID_HANDLE_VALUE) {
+	dir_entry *ret;
+	if (path[0] == PATH_SEP[0] && !path[1]) {
+		int drives = GetLogicalDrives();
+		size_t count = 0;
+		for (int i = 0; i < 26; i++)
+		{
+			if (drives & (1 << i)) {
+				count++;
+			}
+		}
+		ret = calloc(count, sizeof(dir_entry));
+		dir_entry *cur = ret;
+		for (int i = 0; i < 26; i++)
+		{
+			if (drives & (1 << i)) {
+				cur->name = malloc(4);
+				cur->name[0] = 'A' + i;
+				cur->name[1] = ':';
+				cur->name[2] = PATH_SEP[0];
+				cur->name[3] = 0;
+				cur->is_dir = 1;
+				cur++;
+			}
+		}
 		if (numret) {
-			*numret = 0;
+			*numret = count;
 		}
-		return NULL;
-	}
-	
-	size_t storage = 64;
-	dir_entry *ret = malloc(sizeof(dir_entry) * storage);
-	size_t pos = 0;
-	
-	do {
-		if (pos == storage) {
-			storage = storage * 2;
-			ret = realloc(ret, sizeof(dir_entry) * storage);
+	} else {
+		HANDLE dir;
+		WIN32_FIND_DATA file;
+		char *pattern = alloc_concat(path, "/*.*");
+		dir = FindFirstFile(pattern, &file);
+		free(pattern);
+		if (dir == INVALID_HANDLE_VALUE) {
+			if (numret) {
+				*numret = 0;
+			}
+			return NULL;
 		}
-		ret[pos].name = strdup(file.cFileName);
-		ret[pos++].is_dir = (file.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0;
-	} while (FindNextFile(dir, &file));
-	
-	FindClose(dir);
-	if (numret) {
-		*numret = pos;
+		
+		size_t storage = 64;
+		ret = malloc(sizeof(dir_entry) * storage);
+		size_t pos = 0;
+		
+		if (path[1] == ':' && (!path[2] || (path[2] == PATH_SEP[0] && !path[3]))) {
+			//we are in the root of a drive, add a virtual .. entry
+			//for navigating to the virtual root directory
+			ret[pos].name = strdup("..");
+			ret[pos++].is_dir = 1;
+		}
+		
+		do {
+			if (pos == storage) {
+				storage = storage * 2;
+				ret = realloc(ret, sizeof(dir_entry) * storage);
+			}
+			ret[pos].name = strdup(file.cFileName);
+			ret[pos++].is_dir = (file.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0;
+		} while (FindNextFile(dir, &file));
+		
+		FindClose(dir);
+		if (numret) {
+			*numret = pos;
+		}
 	}
 	return ret;
 }