Skip to content

Commit

Permalink
libcommon|SaveSlots: Updated copying of associated .save packages
Browse files Browse the repository at this point in the history
Plus some preparations for replacing the map state Reader with a new
version that does not use LZSS.
  • Loading branch information
danij-deng committed Mar 12, 2014
1 parent 24bb3d4 commit 4327319
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 34 deletions.
3 changes: 0 additions & 3 deletions doomsday/libdeng2/include/de/game/mapstatereader.h
Expand Up @@ -34,9 +34,6 @@ namespace game {
class DENG2_PUBLIC MapStateReader
{
public:
/// An error occurred attempting to open the input file. @ingroup errors
DENG2_ERROR(FileAccessError);

/// Base class for read errors. @ingroup errors
DENG2_ERROR(ReadError);

Expand Down
2 changes: 1 addition & 1 deletion doomsday/libdeng2/src/game/savedsession.cpp
Expand Up @@ -362,7 +362,7 @@ PackageFolder &SavedSession::locateFile()

PackageFolder const &SavedSession::locateFile() const
{
return const_cast<PackageFolder &>(const_cast<SavedSession *>(this)->locateFile());
return const_cast<SavedSession *>(this)->locateFile();
}

bool SavedSession::recognizeFile()
Expand Down
8 changes: 4 additions & 4 deletions doomsday/plugins/common/src/g_game.cpp
Expand Up @@ -3246,15 +3246,15 @@ void G_DoLoadSession(de::String slotId)
// Attempt to recognize and load the saved game state.
try
{
de::game::SavedSession &session = G_SaveSlots()[logicalSlot].savedSession();
de::PackageFolder const &saveFile = session.locateFile();
de::game::SavedSession &session = G_SaveSlots()[logicalSlot].savedSession();
de::PackageFolder const &pack = session.locateFile();

App_Log(DE2_LOG_VERBOSE, "Attempting load save game from \"%s\"",
de::NativePath(saveFile.path()).pretty().toLatin1().constData());
de::NativePath(pack.path()).pretty().toLatin1().constData());

#if __JHEXEN__
// Deserialize the world ACS data.
if(de::File *file = saveFile.tryLocateFile("ACScript"))
if(de::File *file = pack.tryLocateFile("ACScript"))
{
Game_ACScriptInterpreter().readWorldScriptData(de::Reader(*file));
}
Expand Down
10 changes: 3 additions & 7 deletions doomsday/plugins/common/src/mapstatereader.cpp
Expand Up @@ -737,16 +737,12 @@ game::MapStateReader *MapStateReader::make(game::SavedSession const &session) //

void MapStateReader::read(String const &mapUriStr)
{
PackageFolder const &pack = session().locateFile();
game::SessionMetadata const &metadata = session().metadata();
Path const &filePath = Path(mapUriStr);

if(!SV_OpenFile(filePath, false/*for read*/))
{
throw FileAccessError("MapStateReader", "Failed opening \"" + NativePath(filePath).pretty() + "\"");
}

File const &mapStateFile = pack.locate<File>(Path("maps") / mapUriStr);
//SV_OpenFile(mapStateFile);
d->reader = SV_NewReader();
DENG2_ASSERT(d->reader != 0);

d->saveVersion = metadata.geti("version");
d->mapVersion = d->saveVersion; // Default: mapVersion == saveVersion
Expand Down
18 changes: 11 additions & 7 deletions doomsday/plugins/common/src/saveslots.cpp
Expand Up @@ -27,6 +27,7 @@
#include <de/game/SavedSessionRepository>
#include <de/NativePath>
#include <de/Observers>
#include <de/Writer>
#include <map>

static int cvarLastSlot = -1; ///< @c -1= Not yet loaded/saved in this game session.
Expand Down Expand Up @@ -248,9 +249,6 @@ void SaveSlots::copySlot(String sourceSlotId, String destSlotId)
{
LOG_AS("SaveSlots::copySlot");

SavedSessionRepository &saveRepo = G_SavedSessionRepository();
saveRepo.folder().verifyWriteAccess();

Slot &sourceSlot = slot(sourceSlotId);
Slot &destSlot = slot(destSlotId);

Expand All @@ -260,14 +258,20 @@ void SaveSlots::copySlot(String sourceSlotId, String destSlotId)
return;
}

// Clear all save files at destination slot.
// Clear the saved file package for the destination slot.
destSlot.clear();

SV_CopyFile(sourceSlot.savedSession().filePath(), destSlot.savedSession().filePath());
// Copy the saved file package to the destination slot.
if(sourceSlot.savedSession().hasFile())
{
Folder &destFolder = destSlot.savedSession().repository().folder();
de::Writer(destFolder.replaceFile(destSlot.savedSession().fileName()))
<< sourceSlot.savedSession().locateFile().archive();
}

// Copy save info too.
// Copy the session too.
destSlot.replaceSavedSession(new SavedSession(sourceSlot.savedSession()));
// Update the file path associated with the copied save info.
// Update the file path associated with the copied session.
destSlot.savedSession().setFileName(destSlot.fileName());
}

Expand Down
10 changes: 4 additions & 6 deletions doomsday/plugins/doom/src/doomv9mapstatereader.cpp
Expand Up @@ -813,13 +813,11 @@ game::MapStateReader *DoomV9MapStateReader::make(game::SavedSession const &sessi

void DoomV9MapStateReader::read(String const &mapUriStr)
{
Path const &filePath = Path(mapUriStr);

if(!SV_OpenFile_Dm_v19(filePath))
{
throw FileAccessError("DoomV9GameStateReader", "Failed opening \"" + NativePath(filePath).pretty() + "\"");
}
PackageFolder const &pack = session().locateFile();
//game::SessionMetadata const &metadata = session().metadata();

File const &mapStateFile = pack.locate<File>(Path("maps") / mapUriStr);
//SV_OpenFile(mapStateFile);
d->reader = SV_NewReader_Dm_v19();

d->readPlayers();
Expand Down
10 changes: 4 additions & 6 deletions doomsday/plugins/heretic/src/hereticv13mapstatereader.cpp
Expand Up @@ -823,13 +823,11 @@ game::MapStateReader *HereticV13MapStateReader::make(game::SavedSession const &s

void HereticV13MapStateReader::read(String const &mapUriStr)
{
Path const &filePath = Path(mapUriStr);

if(!SV_OpenFile_Hr_v13(filePath))
{
throw FileAccessError("HereticV13GameStateReader", "Failed opening \"" + NativePath(filePath).pretty() + "\"");
}
PackageFolder const &pack = session().locateFile();
//game::SessionMetadata const &metadata = session().metadata();

File const &mapStateFile = pack.locate<File>(Path("maps") / mapUriStr);
//SV_OpenFile(mapStateFile);
d->reader = SV_NewReader_Hr_v13();

d->readPlayers();
Expand Down

0 comments on commit 4327319

Please sign in to comment.