diff --git a/src/App/Application.cpp b/src/App/Application.cpp index ad5b6544e3..281b56946e 100644 --- a/src/App/Application.cpp +++ b/src/App/Application.cpp @@ -1061,7 +1061,12 @@ std::string Application::getTempFileName(const char* FileName) return Base::FileInfo::getTempFileName(FileName, getTempPath().c_str()); } -std::string Application::getUserConfigDir() +std::string Application::getUserCachePath() +{ + return mConfig["UserCachePath"]; +} + +std::string Application::getUserConfigPath() { return mConfig["UserConfigPath"]; } @@ -2958,11 +2963,6 @@ boost::filesystem::path findPath(const QString& stdHome, const QString& customHo boost::filesystem::path appData(stringToPath(dataPath.toStdString())); - //if (!boost::filesystem::exists(appData)) { - // // This should never ever happen - // throw Base::FileSystemError("Application data directory " + appData.string() + " does not exist!"); - //} - // If a custom user home path is given then don't modify it if (customHome.isEmpty()) { for (const auto& it : paths) @@ -3039,20 +3039,20 @@ std::tuple getCustomPaths() * \li XDG_CACHE_HOME * \endlist */ -std::tuple getStandardPaths() +std::tuple getStandardPaths() { QString configHome = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation); QString dataHome = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation); QString cacheHome = QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation); + QString tempPath = QStandardPaths::writableLocation(QStandardPaths::TempLocation); // Keep the old behaviour #if defined(FC_OS_WIN32) configHome = getOldGenericDataLocation(QString()); dataHome = configHome; - cacheHome = QStandardPaths::writableLocation(QStandardPaths::TempLocation); #endif - return std::make_tuple(configHome, dataHome, cacheHome); + return std::make_tuple(configHome, dataHome, cacheHome, tempPath); } } @@ -3075,6 +3075,7 @@ void Application::ExtractUserPath() QString configHome = std::get<0>(stdPaths); QString dataHome = std::get<1>(stdPaths); QString cacheHome = std::get<2>(stdPaths); + QString tempPath = std::get<3>(stdPaths); // User home path // @@ -3116,12 +3117,19 @@ void Application::ExtractUserPath() } - // Set application tmp. directory + // User cache path // std::vector cachedirs = subdirs; cachedirs.emplace_back("Cache"); boost::filesystem::path cache = findPath(cacheHome, customTemp, cachedirs, true); - mConfig["AppTempPath"] = pathToString(cache) + PATHSEP; + mConfig["UserCachePath"] = pathToString(cache) + PATHSEP; + + + // Set application tmp. directory + // + std::vector empty; + boost::filesystem::path tmp = findPath(tempPath, customTemp, empty, true); + mConfig["AppTempPath"] = pathToString(tmp) + PATHSEP; // Set the default macro directory diff --git a/src/App/Application.h b/src/App/Application.h index 265ea8a746..e11b3b1d6f 100644 --- a/src/App/Application.h +++ b/src/App/Application.h @@ -403,7 +403,8 @@ public: */ static std::string getTempPath(); static std::string getTempFileName(const char* FileName=0); - static std::string getUserConfigDir(); + static std::string getUserCachePath(); + static std::string getUserConfigPath(); static std::string getUserAppDataDir(); static std::string getUserMacroDir(); static std::string getResourceDir(); @@ -513,11 +514,13 @@ private: static PyObject* sAddExportType (PyObject *self,PyObject *args); 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); + static PyObject* sGetResourcePath (PyObject *self,PyObject *args); + static PyObject* sGetTempPath (PyObject *self,PyObject *args); + static PyObject* sGetUserCachePath (PyObject *self,PyObject *args); + static PyObject* sGetUserConfigPath (PyObject *self,PyObject *args); + static PyObject* sGetUserAppDataPath(PyObject *self,PyObject *args); + static PyObject* sGetUserMacroPath (PyObject *self,PyObject *args); + static PyObject* sGetHelpPath (PyObject *self,PyObject *args); static PyObject* sGetHomePath (PyObject *self,PyObject *args); static PyObject* sLoadFile (PyObject *self,PyObject *args); diff --git a/src/App/ApplicationPy.cpp b/src/App/ApplicationPy.cpp index 18fcbc88e9..07ca06e5e9 100644 --- a/src/App/ApplicationPy.cpp +++ b/src/App/ApplicationPy.cpp @@ -86,18 +86,22 @@ PyMethodDef Application::Methods[] = { "Change the export module name of a registered filetype"}, {"getExportType", (PyCFunction) Application::sGetExportType, METH_VARARGS, "Get the name of the module that can export the filetype"}, - {"getResourceDir", (PyCFunction) Application::sGetResourceDir, METH_VARARGS, + {"getResourceDir", (PyCFunction) Application::sGetResourcePath, 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, + {"getTempPath", (PyCFunction) Application::sGetTempPath, METH_VARARGS, + "Get the root directory of cached files"}, + {"getUserCachePath", (PyCFunction) Application::sGetUserCachePath, METH_VARARGS, + "Get the root path of cached files"}, + {"getUserConfigDir", (PyCFunction) Application::sGetUserConfigPath, METH_VARARGS, + "Get the root path of user config files"}, + {"getUserAppDataDir", (PyCFunction) Application::sGetUserAppDataPath, METH_VARARGS, "Get the root directory of application data"}, - {"getUserMacroDir", (PyCFunction) Application::sGetUserMacroDir, METH_VARARGS, + {"getUserMacroDir", (PyCFunction) Application::sGetUserMacroPath, METH_VARARGS, "getUserMacroDir(bool=False) -> string" "Get the directory of the user's macro directory\n" "If parameter is False (the default) it returns the standard path in the" "user's home directory, otherwise it returns the user-defined path."}, - {"getHelpDir", (PyCFunction) Application::sGetHelpDir, METH_VARARGS, + {"getHelpDir", (PyCFunction) Application::sGetHelpPath, METH_VARARGS, "Get the directory of the documentation"}, {"getHomePath", (PyCFunction) Application::sGetHomePath, METH_VARARGS, "Get the home path, i.e. the parent directory of the executable"}, @@ -644,38 +648,56 @@ PyObject* Application::sGetExportType(PyObject * /*self*/, PyObject *args) } } -PyObject* Application::sGetResourceDir(PyObject * /*self*/, PyObject *args) +PyObject* Application::sGetResourcePath(PyObject * /*self*/, PyObject *args) { - if (!PyArg_ParseTuple(args, "")) // convert args: Python->C - return NULL; // NULL triggers exception + if (!PyArg_ParseTuple(args, "")) + return nullptr; Py::String datadir(Application::getResourceDir(),"utf-8"); return Py::new_reference_to(datadir); } -PyObject* Application::sGetUserConfigDir(PyObject * /*self*/, PyObject *args) +PyObject* Application::sGetTempPath(PyObject * /*self*/, PyObject *args) { if (!PyArg_ParseTuple(args, "")) return nullptr; - Py::String datadir(Application::getUserConfigDir(),"utf-8"); + Py::String datadir(Application::getTempPath(),"utf-8"); return Py::new_reference_to(datadir); } -PyObject* Application::sGetUserAppDataDir(PyObject * /*self*/, PyObject *args) +PyObject* Application::sGetUserCachePath(PyObject * /*self*/, PyObject *args) { - if (!PyArg_ParseTuple(args, "")) // convert args: Python->C - return NULL; // NULL triggers exception + if (!PyArg_ParseTuple(args, "")) + return nullptr; + + Py::String datadir(Application::getUserCachePath(),"utf-8"); + return Py::new_reference_to(datadir); +} + +PyObject* Application::sGetUserConfigPath(PyObject * /*self*/, PyObject *args) +{ + if (!PyArg_ParseTuple(args, "")) + return nullptr; + + Py::String datadir(Application::getUserConfigPath(),"utf-8"); + return Py::new_reference_to(datadir); +} + +PyObject* Application::sGetUserAppDataPath(PyObject * /*self*/, PyObject *args) +{ + if (!PyArg_ParseTuple(args, "")) + return nullptr; Py::String user_data_dir(Application::getUserAppDataDir(),"utf-8"); return Py::new_reference_to(user_data_dir); } -PyObject* Application::sGetUserMacroDir(PyObject * /*self*/, PyObject *args) +PyObject* Application::sGetUserMacroPath(PyObject * /*self*/, PyObject *args) { PyObject *actual = Py_False; if (!PyArg_ParseTuple(args, "|O!", &PyBool_Type, &actual)) - return NULL; + return nullptr; std::string macroDir = Application::getUserMacroDir(); if (PyObject_IsTrue(actual)) { @@ -688,10 +710,10 @@ PyObject* Application::sGetUserMacroDir(PyObject * /*self*/, PyObject *args) return Py::new_reference_to(user_macro_dir); } -PyObject* Application::sGetHelpDir(PyObject * /*self*/, PyObject *args) +PyObject* Application::sGetHelpPath(PyObject * /*self*/, PyObject *args) { - if (!PyArg_ParseTuple(args, "")) // convert args: Python->C - return NULL; // NULL triggers exception + if (!PyArg_ParseTuple(args, "")) + return nullptr; Py::String user_macro_dir(Application::getHelpDir(),"utf-8"); return Py::new_reference_to(user_macro_dir); @@ -699,8 +721,8 @@ PyObject* Application::sGetHelpDir(PyObject * /*self*/, PyObject *args) PyObject* Application::sGetHomePath(PyObject * /*self*/, PyObject *args) { - if (!PyArg_ParseTuple(args, "")) // convert args: Python->C - return NULL; // NULL triggers exception + if (!PyArg_ParseTuple(args, "")) + return nullptr; Py::String homedir(Application::getHomePath(),"utf-8"); return Py::new_reference_to(homedir); diff --git a/src/App/Document.cpp b/src/App/Document.cpp index 3cd42a548b..270ae7991e 100644 --- a/src/App/Document.cpp +++ b/src/App/Document.cpp @@ -1684,7 +1684,7 @@ std::string Document::getTransientDirectoryName(const std::string& uuid, const s std::stringstream s; QCryptographicHash hash(QCryptographicHash::Sha1); hash.addData(filename.c_str(), filename.size()); - s << App::Application::getTempPath() << App::Application::getExecutableName() + s << App::Application::getUserCachePath() << App::Application::getExecutableName() << "_Doc_" << uuid << "_" << hash.result().toHex().left(6).constData() << "_" << QCoreApplication::applicationPid(); diff --git a/src/Gui/Application.cpp b/src/Gui/Application.cpp index 0dc5ed879a..c75bca76da 100644 --- a/src/Gui/Application.cpp +++ b/src/Gui/Application.cpp @@ -2267,7 +2267,7 @@ void Application::runApplication(void) try { std::stringstream s; - s << App::Application::getTempPath() << App::Application::getExecutableName() + s << App::Application::getUserCachePath() << App::Application::getExecutableName() << "_" << QCoreApplication::applicationPid() << ".lock"; // open a lock file with the PID Base::FileInfo fi(s.str()); diff --git a/src/Gui/DlgEditFileIncludePropertyExternal.cpp b/src/Gui/DlgEditFileIncludePropertyExternal.cpp index b9360fc6c1..deee05fb90 100644 --- a/src/Gui/DlgEditFileIncludePropertyExternal.cpp +++ b/src/Gui/DlgEditFileIncludePropertyExternal.cpp @@ -65,7 +65,7 @@ int DlgEditFileIncludePropertyExternal::Do(void) QFileInfo file = QString::fromUtf8(Prop.getValue()); assert(file.exists()); - QDir tmp = QString::fromUtf8(App::Application::getTempPath().c_str()); + QDir tmp = QString::fromUtf8(App::Application::getUserCachePath().c_str()); QString TempFile = tmp.absoluteFilePath(file.fileName()); QFile::remove(TempFile); diff --git a/src/Gui/DocumentRecovery.cpp b/src/Gui/DocumentRecovery.cpp index 924c4e32fb..3c05c04769 100644 --- a/src/Gui/DocumentRecovery.cpp +++ b/src/Gui/DocumentRecovery.cpp @@ -519,7 +519,7 @@ void DocumentRecovery::onDeleteSection() return; QList items = d_ptr->ui.treeWidget->selectedItems(); - QDir tmp = QString::fromUtf8(App::Application::getTempPath().c_str()); + QDir tmp = QString::fromUtf8(App::Application::getUserCachePath().c_str()); for (QList::iterator it = items.begin(); it != items.end(); ++it) { int index = d_ptr->ui.treeWidget->indexOfTopLevelItem(*it); QTreeWidgetItem* item = d_ptr->ui.treeWidget->takeTopLevelItem(index); @@ -662,7 +662,7 @@ void DocumentRecoveryFinder::showRecoveryDialogIfNeeded() void DocumentRecoveryHandler::checkForPreviousCrashes(const std::function&, const QString&)> & callableFunc) const { - QDir tmp = QString::fromUtf8(App::Application::getTempPath().c_str()); + QDir tmp = QString::fromUtf8(App::Application::getUserCachePath().c_str()); tmp.setNameFilters(QStringList() << QString::fromLatin1("*.lock")); tmp.setFilter(QDir::Files);