diff options
author | Jef <jef@targetspot.com> | 2024-09-24 08:54:57 -0400 |
---|---|---|
committer | Jef <jef@targetspot.com> | 2024-09-24 08:54:57 -0400 |
commit | 20d28e80a5c861a9d5f449ea911ab75b4f37ad0d (patch) | |
tree | 12f17f78986871dd2cfb0a56e5e93b545c1ae0d0 /Src/external_dependencies/openmpt-trunk/unarchiver/unancient.cpp | |
parent | 537bcbc86291b32fc04ae4133ce4d7cac8ebe9a7 (diff) | |
download | winamp-20d28e80a5c861a9d5f449ea911ab75b4f37ad0d.tar.gz |
Initial community commit
Diffstat (limited to 'Src/external_dependencies/openmpt-trunk/unarchiver/unancient.cpp')
-rw-r--r-- | Src/external_dependencies/openmpt-trunk/unarchiver/unancient.cpp | 83 |
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 |