App: Fix safe mode and home directory
This commit is contained in:
committed by
Benjamin Nauck
parent
05e81a01ed
commit
4fbe8e1773
@@ -2569,13 +2569,13 @@ void Application::initConfig(int argc, char ** argv)
|
||||
mConfig["KeepDeprecatedPaths"] = "1";
|
||||
}
|
||||
|
||||
if (vm.contains("safe-mode")) {
|
||||
mConfig["SafeMode"] = "1";
|
||||
}
|
||||
|
||||
// extract home paths
|
||||
_appDirs = std::make_unique<ApplicationDirectories>(mConfig);
|
||||
|
||||
if (vm.contains("safe-mode")) {
|
||||
SafeMode::StartSafeMode();
|
||||
}
|
||||
|
||||
# ifdef FC_DEBUG
|
||||
mConfig["Debug"] = "1";
|
||||
# else
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
|
||||
#include <Base/FileInfo.h>
|
||||
#include <Base/Exception.h>
|
||||
#include "SafeMode.h"
|
||||
|
||||
#include <Python.h>
|
||||
#include <QString>
|
||||
@@ -68,6 +69,11 @@ const fs::path& ApplicationDirectories::getHomePath() const
|
||||
return this->_home;
|
||||
}
|
||||
|
||||
const fs::path& ApplicationDirectories::getUserHomePath() const
|
||||
{
|
||||
return this->_userHome;
|
||||
}
|
||||
|
||||
const fs::path& ApplicationDirectories::getTempPath() const {
|
||||
return this->_temp;
|
||||
}
|
||||
@@ -182,10 +188,19 @@ void ApplicationDirectories::configurePaths(std::map<std::string,std::string>& m
|
||||
// get the system standard paths
|
||||
auto [configHome, dataHome, cacheHome, tempPath] = getStandardPaths();
|
||||
|
||||
if (mConfig.contains("SafeMode")) {
|
||||
if (startSafeMode(mConfig)) {
|
||||
// If we're in safe mode, don't try to set any directories here, they've been overridden
|
||||
// by temp directories in the SafeMode setup.
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// User home path
|
||||
//
|
||||
fs::path homePath = findUserHomePath(customHome);
|
||||
mConfig["UserHomePath"] = Base::FileInfo::pathToString(homePath);
|
||||
_userHome = homePath;
|
||||
|
||||
// the old path name to save config and data files
|
||||
std::vector<std::string> subdirs;
|
||||
@@ -243,6 +258,23 @@ void ApplicationDirectories::configurePaths(std::map<std::string,std::string>& m
|
||||
mConfig["UserMacroPath"] = Base::FileInfo::pathToString(macro) + PATHSEP;
|
||||
}
|
||||
|
||||
bool ApplicationDirectories::startSafeMode(std::map<std::string,std::string>& mConfig)
|
||||
{
|
||||
SafeMode::StartSafeMode();
|
||||
if (SafeMode::SafeModeEnabled()) {
|
||||
_userAppData = mConfig["UserAppData"];
|
||||
_userConfig = mConfig["UserConfigPath"];
|
||||
_userCache = mConfig["UserCachePath"];
|
||||
_temp = mConfig["AppTempPath"];
|
||||
_userMacro = mConfig["UserMacroPath"];
|
||||
_userHome = mConfig["UserHomePath"];
|
||||
_usingCustomDirectories = true;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void ApplicationDirectories::configureResourceDirectory(const std::map<std::string,std::string>& mConfig) {
|
||||
#ifdef RESOURCEDIR
|
||||
// #6892: Conda may inject null characters => remove them using c_str()
|
||||
|
||||
@@ -56,6 +56,10 @@ namespace App {
|
||||
/// `App::ApplicationDirectories` class.
|
||||
const std::filesystem::path& getHomePath() const;
|
||||
|
||||
/// Get the user's home directory. This should not be used for many things, use caution when
|
||||
/// deciding to use it for anything, there are usually better places.
|
||||
const std::filesystem::path& getUserHomePath() const;
|
||||
|
||||
/// Temp path is the location of all temporary files: it is not guaranteed to preserve
|
||||
/// information between runs of the program, but *is* guaranteed to exist for the duration
|
||||
/// of a single program execution (that is, files are not deleted from it *during* the run).
|
||||
@@ -174,6 +178,10 @@ namespace App {
|
||||
|
||||
protected:
|
||||
|
||||
/// Override all application directories with temp directories. Returns true on success and
|
||||
/// false if the temp directory creation failed.
|
||||
bool startSafeMode(std::map<std::string,std::string>& mConfig);
|
||||
|
||||
/// Take a path and add a version to it, if it's possible to do so. A version can be
|
||||
/// appended only if a) the versioned subdirectory already exists, or b) pathToCheck/subdirs
|
||||
/// does NOT yet exist. This does not actually create any directories, just determines
|
||||
@@ -228,6 +236,7 @@ namespace App {
|
||||
std::filesystem::path _userConfig;
|
||||
std::filesystem::path _userAppData;
|
||||
std::filesystem::path _userMacro;
|
||||
std::filesystem::path _userHome;
|
||||
std::filesystem::path _resource;
|
||||
std::filesystem::path _library;
|
||||
std::filesystem::path _help;
|
||||
|
||||
Reference in New Issue
Block a user