Archive.h 2.2 KB

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