mirror of
https://github.com/TerryCavanagh/VVVVVV.git
synced 2024-12-22 17:49:43 +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:
parent
3c318814a4
commit
be2b1564a8
4 changed files with 30 additions and 10 deletions
|
@ -26,7 +26,12 @@ int mkdir(char* path, int mode)
|
||||||
MultiByteToWideChar(CP_UTF8, 0, path, -1, utf16_path, MAX_PATH);
|
MultiByteToWideChar(CP_UTF8, 0, path, -1, utf16_path, MAX_PATH);
|
||||||
return CreateDirectoryW(utf16_path, NULL);
|
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 <limits.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#define MAX_PATH PATH_MAX
|
#define MAX_PATH PATH_MAX
|
||||||
|
@ -857,7 +862,7 @@ fail:
|
||||||
return true;
|
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 */
|
/* XMLDocument.SaveFile doesn't account for Unicode paths, PHYSFS does */
|
||||||
tinyxml2::XMLPrinter printer;
|
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_writeBytes(handle, printer.CStr(), printer.CStrSize() - 1); // subtract one because CStrSize includes terminating null
|
||||||
PHYSFS_close(handle);
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,7 @@ void FILESYSTEM_freeMemory(unsigned char **mem);
|
||||||
|
|
||||||
bool FILESYSTEM_loadBinaryBlob(binaryBlob* blob, const char* filename);
|
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);
|
bool FILESYSTEM_loadTiXml2Document(const char *name, tinyxml2::XMLDocument& doc);
|
||||||
|
|
||||||
void FILESYSTEM_enumerateLevelDirFileNames(void (*callback)(const char* filename));
|
void FILESYSTEM_enumerateLevelDirFileNames(void (*callback)(const char* filename));
|
||||||
|
|
|
@ -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)
|
if (graphics.screenbuffer == NULL)
|
||||||
{
|
{
|
||||||
|
@ -4322,10 +4322,10 @@ bool Game::savestats(void)
|
||||||
ScreenSettings screen_settings;
|
ScreenSettings screen_settings;
|
||||||
graphics.screenbuffer->GetSettings(&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;
|
tinyxml2::XMLDocument doc;
|
||||||
bool already_exists = FILESYSTEM_loadTiXml2Document("saves/unlock.vvv", 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);
|
serializesettings(dataNode, screen_settings);
|
||||||
|
|
||||||
return FILESYSTEM_saveTiXml2Document("saves/unlock.vvv", doc);
|
return FILESYSTEM_saveTiXml2Document("saves/unlock.vvv", doc, sync);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Game::savestatsandsettings(void)
|
bool Game::savestatsandsettings(void)
|
||||||
{
|
{
|
||||||
const bool stats_saved = savestats();
|
const bool stats_saved = savestats(false);
|
||||||
|
|
||||||
const bool settings_saved = savesettings();
|
const bool settings_saved = savesettings();
|
||||||
|
|
||||||
|
|
|
@ -156,8 +156,8 @@ public:
|
||||||
|
|
||||||
void loadstats(ScreenSettings* screen_settings);
|
void loadstats(ScreenSettings* screen_settings);
|
||||||
|
|
||||||
bool savestats(const ScreenSettings* screen_settings);
|
bool savestats(const ScreenSettings* screen_settings, bool sync = true);
|
||||||
bool savestats(void);
|
bool savestats(bool sync = true);
|
||||||
|
|
||||||
void deletestats(void);
|
void deletestats(void);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue