From ed80d032f7da8b9563220b9c4bfee01afec5d101 Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Wed, 29 Mar 2017 23:42:32 -0500 Subject: [PATCH] Continue renter configuration --- htdocs/index.html | 1 + htdocs/js/index.js | 75 +++++++++++++++--------- include/siadrive_api/siacommon.h | 5 +- src/siadrive/siadriveapp.cpp | 19 ++++++ src/siadrive_api/siarenter.cpp | 2 +- src/siadrive_dokan_api/siadokandrive.cpp | 17 +++--- 6 files changed, 81 insertions(+), 38 deletions(-) diff --git a/htdocs/index.html b/htdocs/index.html index 27fe7cc..bc99d50 100644 --- a/htdocs/index.html +++ b/htdocs/index.html @@ -168,6 +168,7 @@

Renew Window



+ diff --git a/htdocs/js/index.js b/htdocs/js/index.js index 8425be1..a22c616 100644 --- a/htdocs/js/index.js +++ b/htdocs/js/index.js @@ -1,28 +1,29 @@ // Main (() => { + function setInnerText(id, text) { + document.getElementById(id).innerText = text; + } + + function setValue(id, value) { + document.getElementById(id).value = value; + } + + function getValue(id) { + return document.getElementById(id).value; + } + + function setSelect(id, itemList) { + const select = document.getElementById(id); + select.innerHTML = ""; + + for (const item of itemList) { + const opt = document.createElement('option'); + opt.innerText = item; + select.appendChild(opt); + } + } + window.uiUpdate = (()=> { - function setInnerText(id, text) { - document.getElementById(id).innerText = text; - } - - function setValue(id, value) { - document.getElementById(id).value = value; - } - - function getValue(id) { - return document.getElementById(id).value; - } - - function setSelect(id, itemList) { - const select = document.getElementById(id); - select.innerHTML = ""; - - for (const item of itemList) { - const opt = document.createElement('option'); - opt.innerText = item; - select.appendChild(opt); - } - } const _renter = (()=> { return { @@ -121,7 +122,11 @@ } function _allocatedRenterFunds() { - return window.uiState.allocatedRenterFunds + return window.uiState.allocatedRenterFunds; + } + + function _defaultRenterSettings() { + return window.uiState.defaultRenterSettings; } return { @@ -129,7 +134,8 @@ isOnline: _isOnline, isWalletConfigured: _isWalletConfigured, isWalletLocked: _isWalletLocked, - allocatedRenterFunds: _allocatedRenterFunds + allocatedRenterFunds: _allocatedRenterFunds, + defaultRenterSettings: _defaultRenterSettings }; })(); @@ -165,8 +171,8 @@ window.appActions.shutdown(); } - function _setRenterAllowance(allowance) { - window.appActions.setRenterAllowance(allowance); + function _setRenterSettings(allowance, cb) { + window.appActions.setRenterSettings(allowance, cb); } return { @@ -177,7 +183,7 @@ unlockWallet: _unlockWallet, unmountDrive: _unmountDrive, shutdown: _shutdown, - setRenterAllowance: _setRenterAllowance + setRenterSettings: _setRenterSettings }; })(); @@ -263,10 +269,22 @@ function handleRenterEditSettings() { setMainWindow('renter_settings_window'); + const defaultsButton = document.getElementById('ID_RenterSettingsDefaults'); + defaultsButton.onclick = ()=> { + const settings = UiState.defaultRenterSettings(); + if (getValue('ID_RenterSetFunds') === '0') { + setValue('ID_RenterSetFunds', settings.Funds); + } + setValue('ID_RenterSetHosts', settings.Hosts); + setValue('ID_RenterSetPeriod', settings.Period); + setValue('ID_RenterSetRenewWindow', settings.RenewWindowInBlocks); + }; + const cancelButton = document.getElementById('ID_RenterSettingsCancel'); cancelButton.onclick = ()=> { saveButton.onclick = null; cancelButton.onclick = null; + defaultsButton.onclick = null; beginMainApplication(); }; @@ -274,7 +292,8 @@ saveButton.onclick = ()=> { saveButton.onclick = null; cancelButton.onclick = null; - AppActions.setRenterAllowance({ + defaultsButton.onclick = null; + AppActions.setRenterSettings({ 'Funds': getValue('ID_RenterSetFunds'), 'Hosts': getValue('ID_RenterSetHosts'), 'Period': getValue('ID_RenterSetPeriod'), diff --git a/include/siadrive_api/siacommon.h b/include/siadrive_api/siacommon.h index 48d2dd0..a3cae69 100644 --- a/include/siadrive_api/siacommon.h +++ b/include/siadrive_api/siacommon.h @@ -116,9 +116,10 @@ typedef ttmath::Big<1, 30> SiaCurrency; const std::uint8_t SIA_BLOCK_TIME_MINS = 10; const std::uint32_t MINUTES_PER_MONTH = (730 * 60); const std::uint32_t SIA_BLOCKS_PER_MONTH = MINUTES_PER_MONTH / SIA_BLOCK_TIME_MINS; -const std::uint32_t SIA_DEFAULT_HOST_COUNT = 24; -const std::uint32_t SIA_DEFAULT_RENEW_WINDOW = (SIA_BLOCK_TIME_MINS * (SIA_DEFAULT_HOST_COUNT * 2)); +const std::uint32_t SIA_DEFAULT_HOST_COUNT = 50; +const std::uint32_t SIA_DEFAULT_RENEW_WINDOW = ((1440 / SIA_BLOCK_TIME_MINS) * 14); const SiaCurrency SIA_DEFAULT_MINIMUM_FUNDS = 4000; +const std::uint32_t SIA_DEFAULT_CONTRACT_LENGTH = SIA_BLOCKS_PER_MONTH * 3; /* BigNumber.config({ EXPONENTIAL_AT: 1e+9 }) diff --git a/src/siadrive/siadriveapp.cpp b/src/siadrive/siadriveapp.cpp index 6221a46..6155226 100644 --- a/src/siadrive/siadriveapp.cpp +++ b/src/siadrive/siadriveapp.cpp @@ -188,7 +188,19 @@ public: _shutdownCallback(); return true; } + else if (name == "setRenterSettings") + { + CefRefPtr vAllowance = arguments[0]; + CefRefPtr cb = arguments[1]; + SiaRenterAllowance allowance({ + SiaCurrency(vAllowance->GetValue("Funds")->GetStringValue().ToWString()), + SString::ToUInt32(vAllowance->GetValue("Hosts")->GetStringValue().ToWString()), + SString::ToUInt32(vAllowance->GetValue("Period")->GetStringValue().ToWString()), + SString::ToUInt32(vAllowance->GetValue("RenewWindowInBlocks")->GetStringValue().ToWString()) + }); + auto ret = _siaApi.GetRenter()->SetAllowance(allowance); + } // Function does not exist. return false; } @@ -275,6 +287,12 @@ void CSiaDriveApp::OnContextCreated( obj->SetValue("isOnline", CefV8Value::CreateBool(_siaApi->GetWallet()->GetConnected()), V8_PROPERTY_ATTRIBUTE_NONE); obj->SetValue("clientVersion", CefV8Value::CreateString(SIDRIVE_VERSION_STRING), V8_PROPERTY_ATTRIBUTE_NONE); obj->SetValue("allocatedRenterFunds", CefV8Value::CreateString(_siaApi->GetRenter()->GetFunds().ToString()), V8_PROPERTY_ATTRIBUTE_NONE); + CefRefPtr defaultFunds = CefV8Value::CreateObject(nullptr, nullptr); + defaultFunds->SetValue("Funds", CefV8Value::CreateString(SIA_DEFAULT_MINIMUM_FUNDS.ToString()), V8_PROPERTY_ATTRIBUTE_NONE); + defaultFunds->SetValue("Hosts", CefV8Value::CreateString(SString::FromUInt32(SIA_DEFAULT_HOST_COUNT).str()), V8_PROPERTY_ATTRIBUTE_NONE); + defaultFunds->SetValue("Period", CefV8Value::CreateString(SString::FromUInt32(SIA_DEFAULT_CONTRACT_LENGTH).str()), V8_PROPERTY_ATTRIBUTE_NONE); + defaultFunds->SetValue("RenewWindowInBlocks", CefV8Value::CreateString(SString::FromUInt32(SIA_DEFAULT_RENEW_WINDOW).str()), V8_PROPERTY_ATTRIBUTE_NONE); + obj->SetValue("defaultRenterSettings", defaultFunds, V8_PROPERTY_ATTRIBUTE_NONE); global->SetValue("uiState", obj, V8_PROPERTY_ATTRIBUTE_NONE); CefRefPtr handler(new FunctionHandler(*_siaApi, _appStarted, _siaDriveConfig, _siaDrive, [this]() {this->ShutdownServices(); }, [this](CefRefPtr context) {this->SiaApiRefreshCallback(context, *_siaCurl, _siaDriveConfig.get()); })); @@ -286,6 +304,7 @@ void CSiaDriveApp::OnContextCreated( obj->SetValue("mountDrive", CefV8Value::CreateFunction("mountDrive", handler), V8_PROPERTY_ATTRIBUTE_NONE); 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); global->SetValue("appActions", obj, V8_PROPERTY_ATTRIBUTE_NONE); _refreshThread.reset(new CAutoThread(*_siaCurl, _siaDriveConfig.get(), [this, context](const CSiaCurl& siaCurl, CSiaDriveConfig* siaDriveConfig) diff --git a/src/siadrive_api/siarenter.cpp b/src/siadrive_api/siarenter.cpp index 51c4e2e..153f769 100644 --- a/src/siadrive_api/siarenter.cpp +++ b/src/siadrive_api/siarenter.cpp @@ -84,7 +84,7 @@ void CSiaApi::_CSiaRenter::Refresh(const CSiaCurl& siaCurl, CSiaDriveConfig* sia { _currentAllowance.Funds = SIA_DEFAULT_MINIMUM_FUNDS; _currentAllowance.Hosts = SIA_DEFAULT_HOST_COUNT; - _currentAllowance.Period = SIA_BLOCKS_PER_MONTH * 3; + _currentAllowance.Period = SIA_DEFAULT_CONTRACT_LENGTH; _currentAllowance.RenewWindowInBlocks = SIA_DEFAULT_RENEW_WINDOW; } if (ApiSuccess(RefreshFileTree())) diff --git a/src/siadrive_dokan_api/siadokandrive.cpp b/src/siadrive_dokan_api/siadokandrive.cpp index f1ef773..d581083 100644 --- a/src/siadrive_dokan_api/siadokandrive.cpp +++ b/src/siadrive_dokan_api/siadokandrive.cpp @@ -484,15 +484,18 @@ private: { if ((wcscmp(fileName, L"\\") != 0) || (wcscmp(findData.cFileName, L".") != 0) && (wcscmp(findData.cFileName, L"..") != 0)) { - if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) + if (!(SString(fileName).EndsWith(".siadrive") || SString(fileName).EndsWith(".siadrive.temp"))) { - dirs.insert({findData.cFileName, 0}); + if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) + { + dirs.insert({ findData.cFileName, 0 }); + } + else + { + files.insert({ findData.cFileName, 1 }); + } + fillFindData(&findData, dokanFileInfo); } - else - { - files.insert({ findData.cFileName, 1 }); - } - fillFindData(&findData, dokanFileInfo); } } while (::FindNextFile(findHandle, &findData) != 0); ::FindClose(findHandle);