mirror of
https://github.com/ZDoom/qzdoom.git
synced 2024-11-10 14:51:51 +00:00
- 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:
parent
2ba029ec8d
commit
4003e7ca11
3 changed files with 9 additions and 21 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue