68 lines
1.2 KiB
C++
68 lines
1.2 KiB
C++
#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)
|
|
{
|
|
#ifdef DEBUG
|
|
DeleteFile(filePath.c_str());
|
|
#endif
|
|
Load();
|
|
}
|
|
|
|
CSiaDriveConfig::~CSiaDriveConfig()
|
|
{
|
|
Save();
|
|
}
|
|
|
|
void CSiaDriveConfig::LoadDefaults()
|
|
{
|
|
SetUI_Main_TabIndex(0);
|
|
SetRenter_UploadDbFilePath("./Config/renter_upload.db3");
|
|
|
|
std::string tempFolder;
|
|
tempFolder.resize(MAX_PATH + 1);
|
|
::GetTempPathA(MAX_PATH, &tempFolder[0]);
|
|
SetTempFolder(tempFolder);
|
|
}
|
|
|
|
void CSiaDriveConfig::Load( )
|
|
{
|
|
CFile f;
|
|
if (f.Open(GetFilePath().c_str(), CFile::modeRead))
|
|
{
|
|
std::string s;
|
|
s.resize(f.GetLength());
|
|
|
|
f.Read(&s[0], static_cast<UINT>(s.length()));
|
|
|
|
f.Close();
|
|
|
|
_configDocument = json::parse(s.begin(), s.end());
|
|
}
|
|
else
|
|
{
|
|
LoadDefaults();
|
|
Save();
|
|
}
|
|
}
|
|
|
|
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;
|
|
} |