1
0
This commit is contained in:
Scott E. Graves
2017-04-23 22:06:29 -05:00
parent 85e8d55dd5
commit fce3e669e0
10 changed files with 155 additions and 14 deletions

View File

@@ -182,7 +182,12 @@
<input type="checkbox" id="ID_SettingsAutoStart"><br><br>
<h2>Use Bundled siad</h2>
<input type="checkbox" id="ID_SettingsLaunchServer"><br><br>
<button id="ID_SiaSettingsDefaults" type="button">Defaults</button>
<h2>API Port</h2>
<input type="number" id="ID_SettingsApiPort"><br><br>
<h2>Host Port</h2>
<input type="number" id="ID_SettingsHostPort"><br><br>
<h2>RPC Port</h2>
<input type="number" id="ID_SettingsRPCPort"><br><br>
<button id="ID_SiaSettingsOK" type="button">Save</button>
<button id="ID_SiaSettingsCancel" type="button">Cancel</button>
</div>

View File

@@ -12,6 +12,10 @@
document.getElementById(id)["checked"] = value;
}
function getChecked(id) {
return document.getElementById(id)["checked"];
}
function getValue(id) {
return document.getElementById(id).value;
}
@@ -153,6 +157,21 @@
if (document.getElementById('sia_settings_window').classList.contains('hidden-element')) {
setChecked('ID_SettingsLaunchServer', launch);
}
},
setApiPort: (port) => {
if (document.getElementById('sia_settings_window').classList.contains('hidden-element')) {
setValue('ID_SettingsApiPort', port);
}
},
setHostPort: (port) => {
if (document.getElementById('sia_settings_window').classList.contains('hidden-element')) {
setValue('ID_SettingsHostPort', port);
}
},
setRpcPort: (port) => {
if (document.getElementById('sia_settings_window').classList.contains('hidden-element')) {
setValue('ID_SettingsRPCPort', port);
}
}
};
})();
@@ -233,6 +252,10 @@
window.appActions.calculateEstimatedStorage(funds, cb)
}
function _setSiaSettings(settings, cb) {
window.appActions.setSiaSettings(settings, cb);
}
return {
createWallet: _createWallet,
mountDrive: _mountDrive,
@@ -242,7 +265,8 @@
unmountDrive: _unmountDrive,
shutdown: _shutdown,
setRenterSettings: _setRenterSettings,
calculateEstimatedStorage: _calculateEstimatedStorage
calculateEstimatedStorage: _calculateEstimatedStorage,
setSiaSettings: _setSiaSettings
};
})();
@@ -298,8 +322,30 @@
const cancelButton = document.getElementById('ID_SiaSettingsCancel');
cancelButton.onclick = () => {
cancelButton.onclick = null;
saveButton.onclick = null;
beginMainApplication();
};
const saveButton = document.getElementById('ID_SiaSettingsOK');
saveButton.onclick = () => {
saveButton.onclick = null;
cancelButton.onclick = null;
AppActions.setSiaSettings({
'UnlockOnExit': getChecked('ID_SettingsLockWalletOnExit'),
'AutoStartOnLogon': getChecked('ID_SettingsAutoStart'),
'UseBundledSiad': getChecked('ID_SettingsLaunchServer'),
'ApiPort': getValue('ID_SettingsApiPort'),
'HostPort': getValue('ID_SettingsHostPort'),
'RpcPort': getValue('ID_SettingsRPCPort')
}, (success, reason) => {
if (success) {
beginMainApplication();
} else {
displayErrorPopup('Settings Failed', reason);
handleSiaEditSettings();
}
});
};
}
function beginMainApplication() {

View File

@@ -27,15 +27,15 @@ class CSiaDriveApp :
public CefBrowserProcessHandler
{
public:
CSiaDriveApp();
CSiaDriveApp(std::shared_ptr<Api::CSiaDriveConfig> siaDriveConfig);
virtual ~CSiaDriveApp();
private:
std::shared_ptr<Api::CSiaDriveConfig> _siaDriveConfig;
std::unique_ptr<Api::CAutoThread> _refreshThread;
std::unique_ptr<Api::CSiaApi> _siaApi;
std::unique_ptr<Api::CSiaCurl> _siaCurl;
std::unique_ptr<Api::CSiaDriveConfig> _siaDriveConfig;
#ifdef _WIN32
std::unique_ptr<Api::Dokan::CSiaDokanDrive> _siaDrive;
#else

View File

@@ -73,6 +73,8 @@ using json = nlohmann::json;
NS_BEGIN(Sia)
NS_BEGIN(Api)
class FilePath;
class CSiaDriveConfig;
class StartupException :
public std::exception
{
@@ -210,6 +212,8 @@ BOOL SIADRIVE_EXPORTABLE RecurDeleteFilesByExtentsion(const SString& folder, con
std::vector<SString> SIADRIVE_EXPORTABLE GetAvailableDrives();
#endif
bool SIADRIVE_EXPORTABLE ExecuteProcess(CSiaDriveConfig* siaDriveConfig, FilePath process, FilePath workingDir, const bool& waitForExit);
#define RetryableAction(exec, count, delayMs) RetryAction([&]()->BOOL{return exec;}, count, delayMs)
#define DEFAULT_RETRY_COUNT 10
#define DEFAULT_RETRY_DELAY_MS 1000

View File

@@ -18,7 +18,9 @@ public:
JProperty(std::string, Renter_UploadDbFilePath, public, private, _configDocument)
JProperty(std::string, TempFolder, public, private, _configDocument)
JProperty(std::string, CacheFolder, public, public, _configDocument)
JProperty(std::uint16_t, ApiPort, public, public, _configDocument)
JProperty(std::uint16_t, HostPort, public, public, _configDocument)
JProperty(std::uint16_t, RpcPort, public, public, _configDocument)
JProperty(std::uint8_t, MaxUploadCount, public, public, _configDocument)
JProperty(std::string, HostNameOrIp, public, public, _configDocument)
JProperty(bool, LockWalletOnExit, public, public, _configDocument)

View File

@@ -8,6 +8,9 @@
#include <eventsystem.h>
#include <debugconsumer.h>
#include <loggingconsumer.h>
#include <siadriveconfig.h>
#include <siaapi.h>
#include <filepath.h>
using namespace Sia;
using namespace Sia::Api;
@@ -29,12 +32,31 @@ int APIENTRY wWinMain(HINSTANCE hInstance,
CefEnableHighDPISupport();
CefMainArgs mainArgs(hInstance);
CefRefPtr<CSiaDriveApp> app(new CSiaDriveApp);
std::shared_ptr<CSiaDriveConfig> siaDriveConfig(new CSiaDriveConfig);
CefRefPtr<CSiaDriveApp> app(new CSiaDriveApp(siaDriveConfig));
int exitCode = CefExecuteProcess(mainArgs, app, nullptr);
if (exitCode >= 0) {
if (exitCode >= 0)
{
return exitCode;
}
if (siaDriveConfig->GetLaunchBundledSiad())
{
SiaHostConfig hostConfig;
hostConfig.HostName = siaDriveConfig->GetHostNameOrIp();
hostConfig.HostPort = siaDriveConfig->GetApiPort();
hostConfig.RequiredVersion = COMPAT_SIAD_VERSION;
CSiaApi api(hostConfig, siaDriveConfig.get());
if (api.GetServerVersion().IsNullOrEmpty())
{
FilePath dataPath(FilePath::GetAppDataDirectory(), "siadrive");
dataPath.Append("data");
dataPath.CreateDirectory();
ExecuteProcess(siaDriveConfig.get(), FilePath("./sia/siad"), dataPath, false);
}
}
CefSettings settings;
settings.no_sandbox = true;
#ifdef _DEBUG

View File

@@ -20,7 +20,7 @@ class FunctionHandler :
public:
FunctionHandler(const CSiaApi& siaApi,
bool& appStarted,
std::unique_ptr<CSiaDriveConfig>& siaDriveConfig,
std::shared_ptr<CSiaDriveConfig>& siaDriveConfig,
std::unique_ptr<Api::Dokan::CSiaDokanDrive>& siaDrive,
std::function<void()> shutdownCallback,
std::function<void(CefRefPtr<CefV8Context> context)> refreshCallback) :
@@ -35,7 +35,7 @@ public:
private:
const CSiaApi& _siaApi;
std::unique_ptr<CSiaDriveConfig>& _siaDriveConfig;
std::shared_ptr<CSiaDriveConfig> _siaDriveConfig;
std::unique_ptr<Api::Dokan::CSiaDokanDrive>& _siaDrive;
bool& _appStarted;
std::function<void()> _shutdownCallback;
@@ -169,6 +169,7 @@ public:
_siaDrive->Mount(drive[0], _siaDriveConfig->GetCacheFolder(), 0);
CefPostTask(TID_RENDERER, base::Bind(&FunctionHandler::MountCallback, this, context, cb));
}).detach();
return true;
}
else if (name == "unmountDrive")
@@ -204,6 +205,24 @@ public:
args.push_back(CefV8Value::CreateBool(ApiSuccess(ret)));
args.push_back(CefV8Value::CreateString(ret.GetReason().str()));
cb->ExecuteFunctionWithContext(context, nullptr, args);
return true;
}
else if (name == "setSiaSettings")
{
CefRefPtr<CefV8Value> settings = arguments[0];
CefRefPtr<CefV8Value> cb = arguments[1];
_siaDriveConfig->SetAutoStartOnLogon(settings->GetValue("AutoStartOnLogon")->GetBoolValue());
_siaDriveConfig->SetLaunchBundledSiad(settings->GetValue("UseBundledSiad")->GetBoolValue());
_siaDriveConfig->SetLockWalletOnExit(settings->GetValue("UnlockOnExit")->GetBoolValue());
_siaDriveConfig->SetApiPort(SString::ToUInt32(settings->GetValue("ApiPort")->GetStringValue().ToWString()));
_siaDriveConfig->SetHostPort(SString::ToUInt32(settings->GetValue("HostPort")->GetStringValue().ToWString()));
_siaDriveConfig->SetRpcPort(SString::ToUInt32(settings->GetValue("RpcPort")->GetStringValue().ToWString()));
CefV8ValueList args;
args.push_back(CefV8Value::CreateBool(true));
cb->ExecuteFunctionWithContext(context, nullptr, args);
return true;
}
else if (name == "calculateEstimatedStorage")
@@ -262,7 +281,8 @@ private:
DISALLOW_COPY_AND_ASSIGN(SimpleWindowDelegate);
};
CSiaDriveApp::CSiaDriveApp()
CSiaDriveApp::CSiaDriveApp(std::shared_ptr<Api::CSiaDriveConfig> siaDriveConfig) :
_siaDriveConfig(siaDriveConfig)
{
}
@@ -298,10 +318,9 @@ void CSiaDriveApp::OnContextCreated(
{
CEF_REQUIRE_RENDERER_THREAD();
_siaDriveConfig.reset(new CSiaDriveConfig());
SiaHostConfig hostConfig;
hostConfig.HostName = _siaDriveConfig->GetHostNameOrIp();
hostConfig.HostPort = _siaDriveConfig->GetHostPort();
hostConfig.HostPort = _siaDriveConfig->GetApiPort();
hostConfig.RequiredVersion = COMPAT_SIAD_VERSION;
_siaCurl.reset(new CSiaCurl(hostConfig));
_siaApi.reset(new CSiaApi(hostConfig, _siaDriveConfig.get()));
@@ -331,6 +350,7 @@ void CSiaDriveApp::OnContextCreated(
obj->SetValue("unmountDrive", CefV8Value::CreateFunction("unmountDrive", handler), V8_PROPERTY_ATTRIBUTE_NONE);
obj->SetValue("shutdown", CefV8Value::CreateFunction("shutdown", handler), V8_PROPERTY_ATTRIBUTE_NONE);
obj->SetValue("setRenterSettings", CefV8Value::CreateFunction("setRenterSettings", handler), V8_PROPERTY_ATTRIBUTE_NONE);
obj->SetValue("setSiaSettings", CefV8Value::CreateFunction("setSiaSettings", handler), V8_PROPERTY_ATTRIBUTE_NONE);
obj->SetValue("calculateEstimatedStorage", CefV8Value::CreateFunction("calculateEstimatedStorage", handler), V8_PROPERTY_ATTRIBUTE_NONE);
global->SetValue("appActions", obj, V8_PROPERTY_ATTRIBUTE_NONE);
@@ -414,6 +434,9 @@ void CSiaDriveApp::SiaApiRefreshCallback(CefRefPtr<CefV8Context> context, const
uiState->SetValue("allocatedRenterFunds", CefV8Value::CreateString(_siaApi->GetRenter()->GetFunds().ToString()), V8_PROPERTY_ATTRIBUTE_NONE);
ExecuteSetter(context, uiActions, "setAutoStartOnLogon", CefV8Value::CreateBool(_siaDriveConfig->GetAutoStartOnLogon()));
ExecuteSetter(context, uiActions, "setLaunchBundledSiad", CefV8Value::CreateBool(_siaDriveConfig->GetLaunchBundledSiad()));
ExecuteSetter(context, uiActions, "setApiPort", CefV8Value::CreateUInt(_siaDriveConfig->GetApiPort()));
ExecuteSetter(context, uiActions, "setHostPort", CefV8Value::CreateUInt(_siaDriveConfig->GetHostPort()));
ExecuteSetter(context, uiActions, "setRpcPort", CefV8Value::CreateUInt(_siaDriveConfig->GetRpcPort()));
// Display wallet data
auto confirmedBalance = _siaApi->GetWallet()->GetConfirmedBalance();

View File

@@ -18,11 +18,11 @@ CSiaApi::CSiaApi(const SiaHostConfig& hostConfig, CSiaDriveConfig* siaDriveConfi
CSiaApi::~CSiaApi()
{
_refreshThread->StopAutoThread();
if (_siaDriveConfig->GetLockWalletOnExit())
{
_wallet->Lock();
}
_refreshThread->StopAutoThread();
}
void CSiaApi::Refresh(const CSiaCurl& siaCurl, CSiaDriveConfig* siaDriveConfig)

View File

@@ -3,6 +3,8 @@
#include <SQLiteCpp/Exception.h>
#include <sqlite3.h>
#include <bitset>
#include <filepath.h>
#include <siadriveconfig.h>
#ifdef _WIN32
#include <Wincrypt.h>
@@ -186,6 +188,31 @@ std::vector<SString> GetAvailableDrives()
return std::move(avail);
}
bool ExecuteProcess(CSiaDriveConfig* siaDriveConfig, FilePath process, FilePath workingDir, const bool& waitForExit)
{
process.MakeAbsolute();
workingDir.MakeAbsolute();
SString command = process;
if (static_cast<SString>(process).EndsWith("siad"))
{
SString apiAdr = siaDriveConfig->GetHostNameOrIp() + ":" + SString::FromUInt32(siaDriveConfig->GetApiPort());
SString hostAdr = ":" + SString::FromUInt32(siaDriveConfig->GetHostPort());
SString rpcAddr = ":" + SString::FromUInt32(siaDriveConfig->GetRpcPort());
command = "cmd.exe /c \"" + static_cast<SString>(process) + "\" --api-addr=" + apiAdr + " --host-addr=" + hostAdr + " --rpc-addr=" + rpcAddr;
}
STARTUPINFO si = { 0 };
si.cb = sizeof(si);
PROCESS_INFORMATION pi;
if (::CreateProcess(nullptr, &command[0], nullptr, nullptr, FALSE, 0, nullptr, &workingDir[0], &si, &pi))
{
return true;
}
return false;
}
#endif
NS_END(2)

View File

@@ -50,9 +50,21 @@ bool CSiaDriveConfig::LoadDefaults()
changed = true;
}
if (!CheckApiPort())
{
SetApiPort(9980);
changed = true;
}
if (!CheckHostPort())
{
SetHostPort(9980);
SetHostPort(9982);
changed = true;
}
if (!CheckRpcPort())
{
SetRpcPort(9981);
changed = true;
}