Explorar o código

UI: Do not generate "already active" logs

When an user launches a multiple instance of obs and don't use the -m
flag, wait until the confirmation to launch to create a new log file.
This avoids a short log with no information when using the Help ->
Update Last Log.

Closes obsproject/obs-studio#1164
Shaolin %!s(int64=8) %!d(string=hai) anos
pai
achega
7fc6ea6ccc
Modificáronse 1 ficheiros con 32 adicións e 19 borrados
  1. 32 19
      UI/obs-app.cpp

+ 32 - 19
UI/obs-app.cpp

@@ -1366,33 +1366,32 @@ static int run_program(fstream &logFile, int argc, char *argv[])
 
 	OBSApp program(argc, argv, profilerNameStore.get());
 	try {
-		program.AppInit();
-
-		OBSTranslator translator;
+		bool created_log = false;
 
-		create_log_file(logFile);
+		program.AppInit();
 		delete_oldest_file(false, "obs-studio/profiler_data");
 
+		OBSTranslator translator;
 		program.installTranslator(&translator);
 
 #ifdef _WIN32
 		/* --------------------------------------- */
 		/* check and warn if already running       */
 
+		bool cancel_launch = false;
 		bool already_running = false;
 		RunOnceMutex rom = GetRunOnceMutex(already_running);
 
-		if (already_running && !multi) {
-			blog(LOG_WARNING, "\n================================");
-			blog(LOG_WARNING, "Warning: OBS is already running!");
-			blog(LOG_WARNING, "================================\n");
+		if (!already_running) {
+			goto run;
+		}
 
+		if (!multi) {
 			QMessageBox::StandardButtons buttons(
 					QMessageBox::Yes | QMessageBox::Cancel);
 			QMessageBox mb(QMessageBox::Question,
 					QTStr("AlreadyRunning.Title"),
-					QTStr("AlreadyRunning.Text"),
-					buttons,
+					QTStr("AlreadyRunning.Text"), buttons,
 					nullptr);
 			mb.setButtonText(QMessageBox::Yes,
 					QTStr("AlreadyRunning.LaunchAnyway"));
@@ -1401,23 +1400,37 @@ static int run_program(fstream &logFile, int argc, char *argv[])
 
 			QMessageBox::StandardButton button;
 			button = (QMessageBox::StandardButton)mb.exec();
-			if (button == QMessageBox::Cancel) {
-				blog(LOG_INFO, "User shut down the program "
-						"because OBS was already "
-						"running");
-				return 0;
-			}
+			cancel_launch = button == QMessageBox::Cancel;
+		}
 
-			blog(LOG_WARNING, "User is now running a secondary "
-					"instance of OBS!");
+		if (cancel_launch)
+			return 0;
+
+		if (!created_log) {
+			create_log_file(logFile);
+			created_log = true;
+		}
 
-		} else if (already_running && multi) {
+		if (multi) {
 			blog(LOG_INFO, "User enabled --multi flag and is now "
 					"running multiple instances of OBS.");
+		} else {
+			blog(LOG_WARNING, "================================");
+			blog(LOG_WARNING, "Warning: OBS is already running!");
+			blog(LOG_WARNING, "================================");
+			blog(LOG_WARNING, "User is now running multiple "
+					"instances of OBS!");
 		}
 
 		/* --------------------------------------- */
+run:
 #endif
+
+		if (!created_log) {
+			create_log_file(logFile);
+			created_log = true;
+		}
+
 		if (argc > 1) {
 			stringstream stor;
 			stor << argv[1];