configuration: Don't leak pointers and add messages to exceptions

This commit is contained in:
Michael Fabian 'Xaymar' Dirks 2020-07-26 18:32:53 +02:00
parent 731dbd26a7
commit f5bc53564d
2 changed files with 10 additions and 8 deletions

View file

@ -44,18 +44,18 @@ streamfx::configuration::~configuration()
streamfx::configuration::configuration() : _data(), _config_path()
{
{ // Retrieve global configuration path.
const char* path = obs_module_config_path("config.json");
char* path = obs_module_config_path("config.json");
_config_path = path;
bfree(path);
}
try {
if (!std::filesystem::exists(_config_path) || !std::filesystem::is_regular_file(_config_path)) {
throw std::exception();
throw std::runtime_error("Configuration does not exist.");
} else {
obs_data_t* data =
obs_data_create_from_json_file_safe(_config_path.string().c_str(), path_backup_ext.data());
obs_data_t* data = obs_data_create_from_json_file_safe(_config_path.string().c_str(), path_backup_ext.data());
if (!data) {
throw std::exception();
throw std::runtime_error("Failed to load configuration from disk.");
} else {
_data = std::shared_ptr<obs_data_t>(data, obs::obs_data_deleter);
}

View file

@ -59,13 +59,15 @@ inline void qt_cleanup_resource()
bool streamfx::ui::handler::have_shown_about_streamfx(bool shown)
{
auto config = streamfx::configuration::instance();
auto data = config->get();
if (shown) {
obs_data_set_bool(streamfx::configuration::instance()->get().get(), _cfg_have_shown_about.data(), true);
obs_data_set_bool(data.get(), _cfg_have_shown_about.data(), true);
}
if (streamfx::configuration::instance()->is_different_version()) {
if (config->is_different_version()) {
return false;
} else {
return obs_data_get_bool(streamfx::configuration::instance()->get().get(), _cfg_have_shown_about.data());
return obs_data_get_bool(data.get(), _cfg_have_shown_about.data());
}
}