diff --git a/src/app/main.cpp b/src/app/main.cpp index fc8188e3fbe..c63d1bc9ac2 100644 --- a/src/app/main.cpp +++ b/src/app/main.cpp @@ -522,6 +522,38 @@ private: ShowInGuiHandler *ShowInGuiHandler::instance = nullptr; +FilePath userPluginsRoot() +{ + FilePath rootPath = FilePath::fromUserInput( + QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation)); + + if (HostOsInfo::isAnyUnixHost() && !HostOsInfo::isMacHost()) + rootPath /= "data"; + + rootPath /= Core::Constants::IDE_SETTINGSVARIANT_STR; + + rootPath /= QLatin1StringView( + HostOsInfo::isMacHost() ? Core::Constants::IDE_DISPLAY_NAME : Core::Constants::IDE_ID); + rootPath /= "plugins"; + + rootPath /= Core::Constants::IDE_VERSION_LONG; + + return rootPath; +} + +FilePath userResourcePath(const QString &settingsPath, const QString &appId) +{ + const FilePath configDir = FilePath::fromUserInput(settingsPath).parentDir(); + const FilePath urp = configDir / appId; + + if (!urp.exists()) { + if (!urp.createDir()) + qWarning() << "could not create" << urp; + } + + return urp; +} + int main(int argc, char **argv) { Restarter restarter(argc, argv); @@ -723,6 +755,14 @@ int main(int argc, char **argv) info.revision = Constants::IDE_REVISION_STR; info.revisionUrl = Constants::IDE_REVISION_URL; info.userFileExtension = Constants::IDE_PROJECT_USER_FILE_EXTENSION; + + const FilePath appDirPath = FilePath::fromUserInput(QApplication::applicationDirPath()); + + info.plugins = (appDirPath / RELATIVE_PLUGIN_PATH).cleanPath(); + info.userPluginsRoot = userPluginsRoot(); + info.resources = (appDirPath / RELATIVE_DATA_PATH).cleanPath(); + info.userResources = userResourcePath(settings->fileName(), Constants::IDE_ID); + Utils::Internal::setAppInfo(info); QTranslator translator; diff --git a/src/libs/utils/appinfo.cpp b/src/libs/utils/appinfo.cpp index 465b3a46e46..2e0a6355a9e 100644 --- a/src/libs/utils/appinfo.cpp +++ b/src/libs/utils/appinfo.cpp @@ -7,7 +7,7 @@ Q_GLOBAL_STATIC(Utils::AppInfo, sAppInfo) namespace Utils { -Utils::AppInfo appInfo() +const Utils::AppInfo &appInfo() { return *sAppInfo; } diff --git a/src/libs/utils/appinfo.h b/src/libs/utils/appinfo.h index 9fd5a3f35e8..a408433c96b 100644 --- a/src/libs/utils/appinfo.h +++ b/src/libs/utils/appinfo.h @@ -5,6 +5,8 @@ #include "utils_global.h" +#include "filepath.h" + #include namespace Utils { @@ -19,9 +21,22 @@ public: QString revision; QString revisionUrl; QString userFileExtension; + + FilePath plugins; + + /*! Local plugin path: /plugins + where is e.g. + "%LOCALAPPDATA%\QtProject\qtcreator" on Windows Vista and later + "$XDG_DATA_HOME/data/QtProject/qtcreator" or "~/.local/share/data/QtProject/qtcreator" on Linux + "~/Library/Application Support/QtProject/Qt Creator" on Mac + */ + FilePath userPluginsRoot; + + FilePath resources; + FilePath userResources; }; -QTCREATOR_UTILS_EXPORT AppInfo appInfo(); +QTCREATOR_UTILS_EXPORT const AppInfo &appInfo(); namespace Internal { QTCREATOR_UTILS_EXPORT void setAppInfo(const AppInfo &info);