More stuff
This commit is contained in:
@@ -2,4 +2,4 @@
|
|||||||
pushd "%~dp0%"
|
pushd "%~dp0%"
|
||||||
|
|
||||||
del /s /q ..\..\UnitTests\data 1>NUL 2>&1
|
del /s /q ..\..\UnitTests\data 1>NUL 2>&1
|
||||||
siad -d ..\..\UnitTests\data
|
siad -d ..\..\UnitTests\data --api-addr localhost:11980
|
@@ -65,7 +65,11 @@ static inline SiaCurrency HastingsStringToSiaCurrency(const String& value)
|
|||||||
|
|
||||||
static inline String SiaCurrencyToString(const SiaCurrency& value)
|
static inline String SiaCurrencyToString(const SiaCurrency& value)
|
||||||
{
|
{
|
||||||
return value.ToWString();
|
ttmath::Conv conv;
|
||||||
|
conv.base = 10;
|
||||||
|
conv.round = 8;
|
||||||
|
|
||||||
|
return value.ToWString(conv);
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_END(2)
|
NS_END(2)
|
@@ -46,6 +46,42 @@ std::string CSiaCurl::ConstructPath(const String& relativePath) const
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SiaCurlError CSiaCurl::CheckHttpError(const std::string& result)
|
||||||
|
{
|
||||||
|
if (result.length() && ((result.length() < 2) || (result[0] != '{')))
|
||||||
|
{
|
||||||
|
return SiaCurlError::HttpError;
|
||||||
|
}
|
||||||
|
|
||||||
|
return SiaCurlError::Success;
|
||||||
|
}
|
||||||
|
|
||||||
|
SiaCurlError CSiaCurl::ProcessResponse(const int& res, const std::string& result, json& response) const
|
||||||
|
{
|
||||||
|
SiaCurlError ret;
|
||||||
|
if (res == CURLE_OK)
|
||||||
|
{
|
||||||
|
ret = CheckHttpError(result);
|
||||||
|
if (API_SUCCESS(SiaCurlError, ret))
|
||||||
|
{
|
||||||
|
ret = (result.length() ? CheckApiError((response = json::parse(result.c_str()))) : SiaCurlError::Success);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if ((res == CURLE_COULDNT_RESOLVE_HOST) || (res == CURLE_COULDNT_CONNECT))
|
||||||
|
{
|
||||||
|
ret = SiaCurlError::NoResponse;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ret = SiaCurlError::UnknownFailure;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
SiaCurlError CSiaCurl::_Get(const String& path, json& response) const
|
SiaCurlError CSiaCurl::_Get(const String& path, json& response) const
|
||||||
{
|
{
|
||||||
curl_easy_reset(_curlHandle);
|
curl_easy_reset(_curlHandle);
|
||||||
@@ -62,24 +98,7 @@ SiaCurlError CSiaCurl::_Get(const String& path, json& response) const
|
|||||||
curl_easy_setopt(_curlHandle, CURLOPT_WRITEDATA, &result);
|
curl_easy_setopt(_curlHandle, CURLOPT_WRITEDATA, &result);
|
||||||
const CURLcode res = curl_easy_perform(_curlHandle);
|
const CURLcode res = curl_easy_perform(_curlHandle);
|
||||||
|
|
||||||
SiaCurlError ret;
|
return ProcessResponse(res, result, response);
|
||||||
if (res == CURLE_OK)
|
|
||||||
{
|
|
||||||
ret = (result.length() ? CheckApiError((response = json::parse(result.c_str()))) : SiaCurlError::Success);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if ((res == CURLE_COULDNT_RESOLVE_HOST) || (res == CURLE_COULDNT_CONNECT))
|
|
||||||
{
|
|
||||||
ret = SiaCurlError::NoResponse;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ret = SiaCurlError::UnknownFailure;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CSiaCurl::CheckVersion(SiaCurlError& error) const
|
bool CSiaCurl::CheckVersion(SiaCurlError& error) const
|
||||||
@@ -151,21 +170,7 @@ SiaCurlError CSiaCurl::Post(const String& path, const PostParameters& parameters
|
|||||||
curl_easy_setopt(_curlHandle, CURLOPT_WRITEDATA, &result);
|
curl_easy_setopt(_curlHandle, CURLOPT_WRITEDATA, &result);
|
||||||
const CURLcode res = curl_easy_perform(_curlHandle);
|
const CURLcode res = curl_easy_perform(_curlHandle);
|
||||||
|
|
||||||
if (res == CURLE_OK)
|
ret = ProcessResponse(res, result, response);
|
||||||
{
|
|
||||||
ret = (result.length() ? CheckApiError((response = json::parse(result.c_str()))) : SiaCurlError::Success);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if ((res == CURLE_COULDNT_RESOLVE_HOST) || (res == CURLE_COULDNT_CONNECT))
|
|
||||||
{
|
|
||||||
ret = SiaCurlError::NoResponse;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ret = SiaCurlError::UnknownFailure;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
@@ -15,6 +15,7 @@ public:
|
|||||||
InvalidRequiredVersion,
|
InvalidRequiredVersion,
|
||||||
NoResponse,
|
NoResponse,
|
||||||
InvalidRequestPath,
|
InvalidRequestPath,
|
||||||
|
HttpError,
|
||||||
UnknownFailure
|
UnknownFailure
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -37,9 +38,11 @@ private:
|
|||||||
static _SiaCurlError CheckApiError(const json& result);
|
static _SiaCurlError CheckApiError(const json& result);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
static _SiaCurlError CheckHttpError(const std::string& result);
|
||||||
std::string ConstructPath(const String& relativePath) const;
|
std::string ConstructPath(const String& relativePath) const;
|
||||||
_SiaCurlError _Get(const String& path, json& response) const;
|
_SiaCurlError _Get(const String& path, json& response) const;
|
||||||
bool CheckVersion(_SiaCurlError& error) const;
|
bool CheckVersion(_SiaCurlError& error) const;
|
||||||
|
_SiaCurlError ProcessResponse(const int& res, const std::string& result, json& response) const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
String GetServerVersion() const;
|
String GetServerVersion() const;
|
||||||
|
@@ -216,7 +216,6 @@
|
|||||||
<ClInclude Include="targetver.h" />
|
<ClInclude Include="targetver.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="..\3rd-party\ttmath-0.9.3\ttmath\ttmathuint_x86_64_msvc.asm" />
|
|
||||||
<None Include="res\SiaDriveApi.rc2" />
|
<None Include="res\SiaDriveApi.rc2" />
|
||||||
<None Include="SiaDrive.Api.def" />
|
<None Include="SiaDrive.Api.def" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
@@ -76,9 +76,6 @@
|
|||||||
<None Include="res\SiaDriveApi.rc2">
|
<None Include="res\SiaDriveApi.rc2">
|
||||||
<Filter>Resource Files</Filter>
|
<Filter>Resource Files</Filter>
|
||||||
</None>
|
</None>
|
||||||
<None Include="..\3rd-party\ttmath-0.9.3\ttmath\ttmathuint_x86_64_msvc.asm">
|
|
||||||
<Filter>Source Files</Filter>
|
|
||||||
</None>
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ResourceCompile Include="SiaDrive.Api.rc">
|
<ResourceCompile Include="SiaDrive.Api.rc">
|
||||||
|
@@ -47,5 +47,13 @@ void CSiaDriveConfig::Load( )
|
|||||||
|
|
||||||
void CSiaDriveConfig::Save() const
|
void CSiaDriveConfig::Save() const
|
||||||
{
|
{
|
||||||
|
String folder = GetFilePath();
|
||||||
|
PathRemoveFileSpec(&folder[0]);
|
||||||
|
|
||||||
|
if (!PathIsDirectory(folder.c_str()))
|
||||||
|
{
|
||||||
|
CreateDirectory(folder.c_str(), nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
std::ofstream(CW2A(GetFilePath().c_str())) << std::setw(2) << _configDocument << std::endl;
|
std::ofstream(CW2A(GetFilePath().c_str())) << std::setw(2) << _configDocument << std::endl;
|
||||||
}
|
}
|
@@ -3,18 +3,19 @@
|
|||||||
</HEAD>
|
</HEAD>
|
||||||
<BODY ID=CSiaDriveDlg BGCOLOR=LIGHTGREY style="font-family: MS Shell Dlg; font-size:13">
|
<BODY ID=CSiaDriveDlg BGCOLOR=LIGHTGREY style="font-family: MS Shell Dlg; font-size:13">
|
||||||
<div align="right">
|
<div align="right">
|
||||||
<label>Server Version: </label><label id="ServerVersion"></label>
|
<label>Client Version: </label><label id="ClientVersion"></label><br />
|
||||||
|
<label>Server Version: </label><label id="ServerVersion"></label><br />
|
||||||
</div>
|
</div>
|
||||||
<div id="main_window">
|
<div id="main_window">
|
||||||
<TABLE WIDTH=100% HEIGHT=100%>
|
<TABLE WIDTH=100% height="75%">
|
||||||
<TR WIDTH=100% HEIGHT=45%>
|
<TR WIDTH=100%>
|
||||||
<TD ALIGN=LEFT VALIGN=TOP>
|
<TD ALIGN=LEFT VALIGN=TOP>
|
||||||
<input id="wallet_btn" type="button" value="Wallet"/>
|
<input id="wallet_btn" type="button" value="Wallet"/>
|
||||||
<input id="host_btn" type="button" value="Host"/>
|
<input id="host_btn" type="button" value="Host"/>
|
||||||
<input id="mount_btn" type="button" value="Mount"/>
|
<input id="mount_btn" type="button" value="Mount"/>
|
||||||
</TD>
|
</TD>
|
||||||
</TR>
|
</TR>
|
||||||
<tr align="center" valign="top">
|
<tr width="100%" align="center" valign="top">
|
||||||
<div id="wallet_tab">
|
<div id="wallet_tab">
|
||||||
<label>Available: </label><label id="WalletBalanceConfirmed"></label><br/>
|
<label>Available: </label><label id="WalletBalanceConfirmed"></label><br/>
|
||||||
<label>Pending: </label><label id="WalletBalanceUnconfirmed"></label><br/>
|
<label>Pending: </label><label id="WalletBalanceUnconfirmed"></label><br/>
|
||||||
@@ -23,7 +24,7 @@
|
|||||||
<div id="host_tab"></div>
|
<div id="host_tab"></div>
|
||||||
<div id="mount_tab"></div>
|
<div id="mount_tab"></div>
|
||||||
</tr>
|
</tr>
|
||||||
<TR WIDTH=100% HEIGHT=100%>
|
<TR WIDTH=100%">
|
||||||
<TD ALIGN=RIGHT VALIGN=BOTTOM>
|
<TD ALIGN=RIGHT VALIGN=BOTTOM>
|
||||||
<BUTTON STYLE="WIDTH: 100" ID="ButtonOK">OK</BUTTON> <BUTTON STYLE="WIDTH: 100" ID="ButtonCancel">Exit</BUTTON>
|
<BUTTON STYLE="WIDTH: 100" ID="ButtonOK">OK</BUTTON> <BUTTON STYLE="WIDTH: 100" ID="ButtonCancel">Exit</BUTTON>
|
||||||
</TD>
|
</TD>
|
||||||
|
Binary file not shown.
@@ -58,12 +58,18 @@ CSiaDriveDlg::CSiaDriveDlg(CWnd* pParent /*=NULL*/)
|
|||||||
_siaApi({L"localhost", 9980, L"1.1.0"})
|
_siaApi({L"localhost", 9980, L"1.1.0"})
|
||||||
{
|
{
|
||||||
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
|
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
|
||||||
|
_serverVersion = L"x.x.x";
|
||||||
|
_clientVersion = L"1.0.0";
|
||||||
|
_walletBalanceConfirmed = L"0";
|
||||||
|
_walletBalanceUnconfirmed = L"0";
|
||||||
|
_walletBalanceTotal = L"0";
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSiaDriveDlg::DoDataExchange(CDataExchange* pDX)
|
void CSiaDriveDlg::DoDataExchange(CDataExchange* pDX)
|
||||||
{
|
{
|
||||||
CDHtmlDialog::DoDataExchange(pDX);
|
CDHtmlDialog::DoDataExchange(pDX);
|
||||||
DDX_DHtml_ElementInnerText(pDX, _T("ServerVersion"), _serverVersion);
|
DDX_DHtml_ElementInnerText(pDX, _T("ServerVersion"), _serverVersion);
|
||||||
|
DDX_DHtml_ElementInnerText(pDX, _T("ClientVersion"), _clientVersion);
|
||||||
DDX_DHtml_ElementInnerText(pDX, _T("WalletBalanceTotal"), _walletBalanceTotal);
|
DDX_DHtml_ElementInnerText(pDX, _T("WalletBalanceTotal"), _walletBalanceTotal);
|
||||||
DDX_DHtml_ElementInnerText(pDX, _T("WalletBalanceConfirmed"), _walletBalanceConfirmed);
|
DDX_DHtml_ElementInnerText(pDX, _T("WalletBalanceConfirmed"), _walletBalanceConfirmed);
|
||||||
DDX_DHtml_ElementInnerText(pDX, _T("WalletBalanceUnconfirmed"), _walletBalanceUnconfirmed);
|
DDX_DHtml_ElementInnerText(pDX, _T("WalletBalanceUnconfirmed"), _walletBalanceUnconfirmed);
|
||||||
@@ -189,9 +195,26 @@ void CSiaDriveDlg::OnTimer(UINT_PTR nIDEvent)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CSiaDriveDlg::SetWalletInfo()
|
||||||
|
{
|
||||||
|
SiaCurrency confirmed;
|
||||||
|
_siaApi.GetWallet()->GetConfirmedBalance(confirmed);
|
||||||
|
|
||||||
|
SiaCurrency unconfirmed;
|
||||||
|
_siaApi.GetWallet()->GetUnonfirmedBalance(unconfirmed);
|
||||||
|
|
||||||
|
SiaCurrency total = confirmed + unconfirmed;
|
||||||
|
|
||||||
|
_walletBalanceConfirmed = SiaCurrencyToString(confirmed).c_str();
|
||||||
|
_walletBalanceUnconfirmed = SiaCurrencyToString(unconfirmed).c_str();
|
||||||
|
_walletBalanceTotal = SiaCurrencyToString(total).c_str();
|
||||||
|
}
|
||||||
|
|
||||||
void CSiaDriveDlg::UpdateUi()
|
void CSiaDriveDlg::UpdateUi()
|
||||||
{
|
{
|
||||||
_serverVersion = _siaApi.GetServerVersion().c_str();
|
_serverVersion = _siaApi.GetServerVersion().c_str();
|
||||||
|
SetWalletInfo();
|
||||||
|
|
||||||
switch (_siaConfig.GetUI_Main_TabIndex())
|
switch (_siaConfig.GetUI_Main_TabIndex())
|
||||||
{
|
{
|
||||||
case WALLET_TAB:
|
case WALLET_TAB:
|
||||||
@@ -208,17 +231,6 @@ void CSiaDriveDlg::DisplayWalletTab()
|
|||||||
{
|
{
|
||||||
if (_siaApi.GetWallet()->GetCreated())
|
if (_siaApi.GetWallet()->GetCreated())
|
||||||
{
|
{
|
||||||
SiaCurrency confirmed;
|
|
||||||
_siaApi.GetWallet()->GetConfirmedBalance(confirmed);
|
|
||||||
|
|
||||||
SiaCurrency unconfirmed;
|
|
||||||
_siaApi.GetWallet()->GetUnonfirmedBalance(unconfirmed);
|
|
||||||
|
|
||||||
SiaCurrency total = confirmed + unconfirmed;
|
|
||||||
|
|
||||||
_walletBalanceConfirmed = SiaCurrencyToString(confirmed).c_str();
|
|
||||||
_walletBalanceUnconfirmed = SiaCurrencyToString(unconfirmed).c_str();
|
|
||||||
_walletBalanceTotal = SiaCurrencyToString(total).c_str();
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@@ -42,12 +42,14 @@ protected:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void DisplayWalletTab();
|
void DisplayWalletTab();
|
||||||
|
void SetWalletInfo();
|
||||||
void UpdateUi();
|
void UpdateUi();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CSiaDriveConfig _siaConfig;
|
CSiaDriveConfig _siaConfig;
|
||||||
CSiaApi _siaApi;
|
CSiaApi _siaApi;
|
||||||
CString _serverVersion;
|
CString _serverVersion;
|
||||||
|
CString _clientVersion;
|
||||||
CString _walletBalanceTotal;
|
CString _walletBalanceTotal;
|
||||||
CString _walletBalanceConfirmed;
|
CString _walletBalanceConfirmed;
|
||||||
CString _walletBalanceUnconfirmed;
|
CString _walletBalanceUnconfirmed;
|
||||||
|
Reference in New Issue
Block a user