]> git.mxchange.org Git - quix0rs-blobwars.git/blobdiff - src/CPak.cpp
Fix and localise exit screen.
[quix0rs-blobwars.git] / src / CPak.cpp
old mode 100755 (executable)
new mode 100644 (file)
index 65f4ab0..0d8c0fa
@@ -29,21 +29,14 @@ Pak::Pak()
        listPos = 0;
        currentFile = NULL;
 
-       strcpy(pakFilename, "");
-       strcpy(filename, "");
+       pakFilename[0] = 0;
+       filename[0] = 0;
 }
 
 Pak::~Pak()
 {
-       if (input != NULL)
-               delete[] input;
-               
-       input = NULL;
-       
-       if (fd != NULL)
-               delete[] fd;
-       
-       fd = NULL;
+       delete[] input;
+       delete[] fd;
 }
 
 void Pak::showPakErrorAndExit()
@@ -61,7 +54,7 @@ void Pak::showPakErrorAndExit()
 void Pak::setPakFile(const char *pakFilename)
 {
        #if USEPAK
-       strcpy(this->pakFilename, pakFilename);
+       strlcpy(this->pakFilename, pakFilename, sizeof this->pakFilename);
        
        debug(("Pak : Filename set to %s\n", pakFilename));
 
@@ -131,11 +124,7 @@ bool Pak::unpack(const char *filename, unsigned char **buffer)
        
        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];
@@ -150,9 +139,7 @@ bool Pak::unpack(const char *filename, unsigned char **buffer)
 
        fclose(pak);
        
-       if (input != NULL)
-               delete[] input;
-
+       delete[] input;
        input = NULL;
        
        debug(("Pak : Unpack %s...Done\n", filename));
@@ -162,14 +149,6 @@ bool Pak::unpack(const char *filename, unsigned char **buffer)
 
 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)
@@ -181,7 +160,7 @@ bool Pak::fileExists(const char *filename)
        return false;
 }
 
-unsigned int Pak::getUncompressedSize()
+unsigned int Pak::getUncompressedSize() const
 {
        return (unsigned int)currentFile->fSize;
 }