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 #4707master
parent
3dbfa4919a
commit
2727dd96bd
|
@ -1774,13 +1774,27 @@ string GetFormatString(const char *format, const char *prefix,
|
|||
{
|
||||
string f;
|
||||
|
||||
if (prefix && *prefix) {
|
||||
f += prefix;
|
||||
if (f.back() != ' ')
|
||||
f += " ";
|
||||
}
|
||||
f = format;
|
||||
|
||||
f += format;
|
||||
if (prefix && *prefix) {
|
||||
string str_prefix = prefix;
|
||||
|
||||
if (str_prefix.back() != ' ')
|
||||
str_prefix += " ";
|
||||
|
||||
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 != ' ')
|
||||
|
|
Loading…
Reference in New Issue