App: add new config key UserConfigPath to store the path to the config files

This commit is contained in:
wmayer
2021-11-09 13:46:26 +01:00
parent 55afa21ba1
commit c83ada98d6
3 changed files with 26 additions and 3 deletions

View File

@@ -1060,6 +1060,11 @@ std::string Application::getTempFileName(const char* FileName)
return Base::FileInfo::getTempFileName(FileName, getTempPath().c_str());
}
std::string Application::getUserConfigDir()
{
return mConfig["UserConfigPath"];
}
std::string Application::getUserAppDataDir()
{
return mConfig["UserAppData"];
@@ -2724,9 +2729,9 @@ void Application::LoadParameters(void)
// Init parameter sets ===========================================================
//
if (mConfig.find("UserParameter") == mConfig.end())
mConfig["UserParameter"] = mConfig["UserAppData"] + "user.cfg";
mConfig["UserParameter"] = mConfig["UserConfigPath"] + "user.cfg";
if (mConfig.find("SystemParameter") == mConfig.end())
mConfig["SystemParameter"] = mConfig["UserAppData"] + "system.cfg";
mConfig["SystemParameter"] = mConfig["UserConfigPath"] + "system.cfg";
// create standard parameter sets
_pcSysParamMngr = new ParameterManager();
@@ -3096,6 +3101,11 @@ void Application::ExtractUserPath()
mConfig["UserAppData"] = pathToString(appData) + PATHSEP;
// User config path (for now equal to UserAppData but will be changed to be XDG compliant)
//
mConfig["UserConfigPath"] = mConfig["UserAppData"];
// Set application tmp. directory
//
boost::filesystem::path cache = findCachePath(mConfig, cacheHome, userTemp);

View File

@@ -403,6 +403,7 @@ public:
*/
static std::string getTempPath();
static std::string getTempFileName(const char* FileName=0);
static std::string getUserConfigDir();
static std::string getUserAppDataDir();
static std::string getUserMacroDir();
static std::string getResourceDir();
@@ -513,6 +514,7 @@ private:
static PyObject* sChangeExportModule(PyObject *self,PyObject *args);
static PyObject* sGetExportType (PyObject *self,PyObject *args);
static PyObject* sGetResourceDir (PyObject *self,PyObject *args);
static PyObject* sGetUserConfigDir (PyObject *self,PyObject *args);
static PyObject* sGetUserAppDataDir (PyObject *self,PyObject *args);
static PyObject* sGetUserMacroDir (PyObject *self,PyObject *args);
static PyObject* sGetHelpDir (PyObject *self,PyObject *args);

View File

@@ -88,8 +88,10 @@ PyMethodDef Application::Methods[] = {
"Get the name of the module that can export the filetype"},
{"getResourceDir", (PyCFunction) Application::sGetResourceDir, METH_VARARGS,
"Get the root directory of all resources"},
{"getUserConfigDir", (PyCFunction) Application::sGetUserConfigDir, METH_VARARGS,
"Get the root directory of user config files"},
{"getUserAppDataDir", (PyCFunction) Application::sGetUserAppDataDir, METH_VARARGS,
"Get the root directory of user settings"},
"Get the root directory of application data"},
{"getUserMacroDir", (PyCFunction) Application::sGetUserMacroDir, METH_VARARGS,
"getUserMacroDir(bool=False) -> string"
"Get the directory of the user's macro directory\n"
@@ -651,6 +653,15 @@ PyObject* Application::sGetResourceDir(PyObject * /*self*/, PyObject *args)
return Py::new_reference_to(datadir);
}
PyObject* Application::sGetUserConfigDir(PyObject * /*self*/, PyObject *args)
{
if (!PyArg_ParseTuple(args, ""))
return nullptr;
Py::String datadir(Application::getUserConfigDir(),"utf-8");
return Py::new_reference_to(datadir);
}
PyObject* Application::sGetUserAppDataDir(PyObject * /*self*/, PyObject *args)
{
if (!PyArg_ParseTuple(args, "")) // convert args: Python->C