Deduplicate executable path computation

This commit is contained in:
Ilya Fedin 2023-06-15 00:36:50 +04:00 committed by John Preston
parent 22235226d6
commit 32f13c3716
3 changed files with 9 additions and 15 deletions

View File

@ -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."));
}

View File

@ -18,7 +18,7 @@ QByteArray gAlphaPrivateKey;
bool gManyInstance = false;
QString gKeyFile;
QString gWorkingDir, gExeDir, gExeName;
QString gWorkingDir;
QStringList gSendPaths;
QString gStartUrl;

View File

@ -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();
}