diff --git a/Telegram/SourceFiles/boxes/passcode_box.cpp b/Telegram/SourceFiles/boxes/passcode_box.cpp index 8963c545d..bd94dd647 100644 --- a/Telegram/SourceFiles/boxes/passcode_box.cpp +++ b/Telegram/SourceFiles/boxes/passcode_box.cpp @@ -750,7 +750,7 @@ bool RecoverBox::codeSubmitFail(const RPCError &error) { _recoverCode->showError(); return true; } - if (cDebug()) { // internal server error + if (Logs::DebugEnabled()) { // internal server error _error = err + ": " + error.description(); } else { _error = Lang::Hard::ServerError(); diff --git a/Telegram/SourceFiles/calls/calls_call.cpp b/Telegram/SourceFiles/calls/calls_call.cpp index ef4e8e92f..90a6263d0 100644 --- a/Telegram/SourceFiles/calls/calls_call.cpp +++ b/Telegram/SourceFiles/calls/calls_call.cpp @@ -529,7 +529,7 @@ void Call::createAndStartController(const MTPDphoneCall &call) { config.enableAGC = true; config.initTimeout = Global::CallConnectTimeoutMs() / 1000; config.recvTimeout = Global::CallPacketTimeoutMs() / 1000; - if (cDebug()) { + if (Logs::DebugEnabled()) { auto callLogFolder = cWorkingDir() + qsl("DebugLogs"); auto callLogPath = callLogFolder + qsl("/last_call_log.txt"); auto callLogNative = QFile::encodeName(QDir::toNativeSeparators(callLogPath)); diff --git a/Telegram/SourceFiles/calls/calls_top_bar.cpp b/Telegram/SourceFiles/calls/calls_top_bar.cpp index 0e440cab3..4c7eb2819 100644 --- a/Telegram/SourceFiles/calls/calls_top_bar.cpp +++ b/Telegram/SourceFiles/calls/calls_top_bar.cpp @@ -108,7 +108,8 @@ void TopBar::initControls() { setInfoLabels(); _info->setClickedCallback([this] { if (auto call = _call.get()) { - if (cDebug() && (_info->clickModifiers() & Qt::ControlModifier)) { + if (Logs::DebugEnabled() + && (_info->clickModifiers() & Qt::ControlModifier)) { Ui::show(Box(_call)); } else { Current().showInfoPanel(call); diff --git a/Telegram/SourceFiles/core/launcher.cpp b/Telegram/SourceFiles/core/launcher.cpp index e2d500f61..5c97c40eb 100644 --- a/Telegram/SourceFiles/core/launcher.cpp +++ b/Telegram/SourceFiles/core/launcher.cpp @@ -215,7 +215,7 @@ void Launcher::processArguments() { } gTestMode = parseResult.contains("-testmode"); - gDebug = parseResult.contains("-debug"); + Logs::SetDebugEnabled(parseResult.contains("-debug")); gManyInstance = parseResult.contains("-many"); gKeyFile = parseResult.value("-key", QStringList()).join(QString()); gLaunchMode = parseResult.contains("-autostart") ? LaunchModeAutoStart diff --git a/Telegram/SourceFiles/core/update_checker.cpp b/Telegram/SourceFiles/core/update_checker.cpp index 27a5a1486..62f531017 100644 --- a/Telegram/SourceFiles/core/update_checker.cpp +++ b/Telegram/SourceFiles/core/update_checker.cpp @@ -1756,7 +1756,7 @@ void Updater::start(bool forceWait) { sendRequest = true; } } - if (cManyInstance() && !cDebug()) { + if (cManyInstance() && !Logs::DebugEnabled()) { // Only main instance is updating. return; } diff --git a/Telegram/SourceFiles/facades.cpp b/Telegram/SourceFiles/facades.cpp index a851c9657..9ca7c6606 100644 --- a/Telegram/SourceFiles/facades.cpp +++ b/Telegram/SourceFiles/facades.cpp @@ -410,8 +410,9 @@ void WorkingDirReady() { if (QFile(cWorkingDir() + qsl("tdata/withtestmode")).exists()) { cSetTestMode(true); } - if (!cDebug() && QFile(cWorkingDir() + qsl("tdata/withdebug")).exists()) { - cSetDebug(true); + if (!Logs::DebugEnabled() + && QFile(cWorkingDir() + qsl("tdata/withdebug")).exists()) { + Logs::SetDebugEnabled(true); } if (cBetaVersion()) { cSetAlphaVersion(false); diff --git a/Telegram/SourceFiles/intro/introcode.cpp b/Telegram/SourceFiles/intro/introcode.cpp index d8f23f501..b071d2a84 100644 --- a/Telegram/SourceFiles/intro/introcode.cpp +++ b/Telegram/SourceFiles/intro/introcode.cpp @@ -242,7 +242,7 @@ bool CodeWidget::codeSubmitFail(const RPCError &error) { _sentRequest = MTP::send(MTPaccount_GetPassword(), rpcDone(&CodeWidget::gotPassword), rpcFail(&CodeWidget::codeSubmitFail)); return true; } - if (cDebug()) { // internal server error + if (Logs::DebugEnabled()) { // internal server error auto text = err + ": " + error.description(); showCodeError([text] { return text; }); } else { @@ -351,7 +351,7 @@ bool CodeWidget::noTelegramCodeFail(const RPCError &error) { } if (MTP::isDefaultHandledError(error)) return false; - if (cDebug()) { // internal server error + if (Logs::DebugEnabled()) { // internal server error auto text = error.type() + ": " + error.description(); showCodeError([text] { return text; }); } else { diff --git a/Telegram/SourceFiles/intro/introphone.cpp b/Telegram/SourceFiles/intro/introphone.cpp index 46363d1d7..8d753fab5 100644 --- a/Telegram/SourceFiles/intro/introphone.cpp +++ b/Telegram/SourceFiles/intro/introphone.cpp @@ -254,7 +254,7 @@ bool PhoneWidget::phoneSubmitFail(const RPCError &error) { [phone] { SendToBannedHelp(phone); Ui::hideLayer(); })); return true; } - if (cDebug()) { // internal server error + if (Logs::DebugEnabled()) { // internal server error auto text = err + ": " + error.description(); showPhoneError([text] { return text; }); } else { diff --git a/Telegram/SourceFiles/intro/intropwdcheck.cpp b/Telegram/SourceFiles/intro/intropwdcheck.cpp index 008ca2162..dfa910ce2 100644 --- a/Telegram/SourceFiles/intro/intropwdcheck.cpp +++ b/Telegram/SourceFiles/intro/intropwdcheck.cpp @@ -151,7 +151,7 @@ bool PwdCheckWidget::pwdSubmitFail(const RPCError &error) { } else if (err == qstr("PASSWORD_EMPTY")) { goBack(); } - if (cDebug()) { // internal server error + if (Logs::DebugEnabled()) { // internal server error auto text = err + ": " + error.description(); showError([text] { return text; }); } else { @@ -188,7 +188,7 @@ bool PwdCheckWidget::codeSubmitFail(const RPCError &error) { _codeField->showError(); return true; } - if (cDebug()) { // internal server error + if (Logs::DebugEnabled()) { // internal server error auto text = err + ": " + error.description(); showError([text] { return text; }); } else { diff --git a/Telegram/SourceFiles/intro/introsignup.cpp b/Telegram/SourceFiles/intro/introsignup.cpp index 97b0cb61f..4dd855cb5 100644 --- a/Telegram/SourceFiles/intro/introsignup.cpp +++ b/Telegram/SourceFiles/intro/introsignup.cpp @@ -161,7 +161,7 @@ bool SignupWidget::nameSubmitFail(const RPCError &error) { _last->setFocus(); return true; } - if (cDebug()) { // internal server error + if (Logs::DebugEnabled()) { // internal server error auto text = err + ": " + error.description(); showError([text] { return text; }); } else { diff --git a/Telegram/SourceFiles/logs.cpp b/Telegram/SourceFiles/logs.cpp index 5ecf2b748..24ec0cf66 100644 --- a/Telegram/SourceFiles/logs.cpp +++ b/Telegram/SourceFiles/logs.cpp @@ -243,7 +243,7 @@ QString LogsBeforeSingleInstanceChecked; // LogsInMemory already dumped in LogsD void _logsWrite(LogDataType type, const QString &msg) { if (LogsData && (type == LogDataMain || LogsStartIndexChosen < 0)) { - if (type == LogDataMain || cDebug()) { + if (type == LogDataMain || Logs::DebugEnabled()) { LogsData->write(type, msg); } } else if (LogsInMemory != DeletedLogsInMemory) { @@ -259,6 +259,8 @@ void _logsWrite(LogDataType type, const QString &msg) { namespace Logs { namespace { +bool DebugModeEnabled = false; + void MoveOldDataFiles(const QString &wasDir) { QFile data(wasDir + "data"), dataConfig(wasDir + "data_config"), tdataConfig(wasDir + "tdata/config"); if (data.exists() && dataConfig.exists() && !QFileInfo(cWorkingDir() + "data").exists() && !QFileInfo(cWorkingDir() + "data_config").exists()) { // move to home dir @@ -307,6 +309,18 @@ void MoveOldDataFiles(const QString &wasDir) { } // namespace +void SetDebugEnabled(bool enabled) { + DebugModeEnabled = enabled; +} + +bool DebugEnabled() { +#if defined _DEBUG + return true; +#else + return DebugModeEnabled; +#endif +} + void start(not_null launcher) { Assert(LogsData == 0); @@ -319,7 +333,7 @@ void start(not_null launcher) { auto workingDirChosen = false; if (cBetaVersion()) { - cSetDebug(true); + SetDebugEnabled(true); workingDirChosen = true; #if defined Q_OS_MAC || defined Q_OS_LINUX } else { @@ -385,7 +399,7 @@ void start(not_null launcher) { LogsData = 0; } - LOG(("Launched version: %1, alpha: %2, beta: %3, debug mode: %4, test dc: %5").arg(AppVersion).arg(Logs::b(cAlphaVersion())).arg(cBetaVersion()).arg(Logs::b(cDebug())).arg(Logs::b(cTestMode()))); + LOG(("Launched version: %1, alpha: %2, beta: %3, debug mode: %4, test dc: %5").arg(AppVersion).arg(Logs::b(cAlphaVersion())).arg(cBetaVersion()).arg(Logs::b(DebugEnabled())).arg(Logs::b(cTestMode()))); LOG(("Executable dir: %1, name: %2").arg(cExeDir()).arg(cExeName())); LOG(("Initial working dir: %1").arg(initialWorkingDir)); LOG(("Working dir: %1").arg(cWorkingDir())); @@ -475,7 +489,7 @@ void multipleInstances() { } LogsInMemory = DeletedLogsInMemory; - if (cDebug()) { + if (Logs::DebugEnabled()) { LOG(("WARNING: debug logs are not written in multiple instances mode!")); } LogsBeforeSingleInstanceChecked.clear(); diff --git a/Telegram/SourceFiles/logs.h b/Telegram/SourceFiles/logs.h index b65e92c26..9c63096de 100644 --- a/Telegram/SourceFiles/logs.h +++ b/Telegram/SourceFiles/logs.h @@ -13,6 +13,9 @@ class Launcher; namespace Logs { +void SetDebugEnabled(bool enabled); +bool DebugEnabled(); + void start(not_null launcher); bool started(); void finish(); @@ -65,11 +68,11 @@ inline MemoryBuffer mb(const void *ptr, uint32 size) { #define LOG(msg) (Logs::writeMain(QString msg)) //usage LOG(("log: %1 %2").arg(1).arg(2)) -#define DEBUG_LOG(msg) { if (cDebug() || !Logs::started()) Logs::writeDebug(__FILE__, __LINE__, QString msg); } +#define DEBUG_LOG(msg) { if (Logs::DebugEnabled() || !Logs::started()) Logs::writeDebug(__FILE__, __LINE__, QString msg); } //usage DEBUG_LOG(("log: %1 %2").arg(1).arg(2)) -#define TCP_LOG(msg) { if (cDebug() || !Logs::started()) Logs::writeTcp(QString msg); } +#define TCP_LOG(msg) { if (Logs::DebugEnabled() || !Logs::started()) Logs::writeTcp(QString msg); } //usage TCP_LOG(("log: %1 %2").arg(1).arg(2)) -#define MTP_LOG(dc, msg) { if (cDebug() || !Logs::started()) Logs::writeMtp(dc, QString msg); } +#define MTP_LOG(dc, msg) { if (Logs::DebugEnabled() || !Logs::started()) Logs::writeMtp(dc, QString msg); } //usage MTP_LOG(dc, ("log: %1 %2").arg(1).arg(2)) diff --git a/Telegram/SourceFiles/mainwindow.cpp b/Telegram/SourceFiles/mainwindow.cpp index da4c98341..732733d82 100644 --- a/Telegram/SourceFiles/mainwindow.cpp +++ b/Telegram/SourceFiles/mainwindow.cpp @@ -493,7 +493,9 @@ void MainWindow::setInnerFocus() { bool MainWindow::eventFilter(QObject *object, QEvent *e) { switch (e->type()) { case QEvent::KeyPress: { - if (cDebug() && e->type() == QEvent::KeyPress && object == windowHandle()) { + if (Logs::DebugEnabled() + && (e->type() == QEvent::KeyPress) + && object == windowHandle()) { auto key = static_cast(e)->key(); FeedLangTestingKey(key); } diff --git a/Telegram/SourceFiles/messenger.cpp b/Telegram/SourceFiles/messenger.cpp index 6a2eb3367..0a9476a0c 100644 --- a/Telegram/SourceFiles/messenger.cpp +++ b/Telegram/SourceFiles/messenger.cpp @@ -744,12 +744,12 @@ void Messenger::photoUpdated(const FullMsgId &msgId, const MTPInputFile &file) { } void Messenger::onSwitchDebugMode() { - if (cDebug()) { + if (Logs::DebugEnabled()) { QFile(cWorkingDir() + qsl("tdata/withdebug")).remove(); - cSetDebug(false); + Logs::SetDebugEnabled(false); App::restart(); } else { - cSetDebug(true); + Logs::SetDebugEnabled(true); DEBUG_LOG(("Debug logs started.")); QFile f(cWorkingDir() + qsl("tdata/withdebug")); if (f.open(QIODevice::WriteOnly)) { diff --git a/Telegram/SourceFiles/mtproto/connection.cpp b/Telegram/SourceFiles/mtproto/connection.cpp index 021cecf59..2c31b63b1 100644 --- a/Telegram/SourceFiles/mtproto/connection.cpp +++ b/Telegram/SourceFiles/mtproto/connection.cpp @@ -1705,7 +1705,7 @@ ConnectionPrivate::HandleResult ConnectionPrivate::handleOneReceived(const mtpPr || (errorCode == 17) // bad msg_id || (errorCode == 64); // bad container if (errorCode == 64) { // bad container! - if (cDebug()) { + if (Logs::DebugEnabled()) { mtpRequest request; { QWriteLocker locker(sessionData->haveSentMutex()); diff --git a/Telegram/SourceFiles/mtproto/mtp_instance.cpp b/Telegram/SourceFiles/mtproto/mtp_instance.cpp index 0e4fe9a82..0cf12ebaf 100644 --- a/Telegram/SourceFiles/mtproto/mtp_instance.cpp +++ b/Telegram/SourceFiles/mtproto/mtp_instance.cpp @@ -919,7 +919,7 @@ void Instance::Private::clearCallbacksDelayed( return; } - if (cDebug()) { + if (Logs::DebugEnabled()) { auto idsString = QStringList(); idsString.reserve(ids.size()); for (auto &value : ids) { @@ -939,7 +939,7 @@ void Instance::Private::clearCallbacks( Expects(!ids.empty()); for (const auto &clearRequest : ids) { - if (cDebug()) { + if (Logs::DebugEnabled()) { QMutexLocker locker(&_parserMapLock); if (_parserMap.find(clearRequest.requestId) != _parserMap.end()) { DEBUG_LOG(("RPC Info: " diff --git a/Telegram/SourceFiles/platform/linux/launcher_linux.cpp b/Telegram/SourceFiles/platform/linux/launcher_linux.cpp index c3cb6830a..494531385 100644 --- a/Telegram/SourceFiles/platform/linux/launcher_linux.cpp +++ b/Telegram/SourceFiles/platform/linux/launcher_linux.cpp @@ -74,7 +74,7 @@ bool Launcher::launchUpdater(UpdaterLaunch action) { if (cLaunchMode() == LaunchModeAutoStart) { argumentsList.push("-autostart"); } - if (cDebug()) { + if (Logs::DebugEnabled()) { argumentsList.push("-debug"); } if (cStartInTray()) { diff --git a/Telegram/SourceFiles/platform/mac/launcher_mac.mm b/Telegram/SourceFiles/platform/mac/launcher_mac.mm index 9344189d6..52b798792 100644 --- a/Telegram/SourceFiles/platform/mac/launcher_mac.mm +++ b/Telegram/SourceFiles/platform/mac/launcher_mac.mm @@ -122,7 +122,7 @@ bool Launcher::launchUpdater(UpdaterLaunch action) { if (cRestartingToSettings()) [args addObject:@"-tosettings"]; if (action == UpdaterLaunch::JustRelaunch) [args addObject:@"-noupdate"]; if (cLaunchMode() == LaunchModeAutoStart) [args addObject:@"-autostart"]; - if (cDebug()) [args addObject:@"-debug"]; + if (Logs::DebugEnabled()) [args addObject:@"-debug"]; if (cStartInTray()) [args addObject:@"-startintray"]; if (cTestMode()) [args addObject:@"-testmode"]; if (cDataFile() != qsl("data")) { diff --git a/Telegram/SourceFiles/platform/win/launcher_win.cpp b/Telegram/SourceFiles/platform/win/launcher_win.cpp index 9ceabde01..36efd7a40 100644 --- a/Telegram/SourceFiles/platform/win/launcher_win.cpp +++ b/Telegram/SourceFiles/platform/win/launcher_win.cpp @@ -80,7 +80,7 @@ bool Launcher::launchUpdater(UpdaterLaunch action) { if (cLaunchMode() == LaunchModeAutoStart) { pushArgument(qsl("-autostart")); } - if (cDebug()) { + if (Logs::DebugEnabled()) { pushArgument(qsl("-debug")); } if (cStartInTray()) { diff --git a/Telegram/SourceFiles/settings.cpp b/Telegram/SourceFiles/settings.cpp index 162369818..680f34715 100644 --- a/Telegram/SourceFiles/settings.cpp +++ b/Telegram/SourceFiles/settings.cpp @@ -16,7 +16,6 @@ uint64 gRealBetaVersion = AppBetaVersion; QByteArray gBetaPrivateKey; bool gTestMode = false; -bool gDebug = false; bool gManyInstance = false; QString gKeyFile; QString gWorkingDir, gExeDir, gExeName; diff --git a/Telegram/SourceFiles/settings.h b/Telegram/SourceFiles/settings.h index 43dc77c1a..1b04d5e6d 100644 --- a/Telegram/SourceFiles/settings.h +++ b/Telegram/SourceFiles/settings.h @@ -7,18 +7,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #pragma once -extern bool gDebug; -inline bool cDebug() { -#if defined _DEBUG - return true; -#else - return gDebug; -#endif -} -inline void cSetDebug(bool debug) { - gDebug = debug; -} - #define DeclareReadSetting(Type, Name) extern Type g##Name; \ inline const Type &c##Name() { \ return g##Name; \ diff --git a/Telegram/SourceFiles/settings/settings_widget.cpp b/Telegram/SourceFiles/settings/settings_widget.cpp index b9e70eeba..0592d58cf 100644 --- a/Telegram/SourceFiles/settings/settings_widget.cpp +++ b/Telegram/SourceFiles/settings/settings_widget.cpp @@ -39,7 +39,10 @@ QMap> Codes; void fillCodes() { Codes.insert(qsl("debugmode"), [] { - QString text = cDebug() ? qsl("Do you want to disable DEBUG logs?") : qsl("Do you want to enable DEBUG logs?\n\nAll network events will be logged."); + QString text = Logs::DebugEnabled() + ? qsl("Do you want to disable DEBUG logs?") + : qsl("Do you want to enable DEBUG logs?\n\n" + "All network events will be logged."); Ui::show(Box(text, [] { Messenger::Instance().onSwitchDebugMode(); })); @@ -59,7 +62,9 @@ void fillCodes() { Lang::CurrentCloudManager().switchToLanguage(qsl("custom")); }); Codes.insert(qsl("debugfiles"), [] { - if (!cDebug()) return; + if (!Logs::DebugEnabled()) { + return; + } if (DebugLogging::FileLoader()) { Global::RefDebugLoggingFlags() &= ~DebugLogging::FileLoaderFlag; } else {