From 20d28e80a5c861a9d5f449ea911ab75b4f37ad0d Mon Sep 17 00:00:00 2001 From: Jef Date: Tue, 24 Sep 2024 14:54:57 +0200 Subject: Initial community commit --- .../openmpt-trunk/unarchiver/unancient.cpp | 83 ++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 Src/external_dependencies/openmpt-trunk/unarchiver/unancient.cpp (limited to 'Src/external_dependencies/openmpt-trunk/unarchiver/unancient.cpp') 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 +#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(dataView.data()), dataView.size())) + { + return; + } + ancient::Decompressor decompressor{mpt::byte_cast(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(dataView.data()), dataView.size(), true, true}; + data = mpt::buffer_cast>(decompressor.decompress(true)); + } catch (const ancient::Error &) + { + return false; + } + return (data.size() > 0); +} + + +#endif // MPT_WITH_ANCIENT + + +OPENMPT_NAMESPACE_END -- cgit