- use FileReader for savegame loading in the menu.

- simplify the check for existing files here, since a function for doing just that already existed.
This commit is contained in:
Christoph Oelckers 2017-12-02 14:10:42 +01:00
parent 2ba029ec8d
commit 4003e7ca11
3 changed files with 9 additions and 21 deletions

View File

@ -456,12 +456,6 @@ PNGHandle *M_VerifyPNG (FileReader *filer, bool takereader)
return NULL;
}
PNGHandle *M_VerifyPNG(FILE *file)
{
FileReader *fr = new FileReader(file);
return M_VerifyPNG(fr, true);
}
//==========================================================================
//
// M_FreePNG

View File

@ -90,7 +90,6 @@ struct PNGHandle
// each chunk is not done. If it is valid, you get a PNGHandle to pass to
// the following functions.
PNGHandle *M_VerifyPNG (FileReader *file, bool takereader = false);
PNGHandle *M_VerifyPNG (FILE *file);
// Finds a chunk in a PNG file. The file pointer will be positioned at the
// beginning of the chunk data, and its length will be returned. A return

View File

@ -236,8 +236,8 @@ void FSavegameManager::ReadSaveStrings()
}
else // check for old formats.
{
FILE *file = fopen(filepath, "rb");
if (file != nullptr)
FileReader file;
if (file.Open(filepath))
{
PNGHandle *png;
char sig[16];
@ -255,8 +255,7 @@ void FSavegameManager::ReadSaveStrings()
title[OLDSAVESTRINGSIZE] = 0;
if (nullptr != (png = M_VerifyPNG(file)))
if (nullptr != (png = M_VerifyPNG(&file, false)))
{
char *ver = M_GetPNGText(png, "ZDoom Save Version");
if (ver != nullptr)
@ -273,13 +272,13 @@ void FSavegameManager::ReadSaveStrings()
}
else
{
fseek(file, 0, SEEK_SET);
if (fread(sig, 1, 16, file) == 16)
file.Seek(0, SEEK_SET);
if (file.Read(sig, 16) == 16)
{
if (strncmp(sig, "ZDOOMSAVE", 9) == 0)
{
if (fread(title, 1, OLDSAVESTRINGSIZE, file) == OLDSAVESTRINGSIZE)
if (file.Read(title, OLDSAVESTRINGSIZE) == OLDSAVESTRINGSIZE)
{
addIt = true;
}
@ -287,8 +286,8 @@ void FSavegameManager::ReadSaveStrings()
else
{
memcpy(title, sig, 16);
if (fread(title + 16, 1, OLDSAVESTRINGSIZE - 16, file) == OLDSAVESTRINGSIZE - 16 &&
fread(sig, 1, 16, file) == 16 &&
if (file.Read(title + 16, OLDSAVESTRINGSIZE - 16) == OLDSAVESTRINGSIZE - 16 &&
file.Read(sig, 16) == 16 &&
strncmp(sig, "ZDOOMSAVE", 9) == 0)
{
addIt = true;
@ -306,7 +305,6 @@ void FSavegameManager::ReadSaveStrings()
node->SaveTitle = title;
InsertSaveNode(node);
}
fclose(file);
}
}
} while (I_FindNext(filefirst, &c_file) == 0);
@ -418,17 +416,14 @@ void FSavegameManager::DoSave(int Selected, const char *savegamestring)
// Find an unused filename and save as that
FString filename;
int i;
FILE *test;
for (i = 0;; ++i)
{
filename = G_BuildSaveName("save", i);
test = fopen(filename, "rb");
if (test == nullptr)
if (!FileExists(filename))
{
break;
}
fclose(test);
}
G_SaveGame(filename, savegamestring);
}