From 3e764a7b59babde9d961c156384db485ca6e4ae7 Mon Sep 17 00:00:00 2001 From: in0finite Date: Sun, 31 Jan 2021 00:14:40 +0100 Subject: [PATCH] more error-prone archive loading --- Assets/Scripts/Importing/Archive/ImageArchive.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Assets/Scripts/Importing/Archive/ImageArchive.cs b/Assets/Scripts/Importing/Archive/ImageArchive.cs index 2fa5bec3..3f77a066 100644 --- a/Assets/Scripts/Importing/Archive/ImageArchive.cs +++ b/Assets/Scripts/Importing/Archive/ImageArchive.cs @@ -43,6 +43,8 @@ namespace SanAndreasUnity.Importing.Archive { _stream = stream; + string archiveName = _stream is FileStream fs ? Path.GetFileName(fs.Name) : string.Empty; + var reader = new BinaryReader(stream); Version = new String(reader.ReadChars(4)); EntryCount = reader.ReadUInt32(); @@ -51,9 +53,22 @@ namespace SanAndreasUnity.Importing.Archive _fileDict = new Dictionary(StringComparer.InvariantCultureIgnoreCase); _extDict = new Dictionary>(StringComparer.InvariantCultureIgnoreCase); + if (Version != "VER2") + { + UnityEngine.Debug.LogWarning($"Archive {archiveName} has unsupported version {Version}"); + return; + } + for (var i = 0; i < EntryCount; ++i) { var entry = new ImageArchiveEntry(reader); + + if (_fileDict.ContainsKey(entry.Name)) + { + UnityEngine.Debug.LogWarning($"file entry (name: {entry.Name}, size: {entry.Size}) already exists in archive {archiveName}"); + continue; + } + _entries.Add(entry); _fileDict.Add(entry.Name, entry);