From 449c5397b705d32e7eb35562418879bdc6d0d989 Mon Sep 17 00:00:00 2001 From: nerix Date: Sun, 3 Mar 2024 13:15:50 +0100 Subject: [PATCH] fix: store IPC file in application directory (#5226) --- CHANGELOG.md | 1 + src/main.cpp | 2 ++ src/singletons/Paths.cpp | 7 +++++++ src/singletons/Paths.hpp | 5 +++++ src/util/IpcQueue.cpp | 43 ++++++++++++++++++++++++++++++++++++++++ src/util/IpcQueue.hpp | 8 ++++++++ 6 files changed, 66 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 67e5d23f7..6601c09e2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,6 +40,7 @@ - Minor: Allow theming of tab live and rerun indicators. (#5188) - Minor: Added a fallback theme field to custom themes that will be used in case the custom theme does not contain a color Chatterino needs. If no fallback theme is specified, we'll pull the color from the included Dark or Light theme. (#5198) - Minor: Image links now reflect the scale of their image instead of an internal label. (#5201) +- Minor: IPC files are now stored in the Chatterino directory instead of system directories on Windows. (#5226) - Minor: 7TV emotes now have a 4x image rather than a 3x image. (#5209) - Bugfix: Fixed an issue where certain emojis did not send to Twitch chat correctly. (#4840) - Bugfix: Fixed capitalized channel names in log inclusion list not being logged. (#4848) diff --git a/src/main.cpp b/src/main.cpp index 871767918..ef59af0c5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -13,6 +13,7 @@ #include "singletons/Settings.hpp" #include "singletons/Updates.hpp" #include "util/AttachToConsole.hpp" +#include "util/IpcQueue.hpp" #include #include @@ -62,6 +63,7 @@ int main(int argc, char **argv) box.exec(); return 1; } + ipc::initPaths(paths.get()); const Args args(a, *paths); diff --git a/src/singletons/Paths.cpp b/src/singletons/Paths.cpp index 4d0ac30db..b315f16da 100644 --- a/src/singletons/Paths.cpp +++ b/src/singletons/Paths.cpp @@ -140,6 +140,13 @@ void Paths::initSubDirectories() this->pluginsDirectory = makePath("Plugins"); this->themesDirectory = makePath("Themes"); this->crashdumpDirectory = makePath("Crashes"); +#ifdef Q_OS_WIN + this->ipcDirectory = makePath("IPC"); +#else + // NOTE: We do *NOT* use IPC on non-Windows platforms. + // If we start, we should re-consider this directory. + this->ipcDirectory = "/tmp"; +#endif } } // namespace chatterino diff --git a/src/singletons/Paths.hpp b/src/singletons/Paths.hpp index bfabd1b1e..eabd06933 100644 --- a/src/singletons/Paths.hpp +++ b/src/singletons/Paths.hpp @@ -39,6 +39,11 @@ public: // Custom themes live here. /Themes QString themesDirectory; + // Directory for shared memory files. + // /IPC on Windows + // /tmp elsewhere + QString ipcDirectory; + bool createFolder(const QString &folderPath); [[deprecated("use Modes::instance().portable instead")]] bool isPortable() const; diff --git a/src/util/IpcQueue.cpp b/src/util/IpcQueue.cpp index 0efc878fc..2e2e3df54 100644 --- a/src/util/IpcQueue.cpp +++ b/src/util/IpcQueue.cpp @@ -1,7 +1,9 @@ #include "util/IpcQueue.hpp" #include "common/QLogging.hpp" +#include "singletons/Paths.hpp" +#define BOOST_INTERPROCESS_SHARED_DIR_FUNC #include #include #include @@ -9,8 +11,49 @@ namespace boost_ipc = boost::interprocess; +namespace { + +static const chatterino::Paths *PATHS = nullptr; + +} // namespace + +namespace boost::interprocess::ipcdetail { + +void get_shared_dir(std::string &shared_dir) +{ + if (!PATHS) + { + assert(false && "PATHS not set"); + qCCritical(chatterinoNativeMessage) + << "PATHS not set for shared directory"; + return; + } + shared_dir = PATHS->ipcDirectory.toStdString(); +} + +#ifdef BOOST_INTERPROCESS_WINDOWS +void get_shared_dir(std::wstring &shared_dir) +{ + if (!PATHS) + { + assert(false && "PATHS not set"); + qCCritical(chatterinoNativeMessage) + << "PATHS not set for shared directory"; + return; + } + shared_dir = PATHS->ipcDirectory.toStdWString(); +} +#endif + +} // namespace boost::interprocess::ipcdetail + namespace chatterino::ipc { +void initPaths(const Paths *paths) +{ + PATHS = paths; +} + void sendMessage(const char *name, const QByteArray &data) { try diff --git a/src/util/IpcQueue.hpp b/src/util/IpcQueue.hpp index 467aa2873..e56cf2ba3 100644 --- a/src/util/IpcQueue.hpp +++ b/src/util/IpcQueue.hpp @@ -6,8 +6,16 @@ class QByteArray; class QString; +namespace chatterino { + +class Paths; + +} // namespace chatterino + namespace chatterino::ipc { +void initPaths(const Paths *paths); + void sendMessage(const char *name, const QByteArray &data); class IpcQueuePrivate;