File_Resource.h (3961B)
1 /* 2 =========================================================================== 3 4 Doom 3 BFG Edition GPL Source Code 5 Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company. 6 7 This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code"). 8 9 Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify 10 it under the terms of the GNU General Public License as published by 11 the Free Software Foundation, either version 3 of the License, or 12 (at your option) any later version. 13 14 Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful, 15 but WITHOUT ANY WARRANTY; without even the implied warranty of 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 GNU General Public License for more details. 18 19 You should have received a copy of the GNU General Public License 20 along with Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>. 21 22 In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below. 23 24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. 25 26 =========================================================================== 27 */ 28 29 #ifndef __FILE_RESOURCE_H__ 30 #define __FILE_RESOURCE_H__ 31 32 /* 33 ============================================================== 34 35 Resource containers 36 37 ============================================================== 38 */ 39 40 class idResourceCacheEntry { 41 public: 42 idResourceCacheEntry() { 43 Clear(); 44 } 45 void Clear() { 46 filename.Empty(); 47 //filename = NULL; 48 offset = 0; 49 length = 0; 50 containerIndex = 0; 51 } 52 size_t Read( idFile *f ) { 53 size_t sz = f->ReadString( filename ); 54 sz += f->ReadBig( offset ); 55 sz += f->ReadBig( length ); 56 return sz; 57 } 58 size_t Write( idFile *f ) { 59 size_t sz = f->WriteString( filename ); 60 sz += f->WriteBig( offset ); 61 sz += f->WriteBig( length ); 62 return sz; 63 } 64 idStrStatic< 256 > filename; 65 int offset; // into the resource file 66 int length; 67 uint8 containerIndex; 68 }; 69 70 static const uint32 RESOURCE_FILE_MAGIC = 0xD000000D; 71 class idResourceContainer { 72 friend class idFileSystemLocal; 73 //friend class idReadSpawnThread; 74 public: 75 idResourceContainer() { 76 resourceFile = NULL; 77 tableOffset = 0; 78 tableLength = 0; 79 resourceMagic = 0; 80 numFileResources = 0; 81 } 82 ~idResourceContainer() { 83 delete resourceFile; 84 cacheTable.Clear(); 85 } 86 bool Init( const char * fileName, uint8 containerIndex ); 87 static void WriteResourceFile( const char *fileName, const idStrList &manifest, const bool &_writeManifest ); 88 static void WriteManifestFile( const char *name, const idStrList &list ); 89 static int ReadManifestFile( const char *filename, idStrList &list ); 90 static void ExtractResourceFile ( const char * fileName, const char * outPath, bool copyWavs ); 91 static void UpdateResourceFile( const char *filename, const idStrList &filesToAdd ); 92 idFile *OpenFile( const char *fileName ); 93 const char * GetFileName() const { return fileName.c_str(); } 94 void SetContainerIndex( const int & _idx ); 95 void ReOpen(); 96 private: 97 idStrStatic< 256 > fileName; 98 idFile * resourceFile; // open file handle 99 // offset should probably be a 64 bit value for development, but 4 gigs won't fit on 100 // a DVD layer, so it isn't a retail limitation. 101 int tableOffset; // table offset 102 int tableLength; // table length 103 int resourceMagic; // magic 104 int numFileResources; // number of file resources in this container 105 idList< idResourceCacheEntry, TAG_RESOURCE> cacheTable; 106 idHashIndex cacheHash; 107 }; 108 109 110 #endif /* !__FILE_RESOURCE_H__ */