mirror of
https://github.com/TerryCavanagh/VVVVVV.git
synced 2024-12-22 09:39:43 +01:00
Prevent writing stats/settings if they're not loaded
This prevents writing to unlock.vvv or settings.vvv if the game hasn't made an attempt to load them yet. Otherwise, if the game aborted via VVV_exit() because of, say, failure to parse a graphics file, it would overwrite perfectly existing valid save data since it hasn't loaded it yet. Fixes #870.
This commit is contained in:
parent
75ee657612
commit
5bd7dce075
1 changed files with 26 additions and 2 deletions
|
@ -4024,6 +4024,8 @@ void Game::unlocknum( int t )
|
|||
#endif
|
||||
}
|
||||
|
||||
static bool stats_loaded = false;
|
||||
|
||||
void Game::loadstats(struct ScreenSettings* screen_settings)
|
||||
{
|
||||
tinyxml2::XMLDocument doc;
|
||||
|
@ -4031,6 +4033,8 @@ void Game::loadstats(struct ScreenSettings* screen_settings)
|
|||
tinyxml2::XMLElement* pElem;
|
||||
tinyxml2::XMLElement* dataNode;
|
||||
|
||||
stats_loaded = true;
|
||||
|
||||
if (!FILESYSTEM_loadTiXml2Document("saves/unlock.vvv", doc))
|
||||
{
|
||||
// Save unlock.vvv only. Maybe we have a settings.vvv laying around too,
|
||||
|
@ -4340,7 +4344,15 @@ bool Game::savestats(bool sync /*= true*/)
|
|||
bool Game::savestats(const struct ScreenSettings* screen_settings, bool sync /*= true*/)
|
||||
{
|
||||
tinyxml2::XMLDocument doc;
|
||||
bool already_exists = FILESYSTEM_loadTiXml2Document("saves/unlock.vvv", doc);
|
||||
bool already_exists;
|
||||
|
||||
if (!stats_loaded)
|
||||
{
|
||||
vlog_warn("Stats not loaded! Not writing unlock.vvv.");
|
||||
return false;
|
||||
}
|
||||
|
||||
already_exists = FILESYSTEM_loadTiXml2Document("saves/unlock.vvv", doc);
|
||||
if (!already_exists)
|
||||
{
|
||||
vlog_info("No unlock.vvv found. Creating new file");
|
||||
|
@ -4567,12 +4579,16 @@ void Game::serializesettings(tinyxml2::XMLElement* dataNode, const struct Screen
|
|||
xml::update_tag(dataNode, "controllerSensitivity", key.sensitivity);
|
||||
}
|
||||
|
||||
static bool settings_loaded = false;
|
||||
|
||||
void Game::loadsettings(struct ScreenSettings* screen_settings)
|
||||
{
|
||||
tinyxml2::XMLDocument doc;
|
||||
tinyxml2::XMLHandle hDoc(&doc);
|
||||
tinyxml2::XMLElement* dataNode;
|
||||
|
||||
settings_loaded = true;
|
||||
|
||||
if (!FILESYSTEM_loadTiXml2Document("saves/settings.vvv", doc))
|
||||
{
|
||||
savesettings(screen_settings);
|
||||
|
@ -4606,7 +4622,15 @@ bool Game::savesettings(void)
|
|||
bool Game::savesettings(const struct ScreenSettings* screen_settings)
|
||||
{
|
||||
tinyxml2::XMLDocument doc;
|
||||
bool already_exists = FILESYSTEM_loadTiXml2Document("saves/settings.vvv", doc);
|
||||
bool already_exists;
|
||||
|
||||
if (!settings_loaded)
|
||||
{
|
||||
vlog_warn("Settings not loaded! Not writing settings.vvv.");
|
||||
return false;
|
||||
}
|
||||
|
||||
already_exists = FILESYSTEM_loadTiXml2Document("saves/settings.vvv", doc);
|
||||
if (!already_exists)
|
||||
{
|
||||
vlog_info("No settings.vvv found. Creating new file");
|
||||
|
|
Loading…
Reference in a new issue