Centralize ZIP filename lookup

Add FindFileIndex to resolve the first case-insensitive filename match
without extracting it. Reuse the lookup in named extraction and library
include resolution, removing the duplicate archive-entry scan while
preserving archive order and source fallback behavior.

Validated with a warning-free Qt 6.10 Debug build and 51 offscreen
lifecycle groups; the final API rename also builds without warnings.
This commit is contained in:
Leonardo Zide committed 2026-10-19 22:51:03 -07:00
1 parent 29c1c142df
commit e1c2df5767
3 files changed
+22 -15

No files matched your search

+8 -11
View File
@@ -1809,20 +1809,17 @@ lcResult<std::unique_ptr<lcFile>> lcPiecesLibrary::OpenPieceDataFile(const char*
{
const QByteArray FileName = (Prefix + Folder + QString::fromLatin1(PieceName)).toLatin1();
for (quint32 Index = 0; Index < Archive->mFiles.size(); Index++)
{
if (qstricmp(Archive->mFiles[Index].file_name, FileName.constData()))
continue;
const std::optional<quint32> FileIndex = Archive->FindFileIndex(FileName.constData());
lcFileSource Source;
Source.ArchiveType = static_cast<int>(Type);
Source.ArchiveIndex = Index;
if (!FileIndex)
continue;
if (lcResult<std::unique_ptr<lcFile>> File = OpenFile(Source))
return File;
lcFileSource Source;
Source.ArchiveType = static_cast<int>(Type);
Source.ArchiveIndex = *FileIndex;
break;
}
if (lcResult<std::unique_ptr<lcFile>> File = OpenFile(Source))
return File;
}
}
+11 -4
View File
@@ -567,17 +567,24 @@ bool lcZipFile::ReadCentralDir()
return true;
}
bool lcZipFile::ExtractFile(const char* FileName, lcMemFile& File, quint32 MaxLength)
std::optional<quint32> lcZipFile::FindFileIndex(const char* FileName) const
{
for (quint32 FileIdx = 0; FileIdx < mFiles.size(); FileIdx++)
{
lcZipFileInfo& FileInfo = mFiles[FileIdx];
const lcZipFileInfo& FileInfo = mFiles[FileIdx];
if (!qstricmp(FileInfo.file_name, FileName))
return ExtractFile(FileIdx, File, MaxLength);
return FileIdx;
}
return false;
return std::nullopt;
}
bool lcZipFile::ExtractFile(const char* FileName, lcMemFile& File, quint32 MaxLength)
{
const std::optional<quint32> FileIndex = FindFileIndex(FileName);
return FileIndex && ExtractFile(*FileIndex, File, MaxLength);
}
bool lcZipFile::ExtractFile(quint32 FileIndex, lcMemFile& File, quint32 MaxLength)
+3
View File
@@ -59,6 +59,9 @@ public:
bool OpenRead(std::unique_ptr<lcFile> File);
bool OpenWrite(const QString& FileName);
// Returns the first case-insensitive filename match in archive order.
std::optional<quint32> FindFileIndex(const char* FileName) const;
bool ExtractFile(quint32 FileIndex, lcMemFile& File, quint32 MaxLength = 0xffffffff);
bool ExtractFile(const char* FileName, lcMemFile& File, quint32 MaxLength = 0xffffffff);