From 32f13c3716f156cd68954cce6a9f10eb8ceeb29c Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Thu, 15 Jun 2023 00:36:50 +0400 Subject: [PATCH] Deduplicate executable path computation --- Telegram/SourceFiles/core/launcher.cpp | 11 ----------- Telegram/SourceFiles/settings.cpp | 2 +- Telegram/SourceFiles/settings.h | 11 ++++++++--- 3 files changed, 9 insertions(+), 15 deletions(-) diff --git a/Telegram/SourceFiles/core/launcher.cpp b/Telegram/SourceFiles/core/launcher.cpp index dc1ac3235..bf5de7ac6 100644 --- a/Telegram/SourceFiles/core/launcher.cpp +++ b/Telegram/SourceFiles/core/launcher.cpp @@ -441,17 +441,6 @@ bool Launcher::customWorkingDir() const { void Launcher::prepareSettings() { auto path = base::Platform::CurrentExecutablePath(_argc, _argv); LOG(("Executable path before check: %1").arg(path)); - if (!path.isEmpty()) { - auto info = QFileInfo(path); - if (info.isSymLink()) { - info = QFileInfo(info.symLinkTarget()); - } - if (info.exists()) { - const auto dir = info.absoluteDir().absolutePath(); - gExeDir = (dir.endsWith('/') ? dir : (dir + '/')); - gExeName = info.fileName(); - } - } if (cExeName().isEmpty()) { LOG(("WARNING: Could not compute executable path, some features will be disabled.")); } diff --git a/Telegram/SourceFiles/settings.cpp b/Telegram/SourceFiles/settings.cpp index e546b14d3..4e2f6e878 100644 --- a/Telegram/SourceFiles/settings.cpp +++ b/Telegram/SourceFiles/settings.cpp @@ -18,7 +18,7 @@ QByteArray gAlphaPrivateKey; bool gManyInstance = false; QString gKeyFile; -QString gWorkingDir, gExeDir, gExeName; +QString gWorkingDir; QStringList gSendPaths; QString gStartUrl; diff --git a/Telegram/SourceFiles/settings.h b/Telegram/SourceFiles/settings.h index 298283651..c99ad9597 100644 --- a/Telegram/SourceFiles/settings.h +++ b/Telegram/SourceFiles/settings.h @@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #pragma once +#include "base/integration.h" #include "ui/style/style_core.h" #define DeclareReadSetting(Type, Name) extern Type g##Name; \ @@ -56,11 +57,15 @@ inline void cForceWorkingDir(const QString &newDir) { } } -DeclareReadSetting(QString, ExeName); -DeclareReadSetting(QString, ExeDir); +inline QString cExeName() { + return base::Integration::Instance().executableName(); +} +inline QString cExeDir() { + return base::Integration::Instance().executableDir(); +} DeclareSetting(QString, DialogLastPath); DeclareSetting(QString, DialogHelperPath); -inline const QString &cDialogHelperPathFinal() { +inline QString cDialogHelperPathFinal() { return cDialogHelperPath().isEmpty() ? cExeDir() : cDialogHelperPath(); }