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

Function GetDirectoriesInPath

Descent3/newui_filedlg.cpp:531–586  ·  view source on GitHub ↗

returns the number of directories in path p it fills in buffer (up to maxcount) with the directories found

Source from the content-addressed store, hash-verified

529// returns the number of directories in path p
530// it fills in buffer (up to maxcount) with the directories found
531int GetDirectoriesInPath(char **buffer, int maxcount, const char *p) {
532 ASSERT(buffer);
533 ASSERT(p);
534 if (maxcount <= 0)
535 return 0;
536
537 int i;
538 for (i = 0; i < maxcount; i++) {
539 buffer[i] = NULL;
540 }
541
542 char old_path[_MAX_PATH], path[_MAX_PATH];
543
544 ddio_GetWorkingDir(old_path, _MAX_PATH);
545 if (!ddio_SetWorkingDir(p)) {
546 // directory doesn't exist
547 ddio_SetWorkingDir(old_path);
548 return -1;
549 }
550
551 ddio_GetWorkingDir(path, _MAX_PATH);
552 if (stricmp(path, p)) {
553 // the working dir is not the same as the passed in path, so try to create a correct path and set it
554 ddio_MakePath(path, p, "", NULL);
555 if (!ddio_SetWorkingDir(path)) {
556 ddio_SetWorkingDir(old_path);
557 return -1;
558 }
559 }
560
561 int count = 0;
562 char tempbuffer[_MAX_PATH];
563
564 if (ddio_FindFileStart("*", tempbuffer)) {
565 if (std::filesystem::is_directory(tempbuffer)) {
566 buffer[count] = mem_strdup(tempbuffer);
567 count++;
568 }
569
570 bool done = false;
571
572 while (!done) {
573 if (ddio_FindNextFile(tempbuffer)) {
574 if (std::filesystem::is_directory(tempbuffer)) {
575 if (count < maxcount)
576 buffer[count] = mem_strdup(tempbuffer);
577 count++;
578 }
579 } else
580 done = true;
581 }
582 }
583 ddio_FindFileClose();
584 ddio_SetWorkingDir(old_path);
585 return count;
586}
587
588// Updates the given listbox with the directories and files that match wildcards (each wildcard seperates by a ;)

Callers 1

UpdateFileListFunction · 0.85

Calls 6

ddio_GetWorkingDirFunction · 0.50
ddio_SetWorkingDirFunction · 0.50
ddio_MakePathFunction · 0.50
ddio_FindFileStartFunction · 0.50
ddio_FindNextFileFunction · 0.50
ddio_FindFileCloseFunction · 0.50

Tested by

no test coverage detected