* Fill the list of the files in a directory, according to some arbitrary rule. * @param fop Purpose of collecting the list. * @param show_dirs Whether to list directories. * @param callback_proc The function that is called where you need to do the filtering. * @param subdir The directory from where to start (global) searching. * @param file_list Destination of the found files. */
| 305 | * @param file_list Destination of the found files. |
| 306 | */ |
| 307 | static void FiosGetFileList(SaveLoadOperation fop, bool show_dirs, FiosGetTypeAndNameProc *callback_proc, Subdirectory subdir, FileList &file_list) |
| 308 | { |
| 309 | size_t sort_start = 0; |
| 310 | |
| 311 | file_list.clear(); |
| 312 | |
| 313 | assert(_fios_path != nullptr); |
| 314 | |
| 315 | if (show_dirs) { |
| 316 | /* A parent directory link exists if we are not in the root directory */ |
| 317 | if (!FiosIsRoot(*_fios_path)) { |
| 318 | FiosItem &fios = file_list.emplace_back(); |
| 319 | fios.type = FIOS_TYPE_PARENT; |
| 320 | fios.mtime = 0; |
| 321 | fios.name = ".."; |
| 322 | fios.title = GetEncodedString(STR_SAVELOAD_PARENT_DIRECTORY, ".."sv); |
| 323 | sort_start = file_list.size(); |
| 324 | } |
| 325 | |
| 326 | /* Show subdirectories */ |
| 327 | std::error_code error_code; |
| 328 | for (const auto &dir_entry : std::filesystem::directory_iterator(OTTD2FS(*_fios_path), error_code)) { |
| 329 | if (!dir_entry.is_directory()) continue; |
| 330 | if (FiosIsHiddenFile(dir_entry) && dir_entry.path().filename() != PERSONAL_DIR) continue; |
| 331 | |
| 332 | FiosItem &fios = file_list.emplace_back(); |
| 333 | fios.type = FIOS_TYPE_DIR; |
| 334 | fios.mtime = 0; |
| 335 | fios.name = FS2OTTD(dir_entry.path().filename().native()); |
| 336 | fios.title = GetEncodedString(STR_SAVELOAD_DIRECTORY, fios.name + PATHSEP); |
| 337 | } |
| 338 | |
| 339 | /* Sort the subdirs always by name, ascending, remember user-sorting order */ |
| 340 | SortingBits order = _savegame_sort_order; |
| 341 | _savegame_sort_order = SORT_BY_NAME | SORT_ASCENDING; |
| 342 | std::sort(file_list.begin() + sort_start, file_list.end()); |
| 343 | _savegame_sort_order = order; |
| 344 | } |
| 345 | |
| 346 | /* This is where to start sorting for the filenames */ |
| 347 | sort_start = file_list.size(); |
| 348 | |
| 349 | /* Show files */ |
| 350 | FiosFileScanner scanner(fop, callback_proc, file_list); |
| 351 | if (subdir == NO_DIRECTORY) { |
| 352 | scanner.Scan({}, *_fios_path, false); |
| 353 | } else { |
| 354 | scanner.Scan({}, subdir, true, true); |
| 355 | } |
| 356 | |
| 357 | std::sort(file_list.begin() + sort_start, file_list.end()); |
| 358 | |
| 359 | /* Show drives */ |
| 360 | FiosGetDrives(file_list); |
| 361 | } |
| 362 | |
| 363 | /** |
| 364 | * Get the title of a file, which (if exists) is stored in a file named |
no test coverage detected