Use standard paths for storing LOOT data on Linux.

Fixes #494.
This commit is contained in:
Oliver Hamlet
2015-10-31 20:35:28 +00:00
parent d874fbb52c
commit 6dd9bc8169
3 changed files with 33 additions and 19 deletions
-4
View File
@@ -38,11 +38,7 @@ namespace loot {
const boost::filesystem::path g_path_readme = boost::filesystem::current_path() / "docs" / "LOOT Readme.html";
const boost::filesystem::path g_path_report = boost::filesystem::current_path() / "resources" / "ui" / "index.html";
const boost::filesystem::path g_path_l10n = boost::filesystem::current_path() / "resources" / "l10n";
#ifdef _WIN32
const boost::filesystem::path g_path_local = GetLocalAppDataPath() / "LOOT";
#else
const boost::filesystem::path g_path_local = boost::filesystem::current_path() / "LOOT";
#endif
const boost::filesystem::path g_path_settings = g_path_local / "settings.yaml";
const boost::filesystem::path g_path_log = g_path_local / "LOOTDebugLog.txt";
}
+30 -12
View File
@@ -130,6 +130,36 @@ namespace loot {
#endif
}
boost::filesystem::path GetLocalAppDataPath() {
#ifdef _WIN32
HWND owner = 0;
PWSTR path;
if (SHGetKnownFolderPath(FOLDERID_LocalAppData, 0, NULL, &path) != S_OK)
throw error(error::windows_error, lc::translate("Failed to get %LOCALAPPDATA% path."));
fs::path localAppDataPath(FromWinWide(path));
CoTaskMemFree(path);
return localAppDataPath;
#else
// Use XDG_CONFIG_HOME environmental variable if it's available.
const char * xdgConfigHome = getenv("XDG_CONFIG_HOME");
if (xdgConfigHome != nullptr)
return fs::path(xdgConfigHome);
// Otherwise, use the HOME env. var. if it's available.
xdgConfigHome = getenv("HOME");
if (xdgConfigHome != nullptr)
return fs::path(xdgConfigHome) / ".config";
// If somehow both are missing, use the current path.
return fs::current_path();
#endif
}
#ifdef _WIN32
//Get registry subkey value string.
string RegKeyStringValue(const std::string& keyStr, const std::string& subkey, const std::string& value) {
@@ -169,18 +199,6 @@ namespace loot {
}
}
boost::filesystem::path GetLocalAppDataPath() {
HWND owner = 0;
TCHAR path[MAX_PATH];
HRESULT res = SHGetFolderPath(owner, CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, path);
if (res == S_OK)
return fs::path(path);
else
return fs::path("");
}
//Helper to turn UTF8 strings into strings that can be used by WinAPI.
std::wstring ToWinWide(const std::string& str) {
size_t len = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), str.length(), 0, 0);
+3 -3
View File
@@ -42,13 +42,13 @@ namespace loot {
//Opens the file in its registered default application.
void OpenInDefaultApplication(const boost::filesystem::path& file);
//Get the local application data path, within which LOOT's data folder should be stored.
boost::filesystem::path GetLocalAppDataPath();
#ifdef _WIN32
//Get registry subkey value string.
std::string RegKeyStringValue(const std::string& keyStr, const std::string& subkey, const std::string& value);
//Get the local application data path, within which LOOT's data folder should be stored.
boost::filesystem::path GetLocalAppDataPath();
//Helper to turn UTF8 strings into strings that can be used by WinAPI.
std::wstring ToWinWide(const std::string& str);