| 35 | } |
| 36 | |
| 37 | streamfx::configuration::configuration() : _config_path(), _data(), _task_lock(), _save_task() |
| 38 | { |
| 39 | // Retrieve global configuration path. |
| 40 | _config_path = streamfx::config_file_path("config.json"); |
| 41 | |
| 42 | try { |
| 43 | if (!std::filesystem::exists(_config_path) || !std::filesystem::is_regular_file(_config_path)) { |
| 44 | throw std::runtime_error("Configuration does not exist."); |
| 45 | } else { |
| 46 | obs_data_t* data = obs_data_create_from_json_file_safe(_config_path.u8string().c_str(), path_backup_ext.data()); |
| 47 | if (!data) { |
| 48 | throw std::runtime_error("Failed to load configuration from disk."); |
| 49 | } else { |
| 50 | _data = std::shared_ptr<obs_data_t>(data, obs::obs_data_deleter); |
| 51 | } |
| 52 | } |
| 53 | } catch (...) { |
| 54 | _data = std::shared_ptr<obs_data_t>(obs_data_create(), obs::obs_data_deleter); |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | void streamfx::configuration::save() |
| 59 | { |