UI: Add function to generate time/date filenames

This commit is contained in:
jp9000 2014-05-20 23:26:19 -07:00
parent 765ac2a76b
commit 52ddee9755
2 changed files with 25 additions and 21 deletions

View File

@ -423,34 +423,37 @@ static void get_last_log(void)
} }
} }
string GenerateTimeDateFilename(const char *extension)
{
time_t now = time(0);
char file[256] = {};
struct tm *cur_time;
cur_time = localtime(&now);
snprintf(file, sizeof(file), "%d-%02d-%02d %02d-%02d-%02d.%s",
cur_time->tm_year+1900,
cur_time->tm_mon+1,
cur_time->tm_mday,
cur_time->tm_hour,
cur_time->tm_min,
cur_time->tm_sec,
extension);
return string(file);
}
static void create_log_file(fstream &logFile) static void create_log_file(fstream &logFile)
{ {
stringstream dst; stringstream dst;
time_t now = time(0);
struct tm *cur_time;
get_last_log(); get_last_log();
cur_time = localtime(&now); currentLogFile = GenerateTimeDateFilename("txt");
if (cur_time) { dst << "obs-studio/logs/" << currentLogFile.c_str();
char file[256] = {};
snprintf(file, sizeof(file), "%d-%02d-%02d %02d-%02d-%02d.txt", BPtr<char> path(os_get_config_path(dst.str().c_str()));
cur_time->tm_year+1900, logFile.open(path,
cur_time->tm_mon+1, ios_base::in | ios_base::out | ios_base::trunc);
cur_time->tm_mday,
cur_time->tm_hour,
cur_time->tm_min,
cur_time->tm_sec);
currentLogFile = file;
dst << "obs-studio/logs/" << file;
BPtr<char> path(os_get_config_path(dst.str().c_str()));
logFile.open(path,
ios_base::in | ios_base::out | ios_base::trunc);
}
if (logFile.is_open()) { if (logFile.is_open()) {
delete_oldest_log(); delete_oldest_log();

View File

@ -28,6 +28,7 @@
std::string CurrentTimeString(); std::string CurrentTimeString();
std::string CurrentDateTimeString(); std::string CurrentDateTimeString();
std::string GenerateTimeDateFilename(const char *extension);
struct BaseLexer { struct BaseLexer {
lexer lex; lexer lex;