More changes
This commit is contained in:
@@ -6,11 +6,7 @@
|
|||||||
|
|
||||||
using json = nlohmann::json;
|
using json = nlohmann::json;
|
||||||
|
|
||||||
#ifdef _UNICODE
|
|
||||||
#define String std::wstring
|
#define String std::wstring
|
||||||
#else
|
|
||||||
#define String std::wstring
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define NS_BEGIN(n) namespace n {
|
#define NS_BEGIN(n) namespace n {
|
||||||
|
|
||||||
@@ -30,6 +26,12 @@ get_access:\
|
|||||||
set_access:\
|
set_access:\
|
||||||
const type& Set##name(const type& value) { _##name = value; return _##name; }
|
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
|
struct SiaHostConfig
|
||||||
{
|
{
|
||||||
String HostName;
|
String HostName;
|
||||||
@@ -37,4 +39,6 @@ struct SiaHostConfig
|
|||||||
String RequiredVersion;
|
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="SiaApi.cpp" />
|
||||||
<ClCompile Include="SiaCurl.cpp" />
|
<ClCompile Include="SiaCurl.cpp" />
|
||||||
<ClCompile Include="SiaDrive.Api.cpp" />
|
<ClCompile Include="SiaDrive.Api.cpp" />
|
||||||
|
<ClCompile Include="SiaDriveConfig.cpp" />
|
||||||
<ClCompile Include="SiaWallet.cpp" />
|
<ClCompile Include="SiaWallet.cpp" />
|
||||||
<ClCompile Include="stdafx.cpp">
|
<ClCompile Include="stdafx.cpp">
|
||||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
|
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
|
||||||
@@ -209,6 +210,7 @@
|
|||||||
<ClInclude Include="SiaCommon.h" />
|
<ClInclude Include="SiaCommon.h" />
|
||||||
<ClInclude Include="SiaCurl.h" />
|
<ClInclude Include="SiaCurl.h" />
|
||||||
<ClInclude Include="SiaDrive.Api.h" />
|
<ClInclude Include="SiaDrive.Api.h" />
|
||||||
|
<ClInclude Include="SiaDriveConfig.h" />
|
||||||
<ClInclude Include="stdafx.h" />
|
<ClInclude Include="stdafx.h" />
|
||||||
<ClInclude Include="targetver.h" />
|
<ClInclude Include="targetver.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
@@ -33,6 +33,9 @@
|
|||||||
<ClCompile Include="SiaCurl.cpp">
|
<ClCompile Include="SiaCurl.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="SiaDriveConfig.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="SiaDrive.Api.h">
|
<ClInclude Include="SiaDrive.Api.h">
|
||||||
@@ -59,6 +62,9 @@
|
|||||||
<ClInclude Include="json.hpp">
|
<ClInclude Include="json.hpp">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="SiaDriveConfig.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="SiaDrive.Api.def">
|
<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>
|
<HTML>
|
||||||
<HEAD>
|
<HEAD>
|
||||||
</HEAD>
|
</HEAD>
|
||||||
<BODY ID=CSiaDriveDlg BGCOLOR=LIGHTGREY style="font-family:MS Shell Dlg;font-size:8">
|
<BODY ID=CSiaDriveDlg BGCOLOR=LIGHTGREY style="font-family: MS Shell Dlg; font-size:13">
|
||||||
<div id="main_window">
|
<div align="right">
|
||||||
<TABLE WIDTH=100% HEIGHT=100%>
|
<label>Server Version: </label><label id="ServerVersion"></label>
|
||||||
<TR WIDTH=100% HEIGHT=45%>
|
</div>
|
||||||
<TD ALIGN=LEFT VALIGN=TOP>
|
<div id="main_window">
|
||||||
<input id="wallet_btn" type="button" value="Wallet" />
|
<TABLE WIDTH=100% HEIGHT=100%>
|
||||||
<input id="host_btn" type="button" value="Host" />
|
<TR WIDTH=100% HEIGHT=45%>
|
||||||
<input id="mount_btn" type="button" value="Mount" />
|
<TD ALIGN=LEFT VALIGN=TOP>
|
||||||
</TD>
|
<input id="wallet_btn" type="button" value="Wallet"/>
|
||||||
</TR>
|
<input id="host_btn" type="button" value="Host"/>
|
||||||
<tr align="center" valign="top">
|
<input id="mount_btn" type="button" value="Mount"/>
|
||||||
<div id="wallet_tab"></div>
|
</TD>
|
||||||
<div id="host_tab"></div>
|
</TR>
|
||||||
<div id="mount_tab"></div>
|
<tr align="center" valign="top">
|
||||||
</tr>
|
<div id="wallet_tab"></div>
|
||||||
<TR WIDTH=100% HEIGHT=100%>
|
<div id="host_tab"></div>
|
||||||
<TD ALIGN=RIGHT VALIGN=BOTTOM>
|
<div id="mount_tab"></div>
|
||||||
<BUTTON STYLE="WIDTH:100" ID="ButtonOK">OK</BUTTON> <BUTTON STYLE="WIDTH:100" ID="ButtonCancel">Exit</BUTTON>
|
</tr>
|
||||||
</TD>
|
<TR WIDTH=100% HEIGHT=100%>
|
||||||
</TR>
|
<TD ALIGN=RIGHT VALIGN=BOTTOM>
|
||||||
</TABLE>
|
<BUTTON STYLE="WIDTH: 100" ID="ButtonOK">OK</BUTTON> <BUTTON STYLE="WIDTH: 100" ID="ButtonCancel">Exit</BUTTON>
|
||||||
</div>
|
</TD>
|
||||||
<div id="exit_window" style="display: none" align="center">
|
</TR>
|
||||||
<BUTTON STYLE="WIDTH:100" ID="ExitYes">Yes</BUTTON> <BUTTON STYLE="WIDTH:100" ID="ExitNo">No</BUTTON>
|
</TABLE>
|
||||||
</div>
|
</div>
|
||||||
</BODY>
|
<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>
|
</HTML>
|
||||||
|
@@ -63,6 +63,7 @@ CSiaDriveDlg::CSiaDriveDlg(CWnd* pParent /*=NULL*/)
|
|||||||
void CSiaDriveDlg::DoDataExchange(CDataExchange* pDX)
|
void CSiaDriveDlg::DoDataExchange(CDataExchange* pDX)
|
||||||
{
|
{
|
||||||
CDHtmlDialog::DoDataExchange(pDX);
|
CDHtmlDialog::DoDataExchange(pDX);
|
||||||
|
DDX_DHtml_ElementInnerText(pDX, _T("ServerVersion"), _serverVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
BEGIN_MESSAGE_MAP(CSiaDriveDlg, CDHtmlDialog)
|
BEGIN_MESSAGE_MAP(CSiaDriveDlg, CDHtmlDialog)
|
||||||
@@ -100,9 +101,7 @@ BOOL CSiaDriveDlg::OnInitDialog()
|
|||||||
// when the application's main window is not a dialog
|
// when the application's main window is not a dialog
|
||||||
SetIcon(m_hIcon, TRUE); // Set big icon
|
SetIcon(m_hIcon, TRUE); // Set big icon
|
||||||
SetIcon(m_hIcon, FALSE); // Set small icon
|
SetIcon(m_hIcon, FALSE); // Set small icon
|
||||||
|
|
||||||
String version = _siaApi.GetServerVersion();
|
|
||||||
|
|
||||||
return TRUE; // return TRUE unless you set the focus to a control
|
return TRUE; // return TRUE unless you set the focus to a control
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -166,3 +165,21 @@ HRESULT CSiaDriveDlg::OnButtonCancel(IHTMLElement* /*pElement*/)
|
|||||||
OnCancel();
|
OnCancel();
|
||||||
return S_OK;
|
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
|
// Generated message map functions
|
||||||
virtual BOOL OnInitDialog();
|
virtual BOOL OnInitDialog();
|
||||||
|
virtual void OnDocumentComplete(LPDISPATCH pDisp, LPCTSTR szUrl);
|
||||||
|
|
||||||
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
|
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
|
||||||
afx_msg void OnPaint();
|
afx_msg void OnPaint();
|
||||||
afx_msg HCURSOR OnQueryDragIcon();
|
afx_msg HCURSOR OnQueryDragIcon();
|
||||||
@@ -38,4 +40,5 @@ protected:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
CSiaApi _siaApi;
|
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
|
#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"
|
#define TEST_SERVER_VERSION L"1.1.0"
|
||||||
|
|
||||||
using namespace Sia::Api;
|
using namespace Sia::Api;
|
||||||
|
|
||||||
class Daemon
|
class Daemon
|
||||||
{
|
{
|
||||||
|
public:
|
||||||
|
~Daemon()
|
||||||
|
{
|
||||||
|
Stop();
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PROCESS_INFORMATION pi;
|
PROCESS_INFORMATION pi;
|
||||||
STARTUPINFO si;
|
STARTUPINFO si;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void Cleanup()
|
void Cleanup()
|
||||||
{
|
{
|
||||||
@@ -26,17 +35,18 @@ private:
|
|||||||
CloseHandle(pi.hProcess);
|
CloseHandle(pi.hProcess);
|
||||||
CloseHandle(pi.hThread);
|
CloseHandle(pi.hThread);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ZeroMemory(&si, sizeof(si));
|
||||||
|
si.cb = sizeof(si);
|
||||||
|
ZeroMemory(&pi, sizeof(pi));
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void Start()
|
void Start()
|
||||||
{
|
{
|
||||||
Cleanup();
|
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);
|
CreateProcess(nullptr, &szCmdline[0], nullptr, nullptr, TRUE, 0, nullptr, nullptr, &si, &pi);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,4 +77,7 @@ public:
|
|||||||
TEST_CLASS_CLEANUP(StopDaemon)\
|
TEST_CLASS_CLEANUP(StopDaemon)\
|
||||||
{\
|
{\
|
||||||
_daemon.Stop();\
|
_daemon.Stop();\
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#define DEFINE_DAEMON(class) Daemon class::_daemon
|
@@ -163,6 +163,10 @@
|
|||||||
<SubType>
|
<SubType>
|
||||||
</SubType>
|
</SubType>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="SiaDriveConfigTests.cpp">
|
||||||
|
<SubType>
|
||||||
|
</SubType>
|
||||||
|
</ClCompile>
|
||||||
<ClCompile Include="SiaWalletApiTests.cpp">
|
<ClCompile Include="SiaWalletApiTests.cpp">
|
||||||
<SubType>
|
<SubType>
|
||||||
</SubType>
|
</SubType>
|
||||||
|
@@ -38,5 +38,8 @@
|
|||||||
<ClCompile Include="SiaWalletApiTests.cpp">
|
<ClCompile Include="SiaWalletApiTests.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="SiaDriveConfigTests.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
Reference in New Issue
Block a user