From cd7539c001495d5daa63375307b5c56417a31a3d Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Sat, 22 Jul 2023 01:07:22 +0400 Subject: [PATCH] Detect when -workdir value is not really custom --- Telegram/SourceFiles/core/launcher.cpp | 20 ++++++++++++++++---- Telegram/SourceFiles/core/launcher.h | 3 ++- Telegram/SourceFiles/logs.cpp | 7 +++++-- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/Telegram/SourceFiles/core/launcher.cpp b/Telegram/SourceFiles/core/launcher.cpp index 52ebbd7c7..35b168d9a 100644 --- a/Telegram/SourceFiles/core/launcher.cpp +++ b/Telegram/SourceFiles/core/launcher.cpp @@ -394,6 +394,18 @@ int Launcher::exec() { return result; } +bool Launcher::validateCustomWorkingDir() { + if (customWorkingDir()) { + if (_customWorkingDir == cWorkingDir()) { + _customWorkingDir = {}; + return false; + } + cForceWorkingDir(_customWorkingDir); + return true; + } + return false; +} + void Launcher::workingFolderReady() { srand((unsigned int)time(nullptr)); @@ -435,7 +447,7 @@ const QStringList &Launcher::arguments() const { } bool Launcher::customWorkingDir() const { - return _customWorkingDir; + return !_customWorkingDir.isEmpty(); } void Launcher::prepareSettings() { @@ -534,9 +546,9 @@ void Launcher::processArguments() { gStartInTray = parseResult.contains("-startintray"); gQuit = parseResult.contains("-quit"); gSendPaths = parseResult.value("-sendpath", {}); - cForceWorkingDir(parseResult.value("-workdir", {}).join(QString())); - if (!gWorkingDir.isEmpty()) { - _customWorkingDir = true; + _customWorkingDir = parseResult.value("-workdir", {}).join(QString()); + if (!_customWorkingDir.isEmpty()) { + _customWorkingDir = QDir(_customWorkingDir).absolutePath() + '/'; } gStartUrl = parseResult.value("--", {}).join(QString()); diff --git a/Telegram/SourceFiles/core/launcher.h b/Telegram/SourceFiles/core/launcher.h index 264085f20..a5e5117a5 100644 --- a/Telegram/SourceFiles/core/launcher.h +++ b/Telegram/SourceFiles/core/launcher.h @@ -34,6 +34,7 @@ public: uint64 installationTag() const; bool checkPortableVersionFolder(); + bool validateCustomWorkingDir(); void workingFolderReady(); void writeDebugModeSetting(); void writeInstallBetaVersionsSetting(); @@ -83,7 +84,7 @@ private: QStringList _arguments; BaseIntegration _baseIntegration; - bool _customWorkingDir = false; + QString _customWorkingDir; }; diff --git a/Telegram/SourceFiles/logs.cpp b/Telegram/SourceFiles/logs.cpp index f645db99d..b8bd88d6c 100644 --- a/Telegram/SourceFiles/logs.cpp +++ b/Telegram/SourceFiles/logs.cpp @@ -363,7 +363,6 @@ void start() { if (!cWorkingDir().isEmpty()) { // This value must come from TelegramForcePortable - // or from the "-workdir" command line argument. cForceWorkingDir(cWorkingDir()); workingDirChosen = true; } else { @@ -391,7 +390,6 @@ void start() { if (!cWorkingDir().isEmpty()) { // This value must come from TelegramForcePortable - // or from the "-workdir" command line argument. cForceWorkingDir(cWorkingDir()); workingDirChosen = true; } @@ -408,6 +406,11 @@ void start() { } } + if (launcher.validateCustomWorkingDir()) { + delete LogsData; + LogsData = new LogsDataFields(); + } + // WinRT build requires the working dir to stay the same for plugin loading. #ifndef Q_OS_WINRT QDir().setCurrent(cWorkingDir());