UI: Rewrite profile system to enable user-provided storage location

This change enables loading profiles from locations different than
OBS' own configuration directory.

It also rewrites profile management in the app to work off an in-memory
collection of profiles found on disk and does not require iterating
over directory contents for most profile interactions by the app.
This commit is contained in:
PatTheMav
2024-09-03 16:29:30 +02:00
committed by Ryan Foster
parent 2635cf3a2a
commit 607d37b423
9 changed files with 1772 additions and 1601 deletions

View File

@@ -2136,12 +2136,16 @@ OBSBasicSettings::CreateEncoderPropertyView(const char *encoder,
OBSPropertiesView *view;
if (path) {
char encoderJsonPath[512];
int ret = GetProfilePath(encoderJsonPath,
sizeof(encoderJsonPath), path);
if (ret > 0) {
const OBSBasic *basic =
reinterpret_cast<OBSBasic *>(App()->GetMainWindow());
const OBSProfile &currentProfile = basic->GetCurrentProfile();
const std::filesystem::path jsonFilePath =
currentProfile.path / std::filesystem::u8path(path);
if (!jsonFilePath.empty()) {
obs_data_t *data = obs_data_create_from_json_file_safe(
encoderJsonPath, "bak");
jsonFilePath.u8string().c_str(), "bak");
obs_data_apply(settings, data);
obs_data_release(data);
}
@@ -3748,17 +3752,22 @@ static inline const char *SplitFileTypeFromIdx(int idx)
static void WriteJsonData(OBSPropertiesView *view, const char *path)
{
char full_path[512];
if (!view || !WidgetChanged(view))
return;
int ret = GetProfilePath(full_path, sizeof(full_path), path);
if (ret > 0) {
const OBSBasic *basic =
reinterpret_cast<OBSBasic *>(App()->GetMainWindow());
const OBSProfile &currentProfile = basic->GetCurrentProfile();
const std::filesystem::path jsonFilePath =
currentProfile.path / std::filesystem::u8path(path);
if (!jsonFilePath.empty()) {
obs_data_t *settings = view->GetSettings();
if (settings) {
obs_data_save_json_safe(settings, full_path, "tmp",
"bak");
obs_data_save_json_safe(settings,
jsonFilePath.u8string().c_str(),
"tmp", "bak");
}
}
}
@@ -5691,14 +5700,16 @@ void OBSBasicSettings::AdvReplayBufferChanged()
if (!settings)
return;
char encoderJsonPath[512];
int ret = GetProfilePath(encoderJsonPath,
sizeof(encoderJsonPath),
"recordEncoder.json");
if (ret > 0) {
const OBSProfile &currentProfile = main->GetCurrentProfile();
const std::filesystem::path jsonFilePath =
currentProfile.path /
std::filesystem::u8path("recordEncoder.json");
if (!jsonFilePath.empty()) {
OBSDataAutoRelease data =
obs_data_create_from_json_file_safe(
encoderJsonPath, "bak");
jsonFilePath.u8string().c_str(), "bak");
obs_data_apply(settings, data);
}
}