More stuff
This commit is contained in:
@@ -2,4 +2,4 @@
|
||||
pushd "%~dp0%"
|
||||
|
||||
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)
|
||||
{
|
||||
return value.ToWString();
|
||||
ttmath::Conv conv;
|
||||
conv.base = 10;
|
||||
conv.round = 8;
|
||||
|
||||
return value.ToWString(conv);
|
||||
}
|
||||
|
||||
NS_END(2)
|
@@ -46,6 +46,42 @@ std::string CSiaCurl::ConstructPath(const String& relativePath) const
|
||||
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
|
||||
{
|
||||
curl_easy_reset(_curlHandle);
|
||||
@@ -62,24 +98,7 @@ SiaCurlError CSiaCurl::_Get(const String& path, json& response) const
|
||||
curl_easy_setopt(_curlHandle, CURLOPT_WRITEDATA, &result);
|
||||
const CURLcode res = curl_easy_perform(_curlHandle);
|
||||
|
||||
SiaCurlError ret;
|
||||
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;
|
||||
return ProcessResponse(res, result, response);
|
||||
}
|
||||
|
||||
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);
|
||||
const CURLcode res = curl_easy_perform(_curlHandle);
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
ret = ProcessResponse(res, result, response);
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
@@ -15,6 +15,7 @@ public:
|
||||
InvalidRequiredVersion,
|
||||
NoResponse,
|
||||
InvalidRequestPath,
|
||||
HttpError,
|
||||
UnknownFailure
|
||||
};
|
||||
|
||||
@@ -37,9 +38,11 @@ private:
|
||||
static _SiaCurlError CheckApiError(const json& result);
|
||||
|
||||
private:
|
||||
static _SiaCurlError CheckHttpError(const std::string& result);
|
||||
std::string ConstructPath(const String& relativePath) const;
|
||||
_SiaCurlError _Get(const String& path, json& response) const;
|
||||
bool CheckVersion(_SiaCurlError& error) const;
|
||||
_SiaCurlError ProcessResponse(const int& res, const std::string& result, json& response) const;
|
||||
|
||||
public:
|
||||
String GetServerVersion() const;
|
||||
|
@@ -216,7 +216,6 @@
|
||||
<ClInclude Include="targetver.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="..\3rd-party\ttmath-0.9.3\ttmath\ttmathuint_x86_64_msvc.asm" />
|
||||
<None Include="res\SiaDriveApi.rc2" />
|
||||
<None Include="SiaDrive.Api.def" />
|
||||
</ItemGroup>
|
||||
|
@@ -76,9 +76,6 @@
|
||||
<None Include="res\SiaDriveApi.rc2">
|
||||
<Filter>Resource Files</Filter>
|
||||
</None>
|
||||
<None Include="..\3rd-party\ttmath-0.9.3\ttmath\ttmathuint_x86_64_msvc.asm">
|
||||
<Filter>Source Files</Filter>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="SiaDrive.Api.rc">
|
||||
|
@@ -47,5 +47,13 @@ void CSiaDriveConfig::Load( )
|
||||
|
||||
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;
|
||||
}
|
@@ -3,18 +3,19 @@
|
||||
</HEAD>
|
||||
<BODY ID=CSiaDriveDlg BGCOLOR=LIGHTGREY style="font-family: MS Shell Dlg; font-size:13">
|
||||
<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 id="main_window">
|
||||
<TABLE WIDTH=100% HEIGHT=100%>
|
||||
<TR WIDTH=100% HEIGHT=45%>
|
||||
<TABLE WIDTH=100% height="75%">
|
||||
<TR WIDTH=100%>
|
||||
<TD ALIGN=LEFT VALIGN=TOP>
|
||||
<input id="wallet_btn" type="button" value="Wallet"/>
|
||||
<input id="host_btn" type="button" value="Host"/>
|
||||
<input id="mount_btn" type="button" value="Mount"/>
|
||||
</TD>
|
||||
</TR>
|
||||
<tr align="center" valign="top">
|
||||
<tr width="100%" align="center" valign="top">
|
||||
<div id="wallet_tab">
|
||||
<label>Available: </label><label id="WalletBalanceConfirmed"></label><br/>
|
||||
<label>Pending: </label><label id="WalletBalanceUnconfirmed"></label><br/>
|
||||
@@ -23,7 +24,7 @@
|
||||
<div id="host_tab"></div>
|
||||
<div id="mount_tab"></div>
|
||||
</tr>
|
||||
<TR WIDTH=100% HEIGHT=100%>
|
||||
<TR WIDTH=100%">
|
||||
<TD ALIGN=RIGHT VALIGN=BOTTOM>
|
||||
<BUTTON STYLE="WIDTH: 100" ID="ButtonOK">OK</BUTTON> <BUTTON STYLE="WIDTH: 100" ID="ButtonCancel">Exit</BUTTON>
|
||||
</TD>
|
||||
|
Binary file not shown.
@@ -58,12 +58,18 @@ CSiaDriveDlg::CSiaDriveDlg(CWnd* pParent /*=NULL*/)
|
||||
_siaApi({L"localhost", 9980, L"1.1.0"})
|
||||
{
|
||||
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)
|
||||
{
|
||||
CDHtmlDialog::DoDataExchange(pDX);
|
||||
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("WalletBalanceConfirmed"), _walletBalanceConfirmed);
|
||||
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()
|
||||
{
|
||||
_serverVersion = _siaApi.GetServerVersion().c_str();
|
||||
SetWalletInfo();
|
||||
|
||||
switch (_siaConfig.GetUI_Main_TabIndex())
|
||||
{
|
||||
case WALLET_TAB:
|
||||
@@ -208,17 +231,6 @@ void CSiaDriveDlg::DisplayWalletTab()
|
||||
{
|
||||
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
|
||||
{
|
||||
|
@@ -42,12 +42,14 @@ protected:
|
||||
|
||||
private:
|
||||
void DisplayWalletTab();
|
||||
void SetWalletInfo();
|
||||
void UpdateUi();
|
||||
|
||||
private:
|
||||
CSiaDriveConfig _siaConfig;
|
||||
CSiaApi _siaApi;
|
||||
CString _serverVersion;
|
||||
CString _clientVersion;
|
||||
CString _walletBalanceTotal;
|
||||
CString _walletBalanceConfirmed;
|
||||
CString _walletBalanceUnconfirmed;
|
||||
|
Reference in New Issue
Block a user