2017-12-11 14:45:29 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2017-12-11 14:45:29 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2017-12-11 14:45:29 +00:00
|
|
|
*/
|
|
|
|
#include "core/launcher.h"
|
|
|
|
|
|
|
|
#include "platform/platform_launcher.h"
|
|
|
|
#include "platform/platform_specific.h"
|
2023-01-12 09:18:28 +00:00
|
|
|
#include "base/options.h"
|
2019-09-17 16:13:12 +00:00
|
|
|
#include "base/platform/base_platform_info.h"
|
2020-10-29 19:56:13 +00:00
|
|
|
#include "base/platform/base_platform_file_utilities.h"
|
2019-09-17 07:51:02 +00:00
|
|
|
#include "ui/main_queue_processor.h"
|
2017-12-11 14:45:29 +00:00
|
|
|
#include "core/crash_reports.h"
|
2018-07-11 22:14:44 +00:00
|
|
|
#include "core/update_checker.h"
|
2019-01-21 13:42:21 +00:00
|
|
|
#include "core/sandbox.h"
|
2018-08-09 20:39:22 +00:00
|
|
|
#include "base/concurrent_timer.h"
|
2022-02-02 09:04:46 +00:00
|
|
|
#include "base/options.h"
|
2017-12-11 14:45:29 +00:00
|
|
|
|
2021-06-14 08:16:00 +00:00
|
|
|
#include <QtCore/QLoggingCategory>
|
2021-06-11 19:01:07 +00:00
|
|
|
|
2017-12-11 14:45:29 +00:00
|
|
|
namespace Core {
|
2019-01-21 13:42:21 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
uint64 InstallationTag = 0;
|
|
|
|
|
2023-02-22 07:44:59 +00:00
|
|
|
base::options::toggle OptionFreeType({
|
|
|
|
.id = kOptionFreeType,
|
|
|
|
.name = "FreeType font engine",
|
|
|
|
.description = "Use the font engine from Linux instead of the system one.",
|
|
|
|
.scope = base::options::windows | base::options::macos,
|
|
|
|
.restartRequired = true,
|
|
|
|
});
|
|
|
|
|
2019-05-06 10:40:04 +00:00
|
|
|
class FilteredCommandLineArguments {
|
|
|
|
public:
|
|
|
|
FilteredCommandLineArguments(int argc, char **argv);
|
|
|
|
|
|
|
|
int &count();
|
|
|
|
char **values();
|
|
|
|
|
|
|
|
private:
|
|
|
|
static constexpr auto kForwardArgumentCount = 1;
|
|
|
|
|
|
|
|
int _count = 0;
|
2020-05-08 22:37:43 +00:00
|
|
|
std::vector<QByteArray> _owned;
|
|
|
|
std::vector<char*> _arguments;
|
|
|
|
|
|
|
|
void pushArgument(const char *text);
|
2019-05-06 10:40:04 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
FilteredCommandLineArguments::FilteredCommandLineArguments(
|
|
|
|
int argc,
|
2020-05-08 22:37:43 +00:00
|
|
|
char **argv) {
|
2019-05-06 10:40:04 +00:00
|
|
|
// For now just pass only the first argument, the executable path.
|
2020-05-08 22:37:43 +00:00
|
|
|
for (auto i = 0; i != kForwardArgumentCount; ++i) {
|
|
|
|
pushArgument(argv[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
#if defined Q_OS_WIN || defined Q_OS_MAC
|
2023-02-22 07:44:59 +00:00
|
|
|
if (OptionFreeType.value()) {
|
2020-05-08 22:37:43 +00:00
|
|
|
pushArgument("-platform");
|
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
pushArgument("windows:fontengine=freetype");
|
|
|
|
#else // Q_OS_WIN
|
|
|
|
pushArgument("cocoa:fontengine=freetype");
|
|
|
|
#endif // !Q_OS_WIN
|
2019-05-06 10:40:04 +00:00
|
|
|
}
|
2022-01-03 17:03:06 +00:00
|
|
|
#elif defined Q_OS_UNIX
|
2022-11-29 21:46:36 +00:00
|
|
|
if (QFile::exists(cWorkingDir() + u"tdata/nowayland"_q)
|
2022-07-28 03:33:04 +00:00
|
|
|
&& qEnvironmentVariableIsEmpty("QT_QPA_PLATFORM")) {
|
|
|
|
LOG(("Wayland: Disable on old installations"));
|
2022-01-03 17:03:06 +00:00
|
|
|
pushArgument("-platform");
|
|
|
|
pushArgument("xcb;wayland");
|
|
|
|
}
|
|
|
|
#endif // Q_OS_WIN || Q_OS_MAC || Q_OS_UNIX
|
2020-05-08 22:37:43 +00:00
|
|
|
|
|
|
|
pushArgument(nullptr);
|
2019-05-06 10:40:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int &FilteredCommandLineArguments::count() {
|
2020-05-08 22:37:43 +00:00
|
|
|
_count = _arguments.size() - 1;
|
2019-05-06 10:40:04 +00:00
|
|
|
return _count;
|
|
|
|
}
|
|
|
|
|
|
|
|
char **FilteredCommandLineArguments::values() {
|
2020-05-08 22:37:43 +00:00
|
|
|
return _arguments.data();
|
|
|
|
}
|
|
|
|
|
|
|
|
void FilteredCommandLineArguments::pushArgument(const char *text) {
|
|
|
|
_owned.emplace_back(text);
|
|
|
|
_arguments.push_back(_owned.back().data());
|
2019-05-06 10:40:04 +00:00
|
|
|
}
|
|
|
|
|
2019-01-21 13:42:21 +00:00
|
|
|
QString DebugModeSettingPath() {
|
2022-11-29 21:46:36 +00:00
|
|
|
return cWorkingDir() + u"tdata/withdebug"_q;
|
2019-01-21 13:42:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void WriteDebugModeSetting() {
|
|
|
|
auto file = QFile(DebugModeSettingPath());
|
|
|
|
if (file.open(QIODevice::WriteOnly)) {
|
|
|
|
file.write(Logs::DebugEnabled() ? "1" : "0");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ComputeDebugMode() {
|
|
|
|
Logs::SetDebugEnabled(cAlphaVersion() != 0);
|
|
|
|
const auto debugModeSettingPath = DebugModeSettingPath();
|
|
|
|
auto file = QFile(debugModeSettingPath);
|
|
|
|
if (file.exists() && file.open(QIODevice::ReadOnly)) {
|
|
|
|
Logs::SetDebugEnabled(file.read(1) != "0");
|
|
|
|
}
|
2020-09-19 19:17:41 +00:00
|
|
|
if (cDebugMode()) {
|
|
|
|
Logs::SetDebugEnabled(true);
|
|
|
|
}
|
2021-06-14 08:16:00 +00:00
|
|
|
if (Logs::DebugEnabled()) {
|
|
|
|
QLoggingCategory::setFilterRules("qt.qpa.gl.debug=true");
|
|
|
|
}
|
2019-01-21 13:42:21 +00:00
|
|
|
}
|
|
|
|
|
2020-05-14 04:35:22 +00:00
|
|
|
void ComputeExternalUpdater() {
|
2022-11-29 21:46:36 +00:00
|
|
|
QFile file(u"/etc/tdesktop/externalupdater"_q);
|
2020-05-14 04:35:22 +00:00
|
|
|
|
|
|
|
if (file.exists() && file.open(QIODevice::ReadOnly)) {
|
|
|
|
QTextStream fileStream(&file);
|
|
|
|
while (!fileStream.atEnd()) {
|
|
|
|
const auto path = fileStream.readLine();
|
|
|
|
|
2021-03-20 21:45:57 +00:00
|
|
|
if (path == (cExeDir() + cExeName())) {
|
2020-05-14 04:35:22 +00:00
|
|
|
SetUpdaterDisabledAtStartup();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-21 13:42:21 +00:00
|
|
|
QString InstallBetaVersionsSettingPath() {
|
2022-11-29 21:46:36 +00:00
|
|
|
return cWorkingDir() + u"tdata/devversion"_q;
|
2019-01-21 13:42:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void WriteInstallBetaVersionsSetting() {
|
|
|
|
QFile f(InstallBetaVersionsSettingPath());
|
|
|
|
if (f.open(QIODevice::WriteOnly)) {
|
|
|
|
f.write(cInstallBetaVersion() ? "1" : "0");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ComputeInstallBetaVersions() {
|
|
|
|
const auto installBetaSettingPath = InstallBetaVersionsSettingPath();
|
|
|
|
if (cAlphaVersion()) {
|
|
|
|
cSetInstallBetaVersion(false);
|
2020-05-14 04:35:22 +00:00
|
|
|
} else if (QFile::exists(installBetaSettingPath)) {
|
2019-01-21 13:42:21 +00:00
|
|
|
QFile f(installBetaSettingPath);
|
|
|
|
if (f.open(QIODevice::ReadOnly)) {
|
|
|
|
cSetInstallBetaVersion(f.read(1) != "0");
|
|
|
|
}
|
|
|
|
} else if (AppBetaVersion) {
|
|
|
|
WriteInstallBetaVersionsSetting();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ComputeInstallationTag() {
|
|
|
|
InstallationTag = 0;
|
2022-11-29 21:46:36 +00:00
|
|
|
auto file = QFile(cWorkingDir() + u"tdata/usertag"_q);
|
2019-01-21 13:42:21 +00:00
|
|
|
if (file.open(QIODevice::ReadOnly)) {
|
|
|
|
const auto result = file.read(
|
|
|
|
reinterpret_cast<char*>(&InstallationTag),
|
|
|
|
sizeof(uint64));
|
|
|
|
if (result != sizeof(uint64)) {
|
|
|
|
InstallationTag = 0;
|
|
|
|
}
|
|
|
|
file.close();
|
|
|
|
}
|
|
|
|
if (!InstallationTag) {
|
2019-07-10 17:28:33 +00:00
|
|
|
auto generator = std::mt19937(std::random_device()());
|
|
|
|
auto distribution = std::uniform_int_distribution<uint64>();
|
2019-01-21 13:42:21 +00:00
|
|
|
do {
|
2019-07-10 17:28:33 +00:00
|
|
|
InstallationTag = distribution(generator);
|
2019-01-21 13:42:21 +00:00
|
|
|
} while (!InstallationTag);
|
|
|
|
|
|
|
|
if (file.open(QIODevice::WriteOnly)) {
|
|
|
|
file.write(
|
|
|
|
reinterpret_cast<char*>(&InstallationTag),
|
|
|
|
sizeof(uint64));
|
|
|
|
file.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MoveLegacyAlphaFolder(const QString &folder, const QString &file) {
|
|
|
|
const auto was = cExeDir() + folder;
|
2022-11-29 21:46:36 +00:00
|
|
|
const auto now = cExeDir() + u"TelegramForcePortable"_q;
|
2019-01-21 13:42:21 +00:00
|
|
|
if (QDir(was).exists() && !QDir(now).exists()) {
|
|
|
|
const auto oldFile = was + "/tdata/" + file;
|
|
|
|
const auto newFile = was + "/tdata/alpha";
|
2020-05-14 04:35:22 +00:00
|
|
|
if (QFile::exists(oldFile) && !QFile::exists(newFile)) {
|
2019-01-21 13:42:21 +00:00
|
|
|
if (!QFile(oldFile).copy(newFile)) {
|
2021-03-13 11:50:34 +00:00
|
|
|
LOG(("FATAL: Could not copy '%1' to '%2'").arg(
|
|
|
|
oldFile,
|
|
|
|
newFile));
|
2019-01-21 13:42:21 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!QDir().rename(was, now)) {
|
2021-03-13 11:50:34 +00:00
|
|
|
LOG(("FATAL: Could not rename '%1' to '%2'").arg(was, now));
|
2019-01-21 13:42:21 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MoveLegacyAlphaFolder() {
|
2022-11-29 21:46:36 +00:00
|
|
|
if (!MoveLegacyAlphaFolder(u"TelegramAlpha_data"_q, u"alpha"_q)
|
|
|
|
|| !MoveLegacyAlphaFolder(u"TelegramBeta_data"_q, u"beta"_q)) {
|
2019-01-21 13:42:21 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CheckPortableVersionFolder() {
|
|
|
|
if (!MoveLegacyAlphaFolder()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-11-29 21:46:36 +00:00
|
|
|
const auto portable = cExeDir() + u"TelegramForcePortable"_q;
|
|
|
|
QFile key(portable + u"/tdata/alpha"_q);
|
2019-01-21 13:42:21 +00:00
|
|
|
if (cAlphaVersion()) {
|
|
|
|
Assert(*AlphaPrivateKey != 0);
|
|
|
|
|
|
|
|
cForceWorkingDir(portable + '/');
|
2022-11-26 21:20:17 +00:00
|
|
|
QDir().mkpath(cWorkingDir() + u"tdata"_q);
|
2019-01-21 13:42:21 +00:00
|
|
|
cSetAlphaPrivateKey(QByteArray(AlphaPrivateKey));
|
|
|
|
if (!key.open(QIODevice::WriteOnly)) {
|
|
|
|
LOG(("FATAL: Could not open '%1' for writing private key!"
|
|
|
|
).arg(key.fileName()));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
QDataStream dataStream(&key);
|
|
|
|
dataStream.setVersion(QDataStream::Qt_5_3);
|
|
|
|
dataStream << quint64(cRealAlphaVersion()) << cAlphaPrivateKey();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (!QDir(portable).exists()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
cForceWorkingDir(portable + '/');
|
|
|
|
if (!key.exists()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!key.open(QIODevice::ReadOnly)) {
|
|
|
|
LOG(("FATAL: could not open '%1' for reading private key. "
|
|
|
|
"Delete it or reinstall private alpha version."
|
|
|
|
).arg(key.fileName()));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
QDataStream dataStream(&key);
|
|
|
|
dataStream.setVersion(QDataStream::Qt_5_3);
|
|
|
|
|
|
|
|
quint64 v;
|
|
|
|
QByteArray k;
|
|
|
|
dataStream >> v >> k;
|
|
|
|
if (dataStream.status() != QDataStream::Ok || k.isEmpty()) {
|
|
|
|
LOG(("FATAL: '%1' is corrupted. "
|
|
|
|
"Delete it or reinstall private alpha version."
|
|
|
|
).arg(key.fileName()));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
cSetAlphaVersion(AppVersion * 1000ULL);
|
|
|
|
cSetAlphaPrivateKey(k);
|
|
|
|
cSetRealAlphaVersion(v);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-01-12 09:18:28 +00:00
|
|
|
base::options::toggle OptionFractionalScalingEnabled({
|
|
|
|
.id = kOptionFractionalScalingEnabled,
|
|
|
|
.name = "Enable precise High DPI scaling",
|
|
|
|
.description = "Follow system interface scale settings exactly.",
|
2023-01-12 15:05:56 +00:00
|
|
|
.scope = base::options::windows | base::options::linux,
|
2023-01-12 09:18:28 +00:00
|
|
|
.restartRequired = true,
|
|
|
|
});
|
|
|
|
|
2019-01-21 13:42:21 +00:00
|
|
|
} // namespace
|
2017-12-11 14:45:29 +00:00
|
|
|
|
2023-01-12 09:18:28 +00:00
|
|
|
const char kOptionFractionalScalingEnabled[] = "fractional-scaling-enabled";
|
2023-02-22 07:44:59 +00:00
|
|
|
const char kOptionFreeType[] = "freetype";
|
2023-01-12 09:18:28 +00:00
|
|
|
|
2017-12-11 14:45:29 +00:00
|
|
|
std::unique_ptr<Launcher> Launcher::Create(int argc, char *argv[]) {
|
|
|
|
return std::make_unique<Platform::Launcher>(argc, argv);
|
|
|
|
}
|
|
|
|
|
2021-08-24 14:43:31 +00:00
|
|
|
Launcher::Launcher(int argc, char *argv[])
|
2017-12-11 14:45:29 +00:00
|
|
|
: _argc(argc)
|
2018-06-03 19:52:23 +00:00
|
|
|
, _argv(argv)
|
2020-12-29 07:17:43 +00:00
|
|
|
, _baseIntegration(_argc, _argv) {
|
2021-08-24 14:43:31 +00:00
|
|
|
crl::toggle_fp_exceptions(true);
|
|
|
|
|
2019-11-02 17:06:47 +00:00
|
|
|
base::Integration::Set(&_baseIntegration);
|
2017-12-11 14:45:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Launcher::init() {
|
2017-12-12 08:15:33 +00:00
|
|
|
_arguments = readArguments(_argc, _argv);
|
|
|
|
|
|
|
|
prepareSettings();
|
2021-04-20 12:40:54 +00:00
|
|
|
initQtMessageLogging();
|
2020-07-01 02:24:54 +00:00
|
|
|
|
2022-11-29 21:46:36 +00:00
|
|
|
QApplication::setApplicationName(u"TelegramDesktop"_q);
|
2017-12-11 14:45:29 +00:00
|
|
|
|
2021-10-19 13:00:21 +00:00
|
|
|
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
|
2020-05-14 17:31:32 +00:00
|
|
|
// fallback session management is useless for tdesktop since it doesn't have
|
|
|
|
// any "are you sure you want to close this window?" dialogs
|
|
|
|
// but it produces bugs like https://github.com/telegramdesktop/tdesktop/issues/5022
|
|
|
|
// and https://github.com/telegramdesktop/tdesktop/issues/7549
|
|
|
|
// and https://github.com/telegramdesktop/tdesktop/issues/948
|
|
|
|
// more info: https://doc.qt.io/qt-5/qguiapplication.html#isFallbackSessionManagementEnabled
|
|
|
|
QApplication::setFallbackSessionManagementEnabled(false);
|
2021-10-19 13:00:21 +00:00
|
|
|
#endif // Qt < 6.0.0
|
2020-05-14 17:31:32 +00:00
|
|
|
|
2017-12-11 14:45:29 +00:00
|
|
|
initHook();
|
|
|
|
}
|
|
|
|
|
2023-01-12 09:18:28 +00:00
|
|
|
void Launcher::initHighDpi() {
|
2023-02-11 03:37:11 +00:00
|
|
|
#if QT_VERSION < QT_VERSION_CHECK(6, 2, 0)
|
|
|
|
qputenv("QT_DPI_ADJUSTMENT_POLICY", "AdjustDpi");
|
|
|
|
#endif // Qt < 6.2.0
|
|
|
|
|
2023-02-10 07:39:13 +00:00
|
|
|
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
|
2023-01-12 09:18:28 +00:00
|
|
|
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling, true);
|
2023-02-10 07:39:13 +00:00
|
|
|
#endif // Qt < 6.0.0
|
|
|
|
|
2023-01-12 09:18:28 +00:00
|
|
|
if (OptionFractionalScalingEnabled.value()) {
|
|
|
|
QApplication::setHighDpiScaleFactorRoundingPolicy(
|
|
|
|
Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
|
|
|
|
} else {
|
|
|
|
QApplication::setHighDpiScaleFactorRoundingPolicy(
|
|
|
|
Qt::HighDpiScaleFactorRoundingPolicy::RoundPreferFloor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-11 14:45:29 +00:00
|
|
|
int Launcher::exec() {
|
|
|
|
init();
|
|
|
|
|
|
|
|
if (cLaunchMode() == LaunchModeFixPrevious) {
|
|
|
|
return psFixPrevious();
|
|
|
|
} else if (cLaunchMode() == LaunchModeCleanup) {
|
|
|
|
return psCleanup();
|
|
|
|
}
|
|
|
|
|
2019-10-13 08:54:38 +00:00
|
|
|
// Must be started before Platform is started.
|
|
|
|
Logs::start(this);
|
2022-02-02 09:04:46 +00:00
|
|
|
base::options::init(cWorkingDir() + "tdata/experimental_options.json");
|
2019-10-13 08:54:38 +00:00
|
|
|
|
2023-01-12 09:18:28 +00:00
|
|
|
// Must be called after options are inited.
|
|
|
|
initHighDpi();
|
|
|
|
|
2020-12-29 11:25:44 +00:00
|
|
|
if (Logs::DebugEnabled()) {
|
|
|
|
const auto openalLogPath = QDir::toNativeSeparators(
|
2022-11-29 21:46:36 +00:00
|
|
|
cWorkingDir() + u"DebugLogs/last_openal_log.txt"_q);
|
2020-12-29 11:25:44 +00:00
|
|
|
|
|
|
|
qputenv("ALSOFT_LOGLEVEL", "3");
|
|
|
|
|
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
_wputenv_s(
|
|
|
|
L"ALSOFT_LOGFILE",
|
|
|
|
openalLogPath.toStdWString().c_str());
|
|
|
|
#else // Q_OS_WIN
|
|
|
|
qputenv(
|
|
|
|
"ALSOFT_LOGFILE",
|
|
|
|
QFile::encodeName(openalLogPath));
|
|
|
|
#endif // !Q_OS_WIN
|
|
|
|
}
|
|
|
|
|
2019-10-13 08:54:38 +00:00
|
|
|
// Must be started before Sandbox is created.
|
|
|
|
Platform::start();
|
2017-12-17 18:41:34 +00:00
|
|
|
auto result = executeApplication();
|
2017-12-11 14:45:29 +00:00
|
|
|
|
|
|
|
DEBUG_LOG(("Telegram finished, result: %1").arg(result));
|
|
|
|
|
2018-07-11 22:14:44 +00:00
|
|
|
if (!UpdaterDisabled() && cRestartingUpdate()) {
|
2019-01-21 13:42:21 +00:00
|
|
|
DEBUG_LOG(("Sandbox Info: executing updater to install update."));
|
2017-12-12 07:52:53 +00:00
|
|
|
if (!launchUpdater(UpdaterLaunch::PerformUpdate)) {
|
2022-11-29 21:46:36 +00:00
|
|
|
base::Platform::DeleteDirectory(cWorkingDir() + u"tupdates/temp"_q);
|
2017-12-12 07:52:53 +00:00
|
|
|
}
|
2018-07-11 22:14:44 +00:00
|
|
|
} else if (cRestarting()) {
|
2019-01-21 13:42:21 +00:00
|
|
|
DEBUG_LOG(("Sandbox Info: executing Telegram because of restart."));
|
2017-12-12 07:52:53 +00:00
|
|
|
launchUpdater(UpdaterLaunch::JustRelaunch);
|
2017-12-11 14:45:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CrashReports::Finish();
|
|
|
|
Platform::finish();
|
|
|
|
Logs::finish();
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2019-01-21 13:42:21 +00:00
|
|
|
void Launcher::workingFolderReady() {
|
|
|
|
srand((unsigned int)time(nullptr));
|
|
|
|
|
|
|
|
ComputeDebugMode();
|
2020-05-14 04:35:22 +00:00
|
|
|
ComputeExternalUpdater();
|
2019-01-21 13:42:21 +00:00
|
|
|
ComputeInstallBetaVersions();
|
|
|
|
ComputeInstallationTag();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Launcher::writeDebugModeSetting() {
|
|
|
|
WriteDebugModeSetting();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Launcher::writeInstallBetaVersionsSetting() {
|
|
|
|
WriteInstallBetaVersionsSetting();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Launcher::checkPortableVersionFolder() {
|
|
|
|
return CheckPortableVersionFolder();
|
|
|
|
}
|
|
|
|
|
2017-12-12 08:15:33 +00:00
|
|
|
QStringList Launcher::readArguments(int argc, char *argv[]) const {
|
|
|
|
Expects(argc >= 0);
|
|
|
|
|
|
|
|
if (const auto native = readArgumentsHook(argc, argv)) {
|
|
|
|
return *native;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto result = QStringList();
|
|
|
|
result.reserve(argc);
|
|
|
|
for (auto i = 0; i != argc; ++i) {
|
2019-09-16 11:14:06 +00:00
|
|
|
result.push_back(base::FromUtf8Safe(argv[i]));
|
2017-12-12 08:15:33 +00:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2017-12-11 14:45:29 +00:00
|
|
|
QString Launcher::argumentsString() const {
|
|
|
|
return _arguments.join(' ');
|
|
|
|
}
|
|
|
|
|
2018-06-03 19:52:23 +00:00
|
|
|
bool Launcher::customWorkingDir() const {
|
|
|
|
return _customWorkingDir;
|
|
|
|
}
|
|
|
|
|
2017-12-12 07:52:53 +00:00
|
|
|
void Launcher::prepareSettings() {
|
2020-10-29 19:56:13 +00:00
|
|
|
auto path = base::Platform::CurrentExecutablePath(_argc, _argv);
|
2017-12-12 07:52:53 +00:00
|
|
|
LOG(("Executable path before check: %1").arg(path));
|
|
|
|
if (!path.isEmpty()) {
|
|
|
|
auto info = QFileInfo(path);
|
|
|
|
if (info.isSymLink()) {
|
2021-10-19 13:00:21 +00:00
|
|
|
info = QFileInfo(info.symLinkTarget());
|
2017-12-12 07:52:53 +00:00
|
|
|
}
|
|
|
|
if (info.exists()) {
|
2018-06-20 18:12:47 +00:00
|
|
|
const auto dir = info.absoluteDir().absolutePath();
|
|
|
|
gExeDir = (dir.endsWith('/') ? dir : (dir + '/'));
|
2017-12-12 07:52:53 +00:00
|
|
|
gExeName = info.fileName();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (cExeName().isEmpty()) {
|
|
|
|
LOG(("WARNING: Could not compute executable path, some features will be disabled."));
|
|
|
|
}
|
|
|
|
|
|
|
|
processArguments();
|
|
|
|
}
|
|
|
|
|
2021-04-20 12:40:54 +00:00
|
|
|
void Launcher::initQtMessageLogging() {
|
|
|
|
static QtMessageHandler OriginalMessageHandler = nullptr;
|
|
|
|
OriginalMessageHandler = qInstallMessageHandler([](
|
|
|
|
QtMsgType type,
|
|
|
|
const QMessageLogContext &context,
|
|
|
|
const QString &msg) {
|
2021-08-17 09:25:13 +00:00
|
|
|
const auto InvokeOriginal = [&] {
|
|
|
|
#ifndef _DEBUG
|
|
|
|
if (Logs::DebugEnabled()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif // _DEBUG
|
|
|
|
if (OriginalMessageHandler) {
|
|
|
|
OriginalMessageHandler(type, context, msg);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
InvokeOriginal();
|
2021-04-20 12:40:54 +00:00
|
|
|
if (Logs::DebugEnabled() || !Logs::started()) {
|
2021-05-12 10:48:44 +00:00
|
|
|
if (!Logs::WritingEntry()) {
|
|
|
|
// Sometimes Qt logs something inside our own logging.
|
2021-04-20 12:40:54 +00:00
|
|
|
LOG((msg));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-01-21 13:42:21 +00:00
|
|
|
uint64 Launcher::installationTag() const {
|
|
|
|
return InstallationTag;
|
|
|
|
}
|
|
|
|
|
2017-12-12 07:52:53 +00:00
|
|
|
void Launcher::processArguments() {
|
|
|
|
enum class KeyFormat {
|
|
|
|
NoValues,
|
|
|
|
OneValue,
|
|
|
|
AllLeftValues,
|
|
|
|
};
|
|
|
|
auto parseMap = std::map<QByteArray, KeyFormat> {
|
2018-07-11 22:14:44 +00:00
|
|
|
{ "-debug" , KeyFormat::NoValues },
|
|
|
|
{ "-key" , KeyFormat::OneValue },
|
|
|
|
{ "-autostart" , KeyFormat::NoValues },
|
|
|
|
{ "-fixprevious" , KeyFormat::NoValues },
|
|
|
|
{ "-cleanup" , KeyFormat::NoValues },
|
|
|
|
{ "-noupdate" , KeyFormat::NoValues },
|
|
|
|
{ "-tosettings" , KeyFormat::NoValues },
|
|
|
|
{ "-startintray" , KeyFormat::NoValues },
|
2021-09-12 23:13:13 +00:00
|
|
|
{ "-quit" , KeyFormat::NoValues },
|
2018-07-11 22:14:44 +00:00
|
|
|
{ "-sendpath" , KeyFormat::AllLeftValues },
|
|
|
|
{ "-workdir" , KeyFormat::OneValue },
|
|
|
|
{ "--" , KeyFormat::OneValue },
|
2019-05-25 10:06:12 +00:00
|
|
|
{ "-scale" , KeyFormat::OneValue },
|
2017-12-12 07:52:53 +00:00
|
|
|
};
|
|
|
|
auto parseResult = QMap<QByteArray, QStringList>();
|
|
|
|
auto parsingKey = QByteArray();
|
|
|
|
auto parsingFormat = KeyFormat::NoValues;
|
2021-03-13 08:26:58 +00:00
|
|
|
for (const auto &argument : std::as_const(_arguments)) {
|
2017-12-12 07:52:53 +00:00
|
|
|
switch (parsingFormat) {
|
|
|
|
case KeyFormat::OneValue: {
|
|
|
|
parseResult[parsingKey] = QStringList(argument.mid(0, 8192));
|
|
|
|
parsingFormat = KeyFormat::NoValues;
|
|
|
|
} break;
|
|
|
|
case KeyFormat::AllLeftValues: {
|
|
|
|
parseResult[parsingKey].push_back(argument.mid(0, 8192));
|
|
|
|
} break;
|
|
|
|
case KeyFormat::NoValues: {
|
|
|
|
parsingKey = argument.toLatin1();
|
|
|
|
auto it = parseMap.find(parsingKey);
|
|
|
|
if (it != parseMap.end()) {
|
|
|
|
parsingFormat = it->second;
|
|
|
|
parseResult[parsingKey] = QStringList();
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-19 19:17:41 +00:00
|
|
|
gDebugMode = parseResult.contains("-debug");
|
2018-08-27 11:35:58 +00:00
|
|
|
gKeyFile = parseResult.value("-key", {}).join(QString()).toLower();
|
|
|
|
gKeyFile = gKeyFile.replace(QRegularExpression("[^a-z0-9\\-_]"), {});
|
2017-12-12 07:52:53 +00:00
|
|
|
gLaunchMode = parseResult.contains("-autostart") ? LaunchModeAutoStart
|
|
|
|
: parseResult.contains("-fixprevious") ? LaunchModeFixPrevious
|
|
|
|
: parseResult.contains("-cleanup") ? LaunchModeCleanup
|
|
|
|
: LaunchModeNormal;
|
|
|
|
gNoStartUpdate = parseResult.contains("-noupdate");
|
|
|
|
gStartToSettings = parseResult.contains("-tosettings");
|
|
|
|
gStartInTray = parseResult.contains("-startintray");
|
2021-09-12 23:13:13 +00:00
|
|
|
gQuit = parseResult.contains("-quit");
|
2018-08-27 11:35:58 +00:00
|
|
|
gSendPaths = parseResult.value("-sendpath", {});
|
2023-02-19 03:18:17 +00:00
|
|
|
cForceWorkingDir(parseResult.value("-workdir", {}).join(QString()));
|
2017-12-12 07:52:53 +00:00
|
|
|
if (!gWorkingDir.isEmpty()) {
|
2023-02-19 03:18:17 +00:00
|
|
|
_customWorkingDir = true;
|
2017-12-12 07:52:53 +00:00
|
|
|
}
|
2018-08-27 11:35:58 +00:00
|
|
|
gStartUrl = parseResult.value("--", {}).join(QString());
|
2019-05-25 10:06:12 +00:00
|
|
|
|
|
|
|
const auto scaleKey = parseResult.value("-scale", {});
|
|
|
|
if (scaleKey.size() > 0) {
|
2022-09-01 07:44:00 +00:00
|
|
|
using namespace style;
|
2019-05-25 10:06:12 +00:00
|
|
|
const auto value = scaleKey[0].toInt();
|
2022-09-01 07:44:00 +00:00
|
|
|
gConfigScale = ((value < kScaleMin) || (value > kScaleMax))
|
|
|
|
? kScaleAuto
|
2019-05-25 10:06:12 +00:00
|
|
|
: value;
|
|
|
|
}
|
2017-12-12 07:52:53 +00:00
|
|
|
}
|
|
|
|
|
2017-12-17 18:41:34 +00:00
|
|
|
int Launcher::executeApplication() {
|
2019-05-06 10:40:04 +00:00
|
|
|
FilteredCommandLineArguments arguments(_argc, _argv);
|
|
|
|
Sandbox sandbox(this, arguments.count(), arguments.values());
|
2019-09-17 07:51:02 +00:00
|
|
|
Ui::MainQueueProcessor processor;
|
2018-08-09 20:39:22 +00:00
|
|
|
base::ConcurrentTimerEnvironment environment;
|
2019-01-21 13:42:21 +00:00
|
|
|
return sandbox.start();
|
2017-12-17 18:41:34 +00:00
|
|
|
}
|
|
|
|
|
2017-12-11 14:45:29 +00:00
|
|
|
} // namespace Core
|