1
0

Mounting changes

This commit is contained in:
Scott E. Graves
2017-03-02 00:16:18 -06:00
parent 37025e5035
commit 27cd8def9b
36 changed files with 124 additions and 36 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -23,7 +23,7 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
#define DOKAN_H_ #define DOKAN_H_
/** Do not include NTSTATUS. Fix duplicate preprocessor definitions */ /** Do not include NTSTATUS. Fix duplicate preprocessor definitions */
#define WIN32_NO_STATUS #define WIN32_NO_STATUS
#include <windows.h> #include <windows.h>
#undef WIN32_NO_STATUS #undef WIN32_NO_STATUS
#include <ntstatus.h> #include <ntstatus.h>

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,28 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "dokan_mirror", "dokan_mirror.vcxproj", "{DADCBCAD-4429-422E-9FA9-D8E538D0EF94}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{DADCBCAD-4429-422E-9FA9-D8E538D0EF94}.Debug|x64.ActiveCfg = Debug|x64
{DADCBCAD-4429-422E-9FA9-D8E538D0EF94}.Debug|x64.Build.0 = Debug|x64
{DADCBCAD-4429-422E-9FA9-D8E538D0EF94}.Debug|x86.ActiveCfg = Debug|Win32
{DADCBCAD-4429-422E-9FA9-D8E538D0EF94}.Debug|x86.Build.0 = Debug|Win32
{DADCBCAD-4429-422E-9FA9-D8E538D0EF94}.Release|x64.ActiveCfg = Release|x64
{DADCBCAD-4429-422E-9FA9-D8E538D0EF94}.Release|x64.Build.0 = Release|x64
{DADCBCAD-4429-422E-9FA9-D8E538D0EF94}.Release|x86.ActiveCfg = Release|Win32
{DADCBCAD-4429-422E-9FA9-D8E538D0EF94}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -9,7 +9,7 @@ CAutoThread::CAutoThread(const CSiaCurl& siaCurl, CSiaDriveConfig* siaDriveConfi
} }
CAutoThread::CAutoThread(const CSiaCurl& siaCurl, CSiaDriveConfig* siaDriveConfig, std::function<void(const CSiaCurl&, CSiaDriveConfig*)> autoThreadCallback) : CAutoThread::CAutoThread(const CSiaCurl& siaCurl, CSiaDriveConfig* siaDriveConfig, std::function<void(const CSiaCurl&, CSiaDriveConfig*)> autoThreadCallback) :
_siaCurl(siaCurl.GetHostConfig()), _siaCurl(siaCurl),
_siaDriveConfig(siaDriveConfig), _siaDriveConfig(siaDriveConfig),
_stopEvent(::CreateEvent(nullptr, FALSE, FALSE, nullptr)), _stopEvent(::CreateEvent(nullptr, FALSE, FALSE, nullptr)),
_AutoThreadCallback(autoThreadCallback) _AutoThreadCallback(autoThreadCallback)

View File

@@ -34,6 +34,10 @@ String CSiaApi::FormatToSiaPath(String path)
path = path.substr(1); path = path.substr(1);
} }
} }
else
{
path = L"/";
}
return path; return path;

View File

