aboutsummaryrefslogtreecommitdiff
path: root/Src/external_dependencies/openmpt-trunk/unarchiver/unancient.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Src/external_dependencies/openmpt-trunk/unarchiver/unancient.cpp')
-rw-r--r--Src/external_dependencies/openmpt-trunk/unarchiver/unancient.cpp83
1 files changed, 83 insertions, 0 deletions
diff --git a/Src/external_dependencies/openmpt-trunk/unarchiver/unancient.cpp b/Src/external_dependencies/openmpt-trunk/unarchiver/unancient.cpp
new file mode 100644
index 00000000..a2b8001e
--- /dev/null
+++ b/Src/external_dependencies/openmpt-trunk/unarchiver/unancient.cpp
@@ -0,0 +1,83 @@
+/*
+ * unancient.cpp
+ * -------------
+ * Purpose: Implementation file for extracting modules from compressed files supported by libancient
+ * Notes : (currently none)
+ * Authors: OpenMPT Devs
+ * The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
+ */
+
+#include "stdafx.h"
+#include "unancient.h"
+
+#ifdef MPT_WITH_ANCIENT
+#include <ancient/ancient.hpp>
+#endif // MPT_WITH_ANCIENT
+
+
+OPENMPT_NAMESPACE_BEGIN
+
+
+#ifdef MPT_WITH_ANCIENT
+
+
+CAncientArchive::CAncientArchive(FileReader &file)
+ : ArchiveBase(file)
+{
+ inFile.Rewind();
+ try
+ {
+ auto dataView = inFile.GetPinnedView();
+ if(!ancient::Decompressor::detect(mpt::byte_cast<const std::uint8_t*>(dataView.data()), dataView.size()))
+ {
+ return;
+ }
+ ancient::Decompressor decompressor{mpt::byte_cast<const std::uint8_t*>(dataView.data()), dataView.size(), true, true};
+ if(decompressor.getImageSize() || decompressor.getImageOffset())
+ {
+ // skip disk images
+ return;
+ }
+ ArchiveFileInfo fileInfo;
+ fileInfo.name = inFile.GetOptionalFileName().value_or(P_(""));
+ fileInfo.type = ArchiveFileType::Normal;
+ fileInfo.size = decompressor.getRawSize().value_or(0);
+ contents.push_back(fileInfo);
+ } catch(const ancient::Error &)
+ {
+ return;
+ }
+}
+
+
+CAncientArchive::~CAncientArchive()
+{
+ return;
+}
+
+
+bool CAncientArchive::ExtractFile(std::size_t index)
+{
+ if(index >= contents.size())
+ {
+ return false;
+ }
+ data.clear();
+ inFile.Rewind();
+ try
+ {
+ auto dataView = inFile.GetPinnedView();
+ ancient::Decompressor decompressor{mpt::byte_cast<const std::uint8_t*>(dataView.data()), dataView.size(), true, true};
+ data = mpt::buffer_cast<std::vector<char>>(decompressor.decompress(true));
+ } catch (const ancient::Error &)
+ {
+ return false;
+ }
+ return (data.size() > 0);
+}
+
+
+#endif // MPT_WITH_ANCIENT
+
+
+OPENMPT_NAMESPACE_END