From 34692ab826abc8f8faa61bdb2280b742424528f1 Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Sat, 7 Dec 2013 15:14:29 -0500 Subject: Remove unnecessary Src/ folders --- Source/Core/Common/FileSearch.cpp | 104 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 Source/Core/Common/FileSearch.cpp (limited to 'Source/Core/Common/FileSearch.cpp') diff --git a/Source/Core/Common/FileSearch.cpp b/Source/Core/Common/FileSearch.cpp new file mode 100644 index 0000000000..7597b91496 --- /dev/null +++ b/Source/Core/Common/FileSearch.cpp @@ -0,0 +1,104 @@ +// Copyright 2013 Dolphin Emulator Project +// Licensed under GPLv2 +// Refer to the license.txt file included. + + +#include "Common.h" +#include "CommonPaths.h" +#ifndef _WIN32 +#include +#include +#else +#include +#endif + +#include + +#include "FileSearch.h" +#include "StringUtil.h" + + +CFileSearch::CFileSearch(const CFileSearch::XStringVector& _rSearchStrings, const CFileSearch::XStringVector& _rDirectories) +{ + // Reverse the loop order for speed? + for (auto& _rSearchString : _rSearchStrings) + { + for (auto& _rDirectory : _rDirectories) + { + FindFiles(_rSearchString, _rDirectory); + } + } +} + + +void CFileSearch::FindFiles(const std::string& _searchString, const std::string& _strPath) +{ + std::string GCMSearchPath; + BuildCompleteFilename(GCMSearchPath, _strPath, _searchString); +#ifdef _WIN32 + WIN32_FIND_DATA findData; + HANDLE FindFirst = FindFirstFile(UTF8ToTStr(GCMSearchPath).c_str(), &findData); + + if (FindFirst != INVALID_HANDLE_VALUE) + { + bool bkeepLooping = true; + + while (bkeepLooping) + { + if (findData.cFileName[0] != '.') + { + std::string strFilename; + BuildCompleteFilename(strFilename, _strPath, TStrToUTF8(findData.cFileName)); + m_FileNames.push_back(strFilename); + } + + bkeepLooping = FindNextFile(FindFirst, &findData) ? true : false; + } + } + FindClose(FindFirst); + + +#else + // TODO: super lame/broken + + auto end_match(_searchString); + + // assuming we have a "*.blah"-like pattern + if (!end_match.empty() && end_match[0] == '*') + end_match.erase(0, 1); + + // ugly + if (end_match == ".*") + end_match.clear(); + + DIR* dir = opendir(_strPath.c_str()); + + if (!dir) + return; + + while (auto const dp = readdir(dir)) + { + std::string found(dp->d_name); + + if ((found != ".") && (found != "..") + && (found.size() >= end_match.size()) + && std::equal(end_match.rbegin(), end_match.rend(), found.rbegin())) + { + std::string full_name; + if (_strPath.c_str()[_strPath.size()-1] == DIR_SEP_CHR) + full_name = _strPath + found; + else + full_name = _strPath + DIR_SEP + found; + + m_FileNames.push_back(full_name); + } + } + + closedir(dir); +#endif +} + +const CFileSearch::XStringVector& CFileSearch::GetFileNames() const +{ + return m_FileNames; +} -- cgit v1.2.3 From 2afe2152712981e21d6bda6f029292ed2b1cf91e Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 17 Feb 2014 05:18:15 -0500 Subject: Convert all includes to relative paths. --- Source/Core/Common/FileSearch.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'Source/Core/Common/FileSearch.cpp') diff --git a/Source/Core/Common/FileSearch.cpp b/Source/Core/Common/FileSearch.cpp index 7597b91496..4cecb2bf83 100644 --- a/Source/Core/Common/FileSearch.cpp +++ b/Source/Core/Common/FileSearch.cpp @@ -2,9 +2,13 @@ // Licensed under GPLv2 // Refer to the license.txt file included. +#include + +#include "Common/Common.h" +#include "Common/CommonPaths.h" +#include "Common/FileSearch.h" +#include "Common/StringUtil.h" -#include "Common.h" -#include "CommonPaths.h" #ifndef _WIN32 #include #include @@ -12,11 +16,6 @@ #include #endif -#include - -#include "FileSearch.h" -#include "StringUtil.h" - CFileSearch::CFileSearch(const CFileSearch::XStringVector& _rSearchStrings, const CFileSearch::XStringVector& _rDirectories) { -- cgit v1.2.3 From 83b7bb64aa5e1ee6b18eaa5d08c17bb5b6c57048 Mon Sep 17 00:00:00 2001 From: Pierre Bourdon Date: Thu, 20 Feb 2014 04:11:52 +0100 Subject: Make Common/ mostly IWYU clean (and fix errors in rest of the project detected by this change). --- Source/Core/Common/FileSearch.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'Source/Core/Common/FileSearch.cpp') diff --git a/Source/Core/Common/FileSearch.cpp b/Source/Core/Common/FileSearch.cpp index 4cecb2bf83..2fe3604f9c 100644 --- a/Source/Core/Common/FileSearch.cpp +++ b/Source/Core/Common/FileSearch.cpp @@ -3,14 +3,13 @@ // Refer to the license.txt file included. #include +#include -#include "Common/Common.h" #include "Common/CommonPaths.h" #include "Common/FileSearch.h" #include "Common/StringUtil.h" #ifndef _WIN32 -#include #include #else #include -- cgit v1.2.3 From 31cfc73a09a8685cbab20502b4bc132e98e2feb5 Mon Sep 17 00:00:00 2001 From: Matthew Parlane Date: Tue, 11 Mar 2014 00:30:55 +1300 Subject: Fixes spacing for "for", "while", "switch" and "if" Also moved && and || to ends of lines instead of start. Fixed misc vertical alignments and some { needed newlining. --- Source/Core/Common/FileSearch.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'Source/Core/Common/FileSearch.cpp') diff --git a/Source/Core/Common/FileSearch.cpp b/Source/Core/Common/FileSearch.cpp index 2fe3604f9c..84026dd4c9 100644 --- a/Source/Core/Common/FileSearch.cpp +++ b/Source/Core/Common/FileSearch.cpp @@ -78,9 +78,9 @@ void CFileSearch::FindFiles(const std::string& _searchString, const std::string& { std::string found(dp->d_name); - if ((found != ".") && (found != "..") - && (found.size() >= end_match.size()) - && std::equal(end_match.rbegin(), end_match.rend(), found.rbegin())) + if ((found != ".") && (found != "..") && + (found.size() >= end_match.size()) && + std::equal(end_match.rbegin(), end_match.rend(), found.rbegin())) { std::string full_name; if (_strPath.c_str()[_strPath.size()-1] == DIR_SEP_CHR) -- cgit v1.2.3 From 93b16a4a2d5f3e6d467d1315c461aff12852b26c Mon Sep 17 00:00:00 2001 From: Stevoisiak Date: Sun, 15 Feb 2015 14:43:31 -0500 Subject: Formatting/Whitespace Cleanup Various fixes to formatting and whitespace --- Source/Core/Common/FileSearch.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Source/Core/Common/FileSearch.cpp') diff --git a/Source/Core/Common/FileSearch.cpp b/Source/Core/Common/FileSearch.cpp index 84026dd4c9..c0f6fc39b6 100644 --- a/Source/Core/Common/FileSearch.cpp +++ b/Source/Core/Common/FileSearch.cpp @@ -83,7 +83,7 @@ void CFileSearch::FindFiles(const std::string& _searchString, const std::string& std::equal(end_match.rbegin(), end_match.rend(), found.rbegin())) { std::string full_name; - if (_strPath.c_str()[_strPath.size()-1] == DIR_SEP_CHR) + if (_strPath.c_str()[_strPath.size() - 1] == DIR_SEP_CHR) full_name = _strPath + found; else full_name = _strPath + DIR_SEP + found; -- cgit v1.2.3 From cefcb0ace9d363b3679b4e93bcc9ec05f1e5f4f8 Mon Sep 17 00:00:00 2001 From: Tillmann Karras Date: Mon, 18 May 2015 01:08:10 +0200 Subject: Update license headers to GPLv2+ --- Source/Core/Common/FileSearch.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Source/Core/Common/FileSearch.cpp') diff --git a/Source/Core/Common/FileSearch.cpp b/Source/Core/Common/FileSearch.cpp index c0f6fc39b6..67d6be70d9 100644 --- a/Source/Core/Common/FileSearch.cpp +++ b/Source/Core/Common/FileSearch.cpp @@ -1,5 +1,5 @@ // Copyright 2013 Dolphin Emulator Project -// Licensed under GPLv2 +// Licensed under GPLv2+ // Refer to the license.txt file included. #include -- cgit v1.2.3 From 30ebb2459eb97ba544547183854775df8460b475 Mon Sep 17 00:00:00 2001 From: Tillmann Karras Date: Sun, 24 May 2015 06:55:12 +0200 Subject: Set copyright year to when a file was created --- Source/Core/Common/FileSearch.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Source/Core/Common/FileSearch.cpp') diff --git a/Source/Core/Common/FileSearch.cpp b/Source/Core/Common/FileSearch.cpp index 67d6be70d9..6170d3de2b 100644 --- a/Source/Core/Common/FileSearch.cpp +++ b/Source/Core/Common/FileSearch.cpp @@ -1,4 +1,4 @@ -// Copyright 2013 Dolphin Emulator Project +// Copyright 2008 Dolphin Emulator Project // Licensed under GPLv2+ // Refer to the license.txt file included. -- cgit v1.2.3 From a225426510fc25316b3868e8764893dff284e77e Mon Sep 17 00:00:00 2001 From: comex Date: Sat, 15 Nov 2014 15:46:40 -0500 Subject: Rewrite FileSearch and improve ScanDirectoryTree. - FileSearch is now just one function, and it converts the original glob into a regex on all platforms rather than relying on native Windows pattern matching on there and a complete hack elsewhere. It now supports recursion out of the box rather than manually expanding into a full list of directories in multiple call sites. - This adds a GCC >= 4.9 dependency due to older versions having outright broken . MSVC is fine with it. - ScanDirectoryTree returns the parent entry rather than filling parts of it in via reference. The count is now stored in the entry like it was for subdirectories. - .glsl file search is now done with DoFileSearch. - IOCTLV_READ_DIR now uses ScanDirectoryTree directly and sorts the results after replacements for better determinism. --- Source/Core/Common/FileSearch.cpp | 121 +++++++++++++------------------------- 1 file changed, 40 insertions(+), 81 deletions(-) (limited to 'Source/Core/Common/FileSearch.cpp') diff --git a/Source/Core/Common/FileSearch.cpp b/Source/Core/Common/FileSearch.cpp index 6170d3de2b..32bffa8ed7 100644 --- a/Source/Core/Common/FileSearch.cpp +++ b/Source/Core/Common/FileSearch.cpp @@ -2,101 +2,60 @@ // Licensed under GPLv2+ // Refer to the license.txt file included. +#if !__clang__ && __GNUC__ == 4 && __GNUC_MINOR__ < 9 +#error is broken in GCC < 4.9; please upgrade +#endif + #include -#include +#include +#include #include "Common/CommonPaths.h" #include "Common/FileSearch.h" -#include "Common/StringUtil.h" - -#ifndef _WIN32 -#include -#else -#include -#endif - +#include "Common/FileUtil.h" -CFileSearch::CFileSearch(const CFileSearch::XStringVector& _rSearchStrings, const CFileSearch::XStringVector& _rDirectories) +static std::vector FileSearchWithTest(const std::vector& directories, bool recursive, std::function callback) { - // Reverse the loop order for speed? - for (auto& _rSearchString : _rSearchStrings) + std::vector result; + for (const std::string& directory : directories) { - for (auto& _rDirectory : _rDirectories) - { - FindFiles(_rSearchString, _rDirectory); - } + File::FSTEntry top = File::ScanDirectoryTree(directory, recursive); + + std::function DoEntry; + DoEntry = [&](File::FSTEntry& entry) { + if (callback(entry)) + result.push_back(entry.physicalName); + for (auto& child : entry.children) + DoEntry(child); + }; + DoEntry(top); } + // remove duplicates + std::sort(result.begin(), result.end()); + result.erase(std::unique(result.begin(), result.end()), result.end()); + return result; } - -void CFileSearch::FindFiles(const std::string& _searchString, const std::string& _strPath) +std::vector DoFileSearch(const std::vector& globs, const std::vector& directories, bool recursive) { - std::string GCMSearchPath; - BuildCompleteFilename(GCMSearchPath, _strPath, _searchString); -#ifdef _WIN32 - WIN32_FIND_DATA findData; - HANDLE FindFirst = FindFirstFile(UTF8ToTStr(GCMSearchPath).c_str(), &findData); - - if (FindFirst != INVALID_HANDLE_VALUE) + std::string regex_str = "^("; + for (const auto& str : globs) { - bool bkeepLooping = true; - - while (bkeepLooping) - { - if (findData.cFileName[0] != '.') - { - std::string strFilename; - BuildCompleteFilename(strFilename, _strPath, TStrToUTF8(findData.cFileName)); - m_FileNames.push_back(strFilename); - } - - bkeepLooping = FindNextFile(FindFirst, &findData) ? true : false; - } + if (regex_str.size() != 2) + regex_str += "|"; + // convert glob to regex + regex_str += std::regex_replace(std::regex_replace(str, std::regex("\\."), "\\."), std::regex("\\*"), ".*"); } - FindClose(FindFirst); - - -#else - // TODO: super lame/broken - - auto end_match(_searchString); - - // assuming we have a "*.blah"-like pattern - if (!end_match.empty() && end_match[0] == '*') - end_match.erase(0, 1); - - // ugly - if (end_match == ".*") - end_match.clear(); - - DIR* dir = opendir(_strPath.c_str()); - - if (!dir) - return; - - while (auto const dp = readdir(dir)) - { - std::string found(dp->d_name); - - if ((found != ".") && (found != "..") && - (found.size() >= end_match.size()) && - std::equal(end_match.rbegin(), end_match.rend(), found.rbegin())) - { - std::string full_name; - if (_strPath.c_str()[_strPath.size() - 1] == DIR_SEP_CHR) - full_name = _strPath + found; - else - full_name = _strPath + DIR_SEP + found; - - m_FileNames.push_back(full_name); - } - } - - closedir(dir); -#endif + regex_str += ")$"; + std::regex regex(regex_str); + return FileSearchWithTest(directories, recursive, [&](const File::FSTEntry& entry) { + return std::regex_match(entry.virtualName, regex); + }); } -const CFileSearch::XStringVector& CFileSearch::GetFileNames() const +std::vector FindSubdirectories(const std::vector& directories, bool recursive) { - return m_FileNames; + return FileSearchWithTest(directories, true, [&](const File::FSTEntry& entry) { + return entry.isDirectory; + }); } -- cgit v1.2.3 From 519d2549dd5c44555e469e0d596c72b930b98945 Mon Sep 17 00:00:00 2001 From: Fog Date: Mon, 8 Jun 2015 21:39:00 -0400 Subject: Fix File Extension Search Being Case Sensitive --- Source/Core/Common/FileSearch.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Source/Core/Common/FileSearch.cpp') diff --git a/Source/Core/Common/FileSearch.cpp b/Source/Core/Common/FileSearch.cpp index 32bffa8ed7..13e99fe88a 100644 --- a/Source/Core/Common/FileSearch.cpp +++ b/Source/Core/Common/FileSearch.cpp @@ -47,7 +47,7 @@ std::vector DoFileSearch(const std::vector& globs, con regex_str += std::regex_replace(std::regex_replace(str, std::regex("\\."), "\\."), std::regex("\\*"), ".*"); } regex_str += ")$"; - std::regex regex(regex_str); + std::regex regex(regex_str, std::regex_constants::icase); return FileSearchWithTest(directories, recursive, [&](const File::FSTEntry& entry) { return std::regex_match(entry.virtualName, regex); }); -- cgit v1.2.3