/*
-Copyright (C) 2004 Parallel Realities
+Copyright (C) 2004-2011 Parallel Realities
+Copyright (C) 2011-2015 Perpendicular Dimensions
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
Pak::~Pak()
{
- if (input != NULL)
- delete[] input;
-
- input = NULL;
-
- if (fd != NULL)
- delete[] fd;
-
- fd = NULL;
+ delete[] input;
+ delete[] fd;
}
void Pak::showPakErrorAndExit()
}
fseek(pak, (-sizeof(Uint32)) * 2, SEEK_END);
- fread(&listPos, sizeof(Uint32), 1, pak);
- fread(&numberOfFiles, sizeof(Uint32), 1, pak);
+ if (fread(&listPos, sizeof(Uint32), 1, pak) != 1)
+ {
+ fclose(pak);
+ showPakErrorAndExit();
+ }
+ if (fread(&numberOfFiles, sizeof(Uint32), 1, pak) != 1)
+ {
+ fclose(pak);
+ showPakErrorAndExit();
+ }
debug(("Pak : File list resides at %d\n", (int)listPos));
debug(("Pak : Number of files are %d\n", (int)numberOfFiles));
fseek(pak, currentFile->location, SEEK_SET);
- if (input != NULL)
- {
- delete[] input;
- }
-
+ delete[] input;
input = NULL;
input = new unsigned char[(int)(currentFile->cSize * 1.01) + 12];
*buffer = new unsigned char[currentFile->fSize + 1];
- fread(input, 1, currentFile->cSize, pak);
+ if (fread(input, 1, currentFile->cSize, pak) != currentFile->cSize)
+ {
+ fclose(pak);
+ showPakErrorAndExit();
+ }
uLongf fSize = (uLongf)currentFile->fSize;
fclose(pak);
- if (input != NULL)
- delete[] input;
-
+ delete[] input;
input = NULL;
debug(("Pak : Unpack %s...Done\n", filename));
bool Pak::fileExists(const char *filename)
{
- unsigned int hashcode = 0;
- unsigned int length = strlen(filename);
-
- for (unsigned int i = 0 ; i < length ; i++)
- {
- hashcode = hashcode + (filename[i] * 31 ^ (length - i));
- }
-
for (unsigned int i = 0 ; i < numberOfFiles ; i++)
{
if (strcmp(fd[i].filename, filename) == 0)
return false;
}
-unsigned int Pak::getUncompressedSize()
+unsigned int Pak::getUncompressedSize() const
{
return (unsigned int)currentFile->fSize;
}