Replace cDebug() with Logs::DebugEnabled().
This commit is contained in:
		
							parent
							
								
									9055b33e92
								
							
						
					
					
						commit
						72f95b984f
					
				
					 22 changed files with 58 additions and 45 deletions
				
			
		|  | @ -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(); | ||||
|  |  | |||
|  | @ -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)); | ||||
|  |  | |||
|  | @ -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<DebugInfoBox>(_call)); | ||||
| 			} else { | ||||
| 				Current().showInfoPanel(call); | ||||
|  |  | |||
|  | @ -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 | ||||
|  |  | |||
|  | @ -1756,7 +1756,7 @@ void Updater::start(bool forceWait) { | |||
| 			sendRequest = true; | ||||
| 		} | ||||
| 	} | ||||
| 	if (cManyInstance() && !cDebug()) { | ||||
| 	if (cManyInstance() && !Logs::DebugEnabled()) { | ||||
| 		// Only main instance is updating.
 | ||||
| 		return; | ||||
| 	} | ||||
|  |  | |||
|  | @ -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); | ||||
|  |  | |||
|  | @ -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 { | ||||
|  |  | |||
|  | @ -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 { | ||||
|  |  | |||
|  | @ -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 { | ||||
|  |  | |||
|  | @ -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 { | ||||
|  |  | |||
|  | @ -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<Core::Launcher*> launcher) { | ||||
| 	Assert(LogsData == 0); | ||||
| 
 | ||||
|  | @ -319,7 +333,7 @@ void start(not_null<Core::Launcher*> 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<Core::Launcher*> 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(); | ||||
|  |  | |||
|  | @ -13,6 +13,9 @@ class Launcher; | |||
| 
 | ||||
| namespace Logs { | ||||
| 
 | ||||
| void SetDebugEnabled(bool enabled); | ||||
| bool DebugEnabled(); | ||||
| 
 | ||||
| void start(not_null<Core::Launcher*> 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))
 | ||||
|  |  | |||
|  | @ -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<QKeyEvent*>(e)->key(); | ||||
| 			FeedLangTestingKey(key); | ||||
| 		} | ||||
|  |  | |||
|  | @ -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)) { | ||||
|  |  | |||
|  | @ -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()); | ||||
|  |  | |||
|  | @ -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: " | ||||
|  |  | |||
|  | @ -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()) { | ||||
|  |  | |||
|  | @ -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")) { | ||||
|  |  | |||
|  | @ -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()) { | ||||
|  |  | |||
|  | @ -16,7 +16,6 @@ uint64 gRealBetaVersion = AppBetaVersion; | |||
| QByteArray gBetaPrivateKey; | ||||
| 
 | ||||
| bool gTestMode = false; | ||||
| bool gDebug = false; | ||||
| bool gManyInstance = false; | ||||
| QString gKeyFile; | ||||
| QString gWorkingDir, gExeDir, gExeName; | ||||
|  |  | |||
|  | @ -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; \ | ||||
|  |  | |||
|  | @ -39,7 +39,10 @@ QMap<QString, Fn<void()>> 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<ConfirmBox>(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 { | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 John Preston
						John Preston