1
0
Fork 0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-11-05 02:39:41 +01:00

Call FS.syncfs on Emscripten (#838)

Also, add a sync parameter to avoid calling syncfs too often.

Calling syncfs twice in a row is both inefficient and leads to errors
displaying twice. This allows us to bypass it when saving unlock.vvv as
part of savestatsandsettings.
This commit is contained in:
leo60228 2021-09-02 13:19:51 -04:00 committed by GitHub
parent 3c318814a4
commit be2b1564a8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 30 additions and 10 deletions

View file

@ -26,7 +26,12 @@ int mkdir(char* path, int mode)
MultiByteToWideChar(CP_UTF8, 0, path, -1, utf16_path, MAX_PATH);
return CreateDirectoryW(utf16_path, NULL);
}
#elif defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__HAIKU__) || defined(__DragonFly__) || defined(__EMSCRIPTEN__) || defined(__unix__)
#elif defined(__EMSCRIPTEN__)
#include <limits.h>
#include <sys/stat.h>
#include <emscripten.h>
#define MAX_PATH PATH_MAX
#elif defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__HAIKU__) || defined(__DragonFly__) || defined(__unix__)
#include <limits.h>
#include <sys/stat.h>
#define MAX_PATH PATH_MAX
@ -857,7 +862,7 @@ fail:
return true;
}
bool FILESYSTEM_saveTiXml2Document(const char *name, tinyxml2::XMLDocument& doc)
bool FILESYSTEM_saveTiXml2Document(const char *name, tinyxml2::XMLDocument& doc, bool sync /*= true*/)
{
/* XMLDocument.SaveFile doesn't account for Unicode paths, PHYSFS does */
tinyxml2::XMLPrinter printer;
@ -869,6 +874,21 @@ bool FILESYSTEM_saveTiXml2Document(const char *name, tinyxml2::XMLDocument& doc)
}
PHYSFS_writeBytes(handle, printer.CStr(), printer.CStrSize() - 1); // subtract one because CStrSize includes terminating null
PHYSFS_close(handle);
#ifdef __EMSCRIPTEN__
if (sync)
{
EM_ASM(FS.syncfs(false, function(err)
{
if (err)
{
console.warn("Error saving:", err);
alert("Error saving. Check console for more information.");
}
}));
}
#endif
return true;
}

View file

@ -35,7 +35,7 @@ void FILESYSTEM_freeMemory(unsigned char **mem);
bool FILESYSTEM_loadBinaryBlob(binaryBlob* blob, const char* filename);
bool FILESYSTEM_saveTiXml2Document(const char *name, tinyxml2::XMLDocument& doc);
bool FILESYSTEM_saveTiXml2Document(const char *name, tinyxml2::XMLDocument& doc, bool sync = true);
bool FILESYSTEM_loadTiXml2Document(const char *name, tinyxml2::XMLDocument& doc);
void FILESYSTEM_enumerateLevelDirFileNames(void (*callback)(const char* filename));

View file

@ -4312,7 +4312,7 @@ void Game::deserializesettings(tinyxml2::XMLElement* dataNode, ScreenSettings* s
}
}
bool Game::savestats(void)
bool Game::savestats(bool sync /*= true*/)
{
if (graphics.screenbuffer == NULL)
{
@ -4322,10 +4322,10 @@ bool Game::savestats(void)
ScreenSettings screen_settings;
graphics.screenbuffer->GetSettings(&screen_settings);
return savestats(&screen_settings);
return savestats(&screen_settings, sync);
}
bool Game::savestats(const ScreenSettings* screen_settings)
bool Game::savestats(const ScreenSettings* screen_settings, bool sync /*= true*/)
{
tinyxml2::XMLDocument doc;
bool already_exists = FILESYSTEM_loadTiXml2Document("saves/unlock.vvv", doc);
@ -4406,12 +4406,12 @@ bool Game::savestats(const ScreenSettings* screen_settings)
serializesettings(dataNode, screen_settings);
return FILESYSTEM_saveTiXml2Document("saves/unlock.vvv", doc);
return FILESYSTEM_saveTiXml2Document("saves/unlock.vvv", doc, sync);
}
bool Game::savestatsandsettings(void)
{
const bool stats_saved = savestats();
const bool stats_saved = savestats(false);
const bool settings_saved = savesettings();

View file

@ -156,8 +156,8 @@ public:
void loadstats(ScreenSettings* screen_settings);
bool savestats(const ScreenSettings* screen_settings);
bool savestats(void);
bool savestats(const ScreenSettings* screen_settings, bool sync = true);
bool savestats(bool sync = true);
void deletestats(void);