| 51 | //========================================================================== |
| 52 | |
| 53 | bool 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 | { |
no test coverage detected