Browse Source

UI: Allow directories in file formatting settings

When configuring file formatting settings in advanced, allow the ability
to specify formatted directories.

For example, "%CCYY-%MM/%DD %hh-%mm-%ss"

would make the year and month a subdirectory, then the
day/hour/minute/seconds as the file name.  January 21st 2121 at 4pm
would end up being:

"21 04-00-00.mp4" in the subdirectory "2121-01".
jp9000 9 years ago
parent
commit
d7cf581b3a
2 changed files with 18 additions and 3 deletions
  1. 15 0
      obs/window-basic-main-outputs.cpp
  2. 3 3
      obs/window-basic-settings.cpp

+ 15 - 0
obs/window-basic-main-outputs.cpp

@@ -1,4 +1,5 @@
 #include <string>
+#include <algorithm>
 #include <QMessageBox>
 #include "audio-encoders.hpp"
 #include "window-basic-main.hpp"
@@ -555,6 +556,18 @@ bool SimpleOutput::StartStreaming(obs_service_t *service)
 	return false;
 }
 
+static void ensure_directory_exists(string &path)
+{
+	replace(path.begin(), path.end(), '\\', '/');
+
+	size_t last = path.rfind('/');
+	if (last == string::npos)
+		return;
+
+	string directory = path.substr(0, last);
+	os_mkdirs(directory.c_str());
+}
+
 bool SimpleOutput::StartRecording()
 {
 	if (usingRecordingPreset) {
@@ -600,6 +613,7 @@ bool SimpleOutput::StartRecording()
 
 	strPath += GenerateSpecifiedFilename(ffmpegOutput ? "avi" : format,
 			noSpace, filenameFormat);
+	ensure_directory_exists(strPath);
 	if (!overwriteIfExists)
 		FindBestFilename(strPath, noSpace);
 
@@ -1136,6 +1150,7 @@ bool AdvancedOutput::StartRecording()
 
 		strPath += GenerateSpecifiedFilename(recFormat, noSpace,
 							filenameFormat);
+		ensure_directory_exists(strPath);
 		if (!overwriteIfExists)
 			FindBestFilename(strPath, noSpace);
 

+ 3 - 3
obs/window-basic-settings.cpp

@@ -2919,12 +2919,12 @@ void OBSBasicSettings::on_filenameFormatting_textEdited(const QString &text)
 {
 #ifdef __APPLE__
 	size_t invalidLocation =
-		text.toStdString().find_first_of(":/\\");
+		text.toStdString().find_first_of(":");
 #elif  _WIN32
 	size_t invalidLocation =
-		text.toStdString().find_first_of("<>:\"/\\|?*");
+		text.toStdString().find_first_of("<>:\"|?*");
 #else
-	size_t invalidLocation = text.toStdString().find_first_of("/");
+	size_t invalidLocation = string::npos;
 #endif
 
 	if (invalidLocation != string::npos)