Check if settings file is open before parsing JSON content from it (#1616)

This commit is contained in:
vldmr11080 2020-03-18 11:17:57 +01:00 committed by GitHub
parent f0f044b766
commit ff0c021162
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -10,8 +10,12 @@ namespace json
try
{
std::wifstream file(file_name.data(), std::ios::binary);
using isbi = std::istreambuf_iterator<wchar_t>;
return JsonValue::Parse(std::wstring{ isbi{ file }, isbi{} }).GetObjectW();
if (file.is_open())
{
using isbi = std::istreambuf_iterator<wchar_t>;
return JsonValue::Parse(std::wstring{ isbi{ file }, isbi{} }).GetObjectW();
}
return std::nullopt;
}
catch (...)
{