]> de.git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
Fixed AK version of the FS code, it should now behave as expected, without much dupli...
authormolivier <molivier@d7cf8633-e32d-0410-b094-e92efae38249>
Wed, 17 Dec 2003 07:58:33 +0000 (07:58 +0000)
committermolivier <molivier@d7cf8633-e32d-0410-b094-e92efae38249>
Wed, 17 Dec 2003 07:58:33 +0000 (07:58 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@3737 d7cf8633-e32d-0410-b094-e92efae38249

fs.c

diff --git a/fs.c b/fs.c
index beddbec613a68da96bce9139c73cf90d81b0cb7c..4b36f512283a06788b374e18207ccdb119a3df2f 100644 (file)
--- a/fs.c
+++ b/fs.c
@@ -738,11 +738,13 @@ void FS_AddGameDirectory (char *dir)
 
        strlcpy (fs_gamedir, dir, sizeof (fs_gamedir));
 
+#ifndef AKVERSION
        // add the directory to the search path
        search = Mem_Alloc(pak_mempool, sizeof(searchpath_t));
        strlcpy (search->filename, dir, sizeof (search->filename));
        search->next = fs_searchpaths;
        fs_searchpaths = search;
+#endif
 
        list = listdirectory(dir);
 
@@ -784,6 +786,15 @@ void FS_AddGameDirectory (char *dir)
                }
        }
        freedirectory(list);
+
+// Unpacked files have the priority over packed files in AKVERSION is defined
+#ifdef AKVERSION
+       // add the directory to the search path
+       search = Mem_Alloc(pak_mempool, sizeof(searchpath_t));
+       strlcpy (search->filename, dir, sizeof (search->filename));
+       search->next = fs_searchpaths;
+       fs_searchpaths = search;
+#endif
 }
 
 
@@ -986,103 +997,6 @@ qfile_t *FS_FOpenFile (const char *filename, qboolean quiet)
 
        filenamelen = strlen (filename);
 
-       // LordHavoc: this is not written right!
-       // (should search have higher priority for files in each gamedir, while
-       // preserving the gamedir priorities, not searching for all paks in all
-       // gamedirs and then all files in all gamedirs)
-#ifdef AKVERSION
-       // first we search for a real file, after that we start to search through the paks
-       // search through the path, one element at a time
-       search = fs_searchpaths;
-
-       for( ; search ; search = search->next)
-               if(!search->pack)
-               {
-                       snprintf (netpath, sizeof (netpath), "%s/%s",search->filename, filename);
-
-                       if (!FS_SysFileExists (netpath))
-                               continue;
-
-                       if (!quiet)
-                               Sys_Printf ("FindFile: %s\n",netpath);
-                       return FS_OpenRead (netpath, -1, -1);
-               }
-
-       search = fs_searchpaths;
-       for ( ; search ; search = search->next)
-               // is the element a pak file?
-               if (search->pack)
-               {
-                       // look through all the pak file elements
-                       pak = search->pack;
-                       for (i=0 ; i<pak->numfiles ; i++)
-                       {
-                               if (pak->ignorecase)
-                                       matched = !strcasecmp (pak->files[i].name, filename);
-                               else
-                                       matched = !strcmp (pak->files[i].name, filename);
-                               if (matched)  // found it?
-                               {
-                                       qfile_t *file;
-
-                                       if (!quiet)
-                                               Sys_Printf ("PackFile: %s : %s\n",pak->filename, pak->files[i].name);
-
-                                       // If we don't have the true offset, get it now
-                                       if (! (pak->files[i].flags & FILE_FLAG_TRUEOFFS))
-                                               PK3_GetTrueFileOffset (&pak->files[i], pak);
-
-                                       // No Zlib DLL = no compressed files
-                                       if (!zlib_dll && (pak->files[i].flags & FILE_FLAG_DEFLATED))
-                                       {
-                                               Con_Printf ("WARNING: can't open the compressed file %s\n"
-                                                                       "You need the Zlib DLL to use compressed files\n", filename);
-                                               fs_filesize = -1;
-                                               return NULL;
-                                       }
-
-                                       // open a new file in the pakfile
-                                       file = FS_OpenRead (pak->filename, pak->files[i].offset, pak->files[i].packsize);
-                                       fs_filesize = pak->files[i].realsize;
-
-                                       if (pak->files[i].flags & FILE_FLAG_DEFLATED)
-                                       {
-                                               ztoolkit_t *ztk;
-
-                                               file->flags |= FS_FLAG_DEFLATED;
-
-                                               // We need some more variables
-                                               ztk = Mem_Alloc (fs_mempool, sizeof (*file->z));
-
-                                               ztk->real_length = pak->files[i].realsize;
-
-                                               // Initialize zlib stream
-                                               ztk->zstream.next_in = ztk->input;
-                                               ztk->zstream.avail_in = 0;
-
-                                               /* From Zlib's "unzip.c":
-                                                *
-                                                * windowBits is passed < 0 to tell that there is no zlib header.
-                                                * Note that in this case inflate *requires* an extra "dummy" byte
-                                                * after the compressed stream in order to complete decompression and
-                                                * return Z_STREAM_END.
-                                                * In unzip, i don't wait absolutely Z_STREAM_END because I known the
-                                                * size of both compressed and uncompressed data
-                                                */
-                                               if (qz_inflateInit2 (&ztk->zstream, -MAX_WBITS) != Z_OK)
-                                                       Sys_Error ("inflate init error (file: %s)", filename);
-
-                                               ztk->zstream.next_out = ztk->output;
-                                               ztk->zstream.avail_out = sizeof (ztk->output);
-
-                                               file->z = ztk;
-                                       }
-
-                                       return file;
-                               }
-                       }
-               }
-#else
        // search through the path, one element at a time
        search = fs_searchpaths;
 
@@ -1172,7 +1086,6 @@ qfile_t *FS_FOpenFile (const char *filename, qboolean quiet)
                        return FS_OpenRead (netpath, -1, -1);
                }
        }
-#endif
 
        if (!quiet)
                Sys_Printf ("FindFile: can't find %s\n", filename);
@@ -2065,32 +1978,29 @@ int FS_ListDirectory(const char *pattern, int oneperline)
        return numfiles;
 }
 
-void FS_Dir_f(void)
+static void FS_ListDirectoryCmd (const char* cmdname, int oneperline)
 {
        char pattern[MAX_OSPATH];
        if (Cmd_Argc() > 3)
        {
-               Con_Printf("usage:\ndir [path/pattern]\n");
+               Con_Printf("usage:\n%s [path/pattern]\n", cmdname);
                return;
        }
-       strcpy(pattern, "*");
        if (Cmd_Argc() == 2)
                snprintf(pattern, sizeof(pattern), "%s", Cmd_Argv(1));
-       if (!FS_ListDirectory(pattern, true))
+       else
+               strcpy(pattern, "*");
+       if (!FS_ListDirectory(pattern, oneperline))
                Con_Printf("No files found.\n");
 }
 
+void FS_Dir_f(void)
+{
+       FS_ListDirectoryCmd("dir", true);
+}
+
 void FS_Ls_f(void)
 {
-       char pattern[MAX_OSPATH];
-       if (Cmd_Argc() > 3)
-       {
-               Con_Printf("usage:\nls [path/pattern]\n");
-               return;
-       }
-       strcpy(pattern, "*");
-       if (Cmd_Argc() == 2)
-               snprintf(pattern, sizeof(pattern), "%s", Cmd_Argv(1));
-       FS_ListDirectory(pattern, false);
+       FS_ListDirectoryCmd("ls", false);
 }