Sync Compress and RVIO with latest from RVWorld

This commit is contained in:
Matt Nadareski
2023-04-21 15:04:31 -04:00
parent de59a91bef
commit ac718efa78
116 changed files with 5197 additions and 3669 deletions

View File

@@ -6,7 +6,6 @@ using System.Linq;
using SabreTools.Core;
using SabreTools.Core.Tools;
using Compress;
using Compress.Utils;
using Compress.ZipFile;
using NaturalSort;
@@ -84,7 +83,7 @@ namespace SabreTools.FileTypes.Archives
ZipReturn zr = zf.ZipFileOpen(this.Filename, -1, true);
if (zr != ZipReturn.ZipGood)
{
throw new Exception(ZipUtils.ZipErrorMessageText(zr));
throw new Exception(CompressUtils.ZipErrorMessageText(zr));
}
for (int i = 0; i < zf.LocalFilesCount() && zr == ZipReturn.ZipGood; i++)
@@ -93,21 +92,21 @@ namespace SabreTools.FileTypes.Archives
zr = zf.ZipFileOpenReadStream(i, false, out Stream readStream, out ulong streamsize, out ushort cm);
// Create the rest of the path, if needed
if (!string.IsNullOrWhiteSpace(Path.GetDirectoryName(zf.Filename(i))))
if (!string.IsNullOrWhiteSpace(Path.GetDirectoryName(zf.GetLocalFile(i).Filename)))
{
Directory.CreateDirectory(Path.Combine(outDir, Path.GetDirectoryName(zf.Filename(i))));
Directory.CreateDirectory(Path.Combine(outDir, Path.GetDirectoryName(zf.GetLocalFile(i).Filename)));
}
// If the entry ends with a directory separator, continue to the next item, if any
if (zf.Filename(i).EndsWith(Path.DirectorySeparatorChar.ToString())
|| zf.Filename(i).EndsWith(Path.AltDirectorySeparatorChar.ToString())
|| zf.Filename(i).EndsWith(Path.PathSeparator.ToString()))
if (zf.GetLocalFile(i).Filename.EndsWith(Path.DirectorySeparatorChar.ToString())
|| zf.GetLocalFile(i).Filename.EndsWith(Path.AltDirectorySeparatorChar.ToString())
|| zf.GetLocalFile(i).Filename.EndsWith(Path.PathSeparator.ToString()))
{
zf.ZipFileCloseReadStream();
continue;
}
FileStream writeStream = File.Create(Path.Combine(outDir, zf.Filename(i)));
FileStream writeStream = File.Create(Path.Combine(outDir, zf.GetLocalFile(i).Filename));
// If the stream is smaller than the buffer, just run one loop through to avoid issues
if (streamsize < _bufferSize)
@@ -209,15 +208,15 @@ namespace SabreTools.FileTypes.Archives
ZipReturn zr = zf.ZipFileOpen(this.Filename, -1, true);
if (zr != ZipReturn.ZipGood)
{
throw new Exception(ZipUtils.ZipErrorMessageText(zr));
throw new Exception(CompressUtils.ZipErrorMessageText(zr));
}
for (int i = 0; i < zf.LocalFilesCount() && zr == ZipReturn.ZipGood; i++)
{
if (zf.Filename(i).Contains(entryName))
if (zf.GetLocalFile(i).Filename.Contains(entryName))
{
// Open the read stream
realEntry = zf.Filename(i);
realEntry = zf.GetLocalFile(i).Filename;
zr = zf.ZipFileOpenReadStream(i, false, out Stream readStream, out ulong streamsize, out ushort cm);
// If the stream is smaller than the buffer, just run one loop through to avoid issues
@@ -278,16 +277,16 @@ namespace SabreTools.FileTypes.Archives
ZipReturn zr = zf.ZipFileOpen(this.Filename, -1, true);
if (zr != ZipReturn.ZipGood)
{
throw new Exception(ZipUtils.ZipErrorMessageText(zr));
throw new Exception(CompressUtils.ZipErrorMessageText(zr));
}
for (int i = 0; i < zf.LocalFilesCount(); i++)
{
// If the entry is a directory (or looks like a directory), we don't want to open it
if (zf.IsDirectory(i)
|| zf.Filename(i).EndsWith(Path.DirectorySeparatorChar.ToString())
|| zf.Filename(i).EndsWith(Path.AltDirectorySeparatorChar.ToString())
|| zf.Filename(i).EndsWith(Path.PathSeparator.ToString()))
if (zf.GetLocalFile(i).IsDirectory
|| zf.GetLocalFile(i).Filename.EndsWith(Path.DirectorySeparatorChar.ToString())
|| zf.GetLocalFile(i).Filename.EndsWith(Path.AltDirectorySeparatorChar.ToString())
|| zf.GetLocalFile(i).Filename.EndsWith(Path.PathSeparator.ToString()))
{
continue;
}
@@ -309,19 +308,19 @@ namespace SabreTools.FileTypes.Archives
// Perform a quickscan, if flagged to
if (this.AvailableHashes == Hash.CRC)
{
zipEntryRom.Size = (long)zf.UncompressedSize(i);
zipEntryRom.CRC = zf.CRC32(i);
zipEntryRom.Size = (long)zf.GetLocalFile(i).UncompressedSize;
zipEntryRom.CRC = zf.GetLocalFile(i).CRC;
}
// Otherwise, use the stream directly
else
{
zipEntryRom = GetInfo(readStream, size: (long)zf.UncompressedSize(i), hashes: this.AvailableHashes, keepReadOpen: true);
zipEntryRom = GetInfo(readStream, size: (long)zf.GetLocalFile(i).UncompressedSize, hashes: this.AvailableHashes, keepReadOpen: true);
}
// Fill in comon details and add to the list
zipEntryRom.Filename = zf.Filename(i);
zipEntryRom.Filename = zf.GetLocalFile(i).Filename;
zipEntryRom.Parent = gamename;
zipEntryRom.Date = zf.LastModified(i).ToString("yyyy/MM/dd hh:mm:ss");
zipEntryRom.Date = zf.GetLocalFile(i).LastModified.ToString("yyyy/MM/dd hh:mm:ss");
found.Add(zipEntryRom);
}
@@ -349,13 +348,13 @@ namespace SabreTools.FileTypes.Archives
ZipReturn zr = zf.ZipFileOpen(this.Filename, -1, true);
if (zr != ZipReturn.ZipGood)
{
throw new Exception(ZipUtils.ZipErrorMessageText(zr));
throw new Exception(CompressUtils.ZipErrorMessageText(zr));
}
List<(string, bool)> zipEntries = new();
for (int i = 0; i < zf.LocalFilesCount(); i++)
{
zipEntries.Add((zf.Filename(i), zf.IsDirectory(i)));
zipEntries.Add((zf.GetLocalFile(i).Filename, zf.GetLocalFile(i).IsDirectory));
}
zipEntries = zipEntries.OrderBy(p => p.Item1, new NaturalReversedComparer()).ToList();
@@ -393,7 +392,7 @@ namespace SabreTools.FileTypes.Archives
ZipReturn zr = zf.ZipFileOpen(this.Filename, -1, true);
if (zr != ZipReturn.ZipGood)
{
throw new Exception(ZipUtils.ZipErrorMessageText(zr));
throw new Exception(CompressUtils.ZipErrorMessageText(zr));
}
return zf.ZipStatus == ZipStatus.TrrntZip;
@@ -486,7 +485,7 @@ namespace SabreTools.FileTypes.Archives
var oldZipFileContents = new List<string>();
for (int i = 0; i < oldZipFile.LocalFilesCount(); i++)
{
oldZipFileContents.Add(oldZipFile.Filename(i));
oldZipFileContents.Add(oldZipFile.GetLocalFile(i).Filename);
}
// If the old one doesn't contain the new file, then add it
@@ -496,7 +495,7 @@ namespace SabreTools.FileTypes.Archives
// Then add all of the old entries to it too
for (int i = 0; i < oldZipFile.LocalFilesCount(); i++)
{
inputIndexMap.Add(oldZipFile.Filename(i), i);
inputIndexMap.Add(oldZipFile.GetLocalFile(i).Filename, i);
}
// If the number of entries is the same as the old archive, skip out
@@ -511,7 +510,7 @@ namespace SabreTools.FileTypes.Archives
// Get the order for the entries with the new file
List<string> keys = inputIndexMap.Keys.ToList();
keys.Sort(ZipUtils.TrrntZipStringCompare);
keys.Sort(CompressUtils.TrrntZipStringCompare);
// Copy over all files to the new archive
foreach (string key in keys)
@@ -554,9 +553,9 @@ namespace SabreTools.FileTypes.Archives
{
// Instantiate the streams
oldZipFile.ZipFileOpenReadStream(index, false, out Stream zreadStream, out ulong istreamSize, out ushort icompressionMethod);
long msDosDateTime = oldZipFile.LastModified(index);
long msDosDateTime = oldZipFile.GetLocalFile(index).LastModified;
TimeStamps ts = new() { ModTime = msDosDateTime };
zipFile.ZipFileOpenWriteStream(false, true, oldZipFile.Filename(index), istreamSize, (ushort)CompressionMethod.Deflated, out writeStream, ts);
zipFile.ZipFileOpenWriteStream(false, true, oldZipFile.GetLocalFile(index).Filename, istreamSize, (ushort)CompressionMethod.Deflated, out writeStream, ts);
// Copy the input stream to the output
byte[] ibuffer = new byte[_bufferSize];
@@ -568,7 +567,7 @@ namespace SabreTools.FileTypes.Archives
}
oldZipFile.ZipFileCloseReadStream();
zipFile.ZipFileCloseWriteStream(oldZipFile.CRC32(index));
zipFile.ZipFileCloseWriteStream(oldZipFile.GetLocalFile(index).CRC);
}
}
}
@@ -655,7 +654,7 @@ namespace SabreTools.FileTypes.Archives
// Sort the keys in TZIP order
List<string> keys = inputIndexMap.Keys.ToList();
keys.Sort(ZipUtils.TrrntZipStringCompare);
keys.Sort(CompressUtils.TrrntZipStringCompare);
// Now add all of the files in order
foreach (string key in keys)
@@ -706,7 +705,7 @@ namespace SabreTools.FileTypes.Archives
var oldZipFileContents = new List<string>();
for (int j = 0; j < oldZipFile.LocalFilesCount(); j++)
{
oldZipFileContents.Add(oldZipFile.Filename(j));
oldZipFileContents.Add(oldZipFile.GetLocalFile(j).Filename);
}
// If the old one contains the new file, then just skip out
@@ -721,7 +720,7 @@ namespace SabreTools.FileTypes.Archives
// Then add all of the old entries to it too
for (int i = 0; i < oldZipFile.LocalFilesCount(); i++)
{
inputIndexMap.Add(oldZipFile.Filename(i), i);
inputIndexMap.Add(oldZipFile.GetLocalFile(i).Filename, i);
}
// If the number of entries is the same as the old archive, skip out
@@ -736,7 +735,7 @@ namespace SabreTools.FileTypes.Archives
// Get the order for the entries with the new file
List<string> keys = inputIndexMap.Keys.ToList();
keys.Sort(ZipUtils.TrrntZipStringCompare);
keys.Sort(CompressUtils.TrrntZipStringCompare);
// Copy over all files to the new archive
foreach (string key in keys)
@@ -780,9 +779,9 @@ namespace SabreTools.FileTypes.Archives
{
// Instantiate the streams
oldZipFile.ZipFileOpenReadStream(index, false, out Stream zreadStream, out ulong istreamSize, out ushort icompressionMethod);
long msDosDateTime = oldZipFile.LastModified(index);
long msDosDateTime = oldZipFile.GetLocalFile(index).LastModified;
TimeStamps ts = new() { ModTime = msDosDateTime };
zipFile.ZipFileOpenWriteStream(false, true, oldZipFile.Filename(index), istreamSize, (ushort)CompressionMethod.Deflated, out writeStream, ts);
zipFile.ZipFileOpenWriteStream(false, true, oldZipFile.GetLocalFile(index).Filename, istreamSize, (ushort)CompressionMethod.Deflated, out writeStream, ts);
// Copy the input stream to the output
byte[] ibuffer = new byte[_bufferSize];
@@ -793,7 +792,7 @@ namespace SabreTools.FileTypes.Archives
writeStream.Flush();
}
zipFile.ZipFileCloseWriteStream(oldZipFile.CRC32(index));
zipFile.ZipFileCloseWriteStream(oldZipFile.GetLocalFile(index).CRC);
}
}
}