]> git.xonotic.org Git - xonotic/netradiant.git/blobdiff - tools/quake3/common/vfs.c
Merge commit '0d5ebb17b29d4263ec4f1634af24a27620ab47a4' into garux-merge
[xonotic/netradiant.git] / tools / quake3 / common / vfs.c
index d26e224906917a4020fbd4d2dd7c4a168e869ed8..e8648e813fd25b95b0b95bff8ef85eff35244ddb 100644 (file)
@@ -52,8 +52,8 @@
 #include "vfs.h"
 #include <minizip/unzip.h>
 #include <glib.h>
-#define BAD_MINIZ
-#ifndef BAD_MINIZ
+#define GARUX_DISABLE_BAD_MINIZ
+#ifndef GARUX_DISABLE_BAD_MINIZ
 #include "miniz.h"
 #endif
 
@@ -496,7 +496,7 @@ int vfsLoadFile( const char *filename, void **bufferptr, int index ){
 
 
 qboolean vfsPackFile( const char *filename, const char *packname, const int compLevel ){
-#ifndef BAD_MINIZ
+#ifndef GARUX_DISABLE_BAD_MINIZ
        int i;
        char tmp[NAME_MAX], fixed[NAME_MAX];
        GSList *lst;
@@ -585,3 +585,45 @@ qboolean vfsPackFile( const char *filename, const char *packname, const int comp
                Error( "Disabled because of miniz issue" );
 #endif
 }
+
+qboolean vfsPackFile_Absolute_Path( const char *filepath, const char *filename, const char *packname, const int compLevel ){
+#ifndef GARUX_DISABLE_BAD_MINIZ
+       char tmp[NAME_MAX];
+       strcpy( tmp, filepath );
+       if ( access( tmp, R_OK ) == 0 ) {
+               if ( access( packname, R_OK ) == 0 ) {
+                       mz_zip_archive zip;
+                       memset( &zip, 0, sizeof(zip) );
+                       mz_zip_reader_init_file( &zip, packname, 0 );
+                       mz_zip_writer_init_from_reader( &zip, packname );
+
+                       mz_bool success = MZ_TRUE;
+                       success &= mz_zip_writer_add_file( &zip, filename, tmp, 0, 0, compLevel );
+                       if ( !success || !mz_zip_writer_finalize_archive( &zip ) ){
+                               Error( "Failed creating zip archive \"%s\"!\n", packname );
+                       }
+                       mz_zip_reader_end( &zip);
+                       mz_zip_writer_end( &zip );
+               }
+               else{
+                       mz_zip_archive zip;
+                       memset( &zip, 0, sizeof(zip) );
+                       if( !mz_zip_writer_init_file( &zip, packname, 0 ) ){
+                               Error( "Failed creating zip archive \"%s\"!\n", packname );
+                       }
+                       mz_bool success = MZ_TRUE;
+                       success &= mz_zip_writer_add_file( &zip, filename, tmp, 0, 0, compLevel );
+                       if ( !success || !mz_zip_writer_finalize_archive( &zip ) ){
+                               Error( "Failed creating zip archive \"%s\"!\n", packname );
+                       }
+                       mz_zip_writer_end( &zip );
+               }
+
+               return qtrue;
+       }
+
+       return qfalse;
+#else
+               Error( "Disabled because of miniz issue" );
+#endif
+}