Archive.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #include "Archive.h"
  2. #include <cstring>
  3. #include <cstdio>
  4. using WalrusRPG::PIAF::Archive;
  5. using WalrusRPG::PIAF::FileEntry;
  6. using WalrusRPG::PIAF::FileType;
  7. namespace
  8. {
  9. template <typename T> T read_big_endian_value(void *ptr)
  10. {
  11. T result = 0;
  12. uint8_t *data = (uint8_t *) ptr;
  13. for (int i = 0; i < sizeof(T); i++)
  14. result |= data[i] << (8 * (sizeof(T) - 1 - i));
  15. return result;
  16. }
  17. }
  18. Archive::Archive(char *filepath)
  19. {
  20. if (filepath == nullptr)
  21. {
  22. }
  23. // TODO : throw NPE
  24. FILE *file = fopen(filepath, "rb");
  25. if (file == nullptr)
  26. {
  27. // TODO : throw Couldn't open
  28. }
  29. // loading stuff happens NOW
  30. // ...
  31. // entries = new File_Entry[];
  32. // ...
  33. }
  34. Archive::~Archive()
  35. {
  36. // delete[] entries;
  37. }
  38. FileEntry Archive::get_file_entry(char *filename)
  39. {
  40. for (uint32_t index = 0; index < nb_files; index++)
  41. {
  42. if (strcmp(entries[index].filename, filename) == 0)
  43. {
  44. return entries[index];
  45. }
  46. }
  47. // throw exception
  48. }
  49. /*PFile*/ void /*FileEntry*/ get(char *filename)
  50. {
  51. // return PFile(get_file_entry(filename));
  52. }