Skip to content
Snippets Groups Projects
Commit 93644a23 authored by svornost's avatar svornost
Browse files

Be a bit stricter about the encoding used for slot saves to avoid slot...

Be a bit stricter about the encoding used for slot saves to avoid slot corruption with certain high-unicode characters, such as :ocean:.
parent c8b0252f
No related branches found
No related tags found
1 merge request!11221Fixes
......@@ -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));
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment