Skip to content

Commit

Permalink
Fixed|libcommon: Updating/replacing .save packages requires Write access
Browse files Browse the repository at this point in the history
As of this commit, all saving and loading in all supported games is
now working as expected.
  • Loading branch information
danij-deng committed Mar 26, 2014
1 parent a61d2e2 commit 040bd81
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
9 changes: 5 additions & 4 deletions doomsday/plugins/common/src/g_game.cpp
Expand Up @@ -3047,19 +3047,20 @@ void G_DoLeaveMap()
if(!gameRules.deathmatch)
{
// Save current map.
de::Folder &saveFolder = DENG2_APP->rootFolder().locate<de::Folder>(G_SaveSlots()["base"].savePath());
de::Folder &saveFolder = DENG2_APP->rootFolder().locate<de::Folder>(G_SaveSlots()["base"].savePath() / "maps");
saveFolder.setMode(de::File::Write);

de::File &outFile = saveFolder.replaceFile(de::String("maps") / Str_Text(Uri_Compose(gameMapUri)) + "State");
de::File &outFile = saveFolder.replaceFile(de::String(Str_Text(Uri_Compose(gameMapUri))) + "State");
de::Block mapStateData;
SV_OpenFileForWrite(mapStateData);
writer_s *writer = SV_NewWriter();
MapStateWriter().write(writer);
outFile << de::FixedByteArray(mapStateData);
Writer_Delete(writer);
SV_CloseFile();
outFile.setMode(de::File::ReadOnly);

saveFolder.populate(); // Populate the new contents of the archive.
saveFolder.setMode(de::File::ReadOnly); // flush to disk.
saveFolder.populate(); // Populate the new contents of the folder.
}
}
else // Entering new hub.
Expand Down
4 changes: 4 additions & 0 deletions doomsday/plugins/common/src/gamesessionwriter.cpp
Expand Up @@ -101,6 +101,10 @@ void GameSessionWriter::write(SessionMetadata const &metadata)

// Write the new package to /home/savegames/<game-id>/<session-name>.save
Folder &folder = DENG2_APP->rootFolder().locate<Folder>(d->savePath.fileNamePath());
if(SavedSession *existing = folder.tryLocate<SavedSession>(d->savePath.fileName()))
{
existing->setMode(File::Write);
}
File &save = folder.replaceFile(d->savePath.fileName());
de::Writer(save) << arch;
save.setMode(File::ReadOnly);
Expand Down
5 changes: 3 additions & 2 deletions doomsday/plugins/common/src/saveslots.cpp
Expand Up @@ -209,10 +209,11 @@ void SaveSlots::Slot::setSavedSession(SavedSession *newSession)

void SaveSlots::Slot::copySavedSession(Slot const &source)
{
LOG_AS("SaveSlots::Slot::copySavedSessionFile");

if(&source == this) return; // Sanity check.

LOG_AS("SaveSlots::Slot::copySavedSession");
LOG_RES_VERBOSE("From '%s' to '%s'") << source.id() << d->id;

// Clear the existing session and .save package (if any).
clear();

Expand Down

0 comments on commit 040bd81

Please sign in to comment.