summaryrefslogtreecommitdiff
path: root/util.c
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 /util.c
parent0cd5890cd283b2ae6b5e2af37f6dde87a6bfe5e8 (diff)
Moved fake virtual root stuff to get_dir_list from legacy menu so it can be used in new UI
Diffstat (limited to 'util.c')
-rw-r--r--util.c86
1 files changed, 61 insertions, 25 deletions
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;
}