mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-03 17:37:18 +00:00
Decode base64-packed settings files
This commit is contained in:
parent
081650a2e5
commit
4cedb3549b
@ -12,16 +12,31 @@
|
|||||||
void Settings::SettingsFileParser::loadSettingsFile(const std::string& file, CategorySettingValueMap& settings, bool base64Encoded)
|
void Settings::SettingsFileParser::loadSettingsFile(const std::string& file, CategorySettingValueMap& settings, bool base64Encoded)
|
||||||
{
|
{
|
||||||
mFile = file;
|
mFile = file;
|
||||||
boost::filesystem::ifstream stream;
|
boost::filesystem::ifstream fstream;
|
||||||
stream.open(boost::filesystem::path(file));
|
fstream.open(boost::filesystem::path(file));
|
||||||
|
auto stream = std::ref<std::istream>(fstream);
|
||||||
|
|
||||||
|
std::istringstream decodedStream;
|
||||||
|
if (base64Encoded)
|
||||||
|
{
|
||||||
|
std::string base64String(std::istreambuf_iterator<char>(fstream), {});
|
||||||
|
std::string decodedString;
|
||||||
|
auto result = Base64::Base64::Decode(base64String, decodedString);
|
||||||
|
if (!result.empty())
|
||||||
|
fail("Could not decode Base64 file: " + result);
|
||||||
|
// Move won't do anything until C++20, but won't hurt to do it anyway.
|
||||||
|
decodedStream.str(std::move(decodedString));
|
||||||
|
stream = std::ref<std::istream>(decodedStream);
|
||||||
|
}
|
||||||
|
|
||||||
Log(Debug::Info) << "Loading settings file: " << file;
|
Log(Debug::Info) << "Loading settings file: " << file;
|
||||||
std::string currentCategory;
|
std::string currentCategory;
|
||||||
mLine = 0;
|
mLine = 0;
|
||||||
while (!stream.eof() && !stream.fail())
|
while (!stream.get().eof() && !stream.get().fail())
|
||||||
{
|
{
|
||||||
++mLine;
|
++mLine;
|
||||||
std::string line;
|
std::string line;
|
||||||
std::getline( stream, line );
|
std::getline( stream.get(), line );
|
||||||
|
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
if (!skipWhiteSpace(i, line))
|
if (!skipWhiteSpace(i, line))
|
||||||
|
Loading…
Reference in New Issue
Block a user