CLodHandler.h 2.3 KB

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