2014-05-30 08:53:19 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2014-12-01 10:47:38 +00:00
|
|
|
the official desktop version of Telegram messaging app, see https://telegram.org
|
2014-05-30 08:53:19 +00:00
|
|
|
|
|
|
|
Telegram Desktop is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
It is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
2015-10-03 13:16:42 +00:00
|
|
|
In addition, as a special exception, the copyright holders give permission
|
|
|
|
to link the code of portions of this program with the OpenSSL library.
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
|
2017-01-11 18:31:31 +00:00
|
|
|
Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
2014-05-30 08:53:19 +00:00
|
|
|
*/
|
|
|
|
#include "settings.h"
|
2016-04-27 12:02:17 +00:00
|
|
|
|
2017-03-04 10:23:56 +00:00
|
|
|
#include "platform/platform_specific.h"
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2015-12-12 22:29:33 +00:00
|
|
|
bool gRtl = false;
|
2015-10-06 19:49:23 +00:00
|
|
|
Qt::LayoutDirection gLangDir = gRtl ? Qt::RightToLeft : Qt::LeftToRight;
|
2015-04-19 10:29:19 +00:00
|
|
|
|
2016-01-11 15:43:29 +00:00
|
|
|
QString gArguments;
|
|
|
|
|
2016-04-27 12:02:17 +00:00
|
|
|
bool gAlphaVersion = AppAlphaVersion;
|
|
|
|
uint64 gBetaVersion = AppBetaVersion;
|
|
|
|
uint64 gRealBetaVersion = AppBetaVersion;
|
2015-12-03 18:16:34 +00:00
|
|
|
QByteArray gBetaPrivateKey;
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
bool gTestMode = false;
|
|
|
|
bool gDebug = false;
|
|
|
|
bool gManyInstance = false;
|
|
|
|
QString gKeyFile;
|
2014-11-27 18:20:48 +00:00
|
|
|
QString gWorkingDir, gExeDir, gExeName;
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2014-07-18 10:37:34 +00:00
|
|
|
QStringList gSendPaths;
|
2014-12-03 13:10:32 +00:00
|
|
|
QString gStartUrl;
|
2014-07-18 10:37:34 +00:00
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
QString gDialogLastPath, gDialogHelperPath; // optimize QFileDialog
|
|
|
|
|
|
|
|
bool gStartMinimized = false;
|
2015-01-27 16:58:58 +00:00
|
|
|
bool gStartInTray = false;
|
2014-05-30 08:53:19 +00:00
|
|
|
bool gAutoStart = false;
|
2014-07-18 10:37:34 +00:00
|
|
|
bool gSendToMenu = false;
|
2017-02-17 12:50:27 +00:00
|
|
|
bool gUseExternalVideoPlayer = false;
|
2014-05-30 08:53:19 +00:00
|
|
|
bool gAutoUpdate = true;
|
|
|
|
TWindowPos gWindowPos;
|
2016-01-11 15:43:29 +00:00
|
|
|
LaunchMode gLaunchMode = LaunchModeNormal;
|
2015-01-15 14:22:15 +00:00
|
|
|
bool gSupportTray = true;
|
2014-05-30 08:53:19 +00:00
|
|
|
bool gSeenTrayTooltip = false;
|
2014-12-19 21:20:30 +00:00
|
|
|
bool gRestartingUpdate = false, gRestarting = false, gRestartingToSettings = false, gWriteProtected = false;
|
2014-05-30 08:53:19 +00:00
|
|
|
int32 gLastUpdateCheck = 0;
|
|
|
|
bool gNoStartUpdate = false;
|
|
|
|
bool gStartToSettings = false;
|
|
|
|
bool gReplaceEmojis = true;
|
|
|
|
|
|
|
|
bool gCtrlEnter = false;
|
2015-02-03 15:02:46 +00:00
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
uint32 gConnectionsInSession = 1;
|
|
|
|
QString gLoggedPhoneNumber;
|
|
|
|
|
|
|
|
QByteArray gLocalSalt;
|
|
|
|
DBIScale gRealScale = dbisAuto, gScreenScale = dbisOne, gConfigScale = dbisAuto;
|
2014-09-20 21:35:46 +00:00
|
|
|
bool gCompressPastedImage = true;
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2015-02-10 18:55:04 +00:00
|
|
|
QString gTimeFormat = qsl("hh:mm");
|
|
|
|
|
2017-02-15 08:50:11 +00:00
|
|
|
RecentEmojiPack gRecentEmoji;
|
|
|
|
RecentEmojiPreload gRecentEmojiPreload;
|
2015-05-08 12:45:14 +00:00
|
|
|
EmojiColorVariants gEmojiVariants;
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2015-05-19 15:46:45 +00:00
|
|
|
RecentStickerPreload gRecentStickersPreload;
|
2015-01-02 14:55:24 +00:00
|
|
|
RecentStickerPack gRecentStickers;
|
|
|
|
|
2015-12-27 21:37:48 +00:00
|
|
|
SavedGifs gSavedGifs;
|
2016-12-01 19:20:33 +00:00
|
|
|
TimeMs gLastSavedGifsUpdate = 0;
|
2015-12-27 21:37:48 +00:00
|
|
|
|
2015-03-24 10:00:27 +00:00
|
|
|
RecentHashtagPack gRecentWriteHashtags, gRecentSearchHashtags;
|
|
|
|
|
2016-01-01 14:48:32 +00:00
|
|
|
RecentInlineBots gRecentInlineBots;
|
|
|
|
|
2015-04-02 10:33:19 +00:00
|
|
|
bool gPasswordRecovered = false;
|
2015-04-04 20:01:34 +00:00
|
|
|
int32 gPasscodeBadTries = 0;
|
2016-12-01 19:20:33 +00:00
|
|
|
TimeMs gPasscodeLastTry = 0;
|
2015-04-02 10:33:19 +00:00
|
|
|
|
2014-06-14 19:32:11 +00:00
|
|
|
bool gRetina = false;
|
|
|
|
float64 gRetinaFactor = 1.;
|
2014-06-15 12:31:03 +00:00
|
|
|
int32 gIntRetinaFactor = 1;
|
2014-06-16 09:31:10 +00:00
|
|
|
|
2014-06-14 19:32:11 +00:00
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
DBIPlatform gPlatform = dbipWindows;
|
|
|
|
#elif defined Q_OS_MAC
|
|
|
|
DBIPlatform gPlatform = dbipMac;
|
2014-07-17 09:42:06 +00:00
|
|
|
#elif defined Q_OS_LINUX64
|
|
|
|
DBIPlatform gPlatform = dbipLinux64;
|
2016-02-02 11:48:46 +00:00
|
|
|
#elif defined Q_OS_LINUX32
|
|
|
|
DBIPlatform gPlatform = dbipLinux32;
|
2014-06-14 19:32:11 +00:00
|
|
|
#else
|
|
|
|
#error Unknown platform
|
|
|
|
#endif
|
2016-02-02 11:48:46 +00:00
|
|
|
QString gPlatformString;
|
|
|
|
QUrl gUpdateURL;
|
2015-12-03 18:16:34 +00:00
|
|
|
bool gIsElCapitan = false;
|
2014-06-14 19:32:11 +00:00
|
|
|
|
2015-01-26 13:04:41 +00:00
|
|
|
int gOtherOnline = 0;
|
|
|
|
|
2015-08-07 12:11:50 +00:00
|
|
|
SavedPeers gSavedPeers;
|
|
|
|
SavedPeersByTime gSavedPeersByTime;
|
|
|
|
|
2015-09-08 17:22:29 +00:00
|
|
|
ReportSpamStatuses gReportSpamStatuses;
|
2015-09-07 15:53:46 +00:00
|
|
|
|
2015-12-23 21:19:57 +00:00
|
|
|
int32 gAutoDownloadPhoto = 0; // all auto download
|
|
|
|
int32 gAutoDownloadAudio = 0;
|
|
|
|
int32 gAutoDownloadGif = 0;
|
2015-12-27 21:37:48 +00:00
|
|
|
bool gAutoPlayGif = true;
|
2015-12-23 21:19:57 +00:00
|
|
|
|
2017-09-05 13:40:39 +00:00
|
|
|
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 },
|
|
|
|
{ "-fixprevios" , 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(QString())).front();
|
|
|
|
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(QString())).front();
|
|
|
|
if (!gWorkingDir.isEmpty() && !QDir().exists(gWorkingDir)) {
|
|
|
|
gWorkingDir = QString();
|
|
|
|
}
|
|
|
|
gStartUrl = parseResult.value("--", QStringList(QString())).front();
|
|
|
|
}
|
|
|
|
|
|
|
|
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]));
|
|
|
|
}
|
|
|
|
gArguments = arguments.join(' ');
|
|
|
|
|
2015-07-28 13:47:21 +00:00
|
|
|
#ifdef Q_OS_MAC
|
2016-08-30 05:24:16 +00:00
|
|
|
#ifndef OS_MAC_OLD
|
2016-02-02 11:48:46 +00:00
|
|
|
if (QSysInfo::macVersion() >= QSysInfo::MV_10_11) {
|
|
|
|
gIsElCapitan = true;
|
2015-07-28 13:47:21 +00:00
|
|
|
}
|
2016-08-30 05:24:16 +00:00
|
|
|
#else // OS_MAC_OLD
|
|
|
|
gPlatform = dbipMacOld;
|
|
|
|
#endif // OS_MAC_OLD
|
|
|
|
#endif // Q_OS_MAC
|
2016-02-18 16:36:33 +00:00
|
|
|
|
2016-02-02 11:48:46 +00:00
|
|
|
switch (cPlatform()) {
|
|
|
|
case dbipWindows:
|
|
|
|
gUpdateURL = QUrl(qsl("http://tdesktop.com/win/tupdates/current"));
|
2017-02-03 10:17:40 +00:00
|
|
|
#ifndef OS_WIN_STORE
|
2016-02-02 11:48:46 +00:00
|
|
|
gPlatformString = qsl("Windows");
|
2017-02-03 10:17:40 +00:00
|
|
|
#else // OS_WIN_STORE
|
|
|
|
gPlatformString = qsl("WinStore");
|
|
|
|
#endif // OS_WIN_STORE
|
2016-02-02 11:48:46 +00:00
|
|
|
break;
|
|
|
|
case dbipMac:
|
|
|
|
gUpdateURL = QUrl(qsl("http://tdesktop.com/mac/tupdates/current"));
|
2016-08-31 17:58:46 +00:00
|
|
|
#ifndef OS_MAC_STORE
|
2016-02-02 11:48:46 +00:00
|
|
|
gPlatformString = qsl("MacOS");
|
2016-08-31 17:58:46 +00:00
|
|
|
#else // OS_MAC_STORE
|
|
|
|
gPlatformString = qsl("MacAppStore");
|
|
|
|
#endif // OS_MAC_STORE
|
2016-02-02 11:48:46 +00:00
|
|
|
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;
|
|
|
|
}
|
2016-01-11 15:43:29 +00:00
|
|
|
|
2017-08-15 17:12:57 +00:00
|
|
|
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."));
|
|
|
|
}
|
2017-09-05 13:40:39 +00:00
|
|
|
|
|
|
|
ParseCommandLineArguments(arguments);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2015-05-19 15:46:45 +00:00
|
|
|
RecentStickerPack &cGetRecentStickers() {
|
|
|
|
if (cRecentStickers().isEmpty() && !cRecentStickersPreload().isEmpty()) {
|
|
|
|
RecentStickerPreload p(cRecentStickersPreload());
|
|
|
|
cSetRecentStickersPreload(RecentStickerPreload());
|
|
|
|
|
|
|
|
RecentStickerPack &recent(cRefRecentStickers());
|
|
|
|
recent.reserve(p.size());
|
|
|
|
for (RecentStickerPreload::const_iterator i = p.cbegin(), e = p.cend(); i != e; ++i) {
|
|
|
|
DocumentData *doc = App::document(i->first);
|
2015-06-30 21:07:05 +00:00
|
|
|
if (!doc || !doc->sticker()) continue;
|
2015-05-19 15:46:45 +00:00
|
|
|
|
|
|
|
recent.push_back(qMakePair(doc, i->second));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return cRefRecentStickers();
|
|
|
|
}
|