X-Git-Url: https://git.xonotic.org/?a=blobdiff_plain;f=fs.c;h=25789e0235888c1f58d199fd65c30184e6711e70;hb=7c82443dc33d8bca7b904e131033bb312c800d1a;hp=f8266c71a2a7e7e10b4ee3c21f1d533f6e657010;hpb=2b065b3efdf9a5aced95aa93aed4db1caf8191bb;p=xonotic%2Fdarkplaces.git diff --git a/fs.c b/fs.c index f8266c71..25789e02 100644 --- a/fs.c +++ b/fs.c @@ -321,6 +321,7 @@ typedef struct pack_s int ignorecase; ///< PK3 ignores case int numfiles; qbool vpack; + qbool dlcache; packfile_t *files; } pack_t; //@} @@ -682,7 +683,7 @@ static int PK3_BuildFileList (pack_t *pack, const pk3_endOfCentralDir_t *eocd) return -1; } - namesize = BuffLittleShort (&ptr[28]); // filename length + namesize = (unsigned short)BuffLittleShort (&ptr[28]); // filename length // Check encryption, compression, and attributes // 1st uint8 : general purpose bit flag @@ -699,7 +700,7 @@ static int PK3_BuildFileList (pack_t *pack, const pk3_endOfCentralDir_t *eocd) if ((ptr[8] & 0x21) == 0 && (ptr[38] & 0x18) == 0) { // Still enough bytes for the name? - if (namesize < 0 || remaining < namesize || namesize >= (int)sizeof (*pack->files)) + if (remaining < namesize || namesize >= (int)sizeof (*pack->files)) { Mem_Free (central_dir); return -1; @@ -743,7 +744,7 @@ static int PK3_BuildFileList (pack_t *pack, const pk3_endOfCentralDir_t *eocd) // Skip the name, additionnal field, and comment // 1er uint16 : extra field length // 2eme uint16 : file comment length - count = namesize + BuffLittleShort (&ptr[30]) + BuffLittleShort (&ptr[32]); + count = namesize + (unsigned short)BuffLittleShort (&ptr[30]) + (unsigned short)BuffLittleShort (&ptr[32]); ptr += ZIP_CDIR_CHUNK_BASE_SIZE + count; remaining -= count; } @@ -1118,7 +1119,7 @@ FS_AddPack_Fullpath * plain directories. * */ -static qbool FS_AddPack_Fullpath(const char *pakfile, const char *shortname, qbool *already_loaded, qbool keep_plain_dirs) +static qbool FS_AddPack_Fullpath(const char *pakfile, const char *shortname, qbool *already_loaded, qbool keep_plain_dirs, qbool dlcache) { searchpath_t *search; pack_t *pak = NULL; @@ -1194,6 +1195,7 @@ static qbool FS_AddPack_Fullpath(const char *pakfile, const char *shortname, qbo fs_searchpaths = search; } search->pack = pak; + search->pack->dlcache = dlcache; if(pak->vpack) { dpsnprintf(search->filename, sizeof(search->filename), "%s/", pakfile); @@ -1232,7 +1234,7 @@ FS_AddPack * If keep_plain_dirs is set, the pack will be added AFTER the first sequence of * plain directories. */ -qbool FS_AddPack(const char *pakfile, qbool *already_loaded, qbool keep_plain_dirs) +qbool FS_AddPack(const char *pakfile, qbool *already_loaded, qbool keep_plain_dirs, qbool dlcache) { char fullpath[MAX_OSPATH]; int index; @@ -1251,7 +1253,7 @@ qbool FS_AddPack(const char *pakfile, qbool *already_loaded, qbool keep_plain_di dpsnprintf(fullpath, sizeof(fullpath), "%s%s", search->filename, pakfile); - return FS_AddPack_Fullpath(fullpath, pakfile, already_loaded, keep_plain_dirs); + return FS_AddPack_Fullpath(fullpath, pakfile, already_loaded, keep_plain_dirs, dlcache); } @@ -1280,7 +1282,7 @@ static void FS_AddGameDirectory (const char *dir) { if (!strcasecmp(FS_FileExtension(list.strings[i]), "pak")) { - FS_AddPack_Fullpath(list.strings[i], list.strings[i] + strlen(dir), NULL, false); + FS_AddPack_Fullpath(list.strings[i], list.strings[i] + strlen(dir), NULL, false, false); } } @@ -1290,7 +1292,7 @@ static void FS_AddGameDirectory (const char *dir) if (!strcasecmp(FS_FileExtension(list.strings[i]), "pk3") || !strcasecmp(FS_FileExtension(list.strings[i]), "obb") || !strcasecmp(FS_FileExtension(list.strings[i]), "pk3dir") || !strcasecmp(FS_FileExtension(list.strings[i]), "dpk") || !strcasecmp(FS_FileExtension(list.strings[i]), "dpkdir")) { - FS_AddPack_Fullpath(list.strings[i], list.strings[i] + strlen(dir), NULL, false); + FS_AddPack_Fullpath(list.strings[i], list.strings[i] + strlen(dir), NULL, false, false); } } @@ -1399,6 +1401,46 @@ static void FS_ClearSearchPath (void) } } +/* +================ +FS_UnloadPacks_dlcache + +Like FS_ClearSearchPath() but unloads only the packs loaded from dlcache +so we don't need to use a full FS_Rescan() to prevent +content from the previous server and/or map from interfering with the next +================ +*/ +void FS_UnloadPacks_dlcache(void) +{ + searchpath_t *search = fs_searchpaths, *searchprev = fs_searchpaths, *searchnext; + + while (search) + { + searchnext = search->next; + if (search->pack && search->pack->dlcache) + { + Con_DPrintf("Unloading pack: %s\n", search->pack->shortname); + + // remove it from the search path list + if (search == fs_searchpaths) + fs_searchpaths = search->next; + else + searchprev->next = search->next; + + // close the file + FILEDESC_CLOSE(search->pack->handle); + // free any memory associated with it + if (search->pack->files) + Mem_Free(search->pack->files); + Mem_Free(search->pack); + Mem_Free(search); + } + else + searchprev = search; + search = searchnext; + } +} + static void FS_AddSelfPack(void) { if(fs_selfpack)