summaryrefslogtreecommitdiff
path: root/src/common/file_search.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/file_search.cpp')
-rw-r--r--src/common/file_search.cpp103
1 files changed, 0 insertions, 103 deletions
diff --git a/src/common/file_search.cpp b/src/common/file_search.cpp
deleted file mode 100644
index b3a0a84fb..000000000
--- a/src/common/file_search.cpp
+++ /dev/null
@@ -1,103 +0,0 @@
1// Copyright 2013 Dolphin Emulator Project / 2014 Citra Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5
6#include "common/common.h"
7
8#ifndef _WIN32
9#include <dirent.h>
10#else
11#include <windows.h>
12#endif
13
14#include <algorithm>
15
16#include "common/file_search.h"
17#include "common/string_util.h"
18
19
20CFileSearch::CFileSearch(const CFileSearch::XStringVector& _rSearchStrings, const CFileSearch::XStringVector& _rDirectories)
21{
22 // Reverse the loop order for speed?
23 for (size_t j = 0; j < _rSearchStrings.size(); j++)
24 {
25 for (size_t i = 0; i < _rDirectories.size(); i++)
26 {
27 FindFiles(_rSearchStrings[j], _rDirectories[i]);
28 }
29 }
30}
31
32
33void CFileSearch::FindFiles(const std::string& _searchString, const std::string& _strPath)
34{
35 std::string GCMSearchPath;
36 Common::BuildCompleteFilename(GCMSearchPath, _strPath, _searchString);
37#ifdef _WIN32
38 WIN32_FIND_DATA findData;
39 HANDLE FindFirst = FindFirstFile(Common::UTF8ToTStr(GCMSearchPath).c_str(), &findData);
40
41 if (FindFirst != INVALID_HANDLE_VALUE)
42 {
43 bool bkeepLooping = true;
44
45 while (bkeepLooping)
46 {
47 if (findData.cFileName[0] != '.')
48 {
49 std::string strFilename;
50 Common::BuildCompleteFilename(strFilename, _strPath, Common::TStrToUTF8(findData.cFileName));
51 m_FileNames.push_back(strFilename);
52 }
53
54 bkeepLooping = FindNextFile(FindFirst, &findData) ? true : false;
55 }
56 }
57 FindClose(FindFirst);
58
59
60#else
61 // TODO: super lame/broken
62
63 auto end_match(_searchString);
64
65 // assuming we have a "*.blah"-like pattern
66 if (!end_match.empty() && end_match[0] == '*')
67 end_match.erase(0, 1);
68
69 // ugly
70 if (end_match == ".*")
71 end_match.clear();
72
73 DIR* dir = opendir(_strPath.c_str());
74
75 if (!dir)
76 return;
77
78 while (auto const dp = readdir(dir))
79 {
80 std::string found(dp->d_name);
81
82 if ((found != ".") && (found != "..")
83 && (found.size() >= end_match.size())
84 && std::equal(end_match.rbegin(), end_match.rend(), found.rbegin()))
85 {
86 std::string full_name;
87 if (_strPath.c_str()[_strPath.size()-1] == DIR_SEP_CHR)
88 full_name = _strPath + found;
89 else
90 full_name = _strPath + DIR_SEP + found;
91
92 m_FileNames.push_back(full_name);
93 }
94 }
95
96 closedir(dir);
97#endif
98}
99
100const CFileSearch::XStringVector& CFileSearch::GetFileNames() const
101{
102 return m_FileNames;
103}