| 2295 | } |
| 2296 | |
| 2297 | void ImGuiFullscreen::PopulateFileSelectorItems() |
| 2298 | { |
| 2299 | s_file_selector_items.clear(); |
| 2300 | |
| 2301 | if (s_file_selector_current_directory.empty()) |
| 2302 | { |
| 2303 | for (std::string& root_path : FileSystem::GetRootDirectoryList()) |
| 2304 | { |
| 2305 | std::string title(fmt::format(ICON_FA_FOLDER " {}", root_path)); |
| 2306 | s_file_selector_items.emplace_back(std::move(title), std::move(root_path), false); |
| 2307 | } |
| 2308 | } |
| 2309 | else |
| 2310 | { |
| 2311 | FileSystem::FindResultsArray results; |
| 2312 | FileSystem::FindFiles(s_file_selector_current_directory.c_str(), "*", |
| 2313 | FILESYSTEM_FIND_FILES | FILESYSTEM_FIND_FOLDERS | FILESYSTEM_FIND_HIDDEN_FILES | |
| 2314 | FILESYSTEM_FIND_RELATIVE_PATHS | FILESYSTEM_FIND_SORT_BY_NAME, |
| 2315 | &results); |
| 2316 | |
| 2317 | std::string parent_path; |
| 2318 | std::string::size_type sep_pos = s_file_selector_current_directory.rfind(FS_OSPATH_SEPARATOR_CHARACTER); |
| 2319 | if (sep_pos != std::string::npos) |
| 2320 | { |
| 2321 | parent_path = s_file_selector_current_directory.substr(0, sep_pos); |
| 2322 | |
| 2323 | #ifndef _WIN32 |
| 2324 | // Special case for going to root list on Linux. |
| 2325 | if (parent_path.empty() && s_file_selector_current_directory.size() > 1) |
| 2326 | parent_path = "/"; |
| 2327 | #endif |
| 2328 | } |
| 2329 | |
| 2330 | s_file_selector_items.emplace_back(ICON_FA_FOLDER_OPEN " <Parent Directory>", std::move(parent_path), false); |
| 2331 | std::sort(results.begin(), results.end(), [](const FILESYSTEM_FIND_DATA& lhs, const FILESYSTEM_FIND_DATA& rhs) { |
| 2332 | if ((lhs.Attributes & FILESYSTEM_FILE_ATTRIBUTE_DIRECTORY) != (rhs.Attributes & FILESYSTEM_FILE_ATTRIBUTE_DIRECTORY)) |
| 2333 | return (lhs.Attributes & FILESYSTEM_FILE_ATTRIBUTE_DIRECTORY) != 0; |
| 2334 | |
| 2335 | return std::lexicographical_compare(lhs.FileName.begin(), lhs.FileName.end(), rhs.FileName.begin(), rhs.FileName.end()); |
| 2336 | }); |
| 2337 | |
| 2338 | for (const FILESYSTEM_FIND_DATA& fd : results) |
| 2339 | { |
| 2340 | std::string full_path(Path::Combine(s_file_selector_current_directory, fd.FileName)); |
| 2341 | |
| 2342 | if (fd.Attributes & FILESYSTEM_FILE_ATTRIBUTE_DIRECTORY) |
| 2343 | { |
| 2344 | std::string title(fmt::format(ICON_FA_FOLDER " {}", fd.FileName)); |
| 2345 | s_file_selector_items.emplace_back(std::move(title), std::move(full_path), false); |
| 2346 | } |
| 2347 | else |
| 2348 | { |
| 2349 | if (s_file_selector_filters.empty() || |
| 2350 | std::none_of(s_file_selector_filters.begin(), s_file_selector_filters.end(), |
| 2351 | [&fd](const std::string& filter) { return StringUtil::WildcardMatch(fd.FileName.c_str(), filter.c_str(), false); })) |
| 2352 | { |
| 2353 | continue; |
| 2354 | } |