UI: Specify whether crash/profiler/logs have prefix

Adds a "has_prefix" parameter to delete_oldest_file and get_last_log in
order to determine whether the file has a prefix when parsing its
timestamp.  For example, crash logs are prefixed with "Crash", and thus
it was unable to get the timestamp because it couldn't parse the
filename correctly due to that fact.
This commit is contained in:
jp9000 2018-03-16 16:17:56 -07:00
parent 27e3ea5b5f
commit d55589ef09

View file

@ -1097,13 +1097,18 @@ static bool expect_token(lexer *lex, const char *str, base_token_type type)
return strref_cmp(&token.text, str) == 0;
}
static uint64_t convert_log_name(const char *name)
static uint64_t convert_log_name(bool has_prefix, const char *name)
{
BaseLexer lex;
string year, month, day, hour, minute, second;
lexer_start(lex, name);
if (has_prefix) {
string temp;
if (!get_token(lex, temp, BASETOKEN_ALPHA)) return 0;
}
if (!get_token(lex, year, BASETOKEN_DIGIT)) return 0;
if (!expect_token(lex, "-", BASETOKEN_OTHER)) return 0;
if (!get_token(lex, month, BASETOKEN_DIGIT)) return 0;
@ -1120,7 +1125,7 @@ static uint64_t convert_log_name(const char *name)
return std::stoull(timestring.str());
}
static void delete_oldest_file(const char *location)
static void delete_oldest_file(bool has_prefix, const char *location)
{
BPtr<char> logDir(GetConfigPathPtr(location));
string oldestLog;
@ -1138,7 +1143,8 @@ static void delete_oldest_file(const char *location)
if (entry->directory || *entry->d_name == '.')
continue;
uint64_t ts = convert_log_name(entry->d_name);
uint64_t ts = convert_log_name(has_prefix,
entry->d_name);
if (ts) {
if (ts < oldest_ts) {
@ -1161,7 +1167,8 @@ static void delete_oldest_file(const char *location)
}
}
static void get_last_log(const char *subdir_to_use, std::string &last)
static void get_last_log(bool has_prefix, const char *subdir_to_use,
std::string &last)
{
BPtr<char> logDir(GetConfigPathPtr(subdir_to_use));
struct os_dirent *entry;
@ -1173,7 +1180,8 @@ static void get_last_log(const char *subdir_to_use, std::string &last)
if (entry->directory || *entry->d_name == '.')
continue;
uint64_t ts = convert_log_name(entry->d_name);
uint64_t ts = convert_log_name(has_prefix,
entry->d_name);
if (ts > highest_ts) {
last = entry->d_name;
@ -1240,7 +1248,7 @@ static void create_log_file(fstream &logFile)
{
stringstream dst;
get_last_log("obs-studio/logs", lastLogFile);
get_last_log(false, "obs-studio/logs", lastLogFile);
currentLogFile = GenerateTimeDateFilename("txt");
dst << "obs-studio/logs/" << currentLogFile.c_str();
@ -1258,7 +1266,7 @@ static void create_log_file(fstream &logFile)
#endif
if (logFile.is_open()) {
delete_oldest_file("obs-studio/logs");
delete_oldest_file(false, "obs-studio/logs");
base_set_log_handler(do_log, &logFile);
} else {
blog(LOG_ERROR, "Failed to open log file");
@ -1354,7 +1362,7 @@ static int run_program(fstream &logFile, int argc, char *argv[])
OBSTranslator translator;
create_log_file(logFile);
delete_oldest_file("obs-studio/profiler_data");
delete_oldest_file(false, "obs-studio/profiler_data");
program.installTranslator(&translator);
@ -1441,7 +1449,7 @@ static void main_crash_handler(const char *format, va_list args, void *param)
vsnprintf(text, MAX_CRASH_REPORT_SIZE, format, args);
text[MAX_CRASH_REPORT_SIZE - 1] = 0;
delete_oldest_file("obs-studio/crashes");
delete_oldest_file(true, "obs-studio/crashes");
string name = "obs-studio/crashes/Crash ";
name += GenerateTimeDateFilename("txt");