File tree and file changes
This commit is contained in:
@@ -26,11 +26,14 @@ public:
|
|||||||
Japanese
|
Japanese
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class _CSiaFileTree;
|
||||||
class AFX_EXT_CLASS _CSiaFile
|
class AFX_EXT_CLASS _CSiaFile
|
||||||
{
|
{
|
||||||
friend CSiaApi;
|
friend CSiaApi;
|
||||||
|
friend _CSiaFileTree;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
_CSiaFile(CSiaCurl& siaCurl);
|
_CSiaFile(CSiaCurl& siaCurl, const json& fileJson);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
~_CSiaFile();
|
~_CSiaFile();
|
||||||
@@ -40,12 +43,18 @@ public:
|
|||||||
|
|
||||||
// Properties
|
// Properties
|
||||||
Property(String, SiaPath, public, private)
|
Property(String, SiaPath, public, private)
|
||||||
|
Property(std::uint64_t, FileSize, public, private)
|
||||||
|
Property(bool, Available, public, private)
|
||||||
|
Property(bool, Renewing, public, private)
|
||||||
|
Property(std::uint32_t, Redundancy, public, private)
|
||||||
|
Property(std::uint32_t, UploadProgress, public, private)
|
||||||
|
Property(std::uint32_t, Expiration, public, private)
|
||||||
};
|
};
|
||||||
|
|
||||||
class AFX_EXT_CLASS _CSiaFileTree
|
class AFX_EXT_CLASS _CSiaFileTree
|
||||||
{
|
{
|
||||||
friend CSiaApi;
|
friend CSiaApi;
|
||||||
private:
|
public:
|
||||||
_CSiaFileTree(CSiaCurl& siaCurl);
|
_CSiaFileTree(CSiaCurl& siaCurl);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@@ -60,6 +69,8 @@ public:
|
|||||||
public:
|
public:
|
||||||
void BuildTree(const json& result);
|
void BuildTree(const json& result);
|
||||||
|
|
||||||
|
std::vector<std::shared_ptr<_CSiaFile>> GetFileList() const;
|
||||||
|
|
||||||
std::vector<std::shared_ptr<_CSiaFile>> QueryFiles(String query) const;
|
std::vector<std::shared_ptr<_CSiaFile>> QueryFiles(String query) const;
|
||||||
|
|
||||||
std::shared_ptr<_CSiaFile> GetFile(const String& siaPath) const;
|
std::shared_ptr<_CSiaFile> GetFile(const String& siaPath) const;
|
||||||
|
@@ -3,8 +3,15 @@
|
|||||||
|
|
||||||
using namespace Sia::Api;
|
using namespace Sia::Api;
|
||||||
|
|
||||||
CSiaApi::_CSiaFile::_CSiaFile(CSiaCurl& siaCurl) :
|
CSiaApi::_CSiaFile::_CSiaFile(CSiaCurl& siaCurl, const json& fileJson) :
|
||||||
_siaCurl(siaCurl)
|
_siaCurl(siaCurl),
|
||||||
|
_SiaPath(CA2W(fileJson["siapath"].get<std::string>().c_str())),
|
||||||
|
_FileSize(fileJson["filesize"].get<std::uint64_t>()),
|
||||||
|
_Available(fileJson["available"].get<bool>()),
|
||||||
|
_Renewing(fileJson["renewing"].get<bool>()),
|
||||||
|
_Redundancy(fileJson["redundancy"].get<std::uint32_t>()),
|
||||||
|
_UploadProgress(fileJson["uploadprogress"].get<std::uint32_t>()),
|
||||||
|
_Expiration(fileJson["expiration"].get<std::uint32_t>())
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -29,6 +29,11 @@ CSiaApi::_CSiaFileTree::~_CSiaFileTree()
|
|||||||
|
|
||||||
void CSiaApi::_CSiaFileTree::BuildTree(const json& result)
|
void CSiaApi::_CSiaFileTree::BuildTree(const json& result)
|
||||||
{
|
{
|
||||||
|
_fileList.clear();
|
||||||
|
for (const auto& file : result["files"])
|
||||||
|
{
|
||||||
|
_fileList.push_back(CSiaFilePtr(new CSiaFile(_siaCurl, file)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CSiaApi::_CSiaFileTree::FileExists(const String& siaPath) const
|
bool CSiaApi::_CSiaFileTree::FileExists(const String& siaPath) const
|
||||||
@@ -41,6 +46,11 @@ bool CSiaApi::_CSiaFileTree::FileExists(const String& siaPath) const
|
|||||||
return (result != _fileList.end());
|
return (result != _fileList.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CSiaFileCollection CSiaApi::_CSiaFileTree::GetFileList() const
|
||||||
|
{
|
||||||
|
return _fileList;
|
||||||
|
}
|
||||||
|
|
||||||
CSiaFilePtr CSiaApi::_CSiaFileTree::GetFile(const String& siaPath) const
|
CSiaFilePtr CSiaApi::_CSiaFileTree::GetFile(const String& siaPath) const
|
||||||
{
|
{
|
||||||
auto result = std::find_if(_fileList.begin(), _fileList.end(), [&](const CSiaFilePtr& item)->bool
|
auto result = std::find_if(_fileList.begin(), _fileList.end(), [&](const CSiaFilePtr& item)->bool
|
||||||
|
49
UnitTests/SiaApiFileTreeTests.cpp
Normal file
49
UnitTests/SiaApiFileTreeTests.cpp
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
#include "stdafx.h"
|
||||||
|
#include "CppUnitTest.h"
|
||||||
|
#include <SiaApi.h>
|
||||||
|
#include "UnitTestConfig.h"
|
||||||
|
|
||||||
|
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
|
||||||
|
|
||||||
|
namespace UnitTests
|
||||||
|
{
|
||||||
|
TEST_CLASS(SiaApiFileTree)
|
||||||
|
{
|
||||||
|
DAEMON_TEST()
|
||||||
|
|
||||||
|
private:
|
||||||
|
const SiaHostConfig _hostConfig = { TEST_SERVER_AND_PORT, TEST_SERVER_VERSION };
|
||||||
|
|
||||||
|
public:
|
||||||
|
TEST_METHOD(BuildFileTree)
|
||||||
|
{
|
||||||
|
CSiaCurl siaCurl;
|
||||||
|
siaCurl.SetHostConfig(_hostConfig);
|
||||||
|
|
||||||
|
json j =
|
||||||
|
{
|
||||||
|
{"files",
|
||||||
|
{
|
||||||
|
{ { "siapath", "root/sub1/file1.txt" },{ "filesize", 1 },{ "available", true },{ "renewing", true },{ "redundancy", 5 },{ "uploadprogress", 100 },{ "expiration", 60000 } },
|
||||||
|
{ { "siapath", "root/sub1/file2.txt" },{ "filesize", 2 },{ "available", true },{ "renewing", true },{ "redundancy", 5 },{ "uploadprogress", 100 },{ "expiration", 60000 } },
|
||||||
|
{ { "siapath", "root/sub1/file3.txt" },{ "filesize", 3 },{ "available", true },{ "renewing", true },{ "redundancy", 5 },{ "uploadprogress", 100 },{ "expiration", 60000 } }
|
||||||
|
}}
|
||||||
|
};
|
||||||
|
|
||||||
|
CSiaFileTree ft(siaCurl);
|
||||||
|
ft.BuildTree(j);
|
||||||
|
auto fileList = ft.GetFileList();
|
||||||
|
Assert::AreEqual(static_cast<size_t>(3), fileList.size());
|
||||||
|
|
||||||
|
Assert::AreEqual(L"root/sub1/file1.txt", fileList[0]->GetSiaPath().c_str());
|
||||||
|
Assert::AreEqual(L"root/sub1/file2.txt", fileList[1]->GetSiaPath().c_str());
|
||||||
|
Assert::AreEqual(L"root/sub1/file3.txt", fileList[2]->GetSiaPath().c_str());
|
||||||
|
|
||||||
|
Assert::AreEqual(static_cast<std::uint64_t>(1), fileList[0]->GetFileSize());
|
||||||
|
Assert::AreEqual(static_cast<std::uint64_t>(2), fileList[1]->GetFileSize());
|
||||||
|
Assert::AreEqual(static_cast<std::uint64_t>(3), fileList[2]->GetFileSize());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
DEFINE_DAEMON(SiaApiFileTree);
|
||||||
|
}
|
@@ -159,6 +159,10 @@
|
|||||||
<ClInclude Include="UnitTestConfig.h" />
|
<ClInclude Include="UnitTestConfig.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<ClCompile Include="SiaApiFileTreeTests.cpp">
|
||||||
|
<SubType>
|
||||||
|
</SubType>
|
||||||
|
</ClCompile>
|
||||||
<ClCompile Include="SiaApiTests.cpp">
|
<ClCompile Include="SiaApiTests.cpp">
|
||||||
<SubType>
|
<SubType>
|
||||||
</SubType>
|
</SubType>
|
||||||
|
@@ -41,5 +41,8 @@
|
|||||||
<ClCompile Include="SiaDriveConfigTests.cpp">
|
<ClCompile Include="SiaDriveConfigTests.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="SiaApiFileTreeTests.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
Reference in New Issue
Block a user