unarchiver.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * unarchiver.h
  3. * ------------
  4. * Purpose: archive loader
  5. * Notes : (currently none)
  6. * Authors: OpenMPT Devs
  7. * The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
  8. */
  9. #pragma once
  10. #include "openmpt/all/BuildSettings.hpp"
  11. #include "../common/FileReader.h"
  12. #include "archive.h"
  13. #if (defined(MPT_WITH_ZLIB) && defined(MPT_WITH_MINIZIP)) || defined(MPT_WITH_MINIZ)
  14. #include "unzip.h"
  15. #endif
  16. #ifdef MPT_WITH_LHASA
  17. #include "unlha.h"
  18. #endif
  19. #if defined(MPT_WITH_ZLIB) || defined(MPT_WITH_MINIZ)
  20. #include "ungzip.h"
  21. #endif
  22. #ifdef MPT_WITH_UNRAR
  23. #include "unrar.h"
  24. #endif
  25. #ifdef MPT_WITH_ANCIENT
  26. #include "unancient.h"
  27. #endif
  28. OPENMPT_NAMESPACE_BEGIN
  29. class CUnarchiver : public IArchive
  30. {
  31. private:
  32. IArchive *impl;
  33. FileReader inFile;
  34. ArchiveBase emptyArchive;
  35. #if (defined(MPT_WITH_ZLIB) && defined(MPT_WITH_MINIZIP)) || defined(MPT_WITH_MINIZ)
  36. CZipArchive zipArchive;
  37. #endif
  38. #ifdef MPT_WITH_LHASA
  39. CLhaArchive lhaArchive;
  40. #endif
  41. #if defined(MPT_WITH_ZLIB) || defined(MPT_WITH_MINIZ)
  42. CGzipArchive gzipArchive;
  43. #endif
  44. #ifdef MPT_WITH_UNRAR
  45. CRarArchive rarArchive;
  46. #endif
  47. #ifdef MPT_WITH_ANCIENT
  48. CAncientArchive ancientArchive;
  49. #endif
  50. public:
  51. CUnarchiver(FileReader &file);
  52. ~CUnarchiver() override;
  53. bool IsArchive() const override;
  54. mpt::ustring GetComment() const override;
  55. bool ExtractFile(std::size_t index) override;
  56. FileReader GetOutputFile() const override;
  57. std::size_t size() const override;
  58. IArchive::const_iterator begin() const override;
  59. IArchive::const_iterator end() const override;
  60. const ArchiveFileInfo & operator [] (std::size_t index) const override;
  61. public:
  62. static const std::size_t failIndex = (std::size_t)-1;
  63. std::size_t FindBestFile(const std::vector<const char *> &extensions);
  64. bool ExtractBestFile(const std::vector<const char *> &extensions);
  65. };
  66. OPENMPT_NAMESPACE_END