CPackage.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. //
  2. // Created by almamu on 8/8/21.
  3. //
  4. #pragma once
  5. #include <string>
  6. #include <vector>
  7. #include <map>
  8. #include <exception>
  9. #include <stdexcept>
  10. #include <cstring>
  11. #include "CContainer.h"
  12. #include "CFileEntry.h"
  13. namespace WallpaperEngine::Assets
  14. {
  15. class CPackage : public CContainer
  16. {
  17. public:
  18. CPackage (const std::string& path);
  19. ~CPackage ();
  20. const void* readFile (std::string filename, uint32_t* length) const override;
  21. protected:
  22. /**
  23. * Loads the current package file and loads all it's contents to memory
  24. */
  25. void init ();
  26. /**
  27. * Reads the header from the current position and ensures it's a compatible version
  28. *
  29. * @param fp The file where to read from
  30. */
  31. void validateHeader (FILE* fp);
  32. /**
  33. * Loads the files in the package into memory
  34. *
  35. * @param fp The file where to read from
  36. */
  37. void loadFiles (FILE* fp);
  38. /**
  39. * Reads a size-prefixed string
  40. *
  41. * @param fp File to read from
  42. *
  43. * @return The read data, important to free it
  44. */
  45. char* readSizedString (FILE* fp);
  46. /**
  47. * Reads a simple unsigned of 32 bits
  48. *
  49. * @param fp File to read from
  50. *
  51. * @return The read value
  52. */
  53. uint32_t readInteger (FILE* fp);
  54. private:
  55. std::string m_path;
  56. std::map <std::string, CFileEntry> m_contents;
  57. };
  58. }