]> git.xonotic.org Git - xonotic/netradiant.git/blobdiff - tools/quake3/common/vfs.c
Merge commit 'eef39952025db1375e33b6e314692ac76badb93c' into garux-merge
[xonotic/netradiant.git] / tools / quake3 / common / vfs.c
index b7a9bbbceaff49259f779177a6a9f11102c84c62..7e1fd6d8b5be235b6e9ee2ca4d4695fc358285fb 100644 (file)
 #include "mathlib.h"
 #include "inout.h"
 #include "vfs.h"
-#include "unzip.h"
+#include <minizip/unzip.h>
+#include <glib.h>
 #include "miniz.h"
 
 typedef struct
 {
        char*   name;
-       unz_s zipinfo;
        unzFile zipfile;
+       unz_file_pos zippos;
        guint32 size;
 } VFS_PAKFILE;
 
@@ -123,6 +124,7 @@ static void vfsInitPakFile( const char *filename ){
        for ( i = 0; i < gi.number_entry; i++ )
        {
                char filename_inzip[NAME_MAX];
+               char *filename_lower;
                unz_file_info file_info;
                VFS_PAKFILE* file;
 
@@ -130,17 +132,23 @@ 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 );
 
                vfsFixDOSName( filename_inzip );
-               g_strdown( filename_inzip );
+                //-1 null terminated string
+               filename_lower = g_ascii_strdown( filename_inzip, -1 );
 
-               file->name = strdup( filename_inzip );
+               file->name = strdup( filename_lower );
                file->size = file_info.uncompressed_size;
                file->zipfile = uf;
-               memcpy( &file->zipinfo, uf, sizeof( unz_s ) );
+               file->zippos = pos;
 
                if ( ( i + 1 ) < gi.number_entry ) {
                        err = unzGoToNextFile( uf );
@@ -148,6 +156,7 @@ static void vfsInitPakFile( const char *filename ){
                                break;
                        }
                }
+               g_free( filename_lower );
        }
 }
 
@@ -219,18 +228,18 @@ void vfsInitDirectory( const char *path ){
                                {
                                        char *ext = strrchr( dirlist, '.' );
 
-                                       if ( ext && !Q_stricmp( ext, ".pk3dir" ) ) {
+                                       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 ) ) {
+                                       if ( ext == NULL || ( Q_stricmp( ext, ".pk3" ) != 0 && Q_stricmp( ext, ".dpk" ) != 0 ) ) {
                                                continue;
                                        }
                                }
@@ -332,17 +341,18 @@ void vfsShutdown(){
 int vfsGetFileCount( const char *filename ){
        int i, count = 0;
        char fixed[NAME_MAX], tmp[NAME_MAX];
+       char *lower;
        GSList *lst;
 
        strcpy( fixed, filename );
        vfsFixDOSName( fixed );
-       g_strdown( fixed );
+       lower = g_ascii_strdown( fixed, -1 );
 
        for ( lst = g_pakFiles; lst != NULL; lst = g_slist_next( lst ) )
        {
                VFS_PAKFILE* file = (VFS_PAKFILE*)lst->data;
 
-               if ( strcmp( file->name, fixed ) == 0 ) {
+               if ( strcmp( file->name, lower ) == 0 ) {
                        count++;
                }
        }
@@ -350,12 +360,12 @@ int vfsGetFileCount( const char *filename ){
        for ( i = 0; i < g_numDirs; i++ )
        {
                strcpy( tmp, g_strDirs[i] );
-               strcat( tmp, fixed );
+               strcat( tmp, lower );
                if ( access( tmp, R_OK ) == 0 ) {
                        count++;
                }
        }
-
+       g_free( lower );
        return count;
 }
 
@@ -363,6 +373,7 @@ int vfsGetFileCount( const char *filename ){
 int vfsLoadFile( const char *filename, void **bufferptr, int index ){
        int i, count = 0;
        char tmp[NAME_MAX], fixed[NAME_MAX];
+       char *lower;
        GSList *lst;
 
        // filename is a full path
@@ -400,7 +411,7 @@ int vfsLoadFile( const char *filename, void **bufferptr, int index ){
        *bufferptr = NULL;
        strcpy( fixed, filename );
        vfsFixDOSName( fixed );
-       g_strdown( fixed );
+       lower = g_ascii_strdown( fixed, -1 );
 
        for ( i = 0; i < g_numDirs; i++ )
        {
@@ -446,13 +457,15 @@ int vfsLoadFile( const char *filename, void **bufferptr, int index ){
        {
                VFS_PAKFILE* file = (VFS_PAKFILE*)lst->data;
 
-               if ( strcmp( file->name, fixed ) != 0 ) {
+               if ( strcmp( file->name, lower ) != 0 ) {
                        continue;
                }
 
                if ( count == index ) {
-                       memcpy( file->zipfile, &file->zipinfo, sizeof( unz_s ) );
 
+               if ( unzGoToFilePos( file->zipfile, &file->zippos ) != UNZ_OK ) {
+                       return -1;
+               }
                        if ( unzOpenCurrentFile( file->zipfile ) != UNZ_OK ) {
                                return -1;
                        }
@@ -467,19 +480,18 @@ int vfsLoadFile( const char *filename, void **bufferptr, int index ){
                                return -1;
                        }
                        else{
+                               g_free( lower );
                                return file->size;
                        }
                }
 
                count++;
        }
-
+       g_free( lower );
        return -1;
 }
 
 
-
-
 qboolean vfsPackFile( const char *filename, const char *packname ){
        int i;
        char tmp[NAME_MAX], fixed[NAME_MAX];