More changes
This commit is contained in:
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;
|
||||
}
|
Reference in New Issue
Block a user