configuration: Fix failed saving due to invalid path

This commit is contained in:
Michael Fabian 'Xaymar' Dirks 2020-05-31 01:30:07 +02:00 committed by Michael Fabian Dirks
parent c667b8a147
commit 85f2ebc7e7
2 changed files with 3 additions and 7 deletions

View file

@ -33,8 +33,7 @@ streamfx::configuration::~configuration()
if (_config_path.has_parent_path()) { if (_config_path.has_parent_path()) {
std::filesystem::create_directories(_config_path.parent_path()); std::filesystem::create_directories(_config_path.parent_path());
} }
if (!obs_data_save_json_safe(_data.get(), _config_path.string().c_str(), ".tmp", if (!obs_data_save_json_safe(_data.get(), _config_path.string().c_str(), ".tmp", path_backup_ext.data())) {
_config_backup_path.string().c_str())) {
throw std::exception(); throw std::exception();
} }
} catch (...) { } catch (...) {
@ -42,20 +41,18 @@ streamfx::configuration::~configuration()
} }
} }
streamfx::configuration::configuration() : _data(), _config_path(), _config_backup_path() streamfx::configuration::configuration() : _data(), _config_path()
{ {
{ // Retrieve global configuration path. { // Retrieve global configuration path.
const char* path = obs_module_config_path("config.json"); const char* path = obs_module_config_path("config.json");
_config_path = path; _config_path = path;
_config_backup_path = std::filesystem::path(_config_path).concat(path_backup_ext);
} }
try { try {
if (!std::filesystem::exists(_config_path) || !std::filesystem::is_regular_file(_config_path)) { if (!std::filesystem::exists(_config_path) || !std::filesystem::is_regular_file(_config_path)) {
throw std::exception(); throw std::exception();
} else { } else {
obs_data_t* data = obs_data_create_from_json_file_safe(_config_path.string().c_str(), obs_data_t* data = obs_data_create_from_json_file_safe(_config_path.string().c_str(), path_backup_ext.data());
_config_backup_path.string().c_str());
if (!data) { if (!data) {
throw std::exception(); throw std::exception();
} else { } else {

View file

@ -27,7 +27,6 @@ namespace streamfx {
std::shared_ptr<obs_data_t> _data; std::shared_ptr<obs_data_t> _data;
std::filesystem::path _config_path; std::filesystem::path _config_path;
std::filesystem::path _config_backup_path;
public: public:
~configuration(); ~configuration();