mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-23 04:22:34 +00:00
- fixed and cleaned up file_whres.cpp
This commit is contained in:
parent
f0bbc32bae
commit
959d0e93f7
1 changed files with 19 additions and 14 deletions
|
@ -35,7 +35,9 @@
|
|||
*/
|
||||
|
||||
#include "resourcefile.h"
|
||||
#include "cmdlib.h"
|
||||
#include "fs_swap.h"
|
||||
|
||||
using namespace fs_private;
|
||||
|
||||
#include "fs_swap.h"
|
||||
|
||||
|
@ -54,7 +56,7 @@ using namespace fs_private;
|
|||
|
||||
class FWHResFile : public FUncompressedFile
|
||||
{
|
||||
FString basename;
|
||||
std::string basename;
|
||||
public:
|
||||
FWHResFile(const char * filename, FileReader &file);
|
||||
bool Open(LumpFilterInfo* filter);
|
||||
|
@ -72,7 +74,7 @@ public:
|
|||
FWHResFile::FWHResFile(const char *filename, FileReader &file)
|
||||
: FUncompressedFile(filename, file)
|
||||
{
|
||||
basename = ExtractFileBase(filename, false);
|
||||
basename = ExtractBaseName(filename, false);
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
|
@ -83,7 +85,7 @@ FWHResFile::FWHResFile(const char *filename, FileReader &file)
|
|||
|
||||
bool FWHResFile::Open(LumpFilterInfo*)
|
||||
{
|
||||
int directory[1024];
|
||||
uint32_t directory[1024];
|
||||
|
||||
Reader.Seek(-4096, FileReader::SeekEnd);
|
||||
Reader.Read(directory, 4096);
|
||||
|
@ -95,11 +97,13 @@ bool FWHResFile::Open(LumpFilterInfo*)
|
|||
int i = 0;
|
||||
for(int k = 0; k < nl; k++)
|
||||
{
|
||||
int offset = LittleLong(directory[k*3]) * 4096;
|
||||
int length = LittleLong(directory[k*3+1]);
|
||||
if (length <= 0) break;
|
||||
FStringf synthname("%s/%04d", basename.GetChars(), k);
|
||||
Lumps[i].LumpNameSetup(synthname);
|
||||
uint32_t offset = LittleLong(directory[k*3]) * 4096;
|
||||
uint32_t length = LittleLong(directory[k*3+1]);
|
||||
if (length == 0) break;
|
||||
char num[5];
|
||||
snprintf(num, 5, "/%04d", k);
|
||||
std::string synthname = basename + num;
|
||||
Lumps[i].LumpNameSetup(synthname.c_str());
|
||||
Lumps[i].Owner = this;
|
||||
Lumps[i].Position = offset;
|
||||
Lumps[i].LumpSize = length;
|
||||
|
@ -122,19 +126,20 @@ FResourceFile *CheckWHRes(const char *filename, FileReader &file, LumpFilterInfo
|
|||
{
|
||||
if (file.GetLength() >= 8192) // needs to be at least 8192 to contain one file and the directory.
|
||||
{
|
||||
int directory[1024];
|
||||
unsigned directory[1024];
|
||||
int nl =1024/3;
|
||||
|
||||
file.Seek(-4096, FileReader::SeekEnd);
|
||||
file.Read(directory, 4096);
|
||||
auto size = file.GetLength();
|
||||
|
||||
int checkpos = 0;
|
||||
uint32_t checkpos = 0;
|
||||
for(int k = 0; k < nl; k++)
|
||||
{
|
||||
int offset = LittleLong(directory[k*3]);
|
||||
int length = LittleLong(directory[k*3+1]);
|
||||
unsigned offset = LittleLong(directory[k*3]);
|
||||
unsigned length = LittleLong(directory[k*3+1]);
|
||||
if (length <= 0 && offset == 0) break;
|
||||
if (offset != checkpos || length <= 0) return nullptr;
|
||||
if (offset != checkpos || length == 0 || offset + length >= (size_t)size - 4096 ) return nullptr;
|
||||
checkpos += (length+4095) / 4096;
|
||||
}
|
||||
auto rf = new FWHResFile(filename, file);
|
||||
|
|
Loading…
Reference in a new issue