]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - tools/quake3/common/vfs.c
fix pk3dir/dpk/dpkdir code
[xonotic/netradiant.git] / tools / quake3 / common / vfs.c
index e0cd888fb46e0ea5ae2746c243127205cf58f763..65a8b6f4275b84f249cb517e8facd6b463cbb826 100644 (file)
 #include "inout.h"
 #include "vfs.h"
 #include <minizip/unzip.h>
+#include <glib.h>
 
 typedef struct
 {
        char*   name;
        unzFile zipfile;
+       unz_file_pos zippos;
        guint32 size;
 } VFS_PAKFILE;
 
@@ -128,6 +130,11 @@ static void vfsInitPakFile( const char *filename ){
                if ( err != UNZ_OK ) {
                        break;
                }
+               unz_file_pos pos;
+               err = unzGetFilePos( uf, &pos );
+               if ( err != UNZ_OK ) {
+                       break;
+               }
 
                file = (VFS_PAKFILE*)safe_malloc( sizeof( VFS_PAKFILE ) );
                g_pakFiles = g_slist_append( g_pakFiles, file );
@@ -138,6 +145,7 @@ static void vfsInitPakFile( const char *filename ){
                file->name = strdup( filename_inzip );
                file->size = file_info.uncompressed_size;
                file->zipfile = uf;
+               file->zippos = pos;
 
                if ( ( i + 1 ) < gi.number_entry ) {
                        err = unzGoToNextFile( uf );
@@ -216,18 +224,18 @@ void vfsInitDirectory( const char *path ){
                                {
                                        char *ext = strrchr( dirlist, '.' );
 
-                                       if ( ext && ( !Q_stricmp( ext, ".pk3dir" ) || !Q_stricmp( ext, ".dpkdir" ) ) ) {
+                                       if ( ext != NULL && ( !Q_stricmp( ext, ".pk3dir" ) || !Q_stricmp( ext, ".dpkdir" ) ) ) {
                                                if ( g_numDirs == VFS_MAXDIRS ) {
                                                        continue;
                                                }
                                                snprintf( g_strDirs[g_numDirs], PATH_MAX, "%s/%s", path, name );
-                                               g_strDirs[g_numDirs][PATH_MAX] = '\0';
+                                               g_strDirs[g_numDirs][PATH_MAX-1] = '\0';
                                                vfsFixDOSName( g_strDirs[g_numDirs] );
                                                vfsAddSlash( g_strDirs[g_numDirs] );
                                                ++g_numDirs;
                                        }
 
-                                       if ( ( ext == NULL ) || ( Q_stricmp( ext, ".pk3" ) != 0 || !Q_stricmp( ext, ".dpk" ) != 0 ) ) {
+                                       if ( ext == NULL || ( Q_stricmp( ext, ".pk3" ) != 0 && Q_stricmp( ext, ".dpk" ) != 0 ) ) {
                                                continue;
                                        }
                                }
@@ -383,6 +391,9 @@ int vfsLoadFile( const char *filename, void **bufferptr, int index ){
 
                if ( count == index ) {
 
+            if ( unzGoToFilePos( file->zipfile, &file->zippos ) != UNZ_OK ) {
+                return -1;
+            }
                        if ( unzOpenCurrentFile( file->zipfile ) != UNZ_OK ) {
                                return -1;
                        }