mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-08-31 06:26:18 +00:00
Move relaunch / update logic to Core::Launcher.
Also pass "-workdir" argument through relaunch / update. Fixes #4149.
This commit is contained in:
@@ -61,7 +61,9 @@ uint32 gConnectionsInSession = 1;
|
||||
QString gLoggedPhoneNumber;
|
||||
|
||||
QByteArray gLocalSalt;
|
||||
DBIScale gRealScale = dbisAuto, gScreenScale = dbisOne, gConfigScale = dbisAuto;
|
||||
DBIScale gRealScale = dbisAuto;
|
||||
DBIScale gScreenScale = dbisOne;
|
||||
DBIScale gConfigScale = dbisAuto;
|
||||
bool gCompressPastedImage = true;
|
||||
|
||||
QString gTimeFormat = qsl("hh:mm");
|
||||
@@ -87,6 +89,8 @@ int32 gIntRetinaFactor = 1;
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
DBIPlatform gPlatform = dbipWindows;
|
||||
#elif defined OS_MAC_OLD
|
||||
DBIPlatform gPlatform = dbipMacOld;
|
||||
#elif defined Q_OS_MAC
|
||||
DBIPlatform gPlatform = dbipMac;
|
||||
#elif defined Q_OS_LINUX64
|
||||
@@ -112,137 +116,3 @@ int32 gAutoDownloadPhoto = 0; // all auto download
|
||||
int32 gAutoDownloadAudio = 0;
|
||||
int32 gAutoDownloadGif = 0;
|
||||
bool gAutoPlayGif = true;
|
||||
|
||||
void ParseCommandLineArguments(const QStringList &arguments) {
|
||||
enum class KeyFormat {
|
||||
NoValues,
|
||||
OneValue,
|
||||
AllLeftValues,
|
||||
};
|
||||
auto parseMap = std::map<QByteArray, KeyFormat> {
|
||||
{ "-testmode" , KeyFormat::NoValues },
|
||||
{ "-debug" , KeyFormat::NoValues },
|
||||
{ "-many" , KeyFormat::NoValues },
|
||||
{ "-key" , KeyFormat::OneValue },
|
||||
{ "-autostart" , KeyFormat::NoValues },
|
||||
{ "-fixprevious", KeyFormat::NoValues },
|
||||
{ "-cleanup" , KeyFormat::NoValues },
|
||||
{ "-noupdate" , KeyFormat::NoValues },
|
||||
{ "-tosettings" , KeyFormat::NoValues },
|
||||
{ "-startintray", KeyFormat::NoValues },
|
||||
{ "-sendpath" , KeyFormat::AllLeftValues },
|
||||
{ "-workdir" , KeyFormat::OneValue },
|
||||
{ "--" , KeyFormat::OneValue },
|
||||
};
|
||||
auto parseResult = QMap<QByteArray, QStringList>();
|
||||
auto parsingKey = QByteArray();
|
||||
auto parsingFormat = KeyFormat::NoValues;
|
||||
for (auto &argument : arguments) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
gTestMode = parseResult.contains("-testmode");
|
||||
gDebug = parseResult.contains("-debug");
|
||||
gManyInstance = parseResult.contains("-many");
|
||||
gKeyFile = parseResult.value("-key", QStringList()).join(QString());
|
||||
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");
|
||||
gSendPaths = parseResult.value("-sendpath", QStringList());
|
||||
gWorkingDir = parseResult.value("-workdir", QStringList()).join(QString());
|
||||
if (!gWorkingDir.isEmpty() && !QDir().exists(gWorkingDir)) {
|
||||
gWorkingDir = QString();
|
||||
}
|
||||
gStartUrl = parseResult.value("--", QStringList()).join(QString());
|
||||
}
|
||||
|
||||
void InitFromCommandLine(int argc, char *argv[]) {
|
||||
Expects(argc >= 0);
|
||||
auto arguments = QStringList();
|
||||
arguments.reserve(argc);
|
||||
for (auto i = 0; i != argc; ++i) {
|
||||
arguments.push_back(fromUtf8Safe(argv[i]));
|
||||
}
|
||||
|
||||
#ifdef Q_OS_MAC
|
||||
#ifndef OS_MAC_OLD
|
||||
if (QSysInfo::macVersion() >= QSysInfo::MV_10_11) {
|
||||
gIsElCapitan = true;
|
||||
}
|
||||
#else // OS_MAC_OLD
|
||||
if (QSysInfo::macVersion() < QSysInfo::MV_10_7) {
|
||||
gIsSnowLeopard = true;
|
||||
}
|
||||
gPlatform = dbipMacOld;
|
||||
#endif // OS_MAC_OLD
|
||||
#endif // Q_OS_MAC
|
||||
|
||||
switch (cPlatform()) {
|
||||
case dbipWindows:
|
||||
gUpdateURL = QUrl(qsl("http://tdesktop.com/win/tupdates/current"));
|
||||
#ifndef OS_WIN_STORE
|
||||
gPlatformString = qsl("Windows");
|
||||
#else // OS_WIN_STORE
|
||||
gPlatformString = qsl("WinStore");
|
||||
#endif // OS_WIN_STORE
|
||||
break;
|
||||
case dbipMac:
|
||||
gUpdateURL = QUrl(qsl("http://tdesktop.com/mac/tupdates/current"));
|
||||
#ifndef OS_MAC_STORE
|
||||
gPlatformString = qsl("MacOS");
|
||||
#else // OS_MAC_STORE
|
||||
gPlatformString = qsl("MacAppStore");
|
||||
#endif // OS_MAC_STORE
|
||||
break;
|
||||
case dbipMacOld:
|
||||
gUpdateURL = QUrl(qsl("http://tdesktop.com/mac32/tupdates/current"));
|
||||
gPlatformString = qsl("MacOSold");
|
||||
break;
|
||||
case dbipLinux64:
|
||||
gUpdateURL = QUrl(qsl("http://tdesktop.com/linux/tupdates/current"));
|
||||
gPlatformString = qsl("Linux64bit");
|
||||
break;
|
||||
case dbipLinux32:
|
||||
gUpdateURL = QUrl(qsl("http://tdesktop.com/linux32/tupdates/current"));
|
||||
gPlatformString = qsl("Linux32bit");
|
||||
break;
|
||||
}
|
||||
|
||||
auto path = Platform::CurrentExecutablePath(argc, argv);
|
||||
LOG(("Executable path before check: %1").arg(path));
|
||||
if (!path.isEmpty()) {
|
||||
auto info = QFileInfo(path);
|
||||
if (info.isSymLink()) {
|
||||
info = info.symLinkTarget();
|
||||
}
|
||||
if (info.exists()) {
|
||||
gExeDir = info.absoluteDir().absolutePath() + '/';
|
||||
gExeName = info.fileName();
|
||||
}
|
||||
}
|
||||
if (cExeName().isEmpty()) {
|
||||
LOG(("WARNING: Could not compute executable path, some features will be disabled."));
|
||||
}
|
||||
|
||||
ParseCommandLineArguments(arguments);
|
||||
}
|
||||
|
Reference in New Issue
Block a user