command line, multisampling, optimisations
[csRadar.git] / vfilesys.h
index 5206d57c4bf5af76829d9982838c1f28e5bd73a8..8441c830bf1545184ed7616d0ade8a88e2f91c70 100644 (file)
@@ -103,8 +103,11 @@ void fs_exit(void)
        csr_sb_free( fs->searchpaths );
        fs->searchpaths = NULL;
 
-       vpk_free( fs->vpk );
-       fs->vpk = NULL;
+       if( fs->vpk )
+       {
+               vpk_free( fs->vpk );
+               fs->vpk = NULL;
+       }
        
        if( fs->current_archive )
        {
@@ -120,61 +123,62 @@ char *valve_fs_get( const char *path )
        VPKDirectoryEntry *entry;
        char pak[ 533 ];
 
-       if( (entry = vpk_find( fs->vpk, path )) )
+       if( fs->vpk )
        {
-               if( entry->ArchiveIndex != fs->current_idx )
+               if( (entry = vpk_find( fs->vpk, path )) )
                {
-                       if( fs->current_archive )
+                       if( entry->ArchiveIndex != fs->current_idx )
                        {
-                               fclose( fs->current_archive );
-                               fs->current_archive = NULL;
+                               if( fs->current_archive )
+                               {
+                                       fclose( fs->current_archive );
+                                       fs->current_archive = NULL;
+                               }
+                               
+                               fs->current_idx = entry->ArchiveIndex;
                        }
                        
-                       fs->current_idx = entry->ArchiveIndex;
-               }
-               
-               if( !fs->current_archive )
-               {
-                       sprintf( pak, "%scsgo/pak01_%03hu.vpk", fs->exedir, fs->current_idx );
-                       fs->current_archive = fopen( pak, "rb" );
-                       
                        if( !fs->current_archive )
                        {
-                               fprintf( stderr, "Could not locate %s\n", pak );
+                               sprintf( pak, "%scsgo/pak01_%03hu.vpk", fs->exedir, fs->current_idx );
+                               fs->current_archive = fopen( pak, "rb" );
+                               
+                               if( !fs->current_archive )
+                               {
+                                       fprintf( stderr, "Could not locate %s\n", pak );
+                                       return NULL;
+                               }
+                       }
+                       
+                       char *filebuf = csr_malloc( entry->EntryLength );
+                       
+                       fseek( fs->current_archive, entry->EntryOffset, SEEK_SET );
+                       if( fread( filebuf, 1, entry->EntryLength, fs->current_archive ) == entry->EntryLength )
+                       {
+                               return filebuf;
+                       }
+                       else
+                       {
+                               free( filebuf );
                                return NULL;
                        }
                }
-               
-               char *filebuf = csr_malloc( entry->EntryLength );
-               
-               fseek( fs->current_archive, entry->EntryOffset, SEEK_SET );
-               if( fread( filebuf, 1, entry->EntryLength, fs->current_archive ) == entry->EntryLength )
-               {
-                       return filebuf;
-               }
-               else
-               {
-                       free( filebuf );
-                       return NULL;
-               }
        }
-       else
+       
+       // Use physical searchpaths
+       char path_buf[ 512 ];
+       
+       for( int i = 0; i < csr_sb_count( fs->searchpaths ); i ++ )
        {
-               // Use physical searchpaths
-               char path_buf[ 512 ];
+               strcpy( path_buf, fs->searchpaths[ i ] );
+               strcat( path_buf, path );
                
-               for( int i = 0; i < csr_sb_count( fs->searchpaths ); i ++ )
+               char *filebuf;
+               if( (filebuf = csr_asset_read( path_buf )) )
                {
-                       strcpy( path_buf, fs->searchpaths[ i ] );
-                       strcat( path_buf, path );
-                       
-                       char *filebuf;
-                       if( (filebuf = csr_asset_read( path_buf )) )
-                       {
-                               return filebuf;
-                       }
+                       return filebuf;
                }
-               
-               return NULL;
        }
+       
+       return NULL;
 }