1
0

Move configuration and logging to local application data

This commit is contained in:
Scott E. Graves
2017-04-20 22:10:08 -05:00
parent d7445d0647
commit eceedb7af5
5 changed files with 26 additions and 12 deletions

View File

@@ -43,6 +43,7 @@ public:
FilePath& SkipRoot();
FilePath& StripToFileName();
bool CreateEmptyFile();
FilePath& Resolve();
public:
FilePath& operator=(const FilePath& filePath);

View File

@@ -94,8 +94,8 @@ const SiaCurrency SIA_DEFAULT_MINIMUM_FUNDS = 4000;
const std::uint32_t SIA_DEFAULT_CONTRACT_LENGTH = SIA_BLOCKS_PER_MONTH * 3;
const std::uint32_t SIA_DEFAULT_RENEW_WINDOW = SIA_DEFAULT_CONTRACT_LENGTH / 3;
#define DEFAULT_CONFIG_FILE_PATH L"./config/siadriveconfig.json"
#define DEFAULT_RENTER_DB_FILE_PATH L"./config/renter_upload.db3"
#define DEFAULT_CONFIG_FILE_PATH L"~/siadrive/siadriveconfig.json"
#define DEFAULT_RENTER_DB_FILE_PATH L"~/siadrive/renter_upload.db3"
#define Property(type, name, get_access, set_access) \
private:\

View File

@@ -263,4 +263,15 @@ bool FilePath::CreateEmptyFile()
}
return false;
}
FilePath& FilePath::Resolve()
{
#ifdef _WIN32
_path = FinalizePath(_path.Replace("~", GetAppDataDirectory()));
#else
a
#endif
return *this;
}

View File

@@ -20,8 +20,8 @@ void CLoggingConsumer::ProcessEvent(const CEvent& eventData)
if (eventData.GetEventLevel() <= GetEventLevel())
{
// TODO Implement rolling/max size and timestamp
FilePath logPath("logs\\siadrive.log");
logPath.MakeAbsolute();
FilePath logPath("~\\siadrive\\logs\\siadrive.log");
logPath.Resolve();
FilePath(logPath).RemoveFileName().CreateDirectory();
std::time_t now = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());

View File

@@ -10,11 +10,8 @@ CSiaDriveConfig::CSiaDriveConfig() :
}
CSiaDriveConfig::CSiaDriveConfig(const SString& filePath) :
_FilePath(filePath)
_FilePath(FilePath(filePath).Resolve())
{
#ifdef _DEBUG
FilePath(filePath).DeleteFile();
#endif
Load();
}
@@ -25,14 +22,13 @@ CSiaDriveConfig::~CSiaDriveConfig()
void CSiaDriveConfig::LoadDefaults()
{
SetRenter_UploadDbFilePath(static_cast<SString>(FilePath(DEFAULT_RENTER_DB_FILE_PATH)));
SetRenter_UploadDbFilePath(static_cast<SString>(FilePath(DEFAULT_RENTER_DB_FILE_PATH).Resolve()));
FilePath tempFolder = FilePath::GetTempDirectory();
SetTempFolder(static_cast<SString>(tempFolder));
FilePath cacheFolder(FilePath::GetAppDataDirectory(), "SiaDrive");
cacheFolder.Append("Cache");
FilePath cacheFolder(FilePath::GetAppDataDirectory(), "siadrive");
cacheFolder.Append("cache");
SetCacheFolder(static_cast<SString>(cacheFolder));
SetHostNameOrIp("localhost");
@@ -57,6 +53,12 @@ void CSiaDriveConfig::Load( )
LoadDefaults();
Save();
}
FilePath cacheFolder(GetCacheFolder());
if (!cacheFolder.IsDirectory())
{
cacheFolder.CreateDirectory();
}
}
void CSiaDriveConfig::Save() const