1
0

Mount changes

This commit is contained in:
Scott E. Graves
2017-03-22 17:22:50 -05:00
parent 42e76bd921
commit 3295c413bc
4 changed files with 58 additions and 11 deletions

View File

@@ -2,7 +2,7 @@
set ROOT=%~dp0% set ROOT=%~dp0%
pushd "%ROOT%" pushd "%ROOT%"
call build_common.cmd REM call build_common.cmd
set CMAKE=%ROOT%bin\cmake-3.7.2-win64-x64\bin\cmake set CMAKE=%ROOT%bin\cmake-3.7.2-win64-x64\bin\cmake
REM call 3rd_party\CEF\create.cmd Debug REM call 3rd_party\CEF\create.cmd Debug

View File

@@ -370,6 +370,19 @@ public:
return std::move(str); return std::move(str);
} }
SString &ToUpper()
{
std::transform(_str.begin(), _str.end(), _str.begin(), ::toupper);
return *this;
}
SString ToUpperCopy() const
{
String str = _str;
std::transform(str.begin(), str.end(), str.begin(), ::toupper);
return std::move(str);
}
bool IsEmpty() const bool IsEmpty() const
{ {
return _str.empty(); return _str.empty();

View File

@@ -19,17 +19,43 @@ class FunctionHandler :
public CefV8Handler public CefV8Handler
{ {
public: public:
FunctionHandler(const CSiaApi& siaApi, bool& appStarted) : FunctionHandler(const CSiaApi& siaApi, bool& appStarted, std::unique_ptr<CSiaDriveConfig>& siaDriveConfig, std::unique_ptr<Api::Dokan::CSiaDokanDrive>& siaDrive) :
_siaApi(siaApi), _siaApi(siaApi),
_siaDriveConfig(siaDriveConfig),
_siaDrive(siaDrive),
_appStarted(appStarted) _appStarted(appStarted)
{ {
} }
private: private:
const CSiaApi& _siaApi; const CSiaApi& _siaApi;
std::unique_ptr<CSiaDriveConfig>& _siaDriveConfig;
std::unique_ptr<Api::Dokan::CSiaDokanDrive>& _siaDrive;
bool& _appStarted; bool& _appStarted;
private: private:
void MountCallback(CefRefPtr<CefV8Context> context, CefRefPtr<CefV8Value> cb) const
{
CefV8ValueList args;
args.push_back(CefV8Value::CreateBool(true));
if (!args[0]->GetBoolValue())
{
args.push_back(CefV8Value::CreateString("Failed to mount"));
}
cb->ExecuteFunctionWithContext(context, nullptr, args);
}
void UnmountCallback(CefRefPtr<CefV8Context> context, CefRefPtr<CefV8Value> cb) const
{
CefV8ValueList args;
args.push_back(CefV8Value::CreateBool(true));
if (!args[0]->GetBoolValue())
{
args.push_back(CefV8Value::CreateString("Failed to unmount"));
}
cb->ExecuteFunctionWithContext(context, nullptr, args);
}
void UnlockCallback(SiaApiError error, CefRefPtr<CefV8Context> context, CefRefPtr<CefV8Value> cb, const SString& password) const void UnlockCallback(SiaApiError error, CefRefPtr<CefV8Context> context, CefRefPtr<CefV8Value> cb, const SString& password) const
{ {
CefV8ValueList args; CefV8ValueList args;
@@ -104,13 +130,22 @@ public:
retval = CefV8Value::CreateBool(true); retval = CefV8Value::CreateBool(true);
SString drive = arguments[0]->GetStringValue().ToWString(); SString drive = arguments[0]->GetStringValue().ToWString();
CefRefPtr<CefV8Value> cb = arguments[1]; CefRefPtr<CefV8Value> cb = arguments[1];
std::thread([this, drive, context, cb]()
{
_siaDrive->Mount(drive[0], _siaDriveConfig->GetCacheFolder(), 0);
CefPostTask(TID_RENDERER, base::Bind(&FunctionHandler::MountCallback, this, context, cb));
}).detach();
return true; return true;
} }
else if (name == "unmountDrive") else if (name == "unmountDrive")
{ {
retval = CefV8Value::CreateBool(true); retval = CefV8Value::CreateBool(true);
CefRefPtr<CefV8Value> cb = arguments[0]; CefRefPtr<CefV8Value> cb = arguments[0];
std::thread([this, context, cb]()
{
_siaDrive->Unmount();
CefPostTask(TID_RENDERER, base::Bind(&FunctionHandler::UnmountCallback, this, context, cb));
}).detach();
return true; return true;
} }
@@ -202,7 +237,7 @@ void CSiaDriveApp::OnContextCreated(
obj->SetValue("clientVersion", CefV8Value::CreateString(SIDRIVE_VERSION_STRING), V8_PROPERTY_ATTRIBUTE_NONE); obj->SetValue("clientVersion", CefV8Value::CreateString(SIDRIVE_VERSION_STRING), V8_PROPERTY_ATTRIBUTE_NONE);
global->SetValue("uiState", obj, V8_PROPERTY_ATTRIBUTE_NONE); global->SetValue("uiState", obj, V8_PROPERTY_ATTRIBUTE_NONE);
CefRefPtr<FunctionHandler> handler(new FunctionHandler(*_siaApi, _appStarted)); CefRefPtr<FunctionHandler> handler(new FunctionHandler(*_siaApi, _appStarted, _siaDriveConfig, _siaDrive));
obj = CefV8Value::CreateObject(nullptr, nullptr); obj = CefV8Value::CreateObject(nullptr, nullptr);
obj->SetValue("unlockWallet", CefV8Value::CreateFunction("unlockWallet", handler), V8_PROPERTY_ATTRIBUTE_NONE); obj->SetValue("unlockWallet", CefV8Value::CreateFunction("unlockWallet", handler), V8_PROPERTY_ATTRIBUTE_NONE);
obj->SetValue("createWallet", CefV8Value::CreateFunction("createWallet", handler), V8_PROPERTY_ATTRIBUTE_NONE); obj->SetValue("createWallet", CefV8Value::CreateFunction("createWallet", handler), V8_PROPERTY_ATTRIBUTE_NONE);

View File

@@ -878,7 +878,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 = 4; // use default
_dokanOptions.Options = DOKAN_OPTION_DEBUG; _dokanOptions.Options = DOKAN_OPTION_DEBUG;
} }
@@ -887,14 +887,15 @@ 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([&]()
{ {
_dokanOptions.MountPoint = _mountPoint.str().c_str(); _dokanOptions.MountPoint = _mountPoint.ToUpper().str().c_str();
_mountStatus = DokanMain(&_dokanOptions, &_dokanOps); _mountStatus = DokanMain(&_dokanOptions, &_dokanOps);
OutputDebugString(std::to_wstring(_mountStatus).c_str()); OutputDebugString(std::to_wstring(_mountStatus).c_str());
})); }));
_mountThread->detach();
} }
} }
@@ -902,10 +903,8 @@ public:
{ {
if (_mountThread) if (_mountThread)
{ {
DokanRemoveMountPoint(_mountPoint.str().c_str()); DokanUnmount(_mountPoint[0]);
_mountThread.reset(nullptr);
_mountThread->join();
_mountThread.reset(nullptr);
_mountPoint = ""; _mountPoint = "";
} }
} }