@@ -3,21 +3,18 @@
#include <curl/curl.h> #include <curl/curl.h>
using namespace Sia::Api; using namespace Sia::Api;
CSiaCurl::CSiaCurl() : CSiaCurl::CSiaCurl()
_curlHandle(curl_easy_init())
{ {
SetHostConfig({ L"localhost", 9980, L""}); SetHostConfig({ L"localhost", 9980, L""});
} }
CSiaCurl::CSiaCurl(const SiaHostConfig& hostConfig) : CSiaCurl::CSiaCurl(const SiaHostConfig& hostConfig)
_curlHandle(curl_easy_init())
{ {
SetHostConfig(hostConfig); SetHostConfig(hostConfig);
} }
CSiaCurl::~CSiaCurl() CSiaCurl::~CSiaCurl()
{ {
curl_easy_cleanup(_curlHandle);
} }
SiaCurlError CSiaCurl::CheckApiError(const json& result) SiaCurlError CSiaCurl::CheckApiError(const json& result)
@@ -88,24 +85,27 @@ SiaCurlError CSiaCurl::ProcessResponse(const int& res, const int& httpCode, cons
SiaCurlError CSiaCurl::_Get(const String& path, json& response) const SiaCurlError CSiaCurl::_Get(const String& path, json& response) const
{ {
curl_easy_reset(_curlHandle); CURL* curlHandle = curl_easy_init();
curl_easy_reset(curlHandle);
curl_easy_setopt(_curlHandle, CURLOPT_USERAGENT, "Sia-Agent"); curl_easy_setopt(curlHandle, CURLOPT_USERAGENT, "Sia-Agent");
curl_easy_setopt(_curlHandle, CURLOPT_URL, ConstructPath(path).c_str()); curl_easy_setopt(curlHandle, CURLOPT_URL, ConstructPath(path).c_str());
curl_easy_setopt(_curlHandle, CURLOPT_WRITEFUNCTION, static_cast<size_t(*)(char*, size_t, size_t, void *)>([](char *buffer, size_t size, size_t nitems, void *outstream) -> size_t curl_easy_setopt(curlHandle, CURLOPT_WRITEFUNCTION, static_cast<size_t(*)(char*, size_t, size_t, void *)>([](char *buffer, size_t size, size_t nitems, void *outstream) -> size_t
{ {
(*reinterpret_cast<std::string*>(outstream)) += std::string(reinterpret_cast<LPCSTR>(buffer), size * nitems); (*reinterpret_cast<std::string*>(outstream)) += std::string(reinterpret_cast<LPCSTR>(buffer), size * nitems);
return size * nitems; return size * nitems;
})); }));
std::string result; std::string result;
curl_easy_setopt(_curlHandle, CURLOPT_WRITEDATA, &result); curl_easy_setopt(curlHandle, CURLOPT_WRITEDATA, &result);
const CURLcode res = curl_easy_perform(_curlHandle); const CURLcode res = curl_easy_perform(curlHandle);
long httpCode = 0; long httpCode = 0;
curl_easy_getinfo(_curlHandle, CURLINFO_RESPONSE_CODE, &httpCode); curl_easy_getinfo(curlHandle, CURLINFO_RESPONSE_CODE, &httpCode);
return ProcessResponse(res, httpCode, result, response); SiaCurlError ret = ProcessResponse(res, httpCode, result, response);
curl_easy_cleanup(curlHandle);
return ret;
} }
bool CSiaCurl::CheckVersion(SiaCurlError& error) const bool CSiaCurl::CheckVersion(SiaCurlError& error) const
@@ -151,11 +151,12 @@ SiaCurlError CSiaCurl::Post(const String& path, const PostParameters& parameters
SiaCurlError ret; SiaCurlError ret;
if (CheckVersion(ret)) if (CheckVersion(ret))
{ {
curl_easy_reset(_curlHandle); CURL* curlHandle = curl_easy_init();
curl_easy_reset(curlHandle);
curl_easy_setopt(_curlHandle, CURLOPT_USERAGENT, "Sia-Agent"); curl_easy_setopt(curlHandle, CURLOPT_USERAGENT, "Sia-Agent");
curl_easy_setopt(_curlHandle, CURLOPT_URL, ConstructPath(path).c_str()); curl_easy_setopt(curlHandle, CURLOPT_URL, ConstructPath(path).c_str());
curl_easy_setopt(_curlHandle, CURLOPT_WRITEFUNCTION, static_cast<size_t(*)(char*, size_t, size_t, void *)>([](char *buffer, size_t size, size_t nitems, void *outstream) -> size_t curl_easy_setopt(curlHandle, CURLOPT_WRITEFUNCTION, static_cast<size_t(*)(char*, size_t, size_t, void *)>([](char *buffer, size_t size, size_t nitems, void *outstream) -> size_t
{ {
(*reinterpret_cast<std::string*>(outstream)) += std::string(reinterpret_cast<LPCSTR>(buffer), size * nitems); (*reinterpret_cast<std::string*>(outstream)) += std::string(reinterpret_cast<LPCSTR>(buffer), size * nitems);
return size * nitems; return size * nitems;
@@ -171,16 +172,17 @@ SiaCurlError CSiaCurl::Post(const String& path, const PostParameters& parameters
fields += (std::string(CW2A(param.first.c_str())) + "=" + std::string(CW2A(param.second.c_str()))); fields += (std::string(CW2A(param.first.c_str())) + "=" + std::string(CW2A(param.second.c_str())));
} }
curl_easy_setopt(_curlHandle, CURLOPT_POSTFIELDS, fields.c_str()); curl_easy_setopt(curlHandle, CURLOPT_POSTFIELDS, fields.c_str());
std::string result; std::string result;
curl_easy_setopt(_curlHandle, CURLOPT_WRITEDATA, &result); curl_easy_setopt(curlHandle, CURLOPT_WRITEDATA, &result);
const CURLcode res = curl_easy_perform(_curlHandle); const CURLcode res = curl_easy_perform(curlHandle);
long httpCode = 0; long httpCode = 0;
curl_easy_getinfo(_curlHandle, CURLINFO_RESPONSE_CODE, &httpCode); curl_easy_getinfo(curlHandle, CURLINFO_RESPONSE_CODE, &httpCode);
ret = ProcessResponse(res, httpCode, result, response); ret = ProcessResponse(res, httpCode, result, response);
curl_easy_cleanup(curlHandle);
} }
return ret; return ret;

View File

@@ -29,8 +29,6 @@ public:
~CSiaCurl(); ~CSiaCurl();
private: private:
LPVOID _curlHandle;
Property(SiaHostConfig, HostConfig, public, public) Property(SiaHostConfig, HostConfig, public, public)
private: private:

View File

@@ -317,7 +317,25 @@ private:
} }
else // Folder Operation (cache operation only) else // Folder Operation (cache operation only)
{ {
ret = STATUS_NOT_IMPLEMENTED; String cacheFilePath;
cacheFilePath.resize(MAX_PATH + 1);
if (String(L"\\") == FileName)
{
cacheFilePath = GetCacheLocation();
}
else
{
PathCombine(&cacheFilePath[0], GetCacheLocation().c_str(), FileName);
}
HANDLE handle = ::CreateFile(cacheFilePath.c_str(), genericDesiredAccess, ShareAccess, &securityAttrib, creationDisposition, fileAttributesAndFlags | FILE_FLAG_BACKUP_SEMANTICS, nullptr);
if (handle == INVALID_HANDLE_VALUE)
{
ret = DokanNtStatusFromWin32(GetLastError());
}
else
{
DokanFileInfo->Context = reinterpret_cast<ULONG64>(handle); // save the file handle in Context
}
} }
} }
@@ -392,6 +410,28 @@ private:
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
static NTSTATUS DOKAN_CALLBACK Sia_GetVolumeInformation(
LPWSTR VolumeNameBuffer, DWORD VolumeNameSize, LPDWORD VolumeSerialNumber,
LPDWORD MaximumComponentLength, LPDWORD FileSystemFlags,
LPWSTR FileSystemNameBuffer, DWORD FileSystemNameSize,
PDOKAN_FILE_INFO DokanFileInfo) {
UNREFERENCED_PARAMETER(DokanFileInfo);
wcscpy_s(VolumeNameBuffer, VolumeNameSize, L"SIA");
*VolumeSerialNumber = 0x19831116;
*MaximumComponentLength = 256;
*FileSystemFlags = FILE_CASE_SENSITIVE_SEARCH | FILE_CASE_PRESERVED_NAMES |
FILE_SUPPORTS_REMOTE_STORAGE | FILE_UNICODE_ON_DISK |
FILE_PERSISTENT_ACLS;
// File system name could be anything up to 10 characters.
// But Windows check few feature availability based on file system name.
// For this, it is recommended to set NTFS or FAT here.
wcscpy_s(FileSystemNameBuffer, FileSystemNameSize, L"FAT");
return STATUS_SUCCESS;
}
public: public:
static void Initialize(CSiaApi* siaApi, CSiaDriveConfig* siaDriveConfig) static void Initialize(CSiaApi* siaApi, CSiaDriveConfig* siaDriveConfig)
{ {
@@ -410,7 +450,7 @@ public:
_dokanOps.GetDiskFreeSpaceW = nullptr; _dokanOps.GetDiskFreeSpaceW = nullptr;
_dokanOps.GetFileInformation = nullptr; _dokanOps.GetFileInformation = nullptr;
_dokanOps.GetFileSecurityW = nullptr; _dokanOps.GetFileSecurityW = nullptr;
_dokanOps.GetVolumeInformationW = nullptr; _dokanOps.GetVolumeInformationW = Sia_GetVolumeInformation;
_dokanOps.LockFile = nullptr; _dokanOps.LockFile = nullptr;
_dokanOps.Mounted = Sia_Mounted; _dokanOps.Mounted = Sia_Mounted;
_dokanOps.MoveFileW = nullptr; _dokanOps.MoveFileW = nullptr;
@@ -428,7 +468,7 @@ public:
ZeroMemory(&_dokanOptions, sizeof(DOKAN_OPTIONS)); ZeroMemory(&_dokanOptions, sizeof(DOKAN_OPTIONS));
_dokanOptions.Version = DOKAN_VERSION; _dokanOptions.Version = DOKAN_VERSION;
_dokanOptions.ThreadCount = 0; // use default _dokanOptions.ThreadCount = 0; // use default
_dokanOptions.Options |= DOKAN_OPTION_CURRENT_SESSION; _dokanOptions.Options = DOKAN_OPTION_DEBUG;
} }
static void Mount(const wchar_t& driveLetter, const String& cacheLocation) static void Mount(const wchar_t& driveLetter, const String& cacheLocation)
@@ -436,7 +476,7 @@ public:
if (_siaApi && !_mountThread) if (_siaApi && !_mountThread)
{ {
_cacheLocation = cacheLocation; _cacheLocation = cacheLocation;
wchar_t tmp[] = { driveLetter, ':', 0 }; wchar_t tmp[] = { driveLetter, ':', '\\', 0 };
_mountPoint = tmp; _mountPoint = tmp;
_mountThread.reset(new std::thread([&]() _mountThread.reset(new std::thread([&]()
{ {
@@ -452,6 +492,7 @@ public:
if (_mountThread) if (_mountThread)
{ {
DokanRemoveMountPoint(_mountPoint.c_str()); DokanRemoveMountPoint(_mountPoint.c_str());
_mountThread->join(); _mountThread->join();
_mountThread.reset(nullptr); _mountThread.reset(nullptr);
_mountPoint.clear(); _mountPoint.clear();
@@ -460,6 +501,7 @@ public:
static void Shutdown() static void Shutdown()
{ {
StopFileListThread();
Unmount(); Unmount();
_uploadManager.reset(nullptr); _uploadManager.reset(nullptr);
_siaApi = nullptr; _siaApi = nullptr;
@@ -511,7 +553,6 @@ CSiaDokanDrive::CSiaDokanDrive(CSiaApi& siaApi, CSiaDriveConfig* siaDriveConfig)
CSiaDokanDrive::~CSiaDokanDrive() CSiaDokanDrive::~CSiaDokanDrive()
{ {
std::lock_guard<std::mutex> l(DokanImpl::GetMutex()); std::lock_guard<std::mutex> l(DokanImpl::GetMutex());
Unmount();
DokanImpl::Shutdown(); DokanImpl::Shutdown();
} }

View File

@@ -121,6 +121,7 @@
</ClCompile> </ClCompile>
<Link> <Link>
<SubSystem>Windows</SubSystem> <SubSystem>Windows</SubSystem>
<UACExecutionLevel>RequireAdministrator</UACExecutionLevel>
</Link> </Link>
<Midl> <Midl>
<MkTypLibCompatible>false</MkTypLibCompatible> <MkTypLibCompatible>false</MkTypLibCompatible>
@@ -177,6 +178,7 @@
<SubSystem>Windows</SubSystem> <SubSystem>Windows</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding> <EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences> <OptimizeReferences>true</OptimizeReferences>
<UACExecutionLevel>RequireAdministrator</UACExecutionLevel>
</Link> </Link>
<Midl> <Midl>
<MkTypLibCompatible>false</MkTypLibCompatible> <MkTypLibCompatible>false</MkTypLibCompatible>

View File

@@ -108,6 +108,13 @@ CSiaDriveDlg::CSiaDriveDlg(CWnd* pParent /*=NULL*/)
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
} }
CSiaDriveDlg::~CSiaDriveDlg()
{
_dokan.reset(nullptr);
_siaApi.reset(nullptr);
}
void CSiaDriveDlg::DoDataExchange(CDataExchange* pDX) void CSiaDriveDlg::DoDataExchange(CDataExchange* pDX)
{ {
CDHtmlDialog::DoDataExchange(pDX); CDHtmlDialog::DoDataExchange(pDX);
@@ -207,21 +214,22 @@ HRESULT CSiaDriveDlg::OnButtonUnlockWallet(IHTMLElement* /*pElement*/)
return S_OK; return S_OK;
} }
std::unique_ptr<Dokan::CSiaDokanDrive> d;
void CSiaDriveDlg::OnDocumentComplete(LPDISPATCH, LPCTSTR) void CSiaDriveDlg::OnDocumentComplete(LPDISPATCH, LPCTSTR)
{ {
KillTimer(IDT_UPDATE); KillTimer(IDT_UPDATE);
KillTimer(IDT_UI_ACTION_QUEUE); KillTimer(IDT_UI_ACTION_QUEUE);
// Create new API to clear all cached data used by threaded implementations // Create new API to clear all cached data used by threaded implementations
_siaApi.reset(new CSiaApi({ L"localhost", 9980, L"1.1.1" }, &_siaConfig)); if (!_siaApi)
{
_siaApi.reset(new CSiaApi({ L"localhost", 9980, L"1.1.1" }, &_siaConfig));
}
ClearDisplay(); ClearDisplay();
CallClientScript(L"setAvailableDrives", json(GetAvailableDrives()), nullptr); CallClientScript(L"setAvailableDrives", json(GetAvailableDrives()), nullptr);
if (!d) if (!_dokan)
{ {
d.reset(new Dokan::CSiaDokanDrive(*_siaApi, &_siaConfig)); _dokan.reset(new Dokan::CSiaDokanDrive(*_siaApi, &_siaConfig));
d->Mount('A', CA2W(_siaConfig.GetCacheFolder().c_str()).m_psz, 10); _dokan->Mount('Y', CA2W(_siaConfig.GetCacheFolder().c_str()).m_psz, 10);
} }
SetTimer(IDT_UPDATE, 2000, nullptr); SetTimer(IDT_UPDATE, 2000, nullptr);

View File

@@ -6,6 +6,7 @@
#include <SiaApi.h> #include <SiaApi.h>
#include "SiaDriveConfig.h" #include "SiaDriveConfig.h"
#include "ntray.h" #include "ntray.h"
#include "../SiaDrive.Dokan.Api/SiaDokanDrive.h"
using namespace Sia::Api; using namespace Sia::Api;
@@ -16,6 +17,9 @@ class CSiaDriveDlg : public CDHtmlDialog
public: public:
CSiaDriveDlg(CWnd* pParent = NULL); // standard constructor CSiaDriveDlg(CWnd* pParent = NULL); // standard constructor
public:
virtual ~CSiaDriveDlg();
// Dialog Data // Dialog Data
#ifdef AFX_DESIGN_TIME #ifdef AFX_DESIGN_TIME
enum { IDD = IDD_SIADRIVE_DIALOG, IDH = IDR_HTML_SIADRIVE_DIALOG }; enum { IDD = IDD_SIADRIVE_DIALOG, IDH = IDR_HTML_SIADRIVE_DIALOG };
@@ -99,6 +103,7 @@ private:
CSiaDriveConfig _siaConfig; CSiaDriveConfig _siaConfig;
CTrayNotifyIcon _tray; CTrayNotifyIcon _tray;
std::unique_ptr<CSiaApi> _siaApi; std::unique_ptr<CSiaApi> _siaApi;
std::unique_ptr<Dokan::CSiaDokanDrive> _dokan;
CString _walletCreatedSeed; CString _walletCreatedSeed;
String _receiveAddress; String _receiveAddress;
std::mutex _uiActionQueueMutex; std::mutex _uiActionQueueMutex;