Mercurial > repos > blastem
comparison util.c @ 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 | ba3fb7a3be6b |
comparison
equal
deleted
inserted
replaced
1673:ab3b465c052c | 1674:c362f2c7766a |
---|---|
535 return path; | 535 return path; |
536 } | 536 } |
537 | 537 |
538 dir_entry *get_dir_list(char *path, size_t *numret) | 538 dir_entry *get_dir_list(char *path, size_t *numret) |
539 { | 539 { |
540 HANDLE dir; | 540 dir_entry *ret; |
541 WIN32_FIND_DATA file; | 541 if (path[0] == PATH_SEP[0] && !path[1]) { |
542 char *pattern = alloc_concat(path, "/*.*"); | 542 int drives = GetLogicalDrives(); |
543 dir = FindFirstFile(pattern, &file); | 543 size_t count = 0; |
544 free(pattern); | 544 for (int i = 0; i < 26; i++) |
545 if (dir == INVALID_HANDLE_VALUE) { | 545 { |
546 if (drives & (1 << i)) { | |
547 count++; | |
548 } | |
549 } | |
550 ret = calloc(count, sizeof(dir_entry)); | |
551 dir_entry *cur = ret; | |
552 for (int i = 0; i < 26; i++) | |
553 { | |
554 if (drives & (1 << i)) { | |
555 cur->name = malloc(4); | |
556 cur->name[0] = 'A' + i; | |
557 cur->name[1] = ':'; | |
558 cur->name[2] = PATH_SEP[0]; | |
559 cur->name[3] = 0; | |
560 cur->is_dir = 1; | |
561 cur++; | |
562 } | |
563 } | |
546 if (numret) { | 564 if (numret) { |
547 *numret = 0; | 565 *numret = count; |
548 } | 566 } |
549 return NULL; | 567 } else { |
550 } | 568 HANDLE dir; |
551 | 569 WIN32_FIND_DATA file; |
552 size_t storage = 64; | 570 char *pattern = alloc_concat(path, "/*.*"); |
553 dir_entry *ret = malloc(sizeof(dir_entry) * storage); | 571 dir = FindFirstFile(pattern, &file); |
554 size_t pos = 0; | 572 free(pattern); |
555 | 573 if (dir == INVALID_HANDLE_VALUE) { |
556 do { | 574 if (numret) { |
557 if (pos == storage) { | 575 *numret = 0; |
558 storage = storage * 2; | 576 } |
559 ret = realloc(ret, sizeof(dir_entry) * storage); | 577 return NULL; |
560 } | 578 } |
561 ret[pos].name = strdup(file.cFileName); | 579 |
562 ret[pos++].is_dir = (file.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0; | 580 size_t storage = 64; |
563 } while (FindNextFile(dir, &file)); | 581 ret = malloc(sizeof(dir_entry) * storage); |
564 | 582 size_t pos = 0; |
565 FindClose(dir); | 583 |
566 if (numret) { | 584 if (path[1] == ':' && (!path[2] || (path[2] == PATH_SEP[0] && !path[3]))) { |
567 *numret = pos; | 585 //we are in the root of a drive, add a virtual .. entry |
586 //for navigating to the virtual root directory | |
587 ret[pos].name = strdup(".."); | |
588 ret[pos++].is_dir = 1; | |
589 } | |
590 | |
591 do { | |
592 if (pos == storage) { | |
593 storage = storage * 2; | |
594 ret = realloc(ret, sizeof(dir_entry) * storage); | |
595 } | |
596 ret[pos].name = strdup(file.cFileName); | |
597 ret[pos++].is_dir = (file.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0; | |
598 } while (FindNextFile(dir, &file)); | |
599 | |
600 FindClose(dir); | |
601 if (numret) { | |
602 *numret = pos; | |
603 } | |
568 } | 604 } |
569 return ret; | 605 return ret; |
570 } | 606 } |
571 | 607 |
572 time_t get_modification_time(char *path) | 608 time_t get_modification_time(char *path) |