More changes
This commit is contained in:
@@ -6,11 +6,7 @@
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
#ifdef _UNICODE
|
||||
#define String std::wstring
|
||||
#else
|
||||
#define String std::wstring
|
||||
#endif
|
||||
|
||||
#define NS_BEGIN(n) namespace n {
|
||||
|
||||
@@ -30,6 +26,12 @@ get_access:\
|
||||
set_access:\
|
||||
const type& Set##name(const type& value) { _##name = value; return _##name; }
|
||||
|
||||
#define JProperty(type, name, get_access, set_access, json_doc) \
|
||||
get_access:\
|
||||
type Get##name() const { return json_doc[#name].get<type>();}\
|
||||
set_access:\
|
||||
type Set##name(const type& value) { json_doc[#name] = value; return value; }
|
||||
|
||||
struct SiaHostConfig
|
||||
{
|
||||
String HostName;
|
||||
@@ -37,4 +39,6 @@ struct SiaHostConfig
|
||||
String RequiredVersion;
|
||||
};
|
||||
|
||||
#define API_SUCCESS(t, x) (x == t::Success)
|
||||
#define API_SUCCESS(t, x) (x == t::Success)
|
||||
|
||||
#define DEFAULT_CONFIG_FILE_PATH L".\\Config\\SiaDriveConfig.json"
|
@@ -194,6 +194,7 @@
|
||||
<ClCompile Include="SiaApi.cpp" />
|
||||
<ClCompile Include="SiaCurl.cpp" />
|
||||
<ClCompile Include="SiaDrive.Api.cpp" />
|
||||
<ClCompile Include="SiaDriveConfig.cpp" />
|
||||
<ClCompile Include="SiaWallet.cpp" />
|
||||
<ClCompile Include="stdafx.cpp">
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
|
||||
@@ -209,6 +210,7 @@
|
||||
<ClInclude Include="SiaCommon.h" />
|
||||
<ClInclude Include="SiaCurl.h" />
|
||||
<ClInclude Include="SiaDrive.Api.h" />
|
||||
<ClInclude Include="SiaDriveConfig.h" />
|
||||
<ClInclude Include="stdafx.h" />
|
||||
<ClInclude Include="targetver.h" />
|
||||
</ItemGroup>
|
||||
|
@@ -33,6 +33,9 @@
|
||||
<ClCompile Include="SiaCurl.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="SiaDriveConfig.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="SiaDrive.Api.h">
|
||||
@@ -59,6 +62,9 @@
|
||||
<ClInclude Include="json.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="SiaDriveConfig.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="SiaDrive.Api.def">
|
||||
|
51
SiaDrive.Api/SiaDriveConfig.cpp
Normal file
51
SiaDrive.Api/SiaDriveConfig.cpp
Normal file
@@ -0,0 +1,51 @@
|
||||
#include "stdafx.h"
|
||||
#include "SiaDriveConfig.h"
|
||||
#include <fstream>
|
||||
using namespace Sia::Api;
|
||||
|
||||
CSiaDriveConfig::CSiaDriveConfig() :
|
||||
CSiaDriveConfig(DEFAULT_CONFIG_FILE_PATH)
|
||||
{
|
||||
}
|
||||
|
||||
CSiaDriveConfig::CSiaDriveConfig(const String& filePath) :
|
||||
_FilePath(filePath)
|
||||
{
|
||||
Load();
|
||||
}
|
||||
|
||||
CSiaDriveConfig::~CSiaDriveConfig()
|
||||
{
|
||||
Save();
|
||||
}
|
||||
|
||||
void CSiaDriveConfig::LoadDefaults()
|
||||
{
|
||||
SetUI_Main_TabIndex(0);
|
||||
}
|
||||
|
||||
void CSiaDriveConfig::Load( )
|
||||
{
|
||||
CFile f;
|
||||
if (f.Open(GetFilePath().c_str(), CFile::modeRead))
|
||||
{
|
||||
std::string s;
|
||||
s.resize(f.GetLength());
|
||||
|
||||
f.Read(&s[0], s.length());
|
||||
|
||||
f.Close();
|
||||
|
||||
_configDocument = json::parse(s.begin(), s.end());
|
||||
}
|
||||
else
|
||||
{
|
||||
LoadDefaults();
|
||||
Save();
|
||||
}
|
||||
}
|
||||
|
||||
void CSiaDriveConfig::Save() const
|
||||
{
|
||||
std::ofstream(CW2A(GetFilePath().c_str())) << std::setw(2) << _configDocument << std::endl;
|
||||
}
|
31
SiaDrive.Api/SiaDriveConfig.h
Normal file
31
SiaDrive.Api/SiaDriveConfig.h
Normal file
@@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
#include <SiaCommon.h>
|
||||
|
||||
NS_BEGIN(Sia)
|
||||
NS_BEGIN(Api)
|
||||
|
||||
class AFX_EXT_CLASS CSiaDriveConfig
|
||||
{
|
||||
public:
|
||||
CSiaDriveConfig();
|
||||
|
||||
CSiaDriveConfig(const String& filePath);
|
||||
|
||||
public:
|
||||
~CSiaDriveConfig();
|
||||
|
||||
Property(String, FilePath, public, private)
|
||||
JProperty(std::uint8_t, UI_Main_TabIndex, public, private, _configDocument)
|
||||
|
||||
private:
|
||||
json _configDocument;
|
||||
|
||||
private:
|
||||
void LoadDefaults();
|
||||
|
||||
void Load( );
|
||||
|
||||
void Save() const;
|
||||
};
|
||||
|
||||
NS_END(2)
|
@@ -1,30 +1,33 @@
|
||||
<HTML>
|
||||
<HEAD>
|
||||
</HEAD>
|
||||
<BODY ID=CSiaDriveDlg BGCOLOR=LIGHTGREY style="font-family:MS Shell Dlg;font-size:8">
|
||||
<div id="main_window">
|
||||
<TABLE WIDTH=100% HEIGHT=100%>
|
||||
<TR WIDTH=100% HEIGHT=45%>
|
||||
<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">
|
||||
<div id="wallet_tab"></div>
|
||||
<div id="host_tab"></div>
|
||||
<div id="mount_tab"></div>
|
||||
</tr>
|
||||
<TR WIDTH=100% HEIGHT=100%>
|
||||
<TD ALIGN=RIGHT VALIGN=BOTTOM>
|
||||
<BUTTON STYLE="WIDTH:100" ID="ButtonOK">OK</BUTTON> <BUTTON STYLE="WIDTH:100" ID="ButtonCancel">Exit</BUTTON>
|
||||
</TD>
|
||||
</TR>
|
||||
</TABLE>
|
||||
</div>
|
||||
<div id="exit_window" style="display: none" align="center">
|
||||
<BUTTON STYLE="WIDTH:100" ID="ExitYes">Yes</BUTTON> <BUTTON STYLE="WIDTH:100" ID="ExitNo">No</BUTTON>
|
||||
</div>
|
||||
</BODY>
|
||||
<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>
|
||||
</div>
|
||||
<div id="main_window">
|
||||
<TABLE WIDTH=100% HEIGHT=100%>
|
||||
<TR WIDTH=100% HEIGHT=45%>
|
||||
<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">
|
||||
<div id="wallet_tab"></div>
|
||||
<div id="host_tab"></div>
|
||||
<div id="mount_tab"></div>
|
||||
</tr>
|
||||
<TR WIDTH=100% HEIGHT=100%>
|
||||
<TD ALIGN=RIGHT VALIGN=BOTTOM>
|
||||
<BUTTON STYLE="WIDTH: 100" ID="ButtonOK">OK</BUTTON> <BUTTON STYLE="WIDTH: 100" ID="ButtonCancel">Exit</BUTTON>
|
||||
</TD>
|
||||
</TR>
|
||||
</TABLE>
|
||||
</div>
|
||||
<div id="exit_window" style="display: none" align="center">
|
||||
<BUTTON STYLE="WIDTH: 100" ID="ExitYes">Yes</BUTTON> <BUTTON STYLE="WIDTH: 100" ID="ExitNo">No</BUTTON>
|
||||
</div>
|
||||
</BODY>
|
||||
</HTML>
|
||||
|
@@ -63,6 +63,7 @@ CSiaDriveDlg::CSiaDriveDlg(CWnd* pParent /*=NULL*/)
|
||||
void CSiaDriveDlg::DoDataExchange(CDataExchange* pDX)
|
||||
{
|
||||
CDHtmlDialog::DoDataExchange(pDX);
|
||||
DDX_DHtml_ElementInnerText(pDX, _T("ServerVersion"), _serverVersion);
|
||||
}
|
||||
|
||||
BEGIN_MESSAGE_MAP(CSiaDriveDlg, CDHtmlDialog)
|
||||
@@ -100,9 +101,7 @@ BOOL CSiaDriveDlg::OnInitDialog()
|
||||
// when the application's main window is not a dialog
|
||||
SetIcon(m_hIcon, TRUE); // Set big icon
|
||||
SetIcon(m_hIcon, FALSE); // Set small icon
|
||||
|
||||
String version = _siaApi.GetServerVersion();
|
||||
|
||||
|
||||
return TRUE; // return TRUE unless you set the focus to a control
|
||||
}
|
||||
|
||||
@@ -166,3 +165,21 @@ HRESULT CSiaDriveDlg::OnButtonCancel(IHTMLElement* /*pElement*/)
|
||||
OnCancel();
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
void CSiaDriveDlg::OnDocumentComplete(LPDISPATCH, LPCTSTR)
|
||||
{
|
||||
_serverVersion = _siaApi.GetServerVersion().c_str();
|
||||
if (_serverVersion)
|
||||
{
|
||||
if (_siaApi.GetWallet()->GetCreated())
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
UpdateData(FALSE);
|
||||
}
|
@@ -30,6 +30,8 @@ protected:
|
||||
|
||||
// Generated message map functions
|
||||
virtual BOOL OnInitDialog();
|
||||
virtual void OnDocumentComplete(LPDISPATCH pDisp, LPCTSTR szUrl);
|
||||
|
||||
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
|
||||
afx_msg void OnPaint();
|
||||
afx_msg HCURSOR OnQueryDragIcon();
|
||||
@@ -38,4 +40,5 @@ protected:
|
||||
|
||||
private:
|
||||
CSiaApi _siaApi;
|
||||
CString _serverVersion;
|
||||
};
|
||||
|
@@ -22,5 +22,5 @@ namespace UnitTests
|
||||
}
|
||||
};
|
||||
|
||||
Daemon SiaApi::_daemon;
|
||||
DEFINE_DAEMON(SiaApi);
|
||||
}
|
@@ -73,5 +73,5 @@ namespace UnitTests
|
||||
}
|
||||
};
|
||||
|
||||
Daemon SiaCurl::_daemon;
|
||||
DEFINE_DAEMON(SiaCurl);
|
||||
}
|
20
UnitTests/SiaDriveConfigTests.cpp
Normal file
20
UnitTests/SiaDriveConfigTests.cpp
Normal file
@@ -0,0 +1,20 @@
|
||||
#include "stdafx.h"
|
||||
#include "CppUnitTest.h"
|
||||
#include "SiaDriveConfig.h"
|
||||
|
||||
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
|
||||
|
||||
namespace UnitTests
|
||||
{
|
||||
TEST_CLASS(SiaDriveConfig)
|
||||
{
|
||||
public:
|
||||
TEST_METHOD(DefaultFileCreation)
|
||||
{
|
||||
Sia::Api::CSiaDriveConfig cfg(L".\\test_cfg.json");
|
||||
Assert::AreEqual(static_cast<uint8_t>(0), cfg.GetUI_Main_TabIndex());
|
||||
Assert::IsTrue(PathFileExists(L".\\test_cfg.json"));
|
||||
Assert::AreEqual(L".\\test_cfg.json", cfg.GetFilePath().c_str());
|
||||
}
|
||||
};
|
||||
}
|
@@ -43,5 +43,5 @@ namespace UnitTests
|
||||
}
|
||||
};
|
||||
|
||||
Daemon SiaWalletApi::_daemon;
|
||||
DEFINE_DAEMON(SiaWalletApi);
|
||||
}
|
@@ -1,15 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
#define TEST_SERVER_AND_PORT L"localhost", 19980
|
||||
#define TEST_SERVER_HOST L"localhost"
|
||||
#define TEST_SERVER_PORT 11980
|
||||
#define TEST_SERVER_AND_PORT TEST_SERVER_HOST, TEST_SERVER_PORT
|
||||
#define TEST_SERVER_VERSION L"1.1.0"
|
||||
|
||||
using namespace Sia::Api;
|
||||
|
||||
class Daemon
|
||||
{
|
||||
public:
|
||||
~Daemon()
|
||||
{
|
||||
Stop();
|
||||
}
|
||||
|
||||
private:
|
||||
PROCESS_INFORMATION pi;
|
||||
STARTUPINFO si;
|
||||
|
||||
private:
|
||||
void Cleanup()
|
||||
{
|
||||
@@ -26,17 +35,18 @@ private:
|
||||
CloseHandle(pi.hProcess);
|
||||
CloseHandle(pi.hThread);
|
||||
}
|
||||
|
||||
ZeroMemory(&si, sizeof(si));
|
||||
si.cb = sizeof(si);
|
||||
ZeroMemory(&pi, sizeof(pi));
|
||||
}
|
||||
|
||||
public:
|
||||
void Start()
|
||||
{
|
||||
Cleanup();
|
||||
ZeroMemory(&si, sizeof(si));
|
||||
si.cb = sizeof(si);
|
||||
ZeroMemory(&pi, sizeof(pi));
|
||||
|
||||
String szCmdline = L"\"..\\..\\3rd-party\\Sia-v1.1.0-windows-amd64\\siad.exe\" -d .\\data --api-addr localhost:19980";
|
||||
String szCmdline = L"\"..\\..\\3rd-party\\Sia-v1.1.0-windows-amd64\\siad.exe\" -d .\\data --api-addr " + String(TEST_SERVER_HOST) + L":" + std::to_wstring(TEST_SERVER_PORT) + L" --no-bootstrap";
|
||||
CreateProcess(nullptr, &szCmdline[0], nullptr, nullptr, TRUE, 0, nullptr, nullptr, &si, &pi);
|
||||
}
|
||||
|
||||
@@ -67,4 +77,7 @@ public:
|
||||
TEST_CLASS_CLEANUP(StopDaemon)\
|
||||
{\
|
||||
_daemon.Stop();\
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#define DEFINE_DAEMON(class) Daemon class::_daemon
|
@@ -163,6 +163,10 @@
|
||||
<SubType>
|
||||
</SubType>
|
||||
</ClCompile>
|
||||
<ClCompile Include="SiaDriveConfigTests.cpp">
|
||||
<SubType>
|
||||
</SubType>
|
||||
</ClCompile>
|
||||
<ClCompile Include="SiaWalletApiTests.cpp">
|
||||
<SubType>
|
||||
</SubType>
|
||||
|
@@ -38,5 +38,8 @@
|
||||
<ClCompile Include="SiaWalletApiTests.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="SiaDriveConfigTests.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
Reference in New Issue
Block a user