Browse Source

UI: Add function to generate time/date filenames

jp9000 11 years ago
parent
commit
52ddee9755
2 changed files with 25 additions and 21 deletions
  1. 24 21
      obs/obs-app.cpp
  2. 1 0
      obs/obs-app.hpp

+ 24 - 21
obs/obs-app.cpp

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

+ 1 - 0
obs/obs-app.hpp

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