CLodHandler.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #ifndef __CLODHANDLER_H__
  2. #define __CLODHANDLER_H__
  3. #include "../global.h"
  4. #include <fstream>
  5. #include <vector>
  6. #include <string>
  7. #include "../nodrze.h"
  8. #include <SDL_stdinc.h>
  9. /*
  10. * CLodhandler.h, part of VCMI engine
  11. *
  12. * Authors: listed in file AUTHORS in main folder
  13. *
  14. * License: GNU General Public License v2.0 or later
  15. * Full text of license available in license.txt file, in main folder
  16. *
  17. */
  18. struct SDL_Surface;
  19. class CDefHandler;
  20. class CDefEssential;
  21. namespace boost
  22. {class mutex;}
  23. namespace NLoadHandlerHelp
  24. {
  25. const int dmHelp=0, dmNoExtractingMask=1;
  26. //std::string P1,P2,CurDir;
  27. const int fCHUNK = 50000;
  28. }
  29. struct LodEntry {
  30. char filename[16];
  31. Uint32 offset; /* little endian */
  32. Uint32 uncompressedSize; /* little endian */
  33. Uint32 unused; /* little endian */
  34. Uint32 size; /* little endian */
  35. };
  36. struct Entry
  37. {
  38. // Info extracted from LOD file
  39. std::string nameStr;
  40. int offset, //from beginning
  41. realSize, //size without compression
  42. size; //and with
  43. bool operator<(const std::string & comp) const
  44. {
  45. return nameStr<comp;
  46. }
  47. bool operator<(const Entry & comp) const
  48. {
  49. return nameStr<comp.nameStr;
  50. }
  51. Entry(std::string con): nameStr(con){};
  52. //Entry(unsigned char ): nameStr(con){};
  53. Entry(){};
  54. };
  55. class DLL_EXPORT CLodHandler
  56. {
  57. std::ifstream LOD;
  58. unsigned int totalFiles;
  59. boost::mutex *mutex;
  60. std::string myDir; //load files from this dir instead of .lod file
  61. public:
  62. nodrze<Entry> entries;
  63. CLodHandler();
  64. ~CLodHandler();
  65. int infs2(unsigned char * in, int size, int realSize, unsigned char*& out, int wBits=15); //zlib fast handler
  66. unsigned char * giveFile(std::string defName, int * length=NULL); //returns pointer to the decompressed data - it must be deleted when no longer needed!
  67. std::string getTextFile(std::string name); //extracts one file
  68. void extractFile(std::string FName, std::string name); //extracts a specific file
  69. void init(std::string lodFile, std::string dirName);
  70. };
  71. #endif // __CLODHANDLER_H__