|
21 | 21 | #include <filesystem> |
22 | 22 | #include <sstream> |
23 | 23 | #include <bitcoin/system/data/data.hpp> |
24 | | -#include <bitcoin/system/unicode/utf8_everywhere/ifstream.hpp> |
| 24 | +#include <bitcoin/system/unicode/unicode.hpp> |
| 25 | +#include <bitcoin/system/unicode/utf8_everywhere/utf8_everywhere.hpp> |
25 | 26 |
|
26 | 27 | namespace libbitcoin { |
27 | 28 | namespace system { |
@@ -51,7 +52,8 @@ std::filesystem::path parser::get_config_option(variables_map& variables, |
51 | 52 | if (config.empty()) |
52 | 53 | return {}; |
53 | 54 |
|
54 | | - return config.as<std::filesystem::path>(); |
| 55 | + // Capture as utf8 so std::filesystem::path does assume ansi code page. |
| 56 | + return { config.as<std::u8string>() }; |
55 | 57 | } |
56 | 58 |
|
57 | 59 | bool parser::get_option(variables_map& variables, |
@@ -88,27 +90,26 @@ void parser::load_environment_variables(variables_map& variables, |
88 | 90 | bool parser::load_configuration_variables(variables_map& variables, |
89 | 91 | const std::string& option_name) THROWS |
90 | 92 | { |
91 | | - const auto config_settings = load_settings(); |
92 | | - const auto config_path = get_config_option(variables, option_name); |
| 93 | + const auto settings = load_settings(); |
| 94 | + const auto path = get_config_option(variables, option_name); |
| 95 | + const auto extended = extended_path(path); |
93 | 96 |
|
94 | 97 | // If the existence test errors out we pretend there's no file :/. |
95 | | - std::error_code code; |
96 | | - if (!config_path.empty() && exists(config_path, code)) |
| 98 | + std::error_code code{}; |
| 99 | + if (!path.empty() && std::filesystem::exists(extended, code)) |
97 | 100 | { |
98 | | - const auto& path = config_path.string(); |
99 | | - ifstream file(path); |
100 | | - |
| 101 | + ifstream file{ path }; |
101 | 102 | if (!file.good()) |
102 | | - throw ifstream_exception(path.c_str()); |
| 103 | + throw ifstream_exception{ from_path(extended).c_str() }; |
103 | 104 |
|
104 | | - const auto config = parse_config_file(file, config_settings); |
| 105 | + const auto config = parse_config_file(file, settings); |
105 | 106 | store(config, variables); |
106 | 107 | return true; |
107 | 108 | } |
108 | 109 |
|
109 | 110 | // Loading from an empty stream causes the defaults to populate. |
110 | | - std::istringstream stream; |
111 | | - const auto config = parse_config_file(stream, config_settings); |
| 111 | + std::istringstream stream{}; |
| 112 | + const auto config = parse_config_file(stream, settings); |
112 | 113 | store(config, variables); |
113 | 114 | return false; |
114 | 115 | } |
|
0 commit comments