Archive.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #ifndef INCLUDE_ARCHIVE_H
  2. #define INCLUDE_ARCHIVE_H
  3. #include <exception>
  4. #include <cstdint>
  5. #include <cstdio>
  6. #include <cstdarg>
  7. #include <TINYSTL/string.h>
  8. namespace WalrusRPG
  9. {
  10. namespace PIAF
  11. {
  12. constexpr uint32_t ARCHIVE_VERSION = 0x01000000;
  13. enum FileType : uint32_t
  14. {
  15. UNKNOWN,
  16. MAP,
  17. EVENT_LIST,
  18. TEXT,
  19. TEXTURE
  20. };
  21. enum CompressionType : uint32_t
  22. {
  23. UNKNWOWN,
  24. RAW,
  25. ZLIB,
  26. RLE
  27. };
  28. class File
  29. {
  30. protected:
  31. const uint8_t *data;
  32. public:
  33. friend class Archive;
  34. char filename[9]; // 8 + a \0 in case of printing
  35. FileType file_type;
  36. CompressionType compression_type;
  37. uint32_t file_size;
  38. std::size_t size;
  39. File(uint8_t *data);
  40. File();
  41. ~File();
  42. const uint8_t *get();
  43. };
  44. class Archive
  45. {
  46. private:
  47. FILE *file;
  48. uint32_t version;
  49. uint32_t nb_files;
  50. uint32_t data_size;
  51. File *entries;
  52. uint8_t **files_data;
  53. bool *files_loaded;
  54. uint32_t *files_data_offset;
  55. public:
  56. // RAII stuff
  57. // Archive(std::unique_ptr<char> *filepath);
  58. Archive(const char *filepath);
  59. Archive(tinystl::string &filepath);
  60. ~Archive();
  61. bool has(const char *filename);
  62. File get(const char *filename);
  63. };
  64. class PIAFException : public std::exception
  65. {
  66. private:
  67. char msg[1024];
  68. public:
  69. PIAFException(const char *format, ...);
  70. virtual ~PIAFException();
  71. const char *what() const throw();
  72. };
  73. }
  74. }
  75. #endif