diff --git a/FCHost/fchost/fchost_storage.cc b/FCHost/fchost/fchost_storage.cc index 7f9c27a6fb1cf99e9c7d71d11689b55db8017ac4..b619e75fece05338300d33d7003e06da1bda8ec9 100644 --- a/FCHost/fchost/fchost_storage.cc +++ b/FCHost/fchost/fchost_storage.cc @@ -58,9 +58,9 @@ void FCHostPersistentStorage::set(const CefString& key, CefRefPtr<CefV8Value> va // we should probably be doing this async but TBT Sugarcube is the slow part, not the file IO std::unique_ptr<std::FILE, closeFile> fh; #if defined(OS_WIN) - fh.reset(_wfopen(get_filename(key).c_str(), L"w")); + fh.reset(_wfopen(get_filename(key).c_str(), L"wb")); #else - fh.reset(std::fopen(get_filename(key).c_str(), "w")); + fh.reset(std::fopen(get_filename(key).c_str(), "wb")); #endif CefString valStr = val->GetStringValue(); if (valStr.size() > 0) { @@ -93,16 +93,17 @@ void FCHostPersistentStorage::load() for (const auto& entry: fs::directory_iterator(path)) { if (fs::is_regular_file(entry.path())) { const auto entrySize = fs::file_size(entry.path()); - readbuf.resize(static_cast<std::size_t>(entrySize + 2)); // +1 wchar_t + readbuf.resize(static_cast<std::size_t>(entrySize + 2)); // +1 char16 #if defined(OS_WIN) - fh.reset(_wfopen(entry.path().c_str(), L"r")); + fh.reset(_wfopen(entry.path().c_str(), L"rb")); #else - fh.reset(std::fopen(entry.path().c_str(), "r")); + fh.reset(std::fopen(entry.path().c_str(), "rb")); #endif if (std::fread(&readbuf[0], entrySize, 1, fh.get())) { readbuf[entrySize + 1] = readbuf[entrySize] = 0; // null terminate - CefString val = static_cast<const wchar_t*>(static_cast<const void*>(readbuf.data())); + CefString val; + val.FromString16(static_cast<const char16_t*>(static_cast<const void*>(readbuf.data()))); storage.emplace(entry.path().filename().native(), CefV8Value::CreateString(val)); } }