summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Pavone <pavone@retrodev.com>2019-01-03 23:30:17 -0800
committerMichael Pavone <pavone@retrodev.com>2019-01-03 23:30:17 -0800
commit5256e5ee5cc4a6e52d42cf3f5e762671bc177ccf (patch)
treed34f7b12a4511b260f6a778bd5ffec9694b1f222
parent0cd5890cd283b2ae6b5e2af37f6dde87a6bfe5e8 (diff)
Moved fake virtual root stuff to get_dir_list from legacy menu so it can be used in new UI
-rw-r--r--menu.c24
-rw-r--r--util.c86
2 files changed, 61 insertions, 49 deletions
diff --git a/menu.c b/menu.c
index 57dc827..347f60c 100644
--- a/menu.c
+++ b/menu.c
@@ -134,24 +134,6 @@ void * menu_write_w(uint32_t address, void * context, uint16_t value)
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 @@ void * menu_write_w(uint32_t address, void * context, uint16_t value)
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++)
diff --git a/util.c b/util.c
index ea9c58c..e54e8ea 100644
--- a/util.c
+++ b/util.c
@@ -537,34 +537,70 @@ char * get_exe_dir()
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;
+ }
+
+ 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;
}
- 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;
}