mirror of
https://github.com/obsproject/obs-studio.git
synced 2026-09-24 23:40:42 -05:00
UI: Use saving functions for profiles/scenes
Replaces all the json/config loading/saving functions with safe variants to reduce the chance of potential file corruption as much as possible. Also does a minor refactor of json writing by using obs_data_save_json_safe for writing json files instead of manually using obs_data_get_json and os_quick_write_utf8 each time.
This commit is contained in:
@@ -1069,12 +1069,10 @@ OBSPropertiesView *OBSBasicSettings::CreateEncoderPropertyView(
|
||||
int ret = GetProfilePath(encoderJsonPath, sizeof(encoderJsonPath),
|
||||
path);
|
||||
if (ret > 0) {
|
||||
BPtr<char> jsonData = os_quick_read_utf8_file(encoderJsonPath);
|
||||
if (!!jsonData) {
|
||||
obs_data_t *data = obs_data_create_from_json(jsonData);
|
||||
obs_data_apply(settings, data);
|
||||
obs_data_release(data);
|
||||
}
|
||||
obs_data_t *data = obs_data_create_from_json_file_safe(
|
||||
encoderJsonPath, "bak");
|
||||
obs_data_apply(settings, data);
|
||||
obs_data_release(data);
|
||||
}
|
||||
|
||||
view = new OBSPropertiesView(settings, encoder,
|
||||
@@ -1985,11 +1983,8 @@ static void WriteJsonData(OBSPropertiesView *view, const char *path)
|
||||
if (ret > 0) {
|
||||
obs_data_t *settings = view->GetSettings();
|
||||
if (settings) {
|
||||
const char *json = obs_data_get_json(settings);
|
||||
if (json && *json) {
|
||||
os_quick_write_utf8_file(full_path, json,
|
||||
strlen(json), false);
|
||||
}
|
||||
obs_data_save_json_safe(settings, full_path,
|
||||
"tmp", "bak");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2247,8 +2242,8 @@ void OBSBasicSettings::SaveSettings()
|
||||
if (videoChanged || advancedChanged)
|
||||
main->ResetVideo();
|
||||
|
||||
config_save(main->Config());
|
||||
config_save(GetGlobalConfig());
|
||||
config_save_safe(main->Config(), "tmp", nullptr);
|
||||
config_save_safe(GetGlobalConfig(), "tmp", nullptr);
|
||||
main->SaveProject();
|
||||
|
||||
if (Changed()) {
|
||||
|
||||
Reference in New Issue
Block a user