Replace TiXmlDocument load and save functions by PHYSFS

The TinyXml functions to load and save files don't properly support
unicode file paths on Windows, so in order to support that properly, I
saw no other option than to do the actual loading and saving via PHYSFS
(or to use the Windows API on Windows and retain doc.LoadFile and
doc.SaveFile on other OSes, but that'd be more complicated and
unnecessary, we already have PHYSFS, right?).

There are two new functions in FileSystemUtils:
bool FILESYSTEM_saveTiXmlDocument(const char *name, TiXmlDocument *doc)
bool FILESYSTEM_loadTiXmlDocument(const char *name, TiXmlDocument *doc)

Any instances of doc.SaveFile(<FULL_PATH>) have been replaced by
FILESYSTEM_saveTiXmlDocument(<VVVVVV_FOLDER_PATH>, &doc), where
<FULL_PATH> included the full path to the saves or levels directory,
and <VVVVVV_FOLDER_PATH> only includes the path relative to the VVVVVV
directory.
When loading a document, a TiXmlDocument used to be created with a full
path in its constructor and doc.LoadFile() would then be called, now a
TiXmlDocument is constructed with no path name and
FILESYSTEM_loadTiXmlDocument(<VVVVVV_FOLDER_PATH>, &doc) is called.
This commit is contained in:
Dav999-v
2020-01-12 15:17:39 +01:00
committed by Ethan Lee
parent ddaa5e13c8
commit b884b7e4e9
5 changed files with 61 additions and 23 deletions

View File

@@ -293,8 +293,8 @@ Game::Game(void):
saveFilePath = FILESYSTEM_getUserSaveDirectory();
TiXmlDocument doc((saveFilePath + "qsave.vvv").c_str());
if (!doc.LoadFile())
TiXmlDocument doc;
if (!FILESYSTEM_loadTiXmlDocument("saves/qsave.vvv", &doc))
{
quickcookieexists = false;
quicksummary = "";
@@ -470,8 +470,8 @@ void Game::loadcustomlevelstats()
//testing
if(!customlevelstatsloaded)
{
TiXmlDocument doc((saveFilePath+"levelstats.vvv").c_str());
if (!doc.LoadFile())
TiXmlDocument doc;
if (!FILESYSTEM_loadTiXmlDocument("saves/levelstats.vvv", &doc))
{
//No levelstats file exists; start new
numcustomlevelstats=0;
@@ -581,7 +581,7 @@ void Game::savecustomlevelstats()
msg->LinkEndChild( new TiXmlText( customlevelstatsstr.c_str() ));
msgs->LinkEndChild( msg );
if(doc.SaveFile( (saveFilePath+"levelstats.vvv").c_str() ))
if(FILESYSTEM_saveTiXmlDocument("saves/levelstats.vvv", &doc))
{
printf("Level stats saved\n");
}
@@ -4105,8 +4105,8 @@ void Game::unlocknum( int t, mapclass& map, Graphics& dwgfx )
void Game::loadstats( mapclass& map, Graphics& dwgfx )
{
// TODO loadstats
TiXmlDocument doc((saveFilePath+"unlock.vvv").c_str());
if (!doc.LoadFile())
TiXmlDocument doc;
if (!FILESYSTEM_loadTiXmlDocument("saves/unlock.vvv", &doc))
{
savestats(map, dwgfx);
printf("No Stats found. Assuming a new player\n");
@@ -4564,7 +4564,7 @@ void Game::savestats( mapclass& _map, Graphics& _dwgfx )
msg->LinkEndChild( new TiXmlText( tu.String(controllerSensitivity).c_str()));
dataNode->LinkEndChild( msg );
doc.SaveFile( (saveFilePath+"unlock.vvv").c_str() );
FILESYSTEM_saveTiXmlDocument("saves/unlock.vvv", &doc);
}
void Game::customstart( entityclass& obj, musicclass& music )
@@ -4792,8 +4792,8 @@ void Game::starttrial( int t, entityclass& obj, musicclass& music )
void Game::loadquick( mapclass& map, entityclass& obj, musicclass& music )
{
TiXmlDocument doc((saveFilePath+"qsave.vvv").c_str());
if (!doc.LoadFile()) return; ;
TiXmlDocument doc;
if (!FILESYSTEM_loadTiXmlDocument("saves/qsave.vvv", &doc)) return;
TiXmlHandle hDoc(&doc);
TiXmlElement* pElem;
@@ -5014,8 +5014,8 @@ void Game::loadquick( mapclass& map, entityclass& obj, musicclass& music )
void Game::customloadquick(std::string savfile, mapclass& map, entityclass& obj, musicclass& music )
{
std::string levelfile = savfile.substr(7);
TiXmlDocument doc((saveFilePath+levelfile+".vvv").c_str());
if (!doc.LoadFile()) return; ;
TiXmlDocument doc;
if (!FILESYSTEM_loadTiXmlDocument(("saves/"+levelfile+".vvv").c_str(), &doc)) return;
TiXmlHandle hDoc(&doc);
TiXmlElement* pElem;
@@ -5389,8 +5389,8 @@ void Game::loadsummary( mapclass& map, UtilityClass& help )
tele_currentarea = map.currentarea(map.area(l_saveX, l_saveY));
}
TiXmlDocument doc((saveFilePath+"qsave.vvv").c_str());
if (!doc.LoadFile())
TiXmlDocument doc;
if (!FILESYSTEM_loadTiXmlDocument("saves/qsave.vvv", &doc))
{
quickcookieexists = false;
quicksummary = "";
@@ -5734,7 +5734,7 @@ void Game::savetele( mapclass& map, entityclass& obj, musicclass& music )
//telecookie.flush();
//telecookie.close();
if(doc.SaveFile( (saveFilePath+"tsave.vvv").c_str() ))
if(FILESYSTEM_saveTiXmlDocument("saves/tsave.vvv", &doc))
{
printf("Game saved\n");
}
@@ -5978,7 +5978,7 @@ void Game::savequick( mapclass& map, entityclass& obj, musicclass& music )
//telecookie.flush();
//telecookie.close();
if(doc.SaveFile( (saveFilePath+ "qsave.vvv").c_str() ))
if(FILESYSTEM_saveTiXmlDocument("saves/qsave.vvv", &doc))
{
printf("Game saved\n");
}
@@ -6239,7 +6239,7 @@ void Game::customsavequick(std::string savfile, mapclass& map, entityclass& obj,
//telecookie.close();
std::string levelfile = savfile.substr(7);
if(doc.SaveFile( (saveFilePath+ levelfile+".vvv").c_str() ))
if(FILESYSTEM_saveTiXmlDocument(("saves/"+levelfile+".vvv").c_str(), &doc))
{
printf("Game saved\n");
}
@@ -6253,8 +6253,8 @@ void Game::customsavequick(std::string savfile, mapclass& map, entityclass& obj,
void Game::loadtele( mapclass& map, entityclass& obj, musicclass& music )
{
TiXmlDocument doc((saveFilePath+"tsave.vvv").c_str());
if (!doc.LoadFile()) return; ;
TiXmlDocument doc;
if (!FILESYSTEM_loadTiXmlDocument("saves/tsave.vvv", &doc)) return;
TiXmlHandle hDoc(&doc);
TiXmlElement* pElem;