CLodHandler.h 2.4 KB

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