Procházet zdrojové kódy

UI: Handle prefixes when using paths in recording format

The replay buffer and screenshot functions add a prefix to the output
filename. The code in GetFormatString assumed the format string was the
entire filename, and inserted the prefix at the beginning. This caused
illegal paths such as "Screenshot /2021/05/22-35.mkv" to be created if
the user had specified a path in the format string, resulting in lost
files.

This commit inserts the prefix before the last / character to ensure it
only affects the filename portion of the format string.

Fixes #4707
Richard Stanway před 4 roky
rodič
revize
2727dd96bd
1 změnil soubory, kde provedl 19 přidání a 5 odebrání
  1. 19 5
      UI/obs-app.cpp

+ 19 - 5
UI/obs-app.cpp

@@ -1774,13 +1774,27 @@ string GetFormatString(const char *format, const char *prefix,
 {
 	string f;
 
+	f = format;
+
 	if (prefix && *prefix) {
-		f += prefix;
-		if (f.back() != ' ')
-			f += " ";
-	}
+		string str_prefix = prefix;
+
+		if (str_prefix.back() != ' ')
+			str_prefix += " ";
 
-	f += format;
+		size_t insert_pos = 0;
+		size_t tmp;
+
+		tmp = f.find_last_of('/');
+		if (tmp != string::npos && tmp > insert_pos)
+			insert_pos = tmp + 1;
+
+		tmp = f.find_last_of('\\');
+		if (tmp != string::npos && tmp > insert_pos)
+			insert_pos = tmp + 1;
+
+		f.insert(insert_pos, str_prefix);
+	}
 
 	if (suffix && *suffix) {
 		if (*suffix != ' ')