File_Resource.h 3.9 KB

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