diff --git a/SabreTools.Library/FileTypes/TorrentZipArchive.cs b/SabreTools.Library/FileTypes/ZipArchive.cs
similarity index 98%
rename from SabreTools.Library/FileTypes/TorrentZipArchive.cs
rename to SabreTools.Library/FileTypes/ZipArchive.cs
index 27dff3fe..60ef3be0 100644
--- a/SabreTools.Library/FileTypes/TorrentZipArchive.cs
+++ b/SabreTools.Library/FileTypes/ZipArchive.cs
@@ -18,22 +18,21 @@ using SeekOrigin = System.IO.SeekOrigin;
using Stream = System.IO.Stream;
#endif
using ROMVault2.SupportedFiles.Zip;
-using SharpCompress.Common;
using SharpCompress.Readers;
namespace SabreTools.Library.FileTypes
{
///
- /// Represents a Torrent7zip archive for reading and writing
+ /// Represents a Zip archive for reading and writing
///
- public class TorrentZipArchive : BaseArchive
+ public class ZipArchive : BaseArchive
{
#region Constructors
///
/// Create a new TorrentZipArchive with no base file
///
- public TorrentZipArchive()
+ public ZipArchive()
: base()
{
_fileType = FileType.ZipArchive;
@@ -45,7 +44,7 @@ namespace SabreTools.Library.FileTypes
/// Name of the file to use as an archive
/// True for opening file as read, false for opening file as write
/// True if hashes for this file should be calculated, false otherwise (default)
- public TorrentZipArchive(string filename, bool getHashes = false)
+ public ZipArchive(string filename, bool getHashes = false)
: base(filename, getHashes)
{
_fileType = FileType.ZipArchive;
@@ -283,11 +282,18 @@ namespace SabreTools.Library.FileTypes
throw new Exception(ZipFile.ZipErrorMessageText(zr));
}
- for (int i = 0; i < zf.EntriesCount && zr == ZipReturn.ZipGood; i++)
+ for (int i = 0; i < zf.EntriesCount; i++)
{
// Open the read stream
zr = zf.OpenReadStream(i, false, out Stream readStream, out ulong streamsize, out SabreTools.Library.Data.CompressionMethod cm, out uint lastMod);
+ // If we get a read error, log it and continue
+ if (zr != ZipReturn.ZipGood)
+ {
+ Globals.Logger.Warning("An error occurred while reading archive {0}: Zip Error - {1}", _filename, zr);
+ continue;
+ }
+
// If the entry ends with a directory separator, continue to the next item, if any
if (zf.Entries[i].FileName.EndsWith(Path.DirectorySeparatorChar.ToString())
|| zf.Entries[i].FileName.EndsWith(Path.AltDirectorySeparatorChar.ToString())
@@ -317,18 +323,17 @@ namespace SabreTools.Library.FileTypes
// Otherwise, use the stream directly
else
{
- BaseFile zipEntryRom = Utilities.GetStreamInfo(readStream, (long)zf.Entries[i].UncompressedSize, omitFromScan: omitFromScan);
+ BaseFile zipEntryRom = Utilities.GetStreamInfo(readStream, (long)zf.Entries[i].UncompressedSize, omitFromScan: omitFromScan, keepReadOpen: true);
zipEntryRom.Filename = zf.Entries[i].FileName;
zipEntryRom.Parent = gamename;
string convertedDate = Utilities.ConvertMsDosTimeFormatToDateTime(zf.Entries[i].LastMod).ToString("yyyy/MM/dd hh:mm:ss");
zipEntryRom.Date = (date ? convertedDate : null);
found.Add(zipEntryRom);
- zr = zf.CloseReadStream();
}
}
-
// Dispose of the archive
+ zr = zf.CloseReadStream();
zf.Close();
}
catch (Exception ex)
diff --git a/SabreTools.Library/SabreTools.Library.csproj b/SabreTools.Library/SabreTools.Library.csproj
index d0ac0233..4ec254f0 100644
--- a/SabreTools.Library/SabreTools.Library.csproj
+++ b/SabreTools.Library/SabreTools.Library.csproj
@@ -172,7 +172,7 @@
-
+
diff --git a/SabreTools.Library/Tools/Utilities.cs b/SabreTools.Library/Tools/Utilities.cs
index 8282a642..9509aa7d 100644
--- a/SabreTools.Library/Tools/Utilities.cs
+++ b/SabreTools.Library/Tools/Utilities.cs
@@ -470,7 +470,7 @@ namespace SabreTools.Library.Tools
archive = new TapeArchive(input);
break;
case FileType.ZipArchive:
- archive = new TorrentZipArchive(input);
+ archive = new ZipArchive(input);
break;
default:
// We ignore all other types for now
@@ -498,7 +498,7 @@ namespace SabreTools.Library.Tools
case FileType.TapeArchive:
return new TapeArchive();
case FileType.ZipArchive:
- return new TorrentZipArchive();
+ return new ZipArchive();
default:
return null;
}
@@ -530,7 +530,7 @@ namespace SabreTools.Library.Tools
case OutputFormat.TorrentXZ:
return new XZArchive();
case OutputFormat.TorrentZip:
- return new TorrentZipArchive();
+ return new ZipArchive();
case OutputFormat.TorrentZPAQ:
return new ZPAQArchive();
case OutputFormat.TorrentZstd: