Attempt to make file searching stuff less crappy on Linux.
Supports a * search now.
This commit is contained in:
parent
6f7b11b9be
commit
a9ff3709e4
|
@ -25,6 +25,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
#include "FileSearch.h"
|
#include "FileSearch.h"
|
||||||
|
|
||||||
|
@ -72,36 +73,36 @@ void CFileSearch::FindFiles(const std::string& _searchString, const std::string&
|
||||||
|
|
||||||
|
|
||||||
#else
|
#else
|
||||||
size_t dot_pos = _searchString.rfind(".");
|
// TODO: super lame/broken
|
||||||
|
|
||||||
if (dot_pos == std::string::npos)
|
auto end_match(_searchString);
|
||||||
return;
|
|
||||||
|
// 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();
|
||||||
|
|
||||||
std::string ext = _searchString.substr(dot_pos);
|
|
||||||
DIR* dir = opendir(_strPath.c_str());
|
DIR* dir = opendir(_strPath.c_str());
|
||||||
|
|
||||||
if (!dir)
|
if (!dir)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
dirent* dp;
|
while (auto const dp = readdir(dir))
|
||||||
|
|
||||||
while (true)
|
|
||||||
{
|
{
|
||||||
dp = readdir(dir);
|
std::string found(dp->d_name);
|
||||||
|
|
||||||
if (!dp)
|
if ((found != ".") && (found != "..")
|
||||||
break;
|
&& (found.size() >= end_match.size())
|
||||||
|
&& std::equal(end_match.rbegin(), end_match.rend(), found.rbegin()))
|
||||||
std::string s(dp->d_name);
|
|
||||||
|
|
||||||
if ( (!ext.compare(".*") && s.compare(".") && s.compare("..")) ||
|
|
||||||
((s.size() > ext.size()) && (!strcasecmp(s.substr(s.size() - ext.size()).c_str(), ext.c_str())) ))
|
|
||||||
{
|
{
|
||||||
std::string full_name;
|
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 + s;
|
full_name = _strPath + found;
|
||||||
else
|
else
|
||||||
full_name = _strPath + DIR_SEP + s;
|
full_name = _strPath + DIR_SEP + found;
|
||||||
|
|
||||||
m_FileNames.push_back(full_name);
|
m_FileNames.push_back(full_name);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue