diff options
author | Aki <please@ignore.pl> | 2022-09-11 19:19:32 +0200 |
---|---|---|
committer | Aki <please@ignore.pl> | 2022-09-11 19:19:32 +0200 |
commit | 5310ea3564fe98b2940a63b72621b79de9290f77 (patch) | |
tree | 0d5b7a09d9cbef287d3af71f48f31f1935d0a075 /StarsEx/DataSource.cpp | |
parent | eb1433d1c9d87470952a8ef626c790a8a60b8d76 (diff) | |
download | starshatter-5310ea3564fe98b2940a63b72621b79de9290f77.zip starshatter-5310ea3564fe98b2940a63b72621b79de9290f77.tar.gz starshatter-5310ea3564fe98b2940a63b72621b79de9290f77.tar.bz2 |
Replaced Datafile and StarsEx/Archive with dat and ArchiveEx
Diffstat (limited to 'StarsEx/DataSource.cpp')
-rw-r--r-- | StarsEx/DataSource.cpp | 24 |
1 files changed, 10 insertions, 14 deletions
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 <cstring> #include <filesystem> -#include "Archive.h" +#include <Archive.h> #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<Text>& 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<Text>& 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 } |