| 1178 | //========================================================================== |
| 1179 | |
| 1180 | unsigned FileSystem::GetFilesInFolder(const char *inpath, std::vector<FolderEntry> &result, bool atomic) const |
| 1181 | { |
| 1182 | std::string path = inpath; |
| 1183 | FixPathSeparator(&path.front()); |
| 1184 | for (auto& c : path) c = tolower(c); |
| 1185 | if (path.back() != '/') path += '/'; |
| 1186 | result.clear(); |
| 1187 | for (size_t i = 0; i < FileInfo.size(); i++) |
| 1188 | { |
| 1189 | if (strncmp(FileInfo[i].LongName, path.c_str(), path.length()) == 0) |
| 1190 | { |
| 1191 | // Only if it hasn't been replaced. |
| 1192 | if ((unsigned)CheckNumForFullName(FileInfo[i].LongName) == i) |
| 1193 | { |
| 1194 | FolderEntry fe{ FileInfo[i].LongName, (uint32_t)i }; |
| 1195 | result.push_back(fe); |
| 1196 | } |
| 1197 | } |
| 1198 | } |
| 1199 | if (result.size()) |
| 1200 | { |
| 1201 | int maxfile = -1; |
| 1202 | if (atomic) |
| 1203 | { |
| 1204 | // Find the highest resource file having content in the given folder. |
| 1205 | for (auto & entry : result) |
| 1206 | { |
| 1207 | int thisfile = GetFileContainer(entry.lumpnum); |
| 1208 | if (thisfile > maxfile) maxfile = thisfile; |
| 1209 | } |
| 1210 | // Delete everything from older files. |
| 1211 | for (int i = (int)result.size() - 1; i >= 0; i--) |
| 1212 | { |
| 1213 | if (GetFileContainer(result[i].lumpnum) != maxfile) result.erase(result.begin() + i); |
| 1214 | } |
| 1215 | } |
| 1216 | qsort(result.data(), result.size(), sizeof(FolderEntry), folderentrycmp); |
| 1217 | } |
| 1218 | return (unsigned)result.size(); |
| 1219 | } |
| 1220 | |
| 1221 | //========================================================================== |
| 1222 | // |