Dokan changes
This commit is contained in:
@@ -1,8 +1,21 @@
|
||||
#include "StdAfx.h"
|
||||
#include "SiaApi.h"
|
||||
#include <regex>
|
||||
|
||||
using namespace Sia::Api;
|
||||
|
||||
static String& ReplaceStringInPlace(String& subject, const String& search, const String& replace)
|
||||
{
|
||||
size_t pos = 0;
|
||||
while ((pos = subject.find(search, pos)) != std::string::npos)
|
||||
{
|
||||
subject.replace(pos, search.length(), replace);
|
||||
pos += replace.length();
|
||||
}
|
||||
|
||||
return subject;
|
||||
}
|
||||
|
||||
CSiaApi::_CSiaFileTree::_CSiaFileTree(CSiaCurl& siaCurl) :
|
||||
_siaCurl(siaCurl)
|
||||
{
|
||||
@@ -14,12 +27,41 @@ CSiaApi::_CSiaFileTree::~_CSiaFileTree()
|
||||
|
||||
}
|
||||
|
||||
bool CSiaApi::_CSiaFileTree::FileExists(const String& siaPath) const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void CSiaApi::_CSiaFileTree::BuildTree(const json& result)
|
||||
{
|
||||
}
|
||||
|
||||
bool CSiaApi::_CSiaFileTree::FileExists(const String& siaPath) const
|
||||
{
|
||||
auto result = std::find_if(_fileList.begin(), _fileList.end(), [&](const CSiaFilePtr& item)->bool
|
||||
{
|
||||
return (item->GetSiaPath().compare(siaPath) == 0);
|
||||
});
|
||||
|
||||
return (result != _fileList.end());
|
||||
}
|
||||
|
||||
CSiaFilePtr CSiaApi::_CSiaFileTree::GetFile(const String& siaPath) const
|
||||
{
|
||||
auto result = std::find_if(_fileList.begin(), _fileList.end(), [&](const CSiaFilePtr& item)->bool
|
||||
{
|
||||
return (item->GetSiaPath().compare(siaPath) == 0);
|
||||
});
|
||||
|
||||
return ((result != _fileList.end()) ? *result : nullptr);
|
||||
}
|
||||
|
||||
CSiaFileCollection CSiaApi::_CSiaFileTree::QueryFiles(String query) const
|
||||
{
|
||||
query = CSiaApi::FormatToSiaPath(query);
|
||||
ReplaceStringInPlace(ReplaceStringInPlace(ReplaceStringInPlace(query, L".", L"\\."), L"*", L".+"), L"?", L".?");
|
||||
std::wregex r(query);
|
||||
|
||||
CSiaFileCollection ret;
|
||||
std::copy_if(_fileList.begin(), _fileList.end(), std::back_inserter(ret), [&](const CSiaFilePtr& v) -> bool
|
||||
{
|
||||
return std::regex_match(v->GetSiaPath(), r);
|
||||
});
|
||||
|
||||
return std::move(ret);
|
||||
}
|
Reference in New Issue
Block a user