MCPcopy Create free account
hub / github.com/ZDoom/gzdoom / D_AddFile

Function D_AddFile

src/common/utility/findfile.cpp:53–122  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

51//==========================================================================
52
53bool D_AddFile(std::vector<std::string>& wadfiles, const char* file, bool check, int position, FConfigFile* config)
54{
55 if (file == nullptr || *file == '\0')
56 {
57 return false;
58 }
59#ifdef __unix__
60 // Confirm file exists in filesystem.
61 struct stat info;
62 bool found = stat(file, &info) == 0;
63 FString fullpath = file;
64 if (!found)
65 {
66 // File not found, so split file into path and filename so we can enumerate the path for the file.
67 auto lastindex = fullpath.LastIndexOf("/");
68 FString basepath = fullpath.Left(lastindex);
69 FString filename = fullpath.Right(fullpath.Len() - lastindex - 1);
70
71 // Proceed only if locating a file (i.e. `file` isn't a path to just a directory.)
72 if (filename.IsNotEmpty())
73 {
74 DIR *d;
75 struct dirent *dir;
76 d = opendir(basepath.GetChars());
77 if (d)
78 {
79 while ((dir = readdir(d)) != NULL)
80 {
81 if (filename.CompareNoCase(dir->d_name) == 0)
82 {
83 found = true;
84 filename = dir->d_name;
85 fullpath = basepath << "/" << filename;
86 file = fullpath.GetChars();
87 break;
88 }
89 }
90 closedir(d);
91 if (!found)
92 {
93 //Printf("Can't find file '%s' in '%s'\n", filename.GetChars(), basepath.GetChars());
94 return false;
95 }
96 }
97 else
98 {
99 Printf("Can't open directory '%s'\n", basepath.GetChars());
100 return false;
101 }
102 }
103 }
104#endif
105
106 if (check && !DirEntryExists(file))
107 {
108 const char* f = BaseFileSearch(file, ".wad", false, config);
109 if (f == nullptr)
110 {

Callers 6

ParseGameInfoFunction · 0.85
AddAutoloadFilesFunction · 0.85
IdentifyVersionMethod · 0.85
AddPullinsMethod · 0.85
D_AddWildFileFunction · 0.85
D_AddDirectoryFunction · 0.85

Calls 14

PrintfFunction · 0.85
DirEntryExistsFunction · 0.85
BaseFileSearchFunction · 0.85
LastIndexOfMethod · 0.80
LenMethod · 0.80
IsNotEmptyMethod · 0.80
CompareNoCaseMethod · 0.80
statClass · 0.70
LeftMethod · 0.45
RightMethod · 0.45
GetCharsMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected