Просмотр исходного кода

UI: Replace os_get_config_path with GetConfigPath

This allows the UI to be able to use a custom config path for cases such
as portable mode, where the config path is relative to the executable.
jp9000 10 лет назад
Родитель
Сommit
4b422d7d23
4 измененных файлов с 35 добавлено и 24 удалено
  1. 21 10
      obs/obs-app.cpp
  2. 1 1
      obs/window-basic-main-outputs.cpp
  3. 10 10
      obs/window-basic-main.cpp
  4. 3 3
      obs/window-basic-settings.cpp

+ 21 - 10
obs/obs-app.cpp

@@ -242,23 +242,34 @@ static bool MakeUserDirs()
 {
 	char path[512];
 
-	if (os_get_config_path(path, sizeof(path), "obs-studio") <= 0)
+	if (portable_mode) {
+		if (GetConfigPath(path, sizeof(path), "") <= 0)
+			return false;
+		if (!do_mkdir(path))
+			return false;
+	}
+
+	if (GetConfigPath(path, sizeof(path), "obs-studio") <= 0)
 		return false;
 	if (!do_mkdir(path))
 		return false;
 
-	if (os_get_config_path(path, sizeof(path), "obs-studio/basic") <= 0)
+	if (GetConfigPath(path, sizeof(path), "obs-studio/basic") <= 0)
 		return false;
 	if (!do_mkdir(path))
 		return false;
 
-	if (os_get_config_path(path, sizeof(path), "obs-studio/logs") <= 0)
+	if (GetConfigPath(path, sizeof(path), "obs-studio/logs") <= 0)
 		return false;
 	if (!do_mkdir(path))
 		return false;
 
+	if (GetConfigPath(path, sizeof(path), "obs-studio/logs") <= 0)
+		return false;
+	if (!do_mkdir(path))
+		return false;
 #ifdef _WIN32
-	if (os_get_config_path(path, sizeof(path), "obs-studio/crashes") <= 0)
+	if (GetConfigPath(path, sizeof(path), "obs-studio/crashes") <= 0)
 		return false;
 	if (!do_mkdir(path))
 		return false;
@@ -271,7 +282,7 @@ bool OBSApp::InitGlobalConfig()
 {
 	char path[512];
 
-	int len = os_get_config_path(path, sizeof(path),
+	int len = GetConfigPath(path, sizeof(path),
 			"obs-studio/global.ini");
 	if (len <= 0) {
 		return false;
@@ -362,7 +373,7 @@ bool OBSApp::SetTheme(std::string name, std::string path)
 		char userDir[512];
 		name = "themes/" + name + ".qss";
 		string temp = "obs-studio/" + name;
-		int ret = os_get_config_path(userDir, sizeof(userDir),
+		int ret = GetConfigPath(userDir, sizeof(userDir),
 				temp.c_str());
 
 		if (ret > 0 && QFile::exists(userDir)) {
@@ -574,7 +585,7 @@ static uint64_t convert_log_name(const char *name)
 
 static void delete_oldest_file(const char *location)
 {
-	BPtr<char>       logDir(os_get_config_path_ptr(location));
+	BPtr<char>       logDir(GetConfigPathPtr(location));
 	string           oldestLog;
 	uint64_t         oldest_ts = (uint64_t)-1;
 	struct os_dirent *entry;
@@ -615,7 +626,7 @@ static void delete_oldest_file(const char *location)
 
 static void get_last_log(void)
 {
-	BPtr<char>       logDir(os_get_config_path_ptr("obs-studio/logs"));
+	BPtr<char>       logDir(GetConfigPathPtr("obs-studio/logs"));
 	struct os_dirent *entry;
 	os_dir_t         *dir        = os_opendir(logDir);
 	uint64_t         highest_ts = 0;
@@ -688,7 +699,7 @@ static void create_log_file(fstream &logFile)
 	currentLogFile = GenerateTimeDateFilename("txt");
 	dst << "obs-studio/logs/" << currentLogFile.c_str();
 
-	BPtr<char> path(os_get_config_path_ptr(dst.str().c_str()));
+	BPtr<char> path(GetConfigPathPtr(dst.str().c_str()));
 	logFile.open(path,
 			ios_base::in | ios_base::out | ios_base::trunc);
 
@@ -745,7 +756,7 @@ static void main_crash_handler(const char *format, va_list args, void *param)
 	string name = "obs-studio/crashes/Crash ";
 	name += GenerateTimeDateFilename("txt");
 
-	BPtr<char> path(os_get_config_path_ptr(name.c_str()));
+	BPtr<char> path(GetConfigPathPtr(name.c_str()));
 
 	fstream file;
 	file.open(path, ios_base::in | ios_base::out | ios_base::trunc);

+ 1 - 1
obs/window-basic-main-outputs.cpp

@@ -292,7 +292,7 @@ static OBSData GetDataFromJsonFile(const char *jsonFile)
 {
 	char fullPath[512];
 
-	int ret = os_get_config_path(fullPath, sizeof(fullPath), jsonFile);
+	int ret = GetConfigPath(fullPath, sizeof(fullPath), jsonFile);
 	if (ret > 0) {
 		BPtr<char> jsonData = os_quick_read_utf8_file(fullPath);
 		if (!!jsonData) {

+ 10 - 10
obs/window-basic-main.cpp

@@ -66,7 +66,7 @@ Q_DECLARE_METATYPE(obs_order_movement);
 static void AddExtraModulePaths()
 {
 	char base_module_dir[512];
-	int ret = os_get_config_path(base_module_dir, sizeof(base_module_dir),
+	int ret = GetConfigPath(base_module_dir, sizeof(base_module_dir),
 			"obs-studio/plugins/%module%");
 
 	if (ret <= 0)
@@ -104,7 +104,7 @@ OBSBasic::OBSBasic(QWidget *parent)
 	}
 
 	char styleSheetPath[512];
-	int ret = os_get_config_path(styleSheetPath, sizeof(styleSheetPath),
+	int ret = GetConfigPath(styleSheetPath, sizeof(styleSheetPath),
 			"obs-studio/basic/stylesheet.qss");
 	if (ret > 0) {
 		if (QFile::exists(styleSheetPath)) {
@@ -369,7 +369,7 @@ void OBSBasic::SaveService()
 		return;
 
 	char serviceJsonPath[512];
-	int ret = os_get_config_path(serviceJsonPath, sizeof(serviceJsonPath),
+	int ret = GetConfigPath(serviceJsonPath, sizeof(serviceJsonPath),
 			SERVICE_PATH);
 	if (ret <= 0)
 		return;
@@ -393,7 +393,7 @@ bool OBSBasic::LoadService()
 	const char *type;
 
 	char serviceJsonPath[512];
-	int ret = os_get_config_path(serviceJsonPath, sizeof(serviceJsonPath),
+	int ret = GetConfigPath(serviceJsonPath, sizeof(serviceJsonPath),
 			SERVICE_PATH);
 	if (ret <= 0)
 		return false;
@@ -550,7 +550,7 @@ bool OBSBasic::InitBasicConfigDefaults()
 bool OBSBasic::InitBasicConfig()
 {
 	char configPath[512];
-	int ret = os_get_config_path(configPath, sizeof(configPath),
+	int ret = GetConfigPath(configPath, sizeof(configPath),
 			"obs-studio/basic/basic.ini");
 	if (ret <= 0) {
 		OBSErrorBox(nullptr, "Failed to get base.ini path");
@@ -622,7 +622,7 @@ void OBSBasic::ResetOutputs()
 void OBSBasic::OBSInit()
 {
 	char savePath[512];
-	int ret = os_get_config_path(savePath, sizeof(savePath),
+	int ret = GetConfigPath(savePath, sizeof(savePath),
 			"obs-studio/basic/scenes.json");
 	if (ret <= 0)
 		throw "Failed to get scenes.json file path";
@@ -893,7 +893,7 @@ OBSBasic::~OBSBasic()
 void OBSBasic::SaveProject()
 {
 	char savePath[512];
-	int ret = os_get_config_path(savePath, sizeof(savePath),
+	int ret = GetConfigPath(savePath, sizeof(savePath),
 			"obs-studio/basic/scenes.json");
 	if (ret <= 0)
 		return;
@@ -2388,7 +2388,7 @@ void OBSBasic::on_actionMoveToBottom_triggered()
 static BPtr<char> ReadLogFile(const char *log)
 {
 	char logDir[512];
-	if (os_get_config_path(logDir, sizeof(logDir), "obs-studio/logs") <= 0)
+	if (GetConfigPath(logDir, sizeof(logDir), "obs-studio/logs") <= 0)
 		return nullptr;
 
 	string path = (char*)logDir;
@@ -2458,7 +2458,7 @@ void OBSBasic::UploadLog(const char *file)
 void OBSBasic::on_actionShowLogs_triggered()
 {
 	char logDir[512];
-	if (os_get_config_path(logDir, sizeof(logDir), "obs-studio/logs") <= 0)
+	if (GetConfigPath(logDir, sizeof(logDir), "obs-studio/logs") <= 0)
 		return;
 
 	QUrl url = QUrl::fromLocalFile(QT_UTF8(logDir));
@@ -2478,7 +2478,7 @@ void OBSBasic::on_actionUploadLastLog_triggered()
 void OBSBasic::on_actionViewCurrentLog_triggered()
 {
 	char logDir[512];
-	if (os_get_config_path(logDir, sizeof(logDir), "obs-studio/logs") <= 0)
+	if (GetConfigPath(logDir, sizeof(logDir), "obs-studio/logs") <= 0)
 		return;
 
 	const char* log = App()->GetCurrentLog();

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

@@ -603,7 +603,7 @@ void OBSBasicSettings::LoadThemeList()
 	QSet<QString> uniqueSet;
 	string themeDir;
 	char userThemeDir[512];
-	int ret = os_get_config_path(userThemeDir, sizeof(userThemeDir),
+	int ret = GetConfigPath(userThemeDir, sizeof(userThemeDir),
 			"obs-studio/themes/");
 	GetDataFilePath("themes/", themeDir);
 
@@ -959,7 +959,7 @@ OBSPropertiesView *OBSBasicSettings::CreateEncoderPropertyView(
 	OBSPropertiesView *view;
 
 	char encoderJsonPath[512];
-	int ret = os_get_config_path(encoderJsonPath, sizeof(encoderJsonPath),
+	int ret = GetConfigPath(encoderJsonPath, sizeof(encoderJsonPath),
 			path);
 	if (ret > 0) {
 		BPtr<char> jsonData = os_quick_read_utf8_file(encoderJsonPath);
@@ -1860,7 +1860,7 @@ static void WriteJsonData(OBSPropertiesView *view, const char *path)
 	if (!view || !WidgetChanged(view))
 		return;
 
-	int ret = os_get_config_path(full_path, sizeof(full_path), path);
+	int ret = GetConfigPath(full_path, sizeof(full_path), path);
 	if (ret > 0) {
 		obs_data_t *settings = view->GetSettings();
 		if (settings) {