]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - plugins/vfspk3/vfs.cpp
Merge branch 'mschwan/gdef-inline-fix' into 'master'
[xonotic/netradiant.git] / plugins / vfspk3 / vfs.cpp
index bb3b5dbf4fc7c8cc237efdf54da6671272aa6872..1cd50a31bd9cf7ed852e6a9f2a7477d0c4ee38da 100644 (file)
@@ -42,6 +42,7 @@
 //
 
 #include "vfs.h"
+#include "globaldefs.h"
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -62,9 +63,9 @@ ArchiveModules& FileSystemQ3API_getArchiveModules();
 #include "dpkdeps.h"
 
 
-#define VFS_MAXDIRS 64
+const int VFS_MAXDIRS = 64;
 
-#if defined( WIN32 )
+#if GDEF_OS_WINDOWS
 #define PATH_MAX 260
 #endif
 
@@ -377,23 +378,43 @@ static Archives g_loaded_dpk_paks;
 // actual pak adding on initialise, deferred from InitDirectory
 // Daemon DPK filesystem doesn't need load all paks it finds
 static void LoadDpkPakWithDeps( const char* pakname ){
-       const char* und = strrchr( pakname, '_' );
-       if ( !und ) pakname = GetLatestDpkPakVersion( pakname );
-       if ( !pakname || g_loaded_dpk_paks.find( pakname ) != g_loaded_dpk_paks.end() ) return;
-
-       PakfilePaths::iterator i = g_pakfile_paths.find( pakname );
-       if ( i == g_pakfile_paths.end() ) return;
-
        Archive* arc;
-       if ( i->second.is_pakfile ){
-               arc = InitPakFile( FileSystemQ3API_getArchiveModules(), i->second.fullpath.c_str() );
+       ArchiveTextFile* depsFile;
+
+       if (pakname == NULL) {
+               // load DEPS from game pack
+               StringOutputStream baseDirectory( 256 );
+               const char* basegame = GlobalRadiant().getRequiredGameDescriptionKeyValue( "basegame" );
+               baseDirectory << GlobalRadiant().getGameToolsPath() << basegame << '/';
+               arc = AddDpkDir( baseDirectory.c_str() );
+               depsFile = arc->openTextFile( "DEPS" );
        } else {
-               arc = AddDpkDir( i->second.fullpath.c_str() );
+               const char* und = strrchr( pakname, '_' );
+               if ( !und ) {
+                       pakname = GetLatestDpkPakVersion( pakname );
+               }
+               if ( !pakname || g_loaded_dpk_paks.find( pakname ) != g_loaded_dpk_paks.end() ) {
+                       return;
+               }
+
+               PakfilePaths::iterator i = g_pakfile_paths.find( pakname );
+               if ( i == g_pakfile_paths.end() ) {
+                       return;
+               }
+
+               if ( i->second.is_pakfile ){
+                       arc = InitPakFile( FileSystemQ3API_getArchiveModules(), i->second.fullpath.c_str() );
+               } else {
+                       arc = AddDpkDir( i->second.fullpath.c_str() );
+               }
+               g_loaded_dpk_paks.insert( pakname );
+
+               depsFile = arc->openTextFile( "DEPS" );
        }
-       g_loaded_dpk_paks.insert( pakname );
 
-       ArchiveTextFile* depsFile = arc->openTextFile( "DEPS" );
-       if ( !depsFile ) return;
+       if ( !depsFile ) {
+               return;
+       }
 
        {
                TextLinesInputStream<TextInputStream> istream = depsFile->getInputStream();
@@ -646,8 +667,8 @@ void Shutdown(){
        g_loaded_dpk_paks.clear();
 }
 
-#define VFS_SEARCH_PAK 0x1
-#define VFS_SEARCH_DIR 0x2
+const int VFS_SEARCH_PAK = 0x1;
+const int VFS_SEARCH_DIR = 0x2;
 
 int GetFileCount( const char *filename, int flag ){
        int count = 0;
@@ -663,8 +684,8 @@ int GetFileCount( const char *filename, int flag ){
 
        for ( archives_t::iterator i = g_archives.begin(); i != g_archives.end(); ++i )
        {
-               if ( ( *i ).is_pakfile && ( flag & VFS_SEARCH_PAK ) != 0
-                        || !( *i ).is_pakfile && ( flag & VFS_SEARCH_DIR ) != 0 ) {
+               if ( (( *i ).is_pakfile && ( flag & VFS_SEARCH_PAK ) != 0)
+                        || (!( *i ).is_pakfile && ( flag & VFS_SEARCH_DIR ) != 0) ) {
                        if ( ( *i ).archive->containsFile( fixed ) ) {
                                ++count;
                        }
@@ -790,10 +811,8 @@ void load(){
                const char* pakname;
                g_loaded_dpk_paks.clear();
 
-               pakname = GetLatestDpkPakVersion( "tex-common" );
-               if (pakname != NULL) {
-                       LoadDpkPakWithDeps( pakname );
-               }
+               // Load DEPS from game pack
+               LoadDpkPakWithDeps( NULL );
 
                // prevent VFS double start, for MapName="" and MapName="unnamed.map"
                if ( string_length( GlobalRadiant().getMapName() ) ){