[ZipArchive, Utilities] Rename to ZipArchive, fix read

This commit is contained in:
Matt Nadareski
2018-02-23 13:46:39 -08:00
parent 85ea721802
commit 37d854b14b
3 changed files with 18 additions and 13 deletions

View File

@@ -18,22 +18,21 @@ using SeekOrigin = System.IO.SeekOrigin;
using Stream = System.IO.Stream; using Stream = System.IO.Stream;
#endif #endif
using ROMVault2.SupportedFiles.Zip; using ROMVault2.SupportedFiles.Zip;
using SharpCompress.Common;
using SharpCompress.Readers; using SharpCompress.Readers;
namespace SabreTools.Library.FileTypes namespace SabreTools.Library.FileTypes
{ {
/// <summary> /// <summary>
/// Represents a Torrent7zip archive for reading and writing /// Represents a Zip archive for reading and writing
/// </summary> /// </summary>
public class TorrentZipArchive : BaseArchive public class ZipArchive : BaseArchive
{ {
#region Constructors #region Constructors
/// <summary> /// <summary>
/// Create a new TorrentZipArchive with no base file /// Create a new TorrentZipArchive with no base file
/// </summary> /// </summary>
public TorrentZipArchive() public ZipArchive()
: base() : base()
{ {
_fileType = FileType.ZipArchive; _fileType = FileType.ZipArchive;
@@ -45,7 +44,7 @@ namespace SabreTools.Library.FileTypes
/// <param name="filename">Name of the file to use as an archive</param> /// <param name="filename">Name of the file to use as an archive</param>
/// <param name="read">True for opening file as read, false for opening file as write</param> /// <param name="read">True for opening file as read, false for opening file as write</param>
/// <param name="getHashes">True if hashes for this file should be calculated, false otherwise (default)</param> /// <param name="getHashes">True if hashes for this file should be calculated, false otherwise (default)</param>
public TorrentZipArchive(string filename, bool getHashes = false) public ZipArchive(string filename, bool getHashes = false)
: base(filename, getHashes) : base(filename, getHashes)
{ {
_fileType = FileType.ZipArchive; _fileType = FileType.ZipArchive;
@@ -283,11 +282,18 @@ namespace SabreTools.Library.FileTypes
throw new Exception(ZipFile.ZipErrorMessageText(zr)); 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 // Open the read stream
zr = zf.OpenReadStream(i, false, out Stream readStream, out ulong streamsize, out SabreTools.Library.Data.CompressionMethod cm, out uint lastMod); 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 the entry ends with a directory separator, continue to the next item, if any
if (zf.Entries[i].FileName.EndsWith(Path.DirectorySeparatorChar.ToString()) if (zf.Entries[i].FileName.EndsWith(Path.DirectorySeparatorChar.ToString())
|| zf.Entries[i].FileName.EndsWith(Path.AltDirectorySeparatorChar.ToString()) || zf.Entries[i].FileName.EndsWith(Path.AltDirectorySeparatorChar.ToString())
@@ -317,18 +323,17 @@ namespace SabreTools.Library.FileTypes
// Otherwise, use the stream directly // Otherwise, use the stream directly
else 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.Filename = zf.Entries[i].FileName;
zipEntryRom.Parent = gamename; zipEntryRom.Parent = gamename;
string convertedDate = Utilities.ConvertMsDosTimeFormatToDateTime(zf.Entries[i].LastMod).ToString("yyyy/MM/dd hh:mm:ss"); string convertedDate = Utilities.ConvertMsDosTimeFormatToDateTime(zf.Entries[i].LastMod).ToString("yyyy/MM/dd hh:mm:ss");
zipEntryRom.Date = (date ? convertedDate : null); zipEntryRom.Date = (date ? convertedDate : null);
found.Add(zipEntryRom); found.Add(zipEntryRom);
zr = zf.CloseReadStream();
} }
} }
// Dispose of the archive // Dispose of the archive
zr = zf.CloseReadStream();
zf.Close(); zf.Close();
} }
catch (Exception ex) catch (Exception ex)

View File

@@ -172,7 +172,7 @@
<Compile Include="FileTypes\RarArchive.cs" /> <Compile Include="FileTypes\RarArchive.cs" />
<Compile Include="FileTypes\SevenZipArchive.cs" /> <Compile Include="FileTypes\SevenZipArchive.cs" />
<Compile Include="FileTypes\TapeArchive.cs" /> <Compile Include="FileTypes\TapeArchive.cs" />
<Compile Include="FileTypes\TorrentZipArchive.cs" /> <Compile Include="FileTypes\ZipArchive.cs" />
<Compile Include="FileTypes\XZArchive.cs" /> <Compile Include="FileTypes\XZArchive.cs" />
<Compile Include="FileTypes\ZPAQArchive.cs" /> <Compile Include="FileTypes\ZPAQArchive.cs" />
<Compile Include="FileTypes\ZstdArchive.cs" /> <Compile Include="FileTypes\ZstdArchive.cs" />

View File

@@ -470,7 +470,7 @@ namespace SabreTools.Library.Tools
archive = new TapeArchive(input); archive = new TapeArchive(input);
break; break;
case FileType.ZipArchive: case FileType.ZipArchive:
archive = new TorrentZipArchive(input); archive = new ZipArchive(input);
break; break;
default: default:
// We ignore all other types for now // We ignore all other types for now
@@ -498,7 +498,7 @@ namespace SabreTools.Library.Tools
case FileType.TapeArchive: case FileType.TapeArchive:
return new TapeArchive(); return new TapeArchive();
case FileType.ZipArchive: case FileType.ZipArchive:
return new TorrentZipArchive(); return new ZipArchive();
default: default:
return null; return null;
} }
@@ -530,7 +530,7 @@ namespace SabreTools.Library.Tools
case OutputFormat.TorrentXZ: case OutputFormat.TorrentXZ:
return new XZArchive(); return new XZArchive();
case OutputFormat.TorrentZip: case OutputFormat.TorrentZip:
return new TorrentZipArchive(); return new ZipArchive();
case OutputFormat.TorrentZPAQ: case OutputFormat.TorrentZPAQ:
return new ZPAQArchive(); return new ZPAQArchive();
case OutputFormat.TorrentZstd: case OutputFormat.TorrentZstd: