From be162a331698b8e68354c40c90bd250beac39056 Mon Sep 17 00:00:00 2001 From: JosJuice Date: Sun, 25 Jun 2017 11:59:28 +0200 Subject: [PATCH 1/3] FileSearch: Remove unnecessary function --- Source/Core/Common/FileSearch.cpp | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/Source/Core/Common/FileSearch.cpp b/Source/Core/Common/FileSearch.cpp index 53eca6fcca..ffae68b718 100644 --- a/Source/Core/Common/FileSearch.cpp +++ b/Source/Core/Common/FileSearch.cpp @@ -45,9 +45,8 @@ FileSearchWithTest(const std::vector& directories, bool recursive, return result; } -static std::vector DoFileSearchNoSTL(const std::vector& directories, - const std::vector& exts, - bool recursive) +std::vector DoFileSearch(const std::vector& directories, + const std::vector& exts, bool recursive) { bool accept_all = exts.empty(); return FileSearchWithTest(directories, recursive, [&](const File::FSTEntry& entry) { @@ -62,12 +61,6 @@ static std::vector DoFileSearchNoSTL(const std::vector }); } -std::vector DoFileSearch(const std::vector& directories, - const std::vector& exts, bool recursive) -{ - return DoFileSearchNoSTL(directories, exts, recursive); -} - #else std::vector DoFileSearch(const std::vector& directories, From 382356627ae06e8b4a84d8ff474d7b4cd279b284 Mon Sep 17 00:00:00 2001 From: JosJuice Date: Mon, 26 Jun 2017 11:44:23 +0200 Subject: [PATCH 2/3] FileSearch: Check isDirectory in the non-Windows code c5fa470 made the extension check discard directories, but only in the new code that currently only is used on Windows. Let's add an equivalent check in the old code so that the behavior is consistent across platforms. --- Source/Core/Common/FileSearch.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Source/Core/Common/FileSearch.cpp b/Source/Core/Common/FileSearch.cpp index ffae68b718..0a8d0b369c 100644 --- a/Source/Core/Common/FileSearch.cpp +++ b/Source/Core/Common/FileSearch.cpp @@ -52,6 +52,8 @@ std::vector DoFileSearch(const std::vector& directorie return FileSearchWithTest(directories, recursive, [&](const File::FSTEntry& entry) { if (accept_all) return true; + if (entry.isDirectory) + return false; std::string name = entry.virtualName; std::transform(name.begin(), name.end(), name.begin(), ::tolower); return std::any_of(exts.begin(), exts.end(), [&](const std::string& ext) { From 1fc5eae5bd99e9a17e634f48e8291e6eed4202cc Mon Sep 17 00:00:00 2001 From: JosJuice Date: Mon, 26 Jun 2017 11:50:10 +0200 Subject: [PATCH 3/3] FileSearch: Add a static_assert for the preferred separator --- Source/Core/Common/FileSearch.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Source/Core/Common/FileSearch.cpp b/Source/Core/Common/FileSearch.cpp index 0a8d0b369c..fd031a524c 100644 --- a/Source/Core/Common/FileSearch.cpp +++ b/Source/Core/Common/FileSearch.cpp @@ -113,9 +113,11 @@ std::vector DoFileSearch(const std::vector& directorie std::sort(result.begin(), result.end()); result.erase(std::unique(result.begin(), result.end()), result.end()); - // Dolphin expects to be able to use "/" (DIR_SEP) everywhere. std::filesystem uses the OS - // separator. - if (fs::path::preferred_separator != DIR_SEP_CHR) + // Dolphin expects to be able to use "/" (DIR_SEP) everywhere. + // std::filesystem uses the OS separator. + constexpr fs::path::value_type os_separator = fs::path::preferred_separator; + static_assert(os_separator == DIR_SEP_CHR || os_separator == '\\', "Unsupported path separator"); + if (os_separator != DIR_SEP_CHR) for (auto& path : result) std::replace(path.begin(), path.end(), '\\', DIR_SEP_CHR);