1
0
This commit is contained in:
Scott E. Graves
2017-03-22 00:23:04 -05:00
parent b277b04521
commit a6c6de75c3
8 changed files with 69 additions and 18 deletions

1
.gitignore vendored
View File

@@ -253,3 +253,4 @@ ModelManifest.xml
3rd_party/CEF/depot_tools
3rd_party/CEF/depot_tools
/3rd_party/CEF/depot_tools.zip
/dist

View File

@@ -2,7 +2,7 @@
set ROOT=%~dp0%
pushd "%ROOT%"
call 3rd_party\CEF\create.cmd Debug
REM call 3rd_party\CEF\create.cmd Debug
mkdir build
mkdir build\debug

View File

@@ -2,7 +2,7 @@
set ROOT=%~dp0%
pushd "%ROOT%"
call 3rd_party\CEF\create.cmd Release
REM call 3rd_party\CEF\create.cmd Release
mkdir build
mkdir build\release

View File

@@ -5,6 +5,17 @@
document.getElementById(id).innerText = balance;
}
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 {
setAllocatedFunds: (currency)=> {
@@ -65,6 +76,9 @@
},
setServerVersion: (version) => {
setInnerText('ID_ServerVersion', version);
},
setAvailableDriveLetters: (drives)=> {
setSelect('ID_MountDrives', drives);
}
};
})();

View File

@@ -48,6 +48,7 @@ public:
private:
static void ExecuteSetter(CefRefPtr<CefV8Context> context, CefRefPtr<CefV8Value> obj, const SString& method, const SString& value);
static void ExecuteSetter(CefRefPtr<CefV8Context> context, CefRefPtr<CefV8Value> obj, const SString& method, CefRefPtr<CefV8Value> value);
void SiaApiRefreshCallback(CefRefPtr<CefV8Context> context, const Api::CSiaCurl& siaCurl, Api::CSiaDriveConfig* siaDriveConfig);
private:

View File

@@ -183,6 +183,10 @@ SString SIADRIVE_EXPORTABLE GenerateSha256(const SString& str);
BOOL SIADRIVE_EXPORTABLE RecurDeleteFilesByExtentsion(const SString& folder, const SString& extensionWithDot);
#ifdef _WIN32
std::vector<SString> SIADRIVE_EXPORTABLE GetAvailableDrives();
#endif
#define RetryableAction(exec, count, delayMs) RetryAction([&]()->BOOL{return exec;}, count, delayMs)
#define DEFAULT_RETRY_COUNT 10
#define DEFAULT_RETRY_DELAY_MS 1000

View File

@@ -162,6 +162,14 @@ void CSiaDriveApp::ExecuteSetter(CefRefPtr<CefV8Context> context, CefRefPtr<CefV
setConfirmed->ExecuteFunctionWithContext(context, nullptr, args);
}
void CSiaDriveApp::ExecuteSetter(CefRefPtr<CefV8Context> context, CefRefPtr<CefV8Value> obj, const SString& method, CefRefPtr<CefV8Value> value)
{
CefRefPtr<CefV8Value> setConfirmed = obj->GetValue(method.str());
CefV8ValueList args;
args.push_back(value);
setConfirmed->ExecuteFunctionWithContext(context, nullptr, args);
}
void CSiaDriveApp::OnContextCreated(
CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
@@ -287,16 +295,6 @@ void CSiaDriveApp::SiaApiRefreshCallback(CefRefPtr<CefV8Context> context, const
ExecuteSetter(context, walletActions, "setReceiveAddress", _walletReceiveAddress);
}
// Display renter data
/*
SiaCurrency t = _siaApi->GetRenter()->GetTotalUsedBytes() ? _siaApi->GetRenter()->GetTotalUsedBytes() / (1024.0 * 1024.0 * 1024.0) : 0.0;
auto a = (t / (allocatedFunds - unspentFunds)) * allocatedFunds;
SetRenterTotalUsed(_siaApi->GetRenter()->GetTotalUsedBytes());
SetRenterTotalAvailable(a.ToDouble());
SetRenterTotalRemain((a-t).ToDouble());
SetRenterTotalUploadProgress(_siaApi->GetRenter()->GetTotalUploadProgress());
*/
// Funding
SiaCurrency allocatedFunds = _siaApi->GetRenter()->GetFunds();
SiaCurrency unspentFunds = _siaApi->GetRenter()->GetUnspent();
@@ -313,7 +311,20 @@ void CSiaDriveApp::SiaApiRefreshCallback(CefRefPtr<CefV8Context> context, const
ExecuteSetter(context, renterActions, "setAvailableSpace", SiaCurrencyToGB(totalRemainGb));
ExecuteSetter(context, renterActions, "setUsedSpace", SiaCurrencyToGB(totalUsedGb));
// Progress
// Upload Progress
/*
SetRenterTotalUploadProgress(_siaApi->GetRenter()->GetTotalUploadProgress());
*/
// Mount
auto uiUpdate = global->GetValue("uiUpdate");
auto drives = GetAvailableDrives();
auto driveList = CefV8Value::CreateArray(drives.size());
for (size_t i = 0; i < drives.size(); i++)
{
driveList->SetValue(i, CefV8Value::CreateString(drives[i].str()));
}
ExecuteSetter(context, uiUpdate, "setAvailableDriveLetters", driveList);
// Display block height
ExecuteSetter(context, uiActions, "setBlockHeight", SString::FromUInt64(_siaApi->GetConsensus()->GetHeight()));

View File

@@ -2,6 +2,7 @@
#include <ttmath/ttmath.h>
#include <SQLiteCpp/Exception.h>
#include <sqlite3.h>
#include <bitset>
#ifdef _WIN32
#include <Wincrypt.h>
@@ -66,7 +67,7 @@ SString GenerateSha256(const SString& str)
return ret;
#else
a
#endif
}
@@ -113,7 +114,7 @@ BOOL RecurDeleteFilesByExtentsion(const SString& folder, const SString& extensio
return ret;
#else
a
#endif
}
@@ -128,7 +129,7 @@ BOOL RetryDeleteFileIfExists(const SString& filePath)
return ret;
#else
a
#endif
}
@@ -143,8 +144,27 @@ BOOL RetryAction(std::function<BOOL()> func, std::uint16_t retryCount, const DWO
return ret;
#else
a
#endif
}
#ifdef _WIN32
std::vector<SString> GetAvailableDrives()
{
static const std::vector<char> alpha = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' };
std::bitset<26> drives(~GetLogicalDrives() & 0xFFFFFFFF);
std::vector<SString> avail;
for (size_t i = 0; i < alpha.size(); i++)
{
if (drives[i] && (alpha[i] != 'A') && (alpha[i] != 'B'))
{
avail.push_back(alpha[i]);
}
}
return std::move(avail);
}
#endif
NS_END(2)