瀏覽代碼

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 4 年之前
父節點
當前提交
2727dd96bd
共有 1 個文件被更改,包括 19 次插入5 次删除
  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 != ' ')