================ idFileSystemLocal::AddGameDirectory Sets gameFolder, adds the directory to the head of the search paths, then loads any pk4 files. ================ */
| 2087 | ================ |
| 2088 | */ |
| 2089 | void idFileSystemLocal::AddGameDirectory( const char *path, const char *dir ) { |
| 2090 | int i; |
| 2091 | searchpath_t * search; |
| 2092 | pack_t * pak; |
| 2093 | idStr pakfile; |
| 2094 | idStrList pakfiles; |
| 2095 | |
| 2096 | // check if the search path already exists |
| 2097 | for ( search = searchPaths; search; search = search->next ) { |
| 2098 | // if this element is a pak file |
| 2099 | if ( !search->dir ) { |
| 2100 | continue; |
| 2101 | } |
| 2102 | if ( search->dir->path.Cmp( path ) == 0 && search->dir->gamedir.Cmp( dir ) == 0 ) { |
| 2103 | return; |
| 2104 | } |
| 2105 | } |
| 2106 | |
| 2107 | gameFolder = dir; |
| 2108 | |
| 2109 | // |
| 2110 | // add the directory to the search path |
| 2111 | // |
| 2112 | search = new searchpath_t; |
| 2113 | search->dir = new directory_t; |
| 2114 | search->pack = NULL; |
| 2115 | |
| 2116 | search->dir->path = path; |
| 2117 | search->dir->gamedir = dir; |
| 2118 | search->next = searchPaths; |
| 2119 | searchPaths = search; |
| 2120 | |
| 2121 | // find all pak files in this directory |
| 2122 | pakfile = BuildOSPath( path, dir, "" ); |
| 2123 | pakfile[ pakfile.Length() - 1 ] = 0; // strip the trailing slash |
| 2124 | |
| 2125 | ListOSFiles( pakfile, ".pk4", pakfiles ); |
| 2126 | |
| 2127 | // sort them so that later alphabetic matches override |
| 2128 | // earlier ones. This makes pak1.pk4 override pak0.pk4 |
| 2129 | pakfiles.Sort(); |
| 2130 | |
| 2131 | for ( i = 0; i < pakfiles.Num(); i++ ) { |
| 2132 | pakfile = BuildOSPath( path, dir, pakfiles[i] ); |
| 2133 | pak = LoadZipFile( pakfile ); |
| 2134 | if ( !pak ) { |
| 2135 | continue; |
| 2136 | } |
| 2137 | // insert the pak after the directory it comes from |
| 2138 | search = new searchpath_t; |
| 2139 | search->dir = NULL; |
| 2140 | search->pack = pak; |
| 2141 | search->next = searchPaths->next; |
| 2142 | searchPaths->next = search; |
| 2143 | common->Printf( "Loaded pk4 %s with checksum 0x%x\n", pakfile.c_str(), pak->checksum ); |
| 2144 | } |
| 2145 | } |
| 2146 |