From 5310ea3564fe98b2940a63b72621b79de9290f77 Mon Sep 17 00:00:00 2001 From: Aki Date: Sun, 11 Sep 2022 19:19:32 +0200 Subject: Replaced Datafile and StarsEx/Archive with dat and ArchiveEx --- StarsEx/DataSource.cpp | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) (limited to 'StarsEx/DataSource.cpp') diff --git a/StarsEx/DataSource.cpp b/StarsEx/DataSource.cpp index 3ace2ca..294f4a5 100644 --- a/StarsEx/DataSource.cpp +++ b/StarsEx/DataSource.cpp @@ -11,7 +11,7 @@ #include #include -#include "Archive.h" +#include #include "List.h" #include "Text.h" #include "Utils.h" @@ -39,12 +39,12 @@ DataSource::Id() const ArchiveDataSource::ArchiveDataSource(const char* name) : - ArchiveDataSource(new DataArchive(name)) + ArchiveDataSource(new ArchiveEx::Archive(name)) { } -ArchiveDataSource::ArchiveDataSource(DataArchive* archive) : +ArchiveDataSource::ArchiveDataSource(ArchiveEx::Archive* archive) : DataSource(), m_archive {archive} { @@ -60,7 +60,7 @@ ArchiveDataSource::~ArchiveDataSource() bool ArchiveDataSource::Find(const Text& prefix, const char* name) const { - const int index = m_archive->FindEntry(prefix.concat(name)); + const int index = m_archive->Find(prefix.concat(name)); return index > -1; } @@ -68,20 +68,18 @@ ArchiveDataSource::Find(const Text& prefix, const char* name) const int ArchiveDataSource::ListFiles(const Text& prefix, Text filter, List& items, bool recurse) const { - (void) recurse; // Lookup in DataArchives was always recursive so far + (void) recurse; // Lookup in Archives was always recursive so far filter = filter.replace("*", ""); // Wildcards worked only on boundaries const int first = prefix.length(); - const int count = m_archive->NumFiles(); - for (int i = 0; i < count; ++i) { - const auto* entry = m_archive->GetFile(i); - Text name = entry->name; + m_archive->ForEachEntry([&](const char* path){ + Text name{path}; name.setSensitive(false); if (name.contains(prefix) && name.contains(filter)) { const auto without_prefix = name.substring(first, name.length()); if (!items.contains(&without_prefix)) items.append(new Text(without_prefix)); } - } + }); return items.size(); } @@ -89,10 +87,8 @@ ArchiveDataSource::ListFiles(const Text& prefix, Text filter, List& items, int ArchiveDataSource::Load(const Text& prefix, const char* name, std::uint8_t*& buf, bool null_terminate) const { - const int index = m_archive->FindEntry(prefix.concat(name)); - if (index > -1) - return m_archive->ExpandEntry(index, buf, null_terminate); - return 0; // -1 would be preferable, but 0 is from legacy + const int result = m_archive->Extract(prefix.concat(name), buf, null_terminate); + return -1 == result ? 0 : result; // -1 would be preferable, but 0 is legacy } -- cgit v1.1