Skip to content

Commit

Permalink
libcommon: Updated .save package reinterpretation to use the new method
Browse files Browse the repository at this point in the history
As of this commit, saving and loading of the game to .save packages
is once again possible.

Also fixed a bug in savedSessionByUserDescription() which meant that
the wrong folder was searched in for SavedSessions.
  • Loading branch information
danij-deng committed Mar 25, 2014
1 parent 28316e0 commit 693b91a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
6 changes: 4 additions & 2 deletions doomsday/plugins/common/src/g_game.cpp
Expand Up @@ -479,7 +479,7 @@ gameaction_t G_GameAction()
return gameAction;
}

/// @return Relative path to a saved session in /home/savegames
/// @return Absolute path to a saved session in /home/savegames
static inline de::String composeSavedSessionPathForSlot(int slot)
{
return de::String("/home/savegames") / G_IdentityKey() / SAVEGAMENAME + de::String::number(slot) + ".save";
Expand Down Expand Up @@ -986,7 +986,7 @@ static de::game::SavedSession *savedSessionByUserDescription(de::String descript
{
if(!description.isEmpty())
{
de::Folder &saveFolder = DENG2_APP->rootFolder().locate<de::Folder>("home/savegames");
de::Folder &saveFolder = DENG2_APP->rootFolder().locate<de::Folder>(de::String("home/savegames") / G_IdentityKey());
DENG2_FOR_EACH_CONST(de::Folder::Contents, i, saveFolder.contents())
{
if(de::game::SavedSession *session = i->second->maybeAs<de::game::SavedSession>())
Expand Down Expand Up @@ -3035,6 +3035,8 @@ void G_DoLeaveMap()
Writer_Delete(writer);
SV_CloseFile();
outFile.setMode(de::File::ReadOnly);

saveFolder.populate(); // Populate the new contents of the archive.
}
}
else // Entering new hub.
Expand Down
7 changes: 5 additions & 2 deletions doomsday/plugins/common/src/gamesessionwriter.cpp
Expand Up @@ -105,9 +105,12 @@ void GameSessionWriter::write(SessionMetadata const &metadata)
de::Writer(save) << arch;
save.setMode(File::ReadOnly);
LOG_RES_MSG("Wrote ") << save.description();
folder.populate();

SavedSession &session = folder.locate<SavedSession>(d->savePath.fileName());
// We can now reinterpret and populate the contents of the archive.
File *updated = save.reinterpret();
updated->as<Folder>().populate();

SavedSession &session = updated->as<SavedSession>();
session.cacheMetadata(metadata); // Avoid immediately reopening the .save package.
d->saveRepo().add(session);
}
7 changes: 5 additions & 2 deletions doomsday/plugins/common/src/saveslots.cpp
Expand Up @@ -224,9 +224,12 @@ void SaveSlots::Slot::copySavedSession(Slot const &source)
de::Writer(save) << sourceSession.archive();
save.setMode(File::ReadOnly);
LOG_RES_MSG("Wrote ") << save.description();
saveFolder.populate();

SavedSession &session = saveFolder.locate<SavedSession>(d->savePath.fileName());
// We can now reinterpret and populate the contents of the archive.
File *updated = save.reinterpret();
updated->as<Folder>().populate();

SavedSession &session = updated->as<SavedSession>();
session.cacheMetadata(sourceSession.metadata()); // Avoid immediately opening the .save package.
d->saveRepo().add(session);
DENG2_ASSERT(d->session == &session); // Sanity check.
Expand Down

0 comments on commit 693b91a

Please sign in to comment.