void SpecialConfigRequest::performDnsRequest() { auto dnsUrl = QUrl(); dnsUrl.setScheme(qsl("https")); dnsUrl.setHost(qsl("google.com")); dnsUrl.setPath(qsl("/resolve")); dnsUrl.setQuery(qsl("name=%1.stel.com&type=16").arg(cTestMode() ? qsl("tap") : qsl("ap"))); auto dnsRequest = QNetworkRequest(QUrl(dnsUrl)); dnsRequest.setRawHeader("Host", "dns.google.com"); _dnsReply.reset(_manager.get(dnsRequest)); connect(_dnsReply.get(), &QNetworkReply::finished, this, [this] { dnsFinished(); }); }
bool _execUpdater(bool update = true) { static const int MaxLen = 65536, MaxArgsCount = 128; char path[MaxLen] = {0}; QByteArray data(QFile::encodeName(cExeDir() + "Updater")); memcpy(path, data.constData(), data.size()); char *args[MaxArgsCount] = {0}, p_noupdate[] = "-noupdate", p_autostart[] = "-autostart", p_debug[] = "-debug", p_tosettings[] = "-tosettings", p_key[] = "-key", p_path[] = "-workpath", p_startintray[] = "-startintray", p_testmode[] = "-testmode"; char p_datafile[MaxLen] = {0}, p_pathbuf[MaxLen] = {0}; int argIndex = 0; args[argIndex++] = path; if (!update) { args[argIndex++] = p_noupdate; args[argIndex++] = p_tosettings; } if (cFromAutoStart()) args[argIndex++] = p_autostart; if (cDebug()) args[argIndex++] = p_debug; if (cStartInTray()) args[argIndex++] = p_startintray; if (cTestMode()) args[argIndex++] = p_testmode; if (cDataFile() != qsl("data")) { QByteArray dataf = QFile::encodeName(cDataFile()); if (dataf.size() < MaxLen) { memcpy(p_datafile, dataf.constData(), dataf.size()); args[argIndex++] = p_key; args[argIndex++] = p_datafile; } } QByteArray pathf = cWorkingDir().toUtf8(); if (pathf.size() < MaxLen) { memcpy(p_pathbuf, pathf.constData(), pathf.size()); args[argIndex++] = p_path; args[argIndex++] = p_pathbuf; } pid_t pid = fork(); switch (pid) { case -1: return false; case 0: execv(path, args); return false; } return true; }
bool Launcher::launchUpdater(UpdaterLaunch action) { if (cExeName().isEmpty()) { return false; } const auto operation = (action == UpdaterLaunch::JustRelaunch) ? QString() : (cWriteProtected() ? qsl("runas") : QString()); const auto binaryPath = (action == UpdaterLaunch::JustRelaunch) ? (cExeDir() + cExeName()) : (cWriteProtected() ? (cWorkingDir() + qsl("tupdates/temp/Updater.exe")) : (cExeDir() + qsl("Updater.exe"))); auto argumentsList = QStringList(); const auto pushArgument = [&](const QString &argument) { argumentsList.push_back(argument.trimmed()); }; if (cLaunchMode() == LaunchModeAutoStart) { pushArgument(qsl("-autostart")); } if (Logs::DebugEnabled()) { pushArgument(qsl("-debug")); } if (cStartInTray()) { pushArgument(qsl("-startintray")); } if (cTestMode()) { pushArgument(qsl("-testmode")); } #ifndef TDESKTOP_DISABLE_AUTOUPDATE if (Core::UpdaterDisabled()) { pushArgument(qsl("-externalupdater")); } #endif // !TDESKTOP_DISABLE_AUTOUPDATE if (customWorkingDir()) { pushArgument(qsl("-workdir")); pushArgument('"' + cWorkingDir() + '"'); } if (cDataFile() != qsl("data")) { pushArgument(qsl("-key")); pushArgument('"' + cDataFile() + '"'); } if (action == UpdaterLaunch::JustRelaunch) { pushArgument(qsl("-noupdate")); if (cRestartingToSettings()) { pushArgument(qsl("-tosettings")); } } else { pushArgument(qsl("-update")); pushArgument(qsl("-exename")); pushArgument('"' + cExeName() + '"'); if (cWriteProtected()) { pushArgument(qsl("-writeprotected")); pushArgument('"' + cExeDir() + '"'); } } return launch(operation, binaryPath, argumentsList); }
int main(int argc, char *argv[]) { #ifdef _NEED_WIN_GENERATE_DUMP _oldWndExceptionFilter = SetUnhandledExceptionFilter(_exceptionFilter); #endif settingsParseArgs(argc, argv); for (int32 i = 0; i < argc; ++i) { if (string("-fixprevious") == argv[i]) { return psFixPrevious(); } else if (string("-cleanup") == argv[i]) { return psCleanup(); } } logsInit(); App::readConfig(); if (cFromAutoStart() && !cAutoStart()) { psAutoStart(false, true); return 0; } DEBUG_LOG(("Application Info: Telegram started, test mode: %1, exe dir: %2").arg(logBool(cTestMode())).arg(cExeDir())); if (cDebug()) { LOG(("Application Info: Telegram started in debug mode")); for (int32 i = 0; i < argc; ++i) { LOG(("Argument: %1").arg(QString::fromLocal8Bit(argv[i]))); } QStringList logs = psInitLogs(); for (int32 i = 0, l = logs.size(); i < l; ++i) { LOG(("Init Log: %1").arg(logs.at(i))); } } psClearInitLogs(); DEBUG_LOG(("Application Info: ideal thread count: %1, using %2 connections per session").arg(QThread::idealThreadCount()).arg(cConnectionsInSession())); psStart(); int result = 0; { Application app(argc, argv); if (!App::quiting()) { result = app.exec(); } } psFinish(); DEBUG_LOG(("Application Info: Telegram done, result: %1").arg(result)); if (cRestartingUpdate()) { DEBUG_LOG(("Application Info: executing updater to install update..")); psExecUpdater(); } else if (cRestarting()) { DEBUG_LOG(("Application Info: executing Telegram, because of restart..")); psExecTelegram(); } logsClose(); return result; }
int main(int argc, char *argv[]) { #ifdef Q_OS_WIN _oldWndExceptionFilter = SetUnhandledExceptionFilter(_exceptionFilter); // CAPIHook apiHook("kernel32.dll", "SetUnhandledExceptionFilter", (PROC)RedirectedSetUnhandledExceptionFilter); #endif settingsParseArgs(argc, argv); for (int32 i = 0; i < argc; ++i) { if (string("-fixprevious") == argv[i]) { return psFixPrevious(); } else if (string("-cleanup") == argv[i]) { return psCleanup(); } } if (!logsInit()) { return 0; } installSignalHandlers(); Global::Initializer _init; Local::readSettings(); if (Local::oldSettingsVersion() < AppVersion) { psNewVersion(); } if (cFromAutoStart() && !cAutoStart()) { psAutoStart(false, true); Local::stop(); return 0; } DEBUG_LOG(("Application Info: Telegram started, test mode: %1, exe dir: %2").arg(logBool(cTestMode())).arg(cExeDir())); if (cDebug()) { LOG(("Application Info: Telegram started in debug mode")); for (int32 i = 0; i < argc; ++i) { LOG(("Argument: %1").arg(fromUtf8Safe(argv[i]))); } QStringList logs = psInitLogs(); for (int32 i = 0, l = logs.size(); i < l; ++i) { LOG(("Init Log: %1").arg(logs.at(i))); } } psClearInitLogs(); DEBUG_LOG(("Application Info: ideal thread count: %1, using %2 connections per session").arg(QThread::idealThreadCount()).arg(cConnectionsInSession())); psStart(); int result = 0; { QByteArray args[] = { "-style=0" }; // prepare fake args static const int a_cnt = sizeof(args) / sizeof(args[0]); int a_argc = a_cnt + 1; char *a_argv[a_cnt + 1] = { argv[0], args[0].data() }; Application app(a_argc, a_argv); if (!App::quiting()) { result = app.exec(); } } psFinish(); Local::stop(); DEBUG_LOG(("Application Info: Telegram done, result: %1").arg(result)); #ifndef TDESKTOP_DISABLE_AUTOUPDATE if (cRestartingUpdate()) { if (!cBetaVersion() && DevVersion) { LOG(("Writing 'devversion' file before launching the Updater!")); QFile f(cWorkingDir() + qsl("tdata/devversion")); if (!f.exists() && f.open(QIODevice::WriteOnly)) { f.write("1"); f.close(); } } DEBUG_LOG(("Application Info: executing updater to install update..")); psExecUpdater(); } else #endif if (cRestarting()) { DEBUG_LOG(("Application Info: executing Telegram, because of restart..")); psExecTelegram(); } logsClose(); return result; }
int main(int argc, char *argv[]) { #ifdef _NEED_WIN_GENERATE_DUMP _oldWndExceptionFilter = SetUnhandledExceptionFilter(_exceptionFilter); #endif InitOpenSSL _init; settingsParseArgs(argc, argv); for (int32 i = 0; i < argc; ++i) { if (string("-fixprevious") == argv[i]) { return psFixPrevious(); } else if (string("-cleanup") == argv[i]) { return psCleanup(); } } logsInit(); Local::readSettings(); if (cFromAutoStart() && !cAutoStart()) { psAutoStart(false, true); Local::stop(); return 0; } DEBUG_LOG(("Application Info: Telegram started, test mode: %1, exe dir: %2").arg(logBool(cTestMode())).arg(cExeDir())); if (cDebug()) { LOG(("Application Info: Telegram started in debug mode")); for (int32 i = 0; i < argc; ++i) { LOG(("Argument: %1").arg(QString::fromLocal8Bit(argv[i]))); } QStringList logs = psInitLogs(); for (int32 i = 0, l = logs.size(); i < l; ++i) { LOG(("Init Log: %1").arg(logs.at(i))); } } psClearInitLogs(); DEBUG_LOG(("Application Info: ideal thread count: %1, using %2 connections per session").arg(QThread::idealThreadCount()).arg(cConnectionsInSession())); psStart(); int result = 0; { QByteArray args[] = { "-style=0" }; // prepare fake args static const int a_cnt = sizeof(args) / sizeof(args[0]); int a_argc = a_cnt + 1; char *a_argv[a_cnt + 1] = { argv[0], args[0].data() }; Application app(a_argc, a_argv); if (!App::quiting()) { result = app.exec(); } } psFinish(); Local::stop(); DEBUG_LOG(("Application Info: Telegram done, result: %1").arg(result)); if (cRestartingUpdate()) { if (DevVersion) { LOG(("Writing 'devversion' file before launching the Updater!")); QFile f(cWorkingDir() + qsl("tdata/devversion")); if (!f.exists() && f.open(QIODevice::WriteOnly)) { f.write("1"); f.close(); } } DEBUG_LOG(("Application Info: executing updater to install update..")); psExecUpdater(); } else if (cRestarting()) { DEBUG_LOG(("Application Info: executing Telegram, because of restart..")); psExecTelegram(); } logsClose(); return result; }