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

Function GetFilesInPath

Descent3/newui_filedlg.cpp:477–527  ·  view source on GitHub ↗

returns the number of files in path p, that matches wildcard it fills in buffer (up to maxcount) with the files found

Source from the content-addressed store, hash-verified

475// returns the number of files in path p, that matches wildcard
476// it fills in buffer (up to maxcount) with the files found
477int GetFilesInPath(char **buffer, int maxcount, const char *p, const char *wildcard) {
478 ASSERT(buffer);
479 ASSERT(p);
480 ASSERT(wildcard);
481 if (maxcount <= 0)
482 return 0;
483
484 char old_path[_MAX_PATH], path[_MAX_PATH];
485 ddio_GetWorkingDir(old_path, _MAX_PATH);
486 if (!ddio_SetWorkingDir(p)) {
487 // directory doesn't exist
488 ddio_SetWorkingDir(old_path);
489 return -1;
490 }
491
492 ddio_GetWorkingDir(path, _MAX_PATH);
493 if (stricmp(path, p)) {
494 // the working dir is not the same as the passed in path, so try to create a correct path and set it
495 ddio_MakePath(path, p, "", NULL);
496 if (!ddio_SetWorkingDir(path)) {
497 ddio_SetWorkingDir(old_path);
498 return -1;
499 }
500 }
501
502 int count = 0;
503 char tempbuffer[_MAX_PATH];
504
505 if (ddio_FindFileStart(wildcard, tempbuffer)) {
506 if (!std::filesystem::is_directory(tempbuffer)) {
507 buffer[count] = mem_strdup(tempbuffer);
508 count++;
509 }
510
511 bool done = false;
512
513 while (!done) {
514 if (ddio_FindNextFile(tempbuffer)) {
515 if (!std::filesystem::is_directory(tempbuffer)) {
516 if (count < maxcount)
517 buffer[count] = mem_strdup(tempbuffer);
518 count++;
519 }
520 } else
521 done = true;
522 }
523 }
524 ddio_FindFileClose();
525 ddio_SetWorkingDir(old_path);
526 return count;
527}
528
529// returns the number of directories in path p
530// it fills in buffer (up to maxcount) with the directories found

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