diff --git a/htdocs/index.html b/htdocs/index.html
index 1c52d99..f969e51 100644
--- a/htdocs/index.html
+++ b/htdocs/index.html
@@ -179,10 +179,11 @@
General Settings
- Lock wallet on exit
+ Auto-mount last location
Auto-start on logon
- Launch file manager on mount
Close to system tray
+ Launch file manager on mount
+ Lock wallet on exit
Store unlock password
Use bundled siad
API Port
diff --git a/htdocs/js/index.js b/htdocs/js/index.js
index ac7fa45..f56ab17 100644
--- a/htdocs/js/index.js
+++ b/htdocs/js/index.js
@@ -345,7 +345,8 @@
'RpcPort': getValue('ID_Settings_RpcPort'),
'LaunchFileMgrOnMount': getChecked('ID_Settings_LaunchFileMgrOnMount'),
'CloseToTray': getChecked('ID_Settings_CloseToTray'),
- 'StoreUnlockPassword': getChecked('ID_Settings_StoreUnlockPassword')
+ 'StoreUnlockPassword': getChecked('ID_Settings_StoreUnlockPassword'),
+ 'AutoMountOnUnlock': getChecked('ID_Settings_AutoMountOnUnlock')
}, (success, reason) => {
if (success) {
beginMainApplication();
diff --git a/include/siadrive_api/siadriveconfig.h b/include/siadrive_api/siadriveconfig.h
index dc0faa2..3b9bec2 100644
--- a/include/siadrive_api/siadriveconfig.h
+++ b/include/siadrive_api/siadriveconfig.h
@@ -33,6 +33,8 @@ public:
JProperty(bool, PromptOnClose, public, public, _configDocument)
JProperty(bool, CloseToTray, public, public, _configDocument)
JProperty(bool, StoreUnlockPassword, public, public, _configDocument)
+ JProperty(bool, AutoMountOnUnlock, public, public, _configDocument)
+ JProperty(std::string, LastMountLocation, public, public, _configDocument)
private:
const bool _autoSave;
diff --git a/src/siadrive/siadriveapp.cpp b/src/siadrive/siadriveapp.cpp
index 786c619..03a4081 100644
--- a/src/siadrive/siadriveapp.cpp
+++ b/src/siadrive/siadriveapp.cpp
@@ -65,7 +65,25 @@ private:
{
CefV8ValueList args;
args.push_back(CefV8Value::CreateBool(ApiSuccess(error)));
- if (!args[0]->GetBoolValue())
+ if (args[0]->GetBoolValue())
+ {
+ if (_siaDriveConfig->GetAutoMountOnUnlock())
+ {
+ const auto lastMountLocation = _siaDriveConfig->GetLastMountLocation();
+ if (!lastMountLocation.empty())
+ {
+ // Change mount location
+ // Disable mount location
+ // Change mount button to 'Unmount'
+ // Disable mount button
+ std::thread([this, lastMountLocation, context, cb]()
+ {
+ _siaDrive->Mount(lastMountLocation[0], _siaDriveConfig->GetCacheFolder(), 0);
+ }).detach();
+ }
+ }
+ }
+ else
{
args.push_back(CefV8Value::CreateString("Failed to unlock wallet"));
}
@@ -246,6 +264,7 @@ public:
_siaDriveConfig->SetRpcPort(SString::ToUInt32(settings->GetValue("RpcPort")->GetStringValue().ToWString()));
_siaDriveConfig->SetCloseToTray(settings->GetValue("CloseToTray")->GetBoolValue());
_siaDriveConfig->SetStoreUnlockPassword(settings->GetValue("StoreUnlockPassword")->GetBoolValue());
+ _siaDriveConfig->SetAutoMountOnUnlock(settings->GetValue("AutoMountOnUnlock")->GetBoolValue());
if (!_siaDriveConfig->GetStoreUnlockPassword())
{
SetRegistry("Unlock", "");
@@ -481,7 +500,8 @@ void CSiaDriveApp::SiaApiRefreshCallback(CefRefPtr context, const
{ "HostPort", _siaDriveConfig->GetHostPort() },
{ "RpcPort", _siaDriveConfig->GetRpcPort() },
{ "CloseToTray", _siaDriveConfig->GetCloseToTray() },
- { "StoreUnlockPassword", _siaDriveConfig->GetStoreUnlockPassword() }
+ { "StoreUnlockPassword", _siaDriveConfig->GetStoreUnlockPassword() },
+ { "AutoMountOnUnlock", _siaDriveConfig->GetAutoMountOnUnlock() }
};
ExecuteSetter(context, uiActions, "setSiaSettings", CefV8Value::CreateString(settings.dump()));
@@ -589,7 +609,23 @@ void CSiaDriveApp::SiaApiRefreshCallback(CefRefPtr context, const
if (isOnline)
{
auto uiActions = global->GetValue("uiUpdate");
- ExecuteSetter(context, uiActions, "setServerVersion", _siaApi->GetServerVersion());
+ ExecuteSetter(context, uiActions, "setServerVersion", _siaApi->GetServerVersion());
+
+ if (_siaDriveConfig->GetAutoMountOnUnlock())
+ {
+ const auto lastMountLocation = _siaDriveConfig->GetLastMountLocation();
+ if (!lastMountLocation.empty())
+ {
+ // Change mount location
+ // Disable mount location
+ // Change mount button to 'Unmount'
+ // Disable mount button
+ std::thread([this, lastMountLocation]()
+ {
+ _siaDrive->Mount(lastMountLocation[0], _siaDriveConfig->GetCacheFolder(), 0);
+ }).detach();
+ }
+ }
}
if (!isOnline && _siaDrive)
diff --git a/src/siadrive_api/siadriveconfig.cpp b/src/siadrive_api/siadriveconfig.cpp
index edd8e98..2dc4445 100644
--- a/src/siadrive_api/siadriveconfig.cpp
+++ b/src/siadrive_api/siadriveconfig.cpp
@@ -190,6 +190,18 @@ bool CSiaDriveConfig::LoadDefaults()
changed = true;
}
+ if (!CheckAutoMountOnUnlock())
+ {
+ SetAutoMountOnUnlock(false);
+ changed = true;
+ }
+
+ if (!CheckLastMountLocation())
+ {
+ SetLastMountLocation("");
+ changed = true;
+ }
+
return changed;
}
diff --git a/src/siadrive_dokan_api/siadokandrive.cpp b/src/siadrive_dokan_api/siadokandrive.cpp
index 0088da4..dcc6115 100644
--- a/src/siadrive_dokan_api/siadokandrive.cpp
+++ b/src/siadrive_dokan_api/siadokandrive.cpp
@@ -1937,6 +1937,7 @@ private:
static NTSTATUS DOKAN_CALLBACK Sia_Mounted(PDOKAN_FILE_INFO dokanFileInfo)
{
CEventSystem::EventSystem.NotifyEvent(CreateSystemEvent(DriveMounted(_mountPoint)));
+ _siaDriveConfig->SetLastMountLocation(_mountPoint);
if (_siaDriveConfig->GetLaunchFileMgrOnMount())
{
::ShellExecute(nullptr, L"open", &_mountPoint[0], nullptr, nullptr, SW_SHOWDEFAULT);
@@ -2288,15 +2289,13 @@ private:
if (dokanFileInfo->DeleteOnClose)
{
- // Should already be deleted by CloseHandle
- // if open with FILE_FLAG_DELETE_ON_CLOSE
if (dokanFileInfo->IsDirectory)
{
- while (!filePath.RemoveDirectory());
+ filePath.RemoveDirectory();
}
else
{
- while (!filePath.DeleteFile());
+ filePath.DeleteFile();
}
_siaApi->GetRenter()->RefreshFileTree();