Play-/Source/AppConfig.cpp

61 lines
1.3 KiB
C++
Raw Normal View History

#include "AppConfig.h"
#include "PathUtils.h"
#include "Utf8.h"
#if !defined(WIN32)
#include <pwd.h>
#endif
#define BASE_DATA_PATH L"Play Data Files"
#define DEFAULT_CONFIG_PATH (L"config.xml")
using namespace Framework;
using namespace boost;
using namespace std;
CAppConfig::CAppConfig() :
CConfig(BuildConfigPath())
{
}
CAppConfig::~CAppConfig()
{
}
CConfig::PathType CAppConfig::GetBasePath()
{
#if defined(WIN32)
return (PathUtils::GetPersonalDataPath() / BASE_DATA_PATH);
#elif defined(MACOSX)
return (Utf8ToPath(PathUtils::GetHomePath().string().c_str()) / BASE_DATA_PATH);
#else
return CConfig::PathType();
#endif
}
CConfig::PathType CAppConfig::Utf8ToPath(const char* path)
{
return CConfig::PathType(Utf8::ConvertFrom(path));
}
string CAppConfig::PathToUtf8(const CConfig::PathType& path)
{
return Utf8::ConvertTo(path.wstring());
}
CConfig::PathType CAppConfig::BuildConfigPath()
{
#if defined(MACOSX)
passwd* userInfo = getpwuid(getuid());
if(userInfo == NULL) return DEFAULT_CONFIG_PATH;
return wstring(Utf8::ConvertFrom(userInfo->pw_dir)) + L"/Library/Preferences/com.vapps.Play.xml";
#elif defined(WIN32)
CConfig::PathType userPath(GetBasePath());
PathUtils::EnsurePathExists(userPath);
return (userPath / L"Config.xml");
#else
return DEFAULT_CONFIG_PATH;
#endif
}