configuration: Fix unicode support

Related: #359
This commit is contained in:
Michael Fabian 'Xaymar' Dirks 2020-11-28 23:31:31 +01:00 committed by Xaymar
parent a666e01506
commit 007974da54

View file

@ -33,28 +33,25 @@ 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", path_backup_ext.data())) { if (!obs_data_save_json_safe(_data.get(), _config_path.u8string().c_str(), ".tmp", path_backup_ext.data())) {
throw std::exception(); throw std::exception();
} }
} catch (...) { } catch (std::exception const& ex) {
DLOG_ERROR("Failed to save configuration, next start will be using defaults or backed up configuration."); DLOG_ERROR("Failed to save configuration: %s", ex.what());
} }
} }
streamfx::configuration::configuration() : _data(), _config_path() streamfx::configuration::configuration() : _data(), _config_path()
{ {
{ // Retrieve global configuration path. // Retrieve global configuration path.
char* path = obs_module_config_path("config.json"); _config_path = streamfx::config_file_path("config.json");
_config_path = path;
bfree(path);
}
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::runtime_error("Configuration does not exist."); throw std::runtime_error("Configuration does not exist.");
} else { } else {
obs_data_t* data = obs_data_t* data =
obs_data_create_from_json_file_safe(_config_path.string().c_str(), path_backup_ext.data()); obs_data_create_from_json_file_safe(_config_path.u8string().c_str(), path_backup_ext.data());
if (!data) { if (!data) {
throw std::runtime_error("Failed to load configuration from disk."); throw std::runtime_error("Failed to load configuration from disk.");
} else { } else {