2008-08-24 21:28:42 +00:00
|
|
|
#include "AppConfig.h"
|
|
|
|
#include "PathUtils.h"
|
2009-04-21 00:01:05 +00:00
|
|
|
#include "Utf8.h"
|
2008-08-24 21:28:42 +00:00
|
|
|
|
2009-04-21 00:01:05 +00:00
|
|
|
#define BASE_DATA_PATH L"Purei Data Files"
|
2008-08-24 21:28:42 +00:00
|
|
|
#define DEFAULT_CONFIG_PATH ("config.xml")
|
|
|
|
|
|
|
|
using namespace Framework;
|
|
|
|
using namespace boost;
|
2009-04-21 00:01:05 +00:00
|
|
|
using namespace std;
|
2008-08-24 21:28:42 +00:00
|
|
|
|
|
|
|
CAppConfig::CAppConfig() :
|
|
|
|
CConfig(BuildConfigPath())
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
CAppConfig::~CAppConfig()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2009-04-21 00:01:05 +00:00
|
|
|
CConfig::PathType CAppConfig::GetBasePath()
|
|
|
|
{
|
|
|
|
return (PathUtils::GetPersonalDataPath() / BASE_DATA_PATH);
|
|
|
|
}
|
|
|
|
|
|
|
|
CConfig::PathType CAppConfig::Utf8ToPath(const char* path)
|
|
|
|
{
|
|
|
|
#if defined(WIN32)
|
|
|
|
return CConfig::PathType(Utf8::ConvertFrom(path));
|
|
|
|
#else
|
|
|
|
return CConfig::PathType(path)
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
string CAppConfig::PathToUtf8(const CConfig::PathType& path)
|
|
|
|
{
|
|
|
|
#if defined(WIN32)
|
|
|
|
return Utf8::ConvertTo(path.string());
|
|
|
|
#else
|
|
|
|
return path.string();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2008-08-24 21:28:42 +00:00
|
|
|
CConfig::PathType CAppConfig::BuildConfigPath()
|
|
|
|
{
|
|
|
|
#if defined(MACOSX)
|
|
|
|
passwd* userInfo = getpwuid(getuid());
|
|
|
|
if(userInfo == NULL) return DEFAULT_CONFIG_PATH;
|
|
|
|
return string(userInfo->pw_dir) + "/Library/Preferences/com.vapps.Purei.xml";
|
|
|
|
#elif defined(WIN32)
|
2009-04-21 00:01:05 +00:00
|
|
|
CConfig::PathType userPath(GetBasePath());
|
2008-08-24 21:28:42 +00:00
|
|
|
PathUtils::EnsurePathExists(userPath);
|
|
|
|
return (userPath / L"Config.xml");
|
|
|
|
#else
|
|
|
|
return DEFAULT_CONFIG_PATH;
|
|
|
|
#endif
|
|
|
|
}
|