MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / UpdateFileList

Function UpdateFileList

Descent3/newui_filedlg.cpp:589–823  ·  view source on GitHub ↗

Updates the given listbox with the directories and files that match wildcards (each wildcard seperates by a ;)

Source from the content-addressed store, hash-verified

587
588// Updates the given listbox with the directories and files that match wildcards (each wildcard seperates by a ;)
589void UpdateFileList(newuiListBox *lb, const char *path, char *wildcards) {
590 FDlg_EnableWaitMessage(true);
591 lb->RemoveAll();
592
593 // if path is NULL or 0 length string then just list the directories
594 if ((!path) || (*path == '\0')) {
595 char *roots[30];
596 int rootcount = ddio_GetFileSysRoots((char **)&roots, 30);
597 if (!rootcount) {
598 FDlg_EnableWaitMessage(false);
599 return;
600 }
601 char tempbuffer[5];
602 for (int i = 0; i < rootcount; i++) {
603 if (roots[i]) {
604 snprintf(tempbuffer, sizeof(tempbuffer), " [%s]", roots[i]);
605 lb->AddItem(tempbuffer);
606 mem_free(roots[i]);
607 }
608 }
609 FDlg_EnableWaitMessage(false);
610 return;
611 }
612
613 char **dirs = NULL;
614 char *tempdir[1];
615 char fullpath[_MAX_PATH];
616 ddio_GetRootFromPath(path, fullpath);
617 if (!stricmp(path, fullpath)) {
618 // we are are the root of the drive, make a dummy path
619 ddio_MakePath(fullpath, path, "", NULL);
620 } else {
621 // just use this
622 strcpy(fullpath, path);
623 }
624
625 int dircount = GetDirectoriesInPath((char **)&tempdir, 1, fullpath);
626 if (dircount == -1) {
627 // invalid directory/path
628 DoMessageBox(TXT_ERROR, TXT_ERRPATHNOTVALID, MSGBOX_OK);
629 FDlg_EnableWaitMessage(false);
630 return;
631 }
632
633 if (tempdir[0])
634 mem_free(tempdir[0]);
635 if (dircount > 0) {
636 dirs = (char **)mem_malloc(sizeof(char *) * dircount);
637 if (!dirs) {
638 // out of memory!
639 dircount = 0;
640 } else {
641 GetDirectoriesInPath(dirs, dircount, fullpath);
642 }
643 } else {
644 dircount = 0;
645 dirs = NULL;
646 }

Callers 1

DoPathFileDialogFunction · 0.85

Calls 9

FDlg_EnableWaitMessageFunction · 0.85
GetDirectoriesInPathFunction · 0.85
DoMessageBoxFunction · 0.85
GetFilesInPathFunction · 0.85
ddio_GetFileSysRootsFunction · 0.50
ddio_GetRootFromPathFunction · 0.50
ddio_MakePathFunction · 0.50
RemoveAllMethod · 0.45
AddItemMethod · 0.45

Tested by

no test coverage detected