Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fixed|libcommon: Logging when writing to SavedSessions
Everything appears to be working once more following SavedSession's
switch to a PackageFolder.

Next step: Remove the now redundant SavedSessionRepository, cleanup.
  • Loading branch information
danij-deng committed Mar 23, 2014
1 parent 4b84c96 commit a0246ac
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 26 deletions.
27 changes: 16 additions & 11 deletions doomsday/plugins/common/src/gamesessionwriter.cpp
Expand Up @@ -41,9 +41,14 @@ DENG2_PIMPL_NOREF(GameSessionWriter)
{
String repoPath; // Path to the saved session in the repository.

inline SavedSessionRepository &repo() const
inline String saveFileName() const
{
return G_SavedSessionRepository();
return repoPath.fileName() + ".save";
}

inline Folder &saveFolder() const
{
return G_SavedSessionRepository().folder().locate<Folder>(repoPath.fileNamePath());
}

String composeInfo(SessionMetadata const &metadata) const
Expand Down Expand Up @@ -74,7 +79,7 @@ GameSessionWriter::GameSessionWriter(String repositoryPath) : d(new Instance())
void GameSessionWriter::write(SessionMetadata const &metadata)
{
LOG_AS("GameSessionWriter");
LOG_RES_VERBOSE("Serializing game state to \"/savegames/%s\"...") << d->repoPath;
LOG_RES_VERBOSE("Serializing game state to \"/home/savegames/%s\"...") << d->repoPath;

// Write the Info file for this .save package.
ZipArchive arch;
Expand All @@ -101,16 +106,16 @@ void GameSessionWriter::write(SessionMetadata const &metadata)
Writer_Delete(writer);
}

File &outFile = d->repo().folder().replaceFile(d->repoPath + ".save");
de::Writer(outFile) << arch;
outFile.setMode(File::ReadOnly);
outFile.parent()->populate(Folder::PopulateOnlyThisFolder);
LOG_RES_MSG("Wrote ") << outFile.as<NativeFile>().nativePath().pretty();
{
File &save = d->saveFolder().replaceFile(d->saveFileName());
de::Writer(save) << arch;
save.setMode(File::ReadOnly);
save.parent()->populate(Folder::PopulateOnlyThisFolder);
}

// Generate a saved session for the db.
//SavedSession *session = new SavedSession(d->repoPath);
SavedSession &session = d->saveFolder().locate<SavedSession>(d->saveFileName());
LOG_RES_MSG("Wrote ") << session.as<NativeFile>().nativePath().pretty();

SavedSession &session = d->repo().folder().locate<SavedSession>(d->repoPath + ".save");
session.cacheMetadata(metadata); // Avoid immediately reopening the .save package.
G_SavedSessionRepository().add(d->repoPath, &session);
}
37 changes: 22 additions & 15 deletions doomsday/plugins/common/src/saveslots.cpp
Expand Up @@ -25,6 +25,7 @@
#include "hu_menu.h"
#include <de/Folder>
#include <de/game/SavedSessionRepository>
#include <de/NativeFile>
#include <de/Observers>
#include <de/Writer>
#include <map>
Expand Down Expand Up @@ -62,9 +63,14 @@ DENG2_PIMPL_NOREF(SaveSlots::Slot)
}
}

inline SavedSessionRepository &repo() const
inline String saveFileName() const
{
return G_SavedSessionRepository();
return repoPath.fileName();
}

inline Folder &saveFolder() const
{
return G_SavedSessionRepository().folder().locate<Folder>(repoPath.fileNamePath());
}

void updateStatus()
Expand Down Expand Up @@ -138,10 +144,7 @@ SaveSlots::Slot::Slot(String id, bool userWritable, String repoPath, int menuWid
d->menuWidgetId = menuWidgetId;

// See if a saved session already exists for this slot.
if(d->repo().has(d->repoPath))
{
setSavedSession(&d->repo().find(d->repoPath));
}
setSavedSession(d->saveFolder().tryLocate<SavedSession>(d->saveFileName()));
}

SaveSlots::Slot::SessionStatus SaveSlots::Slot::sessionStatus() const
Expand Down Expand Up @@ -169,7 +172,7 @@ void SaveSlots::Slot::bindRepositoryPath(String newPath)
if(d->repoPath != newPath)
{
d->repoPath = newPath;
setSavedSession(d->repo().findPtr(d->repoPath));
setSavedSession(d->saveFolder().tryLocate<SavedSession>(d->saveFileName()));
}
}

Expand Down Expand Up @@ -220,14 +223,18 @@ void SaveSlots::Slot::copySavedSessionFile(Slot const &source)
//savedSession().copyFile(sourceSession);
if(&sourceSession == d->session) return; // Sanity check.

File &destFile = d->repo().folder().replaceFile(d->repoPath + ".save");
de::Writer(destFile) << sourceSession.archive();
destFile.setMode(File::ReadOnly);
destFile.parent()->populate(Folder::PopulateOnlyThisFolder);
{
File &save = d->saveFolder().replaceFile(d->saveFileName());
de::Writer(save) << sourceSession.archive();
save.setMode(File::ReadOnly);
save.parent()->populate(Folder::PopulateOnlyThisFolder);
}

SavedSession &session = d->saveFolder().locate<SavedSession>(d->saveFileName());
LOG_RES_MSG("Wrote ") << session.as<NativeFile>().nativePath().pretty();

SavedSession *session = &destFile.as<SavedSession>();
d->repo().add(d->repoPath, session);
setSavedSession(session);
G_SavedSessionRepository().add(d->repoPath, &session);
setSavedSession(&session);
}

void SaveSlots::Slot::clear()
Expand All @@ -244,7 +251,7 @@ void SaveSlots::Slot::clear()
{
SavedSession &session = *d->session;
setSavedSession(0);
d->repo().add(d->repoPath, 0);
G_SavedSessionRepository().add(d->repoPath, 0);
delete &session;
}
}
Expand Down

0 comments on commit a0246ac

Please sign in to comment.