From caad4dfc147b93eea224d23256f96044327b7fd3 Mon Sep 17 00:00:00 2001 From: mlangkabel Date: Fri, 24 Aug 2018 10:50:00 +0200 Subject: [PATCH] logic: fixed policy for finding windows user data folder (issue #612) * creating "user_fallback" path in application directory if everything else fails --- .../platform_includes/includesWindows.h | 28 +++++++++++++++---- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/src/lib_gui/platform_includes/includesWindows.h b/src/lib_gui/platform_includes/includesWindows.h index 9929293b..be23f0e4 100644 --- a/src/lib_gui/platform_includes/includesWindows.h +++ b/src/lib_gui/platform_includes/includesWindows.h @@ -35,24 +35,40 @@ void setupApp(int argc, char *argv[]) { appPath = appPath.substr(0, pos + 1); } - AppPath::setAppPath(FilePath(appPath)); + AppPath::setAppPath(FilePath(appPath)); } { FilePath userDataPath = AppPath::getAppPath().concatenate(L"user/"); if (!userDataPath.exists()) { - userDataPath = FilePath(std::string(std::getenv("APPDATA")) + "/../local/Coati Software/"); - if (utility::getApplicationArchitectureType() == APPLICATION_ARCHITECTURE_X86_64) + FilePath userLocalPath = FilePath(std::string(std::getenv("LOCALAPPDATA"))); + if (!userLocalPath.exists()) { - userDataPath.concatenate(L"Sourcetrail 64-bit/"); + userLocalPath = FilePath(std::string(std::getenv("APPDATA")) + "/../local"); + } + + if (userLocalPath.exists()) + { + userDataPath = userLocalPath.getConcatenated(L"Coati Software/"); + if (utility::getApplicationArchitectureType() == APPLICATION_ARCHITECTURE_X86_64) + { + userDataPath.concatenate(L"Sourcetrail 64-bit/"); + } + else + { + userDataPath.concatenate(L"Sourcetrail/"); + } + userDataPath.makeCanonical(); } else { - userDataPath.concatenate(L"Sourcetrail/"); + userDataPath = AppPath::getAppPath().concatenate(L"user_fallback/"); + LOG_ERROR(L"The \"%LOCALAPPDATA%\" path could not be found. Falling back to \"" + userDataPath.wstr() + L"\" to store settings data."); + FileSystem::createDirectory(userDataPath); } - userDataPath.makeCanonical(); } + UserPaths::setUserDataPath(userDataPath); }