2019-11-08 22:02:52 +00:00
|
|
|
/*
|
|
|
|
** loadsavemenu.cpp
|
|
|
|
** The load game and save game menus
|
|
|
|
**
|
|
|
|
**---------------------------------------------------------------------------
|
|
|
|
** Copyright 2001-2010 Randy Heit
|
2020-10-07 16:32:57 +00:00
|
|
|
** Copyright 2010-2020 Christoph Oelckers
|
2019-11-08 22:02:52 +00:00
|
|
|
** All rights reserved.
|
|
|
|
**
|
|
|
|
** Redistribution and use in source and binary forms, with or without
|
|
|
|
** modification, are permitted provided that the following conditions
|
|
|
|
** are met:
|
|
|
|
**
|
|
|
|
** 1. Redistributions of source code must retain the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer.
|
|
|
|
** 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer in the
|
|
|
|
** documentation and/or other materials provided with the distribution.
|
|
|
|
** 3. The name of the author may not be used to endorse or promote products
|
|
|
|
** derived from this software without specific prior written permission.
|
|
|
|
**
|
|
|
|
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
**---------------------------------------------------------------------------
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
|
2020-10-04 16:31:48 +00:00
|
|
|
#include "razemenu.h"
|
2019-11-08 22:02:52 +00:00
|
|
|
#include "version.h"
|
|
|
|
#include "m_png.h"
|
|
|
|
#include "filesystem.h"
|
|
|
|
#include "v_text.h"
|
|
|
|
#include "gstrings.h"
|
2020-10-04 16:31:48 +00:00
|
|
|
#include "serializer.h"
|
|
|
|
#include "vm.h"
|
|
|
|
#include "i_system.h"
|
2020-05-25 15:11:32 +00:00
|
|
|
#include "v_video.h"
|
2020-10-04 16:31:48 +00:00
|
|
|
#include "findfile.h"
|
|
|
|
#include "v_draw.h"
|
2023-08-19 16:08:27 +00:00
|
|
|
#include "fs_findfile.h"
|
2020-10-07 16:32:57 +00:00
|
|
|
#include "savegamehelp.h"
|
2019-11-29 23:49:50 +00:00
|
|
|
|
2023-08-23 18:36:19 +00:00
|
|
|
using namespace FileSys;
|
2020-10-04 16:31:48 +00:00
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
// M_ReadSaveStrings
|
|
|
|
//
|
|
|
|
// Find savegames and read their titles
|
|
|
|
//
|
|
|
|
//=============================================================================
|
2019-11-29 23:49:50 +00:00
|
|
|
|
2020-10-04 16:31:48 +00:00
|
|
|
void FSavegameManager::ReadSaveStrings()
|
|
|
|
{
|
|
|
|
if (SaveGames.Size() == 0)
|
2019-11-29 23:49:50 +00:00
|
|
|
{
|
2020-10-04 16:31:48 +00:00
|
|
|
LastSaved = LastAccessed = -1;
|
|
|
|
quickSaveSlot = nullptr;
|
2023-08-19 16:08:27 +00:00
|
|
|
FileList list;
|
|
|
|
if (ScanDirectory(list, G_GetSavegamesFolder().GetChars(), "*." SAVEGAME_EXT, true))
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
2023-08-19 16:08:27 +00:00
|
|
|
for (auto& entry : list)
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
2023-08-19 16:08:27 +00:00
|
|
|
FResourceFile *savegame = FResourceFile::OpenResourceFile(entry.FilePath.c_str(), true);
|
2020-10-04 16:31:48 +00:00
|
|
|
if (savegame != nullptr)
|
2019-11-29 23:49:50 +00:00
|
|
|
{
|
2020-10-04 16:31:48 +00:00
|
|
|
FResourceLump *info = savegame->FindLump("info.json");
|
|
|
|
if (info == nullptr)
|
|
|
|
{
|
|
|
|
// savegame info not found. This is not a savegame so leave it alone.
|
2020-10-07 16:32:57 +00:00
|
|
|
delete savegame;
|
2020-10-04 16:31:48 +00:00
|
|
|
continue;
|
|
|
|
}
|
2020-10-07 16:32:57 +00:00
|
|
|
auto fr = info->NewReader();
|
|
|
|
FString title;
|
|
|
|
int check = G_ValidateSavegame(fr, &title, true);
|
|
|
|
fr.Close();
|
|
|
|
delete savegame;
|
|
|
|
if (check != 0)
|
2020-10-04 16:31:48 +00:00
|
|
|
{
|
|
|
|
FSaveGameNode *node = new FSaveGameNode;
|
2023-08-19 16:08:27 +00:00
|
|
|
node->Filename = entry.FilePath.c_str();
|
2020-10-07 16:32:57 +00:00
|
|
|
node->bOldVersion = check == -1;
|
|
|
|
node->bMissingWads = check == -2;
|
2020-10-04 16:31:48 +00:00
|
|
|
node->SaveTitle = title;
|
|
|
|
InsertSaveNode(node);
|
|
|
|
}
|
2019-11-29 23:49:50 +00:00
|
|
|
}
|
2023-08-19 16:08:27 +00:00
|
|
|
}
|
2020-10-04 16:31:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-11-08 22:02:52 +00:00
|
|
|
|
|
|
|
|
2020-10-04 16:31:48 +00:00
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//=============================================================================
|
2019-11-08 22:02:52 +00:00
|
|
|
|
2020-10-07 16:32:57 +00:00
|
|
|
void FSavegameManager::PerformLoadGame(const char *f, bool s)
|
2020-10-04 16:31:48 +00:00
|
|
|
{
|
2021-05-11 22:31:49 +00:00
|
|
|
G_LoadGame(f, s);
|
2020-10-04 16:31:48 +00:00
|
|
|
}
|
|
|
|
|
2020-10-07 16:32:57 +00:00
|
|
|
void FSavegameManager::PerformSaveGame(const char *f, const char *s)
|
2020-10-04 16:31:48 +00:00
|
|
|
{
|
2021-05-11 22:21:26 +00:00
|
|
|
G_SaveGame(f, s);
|
2020-10-04 16:31:48 +00:00
|
|
|
}
|
|
|
|
|
2020-10-07 16:32:57 +00:00
|
|
|
FString FSavegameManager::BuildSaveName(const char* fn, int slot)
|
2020-10-04 16:31:48 +00:00
|
|
|
{
|
2020-10-07 16:32:57 +00:00
|
|
|
return G_BuildSaveName(FStringf("%s%04d", fn, slot));
|
2020-10-04 16:31:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
2020-10-07 16:32:57 +00:00
|
|
|
FString FSavegameManager::ExtractSaveComment(FSerializer& arc)
|
2020-10-04 16:31:48 +00:00
|
|
|
{
|
2020-10-07 16:32:57 +00:00
|
|
|
FString comment, fcomment, ncomment, mtime;
|
2020-10-04 16:31:48 +00:00
|
|
|
|
2020-10-07 16:32:57 +00:00
|
|
|
arc("Creation Time", comment)
|
|
|
|
("Map Label", fcomment)
|
|
|
|
("Map Name", ncomment)
|
|
|
|
("Map Time", mtime);
|
2020-10-04 16:31:48 +00:00
|
|
|
|
2020-10-07 16:32:57 +00:00
|
|
|
comment.AppendFormat("\n%s - %s\n%s", fcomment.GetChars(), ncomment.GetChars(), mtime.GetChars());
|
|
|
|
return comment;
|
2020-10-04 16:31:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
FSavegameManager savegameManager;
|
|
|
|
|
|
|
|
DEFINE_ACTION_FUNCTION(FSavegameManager, GetManager)
|
2019-11-28 22:27:10 +00:00
|
|
|
{
|
2020-10-04 16:31:48 +00:00
|
|
|
PARAM_PROLOGUE;
|
|
|
|
ACTION_RETURN_POINTER(&savegameManager);
|
2019-11-28 22:27:10 +00:00
|
|
|
}
|
2020-10-04 16:31:48 +00:00
|
|
|
|