Dokan changes
This commit is contained in:
@@ -26,6 +26,22 @@ public:
|
|||||||
Japanese
|
Japanese
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class AFX_EXT_CLASS _CSiaFile
|
||||||
|
{
|
||||||
|
friend CSiaApi;
|
||||||
|
private:
|
||||||
|
_CSiaFile(CSiaCurl& siaCurl);
|
||||||
|
|
||||||
|
public:
|
||||||
|
~_CSiaFile();
|
||||||
|
|
||||||
|
private:
|
||||||
|
CSiaCurl& _siaCurl;
|
||||||
|
|
||||||
|
// Properties
|
||||||
|
Property(String, SiaPath, public, private)
|
||||||
|
};
|
||||||
|
|
||||||
class AFX_EXT_CLASS _CSiaFileTree
|
class AFX_EXT_CLASS _CSiaFileTree
|
||||||
{
|
{
|
||||||
friend CSiaApi;
|
friend CSiaApi;
|
||||||
@@ -38,9 +54,16 @@ public:
|
|||||||
private:
|
private:
|
||||||
CSiaCurl& _siaCurl;
|
CSiaCurl& _siaCurl;
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::vector<std::shared_ptr<_CSiaFile>> _fileList;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void BuildTree(const json& result);
|
void BuildTree(const json& result);
|
||||||
|
|
||||||
|
std::vector<std::shared_ptr<_CSiaFile>> QueryFiles(String query) const;
|
||||||
|
|
||||||
|
std::shared_ptr<_CSiaFile> GetFile(const String& siaPath) const;
|
||||||
|
|
||||||
bool FileExists(const String& siaPath) const;
|
bool FileExists(const String& siaPath) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -117,6 +140,9 @@ typedef CSiaApi::_CSiaWallet CSiaWallet;
|
|||||||
typedef CSiaApi::_CSiaRenter CSiaRenter;
|
typedef CSiaApi::_CSiaRenter CSiaRenter;
|
||||||
typedef std::shared_ptr<CSiaWallet> CSiaWalletPtr;
|
typedef std::shared_ptr<CSiaWallet> CSiaWalletPtr;
|
||||||
typedef std::shared_ptr<CSiaRenter> CSiaRenterPtr;
|
typedef std::shared_ptr<CSiaRenter> CSiaRenterPtr;
|
||||||
|
typedef CSiaApi::_CSiaFile CSiaFile;
|
||||||
|
typedef std::shared_ptr<CSiaFile> CSiaFilePtr;
|
||||||
|
typedef std::vector<CSiaFilePtr> CSiaFileCollection;
|
||||||
typedef CSiaApi::_CSiaFileTree CSiaFileTree;
|
typedef CSiaApi::_CSiaFileTree CSiaFileTree;
|
||||||
typedef std::shared_ptr<CSiaFileTree> CSiaFileTreePtr;
|
typedef std::shared_ptr<CSiaFileTree> CSiaFileTreePtr;
|
||||||
|
|
||||||
|
@@ -196,6 +196,7 @@
|
|||||||
<ClCompile Include="SiaCurl.cpp" />
|
<ClCompile Include="SiaCurl.cpp" />
|
||||||
<ClCompile Include="SiaDrive.Api.cpp" />
|
<ClCompile Include="SiaDrive.Api.cpp" />
|
||||||
<ClCompile Include="SiaDriveConfig.cpp" />
|
<ClCompile Include="SiaDriveConfig.cpp" />
|
||||||
|
<ClCompile Include="SiaFile.cpp" />
|
||||||
<ClCompile Include="SiaFileTree.cpp" />
|
<ClCompile Include="SiaFileTree.cpp" />
|
||||||
<ClCompile Include="SiaRenter.cpp" />
|
<ClCompile Include="SiaRenter.cpp" />
|
||||||
<ClCompile Include="SiaWallet.cpp" />
|
<ClCompile Include="SiaWallet.cpp" />
|
||||||
|
@@ -45,6 +45,9 @@
|
|||||||
<ClCompile Include="SiaFileTree.cpp">
|
<ClCompile Include="SiaFileTree.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="SiaFile.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="SiaDrive.Api.h">
|
<ClInclude Include="SiaDrive.Api.h">
|
||||||
|
15
SiaDrive.Api/SiaFile.cpp
Normal file
15
SiaDrive.Api/SiaFile.cpp
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
#include "StdAfx.h"
|
||||||
|
#include "SiaApi.h"
|
||||||
|
|
||||||
|
using namespace Sia::Api;
|
||||||
|
|
||||||
|
CSiaApi::_CSiaFile::_CSiaFile(CSiaCurl& siaCurl) :
|
||||||
|
_siaCurl(siaCurl)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
CSiaApi::_CSiaFile::~_CSiaFile()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
@@ -1,8 +1,21 @@
|
|||||||
#include "StdAfx.h"
|
#include "StdAfx.h"
|
||||||
#include "SiaApi.h"
|
#include "SiaApi.h"
|
||||||
|
#include <regex>
|
||||||
|
|
||||||
using namespace Sia::Api;
|
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) :
|
CSiaApi::_CSiaFileTree::_CSiaFileTree(CSiaCurl& siaCurl) :
|
||||||
_siaCurl(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)
|
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);
|
||||||
}
|
}
|
@@ -6,6 +6,10 @@
|
|||||||
using namespace Sia::Api;
|
using namespace Sia::Api;
|
||||||
using namespace Sia::Api::Dokan;
|
using namespace Sia::Api::Dokan;
|
||||||
|
|
||||||
|
// The general idea is that normal file I/O occurs in a local cache folder and once the file is closed, it is scheduled for upload into Sia.
|
||||||
|
// Files requested to be openned that are not cached will be downloaded first. If the file is not found in Sia, it will be treated as new.
|
||||||
|
// Keeping cache and Sia in synch will be a bit of a hastle, so it's strongly suggested to treat the cache folder as if it doesn't exist;
|
||||||
|
// however, simply deleting files in the cache folder should not be an issue as long as the drive is not mounted.
|
||||||
class DokanImpl
|
class DokanImpl
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
@@ -318,7 +322,21 @@ private:
|
|||||||
PDOKAN_FILE_INFO DokanFileInfo)
|
PDOKAN_FILE_INFO DokanFileInfo)
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> l(_dokanMutex);
|
std::lock_guard<std::mutex> l(_dokanMutex);
|
||||||
return STATUS_NOT_IMPLEMENTED;
|
auto siaFileTree = _siaFileTree;
|
||||||
|
if (siaFileTree)
|
||||||
|
{
|
||||||
|
String siaQuery = CSiaApi::FormatToSiaPath(PathSkipRoot(FileName));
|
||||||
|
auto fileList = siaFileTree->QueryFiles(siaQuery);
|
||||||
|
for (auto& file : fileList)
|
||||||
|
{
|
||||||
|
WIN32_FIND_DATA fd = { 0 };
|
||||||
|
wcscpy_s(fd.cFileName, PathFindFileName(file->GetSiaPath().c_str()));
|
||||||
|
|
||||||
|
FillFindData(&fd, DokanFileInfo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void DOKAN_CALLBACK Sia_CloseFile(LPCWSTR FileName, PDOKAN_FILE_INFO DokanFileInfo)
|
static void DOKAN_CALLBACK Sia_CloseFile(LPCWSTR FileName, PDOKAN_FILE_INFO DokanFileInfo)
|
||||||
@@ -461,6 +479,7 @@ std::unique_ptr<std::thread> DokanImpl::_mountThread;
|
|||||||
NTSTATUS DokanImpl::_mountStatus = STATUS_SUCCESS;
|
NTSTATUS DokanImpl::_mountStatus = STATUS_SUCCESS;
|
||||||
String DokanImpl::_mountPoint;
|
String DokanImpl::_mountPoint;
|
||||||
|
|
||||||
|
|
||||||
CSiaDokanDrive::CSiaDokanDrive(CSiaApi& siaApi) :
|
CSiaDokanDrive::CSiaDokanDrive(CSiaApi& siaApi) :
|
||||||
_siaApi(siaApi),
|
_siaApi(siaApi),
|
||||||
_Mounted(false)
|
_Mounted(false)
|
||||||
|
Binary file not shown.
Reference in New Issue
Block a user