CLodHandler.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. realName;
  41. int offset, //from beginning
  42. realSize, //size without compression
  43. size; //and with
  44. bool operator<(const std::string & comp) const
  45. {
  46. return nameStr<comp;
  47. }
  48. bool operator<(const Entry & comp) const
  49. {
  50. return nameStr<comp.nameStr;
  51. }
  52. Entry(std::string con): nameStr(con){};
  53. //Entry(unsigned char ): nameStr(con){};
  54. Entry(){};
  55. };
  56. class DLL_EXPORT CLodHandler
  57. {
  58. std::ifstream LOD;
  59. unsigned int totalFiles;
  60. boost::mutex *mutex;
  61. std::string myDir; //load files from this dir instead of .lod file
  62. public:
  63. nodrze<Entry> entries;
  64. CLodHandler();
  65. ~CLodHandler();
  66. int infs2(unsigned char * in, int size, int realSize, unsigned char*& out, int wBits=15); //zlib fast handler
  67. unsigned char * giveFile(std::string defName, int * length=NULL); //returns pointer to the decompressed data - it must be deleted when no longer needed!
  68. std::string getTextFile(std::string name); //extracts one file
  69. void extractFile(std::string FName, std::string name); //extracts a specific file
  70. void init(std::string lodFile, std::string dirName);
  71. };
  72. #endif // __CLODHANDLER_H__