2009-09-07 19:23:46 +00:00
|
|
|
#include "AppConfig.h"
|
|
|
|
#include "PathUtils.h"
|
|
|
|
#include "Utf8.h"
|
|
|
|
#if !defined(WIN32)
|
|
|
|
#include <pwd.h>
|
|
|
|
#endif
|
|
|
|
|
2010-07-22 04:09:16 +00:00
|
|
|
#define BASE_DATA_PATH L"Play Data Files"
|
2009-09-07 19:23:46 +00:00
|
|
|
#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)
|
|
|
|
{
|
2011-04-08 02:38:32 +00:00
|
|
|
return Utf8::ConvertTo(path.wstring());
|
2009-09-07 19:23:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CConfig::PathType CAppConfig::BuildConfigPath()
|
|
|
|
{
|
|
|
|
#if defined(MACOSX)
|
|
|
|
passwd* userInfo = getpwuid(getuid());
|
|
|
|
if(userInfo == NULL) return DEFAULT_CONFIG_PATH;
|
2010-07-22 04:09:16 +00:00
|
|
|
return wstring(Utf8::ConvertFrom(userInfo->pw_dir)) + L"/Library/Preferences/com.vapps.Play.xml";
|
2009-09-07 19:23:46 +00:00
|
|
|
#elif defined(WIN32)
|
|
|
|
CConfig::PathType userPath(GetBasePath());
|
|
|
|
PathUtils::EnsurePathExists(userPath);
|
|
|
|
return (userPath / L"Config.xml");
|
|
|
|
#else
|
|
|
|
return DEFAULT_CONFIG_PATH;
|
|
|
|
#endif
|
|
|
|
}
|