diff --git a/SiaDrive/SiaDriveDlg.cpp b/SiaDrive/SiaDriveDlg.cpp
index 17fed01..cdde0f8 100644
--- a/SiaDrive/SiaDriveDlg.cpp
+++ b/SiaDrive/SiaDriveDlg.cpp
@@ -27,7 +27,7 @@ ornament alkaline gasp pepper upkeep ablaze number sizes toyed sawmill looking b
static std::set GetAvailableDrives()
{
static const std::vector 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 drives(~GetLogicalDrives());
+ std::bitset<26> drives(~GetLogicalDrives() & 0xFFFFFFFF);
std::set avail;
for (size_t i = 0; i < alpha.size(); i++)
@@ -96,12 +96,7 @@ CSiaDriveDlg::CSiaDriveDlg(CWnd* pParent /*=NULL*/)
void CSiaDriveDlg::DoDataExchange(CDataExchange* pDX)
{
CDHtmlDialog::DoDataExchange(pDX);
- DDX_DHtml_ElementInnerText(pDX, _T("WalletBalanceTotal"), _walletBalanceTotal);
- DDX_DHtml_ElementInnerText(pDX, _T("WalletBalanceConfirmed"), _walletBalanceConfirmed);
- DDX_DHtml_ElementInnerText(pDX, _T("WalletBalanceUnconfirmed"), _walletBalanceUnconfirmed);
- DDX_DHtml_ElementInnerText(pDX, _T("WalletAddress"), _walletAddress);
DDX_DHtml_ElementInnerText(pDX, _T("WalletCreatedSeed"), _walletCreatedSeed);
- DDX_DHtml_ElementValue(pDX, _T("WalletUnlockPwd"), _unlockWalletPwd);
}
BEGIN_MESSAGE_MAP(CSiaDriveDlg, CDHtmlDialog)
@@ -238,6 +233,47 @@ BOOL CSiaDriveDlg::CallClientScript(LPCTSTR pStrFuncName, const json& json, CCom
return CallClientScript(pStrFuncName, data, pOutVarRes);
}
+BOOL CSiaDriveDlg::CallClientScript(LPCTSTR pStrFuncName, CComVariant* pOutVarRes)
+{
+
+ BOOL bRes = FALSE;
+ CComVariant vaResult;
+ CComPtr pIDoc2;
+ if (SUCCEEDED(this->GetDHtmlDocument(&pIDoc2))) //Uses CDHtmlDialog as 'this'
+ {
+ //Getting IDispatch for Java Script objects
+ CComPtr spScript;
+ if (SUCCEEDED(pIDoc2->get_Script(&spScript)))
+ {
+ //Find dispid for given function in the object
+ CComBSTR bstrMember(pStrFuncName);
+ DISPID dispid = NULL;
+ if (SUCCEEDED(spScript->GetIDsOfNames(IID_NULL, &bstrMember, 1, LOCALE_USER_DEFAULT, &dispid)))
+ {
+ EXCEPINFO excepInfo;
+ memset(&excepInfo, 0, sizeof excepInfo);
+ DISPPARAMS dispparams;
+ memset(&dispparams, 0, sizeof dispparams);
+ dispparams.cArgs = 0;
+ dispparams.cNamedArgs = 0;
+
+ UINT nArgErr = static_cast(-1); // initialize to invalid arg
+ //Call JavaScript function
+ if (SUCCEEDED(spScript->Invoke(dispid, IID_NULL, 0, DISPATCH_METHOD, &dispparams, &vaResult, &excepInfo, &nArgErr)))
+ {
+ //Done!
+ bRes = TRUE;
+ }
+ }
+ }
+ }
+
+ if (pOutVarRes)
+ *pOutVarRes = vaResult;
+
+ return bRes;
+}
+
// The system calls this function to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CSiaDriveDlg::OnQueryDragIcon()
@@ -269,20 +305,16 @@ HRESULT CSiaDriveDlg::OnButtonConfirmSeed(IHTMLElement* /*pElement*/)
HRESULT CSiaDriveDlg::OnButtonUnlockWallet(IHTMLElement* /*pElement*/)
{
- UpdateData(TRUE);
-
- if (API_SUCCESS(SiaApiError, _siaApi.GetWallet()->Unlock(_unlockWalletPwd.GetBuffer())))
+ if (API_SUCCESS(SiaApiError, _siaApi.GetWallet()->Unlock(GetWalletUnlockPassword())))
{
- _unlockWalletPwd = L"";
- UpdateData(FALSE);
+ SetWalletUnlockPassword(L"");
this->Navigate(this->m_strCurrentUrl);
}
else
{
- _unlockWalletPwd = L"";
- UpdateData(FALSE);
+ SetWalletUnlockPassword(L"");
AfxMessageBox(L"Invalid password entered");
- SetFocusToElement(L"WalletUnlockPwd");
+ SetFocusToElement(L"ID_WalletUnlockPwd");
}
return S_OK;
@@ -321,16 +353,57 @@ void CSiaDriveDlg::SetServerVersion(const String& version)
CallClientScript(L"setServerVersion", version, nullptr);
}
+void CSiaDriveDlg::SetWalletConfirmedBalance(const String& balance)
+{
+ CallClientScript(L"setWalletConfirmedBalance", balance, nullptr);
+}
+
+void CSiaDriveDlg::SetWalletUnconfirmedBalance(const String& balance)
+{
+ CallClientScript(L"setWalletUnconfirmedBalance", balance, nullptr);
+}
+
+void CSiaDriveDlg::SetWalletTotalBalance(const String& balance)
+{
+ CallClientScript(L"setWalletTotalBalance", balance, nullptr);
+}
+
+void CSiaDriveDlg::SetWalletReceiveAddress(const String& address)
+{
+ CallClientScript(L"setWalletReceiveAddress", address, nullptr);
+}
+
+String CSiaDriveDlg::GetWalletReceiveAddress()
+{
+ CComVariant result;
+ CallClientScript(L"getWalletReceiveAddress", &result);
+
+ return result.bstrVal ? result.bstrVal : L"";
+}
+
+void CSiaDriveDlg::SetWalletUnlockPassword(const String& password)
+{
+ CallClientScript(L"setWalletUnlockPassword", password, nullptr);
+}
+
+String CSiaDriveDlg::GetWalletUnlockPassword()
+{
+ CComVariant result;
+ CallClientScript(L"getWalletUnlockPassword", &result);
+
+ return result.bstrVal ? result.bstrVal : L"";
+}
+
void CSiaDriveDlg::OnDocumentComplete(LPDISPATCH, LPCTSTR)
{
KillTimer(IDT_UPDATE);
SetServerVersion(L"x.x.x.");
SetClientVersion(L"1.0.0");
- _walletBalanceConfirmed = L"";
- _walletBalanceUnconfirmed = L"";
- _walletBalanceTotal = L"";
- _walletAddress = L"";
+ SetWalletConfirmedBalance(L"");
+ SetWalletUnconfirmedBalance(L"");
+ SetWalletTotalBalance(L"");
+ SetWalletReceiveAddress(L"");
SetTimer(IDT_UPDATE, 2000, nullptr);
@@ -338,10 +411,6 @@ void CSiaDriveDlg::OnDocumentComplete(LPDISPATCH, LPCTSTR)
{
ConfigureWallet();
}
- else
- {
- UpdateData(FALSE);
- }
}
void CSiaDriveDlg::OnTimer(UINT_PTR nIDEvent)
@@ -353,6 +422,9 @@ void CSiaDriveDlg::OnTimer(UINT_PTR nIDEvent)
UpdateUi();
}
break;
+
+ default:
+ break;
}
}
@@ -370,18 +442,18 @@ bool CSiaDriveDlg::UpdateSiaInfo()
if (API_SUCCESS(SiaApiError, _siaApi.GetWallet()->GetUnonfirmedBalance(unconfirmed)))
{
SiaCurrency total = confirmed + unconfirmed;
-
- _walletBalanceConfirmed = SiaCurrencyToString(confirmed).c_str();
- _walletBalanceUnconfirmed = SiaCurrencyToString(unconfirmed).c_str();
- _walletBalanceTotal = SiaCurrencyToString(total).c_str();
- if (!_walletAddress.GetLength())
+ SetServerVersion(serverVersion);
+ SetWalletConfirmedBalance(SiaCurrencyToString(confirmed));
+ SetWalletUnconfirmedBalance(SiaCurrencyToString(unconfirmed));
+ SetWalletTotalBalance(SiaCurrencyToString(total));
+
+ if (GetWalletReceiveAddress().empty())
{
String address;
_siaApi.GetWallet()->GetAddress(address);
- _walletAddress = address.c_str();
+ SetWalletReceiveAddress(address);
}
- SetServerVersion(serverVersion);
return true;
}
}
@@ -389,7 +461,10 @@ bool CSiaDriveDlg::UpdateSiaInfo()
}
SetServerVersion(L"x.x.x");
- _walletAddress = _walletBalanceConfirmed = _walletBalanceUnconfirmed = _walletBalanceTotal = L"";
+ SetWalletConfirmedBalance(L"");
+ SetWalletUnconfirmedBalance(L"");
+ SetWalletTotalBalance(L"");
+ SetWalletReceiveAddress(L"");
return false;
}
@@ -399,11 +474,7 @@ bool CSiaDriveDlg::UpdateUi(const bool& refresh)
bool ret = UpdateSiaInfo();
if (ret)
{
- if (_connected)
- {
- UpdateData(FALSE);
- }
- else if (!_seedCreation)
+ if (!_connected && !_seedCreation)
{
KillTimer(IDT_UPDATE);
this->Navigate(this->m_strCurrentUrl);
@@ -502,7 +573,7 @@ void CSiaDriveDlg::DisplayUnlockWallet()
{
KillTimer(IDT_UPDATE);
SetMainWindow(L"unlock_wallet");
- SetFocusToElement(L"WalletUnlockPwd");
+ SetFocusToElement(L"ID_WalletUnlockPwd");
}
void CSiaDriveDlg::SetMainWindow(const String& name)
diff --git a/SiaDrive/SiaDriveDlg.h b/SiaDrive/SiaDriveDlg.h
index 2202f51..3bd8bbd 100644
--- a/SiaDrive/SiaDriveDlg.h
+++ b/SiaDrive/SiaDriveDlg.h
@@ -59,18 +59,22 @@ private:
HRESULT GetDomNodeById(const String& id, CComPtr& node);
BOOL CallClientScript(LPCTSTR pStrFuncName, const json& json, CComVariant* pOutVarRes);
BOOL CallClientScript(LPCTSTR pStrFuncName, const String& string, CComVariant* pOutVarRes);
+ BOOL CallClientScript(LPCTSTR pStrFuncName, CComVariant* pOutVarRes);
void SetServerVersion(const String& version);
void SetClientVersion(const String& version);
+ void SetWalletConfirmedBalance(const String& balance);
+ void SetWalletUnconfirmedBalance(const String& balance);
+ void SetWalletTotalBalance(const String& balance);
+ String GetWalletReceiveAddress();
+ void SetWalletReceiveAddress(const String& address);
+ String GetWalletUnlockPassword();
+ void SetWalletUnlockPassword(const String& address);
+
private:
CSiaDriveConfig _siaConfig;
CSiaApi _siaApi;
- CString _walletBalanceConfirmed;
- CString _walletBalanceTotal;
- CString _walletBalanceUnconfirmed;
CString _walletCreatedSeed;
- CString _walletAddress;
- CString _unlockWalletPwd;
bool _connected = false;
bool _seedCreation = false;
static const UINT IDT_UPDATE = 1;
diff --git a/SiaDrive/res/code.js b/SiaDrive/res/code.js
index 9be6afc..4517275 100644
--- a/SiaDrive/res/code.js
+++ b/SiaDrive/res/code.js
@@ -1,10 +1,53 @@
+function setValue(elementName, data) {
+ var elem = document.getElementById(elementName);
+ elem.value = data;
+}
+
function setInnerText(elementName, data) {
var elem = document.getElementById(elementName);
elem.innerText = data;
}
+function getInnerText(elementName) {
+ var elem = document.getElementById(elementName);
+ return elem.innerText;
+}
+
+function getValue(elementName) {
+ var elem = document.getElementById(elementName);
+ return elem.value;
+}
+
+function setWalletUnlockPassword(pwd) {
+ setValue("ID_WalletUnlockPwd", pwd);
+}
+
+function getWalletUnlockPassword() {
+ return getValue("ID_WalletUnlockPwd");
+}
+
+function setWalletReceiveAddress(address) {
+ setInnerText("ID_WalletReceiveAddress", address);
+}
+
+function getWalletReceiveAddress() {
+ return getInnerText("ID_WalletReceiveAddress");
+}
+
+function setWalletTotalBalance(balance) {
+ setInnerText("ID_WalletTotalBalance", balance);
+}
+
+function setWalletConfirmedBalance(balance) {
+ setInnerText("ID_WalletConfirmedBalance", balance);
+}
+
+function setWalletUnconfirmedBalance(balance) {
+ setInnerText("ID_WalletBalanceUnconfirmed", balance);
+}
+
function setClientVersion(version) {
setInnerText("ID_ClientVersion", version);
}
|