mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Support ancient .NET in FileTypes
This commit is contained in:
@@ -1054,7 +1054,11 @@ namespace SabreTools.DatFiles
|
||||
// Add the list back to the dictionary
|
||||
Reset(key);
|
||||
AddRange(key, sortedlist);
|
||||
#if NET40_OR_GREATER || NETCOREAPP
|
||||
});
|
||||
#else
|
||||
}
|
||||
#endif
|
||||
}
|
||||
// If the merge type is the same, we want to sort the dictionary to be consistent
|
||||
else
|
||||
@@ -1068,7 +1072,11 @@ namespace SabreTools.DatFiles
|
||||
// Sort the list of items to be consistent
|
||||
if (sortedlist != null)
|
||||
DatItem.Sort(ref sortedlist, false);
|
||||
#if NET40_OR_GREATER || NETCOREAPP
|
||||
});
|
||||
#else
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1254,7 +1254,11 @@ CREATE TABLE IF NOT EXISTS groups (
|
||||
// Add the list back to the dictionary
|
||||
Reset(key);
|
||||
AddRange(key, sortedlist);
|
||||
#if NET40_OR_GREATER || NETCOREAPP
|
||||
});
|
||||
#else
|
||||
}
|
||||
#endif
|
||||
}
|
||||
// If the merge type is the same, we want to sort the dictionary to be consistent
|
||||
else
|
||||
@@ -1268,7 +1272,11 @@ CREATE TABLE IF NOT EXISTS groups (
|
||||
// Sort the list of items to be consistent
|
||||
if (sortedlist != null)
|
||||
DatItem.Sort(ref sortedlist, false);
|
||||
#if NET40_OR_GREATER || NETCOREAPP
|
||||
});
|
||||
#else
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -66,7 +66,11 @@ namespace SabreTools.DatTools
|
||||
|
||||
datFile.Items.Remove(key);
|
||||
datFile.Items.AddRange(key, newItems);
|
||||
#if NET40_OR_GREATER || NETCOREAPP
|
||||
});
|
||||
#else
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -117,7 +121,11 @@ namespace SabreTools.DatTools
|
||||
// Now add the new list to the key
|
||||
intDat.Items.Remove(key);
|
||||
intDat.Items.AddRange(key, newDatItems);
|
||||
#if NET40_OR_GREATER || NETCOREAPP
|
||||
});
|
||||
#else
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// If we are matching based on Machine fields of any sort
|
||||
@@ -152,7 +160,11 @@ namespace SabreTools.DatTools
|
||||
// Now add the new list to the key
|
||||
intDat.Items.Remove(key);
|
||||
intDat.Items.AddRange(key, newDatItems);
|
||||
#if NET40_OR_GREATER || NETCOREAPP
|
||||
});
|
||||
#else
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
watch.Stop();
|
||||
@@ -234,7 +246,11 @@ namespace SabreTools.DatTools
|
||||
intDat.Items.Remove(key);
|
||||
intDat.Items.AddRange(key, keepDatItems);
|
||||
}
|
||||
#if NET40_OR_GREATER || NETCOREAPP
|
||||
});
|
||||
#else
|
||||
}
|
||||
#endif
|
||||
|
||||
watch.Stop();
|
||||
}
|
||||
@@ -336,7 +352,11 @@ namespace SabreTools.DatTools
|
||||
dupeData.Items.Add(key, newrom);
|
||||
}
|
||||
}
|
||||
#if NET40_OR_GREATER || NETCOREAPP
|
||||
});
|
||||
#else
|
||||
}
|
||||
#endif
|
||||
|
||||
watch.Stop();
|
||||
|
||||
@@ -412,7 +432,11 @@ namespace SabreTools.DatTools
|
||||
if (item.DupeType.HasFlag(DupeType.Internal) || item.DupeType == 0x00)
|
||||
outDats[item.Source.Index].Items.Add(key, item);
|
||||
}
|
||||
#if NET40_OR_GREATER || NETCOREAPP
|
||||
});
|
||||
#else
|
||||
}
|
||||
#endif
|
||||
|
||||
watch.Stop();
|
||||
|
||||
@@ -481,7 +505,11 @@ namespace SabreTools.DatTools
|
||||
outerDiffData.Items.Add(key, newrom);
|
||||
}
|
||||
}
|
||||
#if NET40_OR_GREATER || NETCOREAPP
|
||||
});
|
||||
#else
|
||||
}
|
||||
#endif
|
||||
|
||||
watch.Stop();
|
||||
|
||||
@@ -581,7 +609,11 @@ namespace SabreTools.DatTools
|
||||
if (item.Source != null && item.Source.Index == index)
|
||||
indexDat.Items.Add(key, item);
|
||||
}
|
||||
#if NET40_OR_GREATER || NETCOREAPP
|
||||
});
|
||||
#else
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,7 +64,11 @@ namespace SabreTools.DatTools
|
||||
Parallel.ForEach(files, Globals.ParallelOptions, item =>
|
||||
{
|
||||
Interlocked.Add(ref totalSize, new FileInfo(item).Length);
|
||||
#if NET40_OR_GREATER || NETCOREAPP
|
||||
});
|
||||
#else
|
||||
}
|
||||
#endif
|
||||
|
||||
// Process the files in the main folder or any subfolder
|
||||
logger.User(totalSize, currentSize);
|
||||
@@ -226,7 +230,11 @@ namespace SabreTools.DatTools
|
||||
return;
|
||||
|
||||
ProcessFileHelper(datFile, item, datItem, basePath, parent);
|
||||
#if NET40_OR_GREATER || NETCOREAPP
|
||||
});
|
||||
#else
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -252,7 +260,11 @@ namespace SabreTools.DatTools
|
||||
{
|
||||
Rom emptyRom = new(Path.Combine(empty, "_"), item);
|
||||
ProcessFileHelper(datFile, item, emptyRom, basePath, parent);
|
||||
#if NET40_OR_GREATER || NETCOREAPP
|
||||
});
|
||||
#else
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -308,7 +320,11 @@ namespace SabreTools.DatTools
|
||||
|
||||
logger.Verbose($"Adding blank empty folder: {gamename}");
|
||||
datFile.Items["null"]?.Add(new Rom(romname, gamename));
|
||||
#if NET40_OR_GREATER || NETCOREAPP
|
||||
});
|
||||
#else
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -87,7 +87,11 @@ namespace SabreTools.DatTools
|
||||
directories.Add(input);
|
||||
}
|
||||
}
|
||||
#if NET40_OR_GREATER || NETCOREAPP
|
||||
});
|
||||
#else
|
||||
}
|
||||
#endif
|
||||
|
||||
// If we don't have any directories, we want to exit
|
||||
if (directories.Count == 0)
|
||||
|
||||
@@ -85,7 +85,11 @@ namespace SabreTools.DatTools
|
||||
extBDat.Items.Add(key, item);
|
||||
}
|
||||
}
|
||||
#if NET40_OR_GREATER || NETCOREAPP
|
||||
});
|
||||
#else
|
||||
}
|
||||
#endif
|
||||
|
||||
// Then return both DatFiles
|
||||
watch.Stop();
|
||||
@@ -212,7 +216,11 @@ namespace SabreTools.DatTools
|
||||
fieldDats[DatItemField.NULL].Items.Add(key, item);
|
||||
}
|
||||
}
|
||||
#if NET40_OR_GREATER || NETCOREAPP
|
||||
});
|
||||
#else
|
||||
}
|
||||
#endif
|
||||
|
||||
watch.Stop();
|
||||
return fieldDats;
|
||||
@@ -265,7 +273,11 @@ namespace SabreTools.DatTools
|
||||
|
||||
// Then set the DAT name to be the parent directory name
|
||||
tempDat.Header.Name = Path.GetDirectoryName(key);
|
||||
#if NET40_OR_GREATER || NETCOREAPP
|
||||
});
|
||||
#else
|
||||
}
|
||||
#endif
|
||||
|
||||
watch.Stop();
|
||||
return true;
|
||||
@@ -366,7 +378,11 @@ namespace SabreTools.DatTools
|
||||
else if (item.ItemType == ItemType.Rom && (item as Rom)!.Size >= radix)
|
||||
greaterThan.Items.Add(key, item);
|
||||
}
|
||||
#if NET40_OR_GREATER || NETCOREAPP
|
||||
});
|
||||
#else
|
||||
}
|
||||
#endif
|
||||
|
||||
// Then return both DatFiles
|
||||
watch.Stop();
|
||||
@@ -497,7 +513,11 @@ namespace SabreTools.DatTools
|
||||
Parallel.ForEach(outputTypes, Globals.ParallelOptions, itemType =>
|
||||
{
|
||||
FillWithItemType(datFile, typeDats[itemType], itemType);
|
||||
#if NET40_OR_GREATER || NETCOREAPP
|
||||
});
|
||||
#else
|
||||
}
|
||||
#endif
|
||||
|
||||
watch.Stop();
|
||||
return typeDats;
|
||||
@@ -526,7 +546,11 @@ namespace SabreTools.DatTools
|
||||
if (item.ItemType == itemType)
|
||||
indexDat.Items.Add(key, item);
|
||||
}
|
||||
#if NET40_OR_GREATER || NETCOREAPP
|
||||
});
|
||||
#else
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -182,8 +182,11 @@ namespace SabreTools.DatTools
|
||||
{
|
||||
logger.Error(ex, $"Report '{outfile}' could not be written out");
|
||||
}
|
||||
|
||||
#if NET40_OR_GREATER || NETCOREAPP
|
||||
});
|
||||
#else
|
||||
}
|
||||
#endif
|
||||
}
|
||||
catch (Exception ex) when (!throwOnError)
|
||||
{
|
||||
|
||||
@@ -78,6 +78,7 @@ namespace SabreTools.DatTools
|
||||
try
|
||||
{
|
||||
// Write out all required formats
|
||||
|
||||
Parallel.ForEach(outfiles.Keys, Globals.ParallelOptions, datFormat =>
|
||||
{
|
||||
string outfile = outfiles[datFormat];
|
||||
@@ -89,8 +90,11 @@ namespace SabreTools.DatTools
|
||||
{
|
||||
logger.Error(ex, $"Datfile '{outfile}' could not be written out");
|
||||
}
|
||||
|
||||
#if NET40_OR_GREATER || NETCOREAPP
|
||||
});
|
||||
#else
|
||||
}
|
||||
#endif
|
||||
}
|
||||
catch (Exception ex) when (!throwOnError)
|
||||
{
|
||||
|
||||
@@ -119,7 +119,11 @@ namespace SabreTools.FileTypes.Aaru
|
||||
{
|
||||
AaruFormat aif = new();
|
||||
|
||||
#if NET20 || NET35 || NET40
|
||||
using (BinaryReader br = new(stream, Encoding.Default))
|
||||
#else
|
||||
using (BinaryReader br = new(stream, Encoding.Default, true))
|
||||
#endif
|
||||
{
|
||||
aif.Identifier = br.ReadUInt64();
|
||||
aif.Application = Encoding.Unicode.GetString(br.ReadBytes(64), 0, 64);
|
||||
|
||||
@@ -27,7 +27,11 @@ namespace SabreTools.FileTypes.Aaru
|
||||
{
|
||||
var checksumEntry = new ChecksumEntry();
|
||||
|
||||
#if NET20 || NET35 || NET40
|
||||
using (var br = new BinaryReader(stream, Encoding.Default))
|
||||
#else
|
||||
using (var br = new BinaryReader(stream, Encoding.Default, true))
|
||||
#endif
|
||||
{
|
||||
checksumEntry.type = (AaruChecksumAlgorithm)br.ReadByte();
|
||||
checksumEntry.length = br.ReadUInt32();
|
||||
|
||||
@@ -26,7 +26,11 @@ namespace SabreTools.FileTypes.Aaru
|
||||
{
|
||||
ChecksumHeader checksumHeader = new ChecksumHeader();
|
||||
|
||||
using (BinaryReader br = new BinaryReader(stream, Encoding.Default, true))
|
||||
#if NET20 || NET35 || NET40
|
||||
using (var br = new BinaryReader(stream, Encoding.Default))
|
||||
#else
|
||||
using (var br = new BinaryReader(stream, Encoding.Default, true))
|
||||
#endif
|
||||
{
|
||||
checksumHeader.identifier = (AaruBlockType)br.ReadUInt32();
|
||||
checksumHeader.length = br.ReadUInt32();
|
||||
|
||||
@@ -25,7 +25,11 @@ namespace SabreTools.FileTypes.Aaru
|
||||
{
|
||||
IndexEntry indexEntry = new IndexEntry();
|
||||
|
||||
using (BinaryReader br = new BinaryReader(stream, Encoding.Default, true))
|
||||
#if NET20 || NET35 || NET40
|
||||
using (var br = new BinaryReader(stream, Encoding.Default))
|
||||
#else
|
||||
using (var br = new BinaryReader(stream, Encoding.Default, true))
|
||||
#endif
|
||||
{
|
||||
indexEntry.blockType = (AaruBlockType)br.ReadUInt32();
|
||||
indexEntry.dataType = (AaruDataType)br.ReadUInt16();
|
||||
|
||||
@@ -25,7 +25,11 @@ namespace SabreTools.FileTypes.Aaru
|
||||
{
|
||||
var indexHeader = new IndexHeader();
|
||||
|
||||
#if NET20 || NET35 || NET40
|
||||
using (var br = new BinaryReader(stream, Encoding.Default))
|
||||
#else
|
||||
using (var br = new BinaryReader(stream, Encoding.Default, true))
|
||||
#endif
|
||||
{
|
||||
indexHeader.identifier = (AaruBlockType)br.ReadUInt32();
|
||||
indexHeader.entries = br.ReadUInt16();
|
||||
|
||||
@@ -94,7 +94,16 @@ namespace SabreTools.FileTypes.Archives
|
||||
var gz = new gZip();
|
||||
ZipReturn ret = gz.ZipFileOpen(this.Filename);
|
||||
ret = gz.ZipFileOpenReadStream(0, out Stream gzstream, out ulong streamSize);
|
||||
#if NET20 || NET35
|
||||
byte[] buffer = new byte[32768];
|
||||
int read;
|
||||
while ((read = gzstream.Read(buffer, 0, buffer.Length)) > 0)
|
||||
{
|
||||
outstream.Write(buffer, 0, read);
|
||||
}
|
||||
#else
|
||||
gzstream.CopyTo(outstream);
|
||||
#endif
|
||||
|
||||
// Dispose of the streams
|
||||
outstream.Dispose();
|
||||
@@ -319,7 +328,9 @@ namespace SabreTools.FileTypes.Archives
|
||||
br.ReadBytes(16); // headermd5
|
||||
br.ReadBytes(4); // headercrc
|
||||
br.ReadUInt64(); // headersz
|
||||
#if NET40_OR_GREATER
|
||||
br.Dispose();
|
||||
#endif
|
||||
|
||||
// If the header is not correct, return a blank rom
|
||||
bool correct = true;
|
||||
@@ -382,7 +393,9 @@ namespace SabreTools.FileTypes.Archives
|
||||
headermd5 = br.ReadBytes(16);
|
||||
headercrc = br.ReadBytes(4);
|
||||
headersz = br.ReadUInt64();
|
||||
#if NET40_OR_GREATER
|
||||
br.Dispose();
|
||||
#endif
|
||||
|
||||
// If the header is not correct, return a blank rom
|
||||
bool correct = true;
|
||||
@@ -497,7 +510,9 @@ namespace SabreTools.FileTypes.Archives
|
||||
sw.Write((uint)(baseFile.Size ?? 0));
|
||||
|
||||
// Dispose of everything
|
||||
#if NET40_OR_GREATER
|
||||
sw.Dispose();
|
||||
#endif
|
||||
outputStream.Dispose();
|
||||
}
|
||||
|
||||
|
||||
@@ -2,11 +2,12 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
using SabreTools.Core;
|
||||
#if NET462_OR_GREATER || NETCOREAPP
|
||||
using SharpCompress.Archives;
|
||||
using SharpCompress.Archives.Rar;
|
||||
using SharpCompress.Readers;
|
||||
#endif
|
||||
|
||||
namespace SabreTools.FileTypes.Archives
|
||||
{
|
||||
@@ -45,6 +46,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
/// <inheritdoc/>
|
||||
public override bool CopyAll(string outDir)
|
||||
{
|
||||
#if NET462_OR_GREATER || NETCOREAPP
|
||||
bool encounteredErrors = true;
|
||||
|
||||
// If we have an invalid file
|
||||
@@ -82,6 +84,10 @@ namespace SabreTools.FileTypes.Archives
|
||||
}
|
||||
|
||||
return encounteredErrors;
|
||||
#else
|
||||
// TODO: Support RAR archives in old .NET
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
@@ -128,6 +134,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
/// <inheritdoc/>
|
||||
public override (MemoryStream?, string?) CopyToStream(string entryName)
|
||||
{
|
||||
#if NET462_OR_GREATER || NETCOREAPP
|
||||
MemoryStream? ms = new();
|
||||
string? realEntry = null;
|
||||
|
||||
@@ -157,6 +164,10 @@ namespace SabreTools.FileTypes.Archives
|
||||
}
|
||||
|
||||
return (ms, realEntry);
|
||||
#else
|
||||
// TODO: Support RAR archives in old .NET
|
||||
return (null, null);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -166,6 +177,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
/// <inheritdoc/>
|
||||
public override List<BaseFile>? GetChildren()
|
||||
{
|
||||
#if NET462_OR_GREATER || NETCOREAPP
|
||||
// If we have an invalid file
|
||||
if (this.Filename == null)
|
||||
return null;
|
||||
@@ -211,11 +223,16 @@ namespace SabreTools.FileTypes.Archives
|
||||
}
|
||||
|
||||
return found;
|
||||
#else
|
||||
// TODO: Support RAR archives in old .NET
|
||||
return null;
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override List<string> GetEmptyFolders()
|
||||
{
|
||||
#if NET462_OR_GREATER || NETCOREAPP
|
||||
List<string> empties = [];
|
||||
|
||||
// If we have an invalid file
|
||||
@@ -251,6 +268,10 @@ namespace SabreTools.FileTypes.Archives
|
||||
}
|
||||
|
||||
return empties;
|
||||
#else
|
||||
// TODO: Support RAR archives in old .NET
|
||||
return [];
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
|
||||
@@ -119,7 +119,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
zr = zf.ZipFileOpenReadStream(i, out Stream readStream, out ulong streamsize);
|
||||
|
||||
// Create the rest of the path, if needed
|
||||
if (!string.IsNullOrWhiteSpace(Path.GetDirectoryName(zf.GetLocalFile(i).Filename)))
|
||||
if (!string.IsNullOrEmpty(Path.GetDirectoryName(zf.GetLocalFile(i).Filename)))
|
||||
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
|
||||
@@ -492,7 +492,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
ulong istreamSize = (ulong)(inputStream.Length);
|
||||
|
||||
DateTime dt = DateTime.Now;
|
||||
if (UseDates && !string.IsNullOrWhiteSpace(baseFile.Date) && DateTime.TryParse(baseFile.Date.Replace('\\', '/'), out dt))
|
||||
if (UseDates && !string.IsNullOrEmpty(baseFile.Date) && DateTime.TryParse(baseFile.Date.Replace('\\', '/'), out dt))
|
||||
{
|
||||
long msDosDateTime = DateTimeHelper.ConvertToMsDosTimeFormat(dt);
|
||||
TimeStamps ts = new() { ModTime = msDosDateTime };
|
||||
@@ -571,7 +571,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
ulong istreamSize = (ulong)(inputStream.Length);
|
||||
|
||||
DateTime dt = DateTime.Now;
|
||||
if (UseDates && !string.IsNullOrWhiteSpace(baseFile.Date) && DateTime.TryParse(baseFile.Date.Replace('\\', '/'), out dt))
|
||||
if (UseDates && !string.IsNullOrEmpty(baseFile.Date) && DateTime.TryParse(baseFile.Date.Replace('\\', '/'), out dt))
|
||||
{
|
||||
long msDosDateTime = DateTimeHelper.ConvertToMsDosTimeFormat(dt);
|
||||
TimeStamps ts = new() { ModTime = msDosDateTime };
|
||||
@@ -715,7 +715,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
ulong istreamSize = (ulong)new FileInfo(inputFiles[index]).Length;
|
||||
|
||||
DateTime dt = DateTime.Now;
|
||||
if (UseDates && !string.IsNullOrWhiteSpace(baseFiles[index].Date) && DateTime.TryParse(baseFiles[index].Date?.Replace('\\', '/'), out dt))
|
||||
if (UseDates && !string.IsNullOrEmpty(baseFiles[index].Date) && DateTime.TryParse(baseFiles[index].Date?.Replace('\\', '/'), out dt))
|
||||
{
|
||||
long msDosDateTime = DateTimeHelper.ConvertToMsDosTimeFormat(dt);
|
||||
TimeStamps ts = new() { ModTime = msDosDateTime };
|
||||
@@ -799,7 +799,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
ulong istreamSize = (ulong)(new FileInfo(inputFiles[-index - 1]).Length);
|
||||
|
||||
DateTime dt = DateTime.Now;
|
||||
if (UseDates && !string.IsNullOrWhiteSpace(baseFiles[-index - 1].Date) && DateTime.TryParse(baseFiles[-index - 1].Date?.Replace('\\', '/'), out dt))
|
||||
if (UseDates && !string.IsNullOrEmpty(baseFiles[-index - 1].Date) && DateTime.TryParse(baseFiles[-index - 1].Date?.Replace('\\', '/'), out dt))
|
||||
{
|
||||
long msDosDateTime = DateTimeHelper.ConvertToMsDosTimeFormat(dt);
|
||||
TimeStamps ts = new() { ModTime = msDosDateTime };
|
||||
|
||||
@@ -2,15 +2,16 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
using SabreTools.Core;
|
||||
using SabreTools.Core.Tools;
|
||||
using Compress;
|
||||
#if NET462_OR_GREATER || NETCOREAPP
|
||||
using SharpCompress.Archives;
|
||||
using SharpCompress.Archives.Tar;
|
||||
using SharpCompress.Common;
|
||||
using SharpCompress.Readers;
|
||||
using SharpCompress.Writers;
|
||||
#endif
|
||||
|
||||
namespace SabreTools.FileTypes.Archives
|
||||
{
|
||||
@@ -50,6 +51,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
/// <inheritdoc/>
|
||||
public override bool CopyAll(string outDir)
|
||||
{
|
||||
#if NET462_OR_GREATER || NETCOREAPP
|
||||
bool encounteredErrors = true;
|
||||
|
||||
try
|
||||
@@ -83,6 +85,10 @@ namespace SabreTools.FileTypes.Archives
|
||||
}
|
||||
|
||||
return encounteredErrors;
|
||||
#else
|
||||
// TODO: Support tape archives in old .NET
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
@@ -129,6 +135,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
/// <inheritdoc/>
|
||||
public override (MemoryStream?, string?) CopyToStream(string entryName)
|
||||
{
|
||||
#if NET462_OR_GREATER || NETCOREAPP
|
||||
MemoryStream? ms = new();
|
||||
string? realEntry = null;
|
||||
|
||||
@@ -154,6 +161,10 @@ namespace SabreTools.FileTypes.Archives
|
||||
}
|
||||
|
||||
return (ms, realEntry);
|
||||
#else
|
||||
// TODO: Support tape archives in old .NET
|
||||
return (null, null);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -163,7 +174,8 @@ namespace SabreTools.FileTypes.Archives
|
||||
/// <inheritdoc/>
|
||||
public override List<BaseFile>? GetChildren()
|
||||
{
|
||||
List<BaseFile> found = new();
|
||||
#if NET462_OR_GREATER || NETCOREAPP
|
||||
List<BaseFile> found = [];
|
||||
string? gamename = Path.GetFileNameWithoutExtension(this.Filename);
|
||||
|
||||
try
|
||||
@@ -204,12 +216,17 @@ namespace SabreTools.FileTypes.Archives
|
||||
}
|
||||
|
||||
return found;
|
||||
#else
|
||||
// TODO: Support tape archives in old .NET
|
||||
return null;
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override List<string> GetEmptyFolders()
|
||||
{
|
||||
List<string> empties = new();
|
||||
#if NET462_OR_GREATER || NETCOREAPP
|
||||
List<string> empties = [];
|
||||
|
||||
try
|
||||
{
|
||||
@@ -240,6 +257,10 @@ namespace SabreTools.FileTypes.Archives
|
||||
}
|
||||
|
||||
return empties;
|
||||
#else
|
||||
// TODO: Support tape archives in old .NET
|
||||
return [];
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
@@ -262,6 +283,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
/// <inheritdoc/>
|
||||
public override bool Write(Stream? inputStream, string outDir, BaseFile? baseFile)
|
||||
{
|
||||
#if NET462_OR_GREATER || NETCOREAPP
|
||||
bool success = false;
|
||||
string tempFile = Path.Combine(outDir, $"tmp{Guid.NewGuid()}");
|
||||
|
||||
@@ -291,7 +313,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
{
|
||||
// Get temporary date-time if possible
|
||||
DateTime? usableDate = null;
|
||||
if (UseDates && !string.IsNullOrWhiteSpace(baseFile.Date) && DateTime.TryParse(baseFile.Date.Replace('\\', '/'), out DateTime dt))
|
||||
if (UseDates && !string.IsNullOrEmpty(baseFile.Date) && DateTime.TryParse(baseFile.Date.Replace('\\', '/'), out DateTime dt))
|
||||
usableDate = dt;
|
||||
|
||||
// Copy the input stream to the output
|
||||
@@ -340,7 +362,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
|
||||
// Get temporary date-time if possible
|
||||
DateTime? usableDate = null;
|
||||
if (UseDates && !string.IsNullOrWhiteSpace(baseFile.Date) && DateTime.TryParse(baseFile.Date.Replace('\\', '/'), out DateTime dt))
|
||||
if (UseDates && !string.IsNullOrEmpty(baseFile.Date) && DateTime.TryParse(baseFile.Date.Replace('\\', '/'), out DateTime dt))
|
||||
usableDate = dt;
|
||||
|
||||
// If we have the input file, add it now
|
||||
@@ -388,11 +410,16 @@ namespace SabreTools.FileTypes.Archives
|
||||
File.Move(tempFile, archiveFileName);
|
||||
|
||||
return success;
|
||||
#else
|
||||
// TODO: Support tape archives in old .NET
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool Write(List<string> inputFiles, string outDir, List<BaseFile>? baseFiles)
|
||||
{
|
||||
#if NET462_OR_GREATER || NETCOREAPP
|
||||
bool success = false;
|
||||
string tempFile = Path.Combine(outDir, $"tmp{Guid.NewGuid()}");
|
||||
|
||||
@@ -454,7 +481,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
|
||||
// Get temporary date-time if possible
|
||||
DateTime? usableDate = null;
|
||||
if (UseDates && !string.IsNullOrWhiteSpace(baseFiles[index].Date) && DateTime.TryParse(baseFiles[index].Date?.Replace('\\', '/'), out DateTime dt))
|
||||
if (UseDates && !string.IsNullOrEmpty(baseFiles[index].Date) && DateTime.TryParse(baseFiles[index].Date?.Replace('\\', '/'), out DateTime dt))
|
||||
usableDate = dt;
|
||||
|
||||
// Copy the input stream to the output
|
||||
@@ -512,7 +539,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
{
|
||||
// Get temporary date-time if possible
|
||||
DateTime? usableDate = null;
|
||||
if (UseDates && !string.IsNullOrWhiteSpace(baseFiles[-index - 1].Date) && DateTime.TryParse(baseFiles[-index - 1].Date?.Replace('\\', '/'), out DateTime dt))
|
||||
if (UseDates && !string.IsNullOrEmpty(baseFiles[-index - 1].Date) && DateTime.TryParse(baseFiles[-index - 1].Date?.Replace('\\', '/'), out DateTime dt))
|
||||
usableDate = dt;
|
||||
|
||||
// Copy the input file to the output
|
||||
@@ -557,6 +584,10 @@ namespace SabreTools.FileTypes.Archives
|
||||
File.Move(tempFile, archiveFileName);
|
||||
|
||||
return true;
|
||||
#else
|
||||
// TODO: Support tape archives in old .NET
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -2,11 +2,12 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
using SabreTools.Core;
|
||||
using SabreTools.Core.Tools;
|
||||
using SabreTools.IO;
|
||||
#if NET462_OR_GREATER || NETCOREAPP
|
||||
using SharpCompress.Compressors.Xz;
|
||||
#endif
|
||||
|
||||
namespace SabreTools.FileTypes.Archives
|
||||
{
|
||||
@@ -67,6 +68,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
/// <inheritdoc/>
|
||||
public override bool CopyAll(string outDir)
|
||||
{
|
||||
#if NET462_OR_GREATER || NETCOREAPP
|
||||
bool encounteredErrors = true;
|
||||
|
||||
try
|
||||
@@ -102,6 +104,10 @@ namespace SabreTools.FileTypes.Archives
|
||||
}
|
||||
|
||||
return encounteredErrors;
|
||||
#else
|
||||
// TODO: Support XZ archives in old .NET
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
@@ -148,6 +154,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
/// <inheritdoc/>
|
||||
public override (MemoryStream?, string?) CopyToStream(string entryName)
|
||||
{
|
||||
#if NET462_OR_GREATER || NETCOREAPP
|
||||
MemoryStream? ms = new();
|
||||
string? realEntry;
|
||||
|
||||
@@ -178,6 +185,10 @@ namespace SabreTools.FileTypes.Archives
|
||||
}
|
||||
|
||||
return (ms, realEntry);
|
||||
#else
|
||||
// TODO: Support XZ archives in old .NET
|
||||
return (null, null);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -187,9 +198,10 @@ namespace SabreTools.FileTypes.Archives
|
||||
/// <inheritdoc/>
|
||||
public override List<BaseFile>? GetChildren()
|
||||
{
|
||||
#if NET462_OR_GREATER || NETCOREAPP
|
||||
if (_children == null || _children.Count == 0)
|
||||
{
|
||||
_children = new List<BaseFile>();
|
||||
_children = [];
|
||||
|
||||
string? gamename = Path.GetFileNameWithoutExtension(this.Filename);
|
||||
|
||||
@@ -239,6 +251,10 @@ namespace SabreTools.FileTypes.Archives
|
||||
}
|
||||
|
||||
return _children;
|
||||
#else
|
||||
// TODO: Support XZ archives in old .NET
|
||||
return [];
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
@@ -320,6 +336,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
/// <inheritdoc/>
|
||||
public override bool Write(Stream? inputStream, string outDir, BaseFile? baseFile)
|
||||
{
|
||||
#if NET462_OR_GREATER || NETCOREAPP
|
||||
bool success = false;
|
||||
|
||||
// If the stream is not readable, return
|
||||
@@ -355,6 +372,10 @@ namespace SabreTools.FileTypes.Archives
|
||||
}
|
||||
|
||||
return true;
|
||||
#else
|
||||
// TODO: Support XZ archives in old .NET
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
|
||||
@@ -91,7 +91,7 @@ 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.GetLocalFile(i).Filename)))
|
||||
if (!string.IsNullOrEmpty(Path.GetDirectoryName(zf.GetLocalFile(i).Filename)))
|
||||
{
|
||||
Directory.CreateDirectory(Path.Combine(outDir, Path.GetDirectoryName(zf.GetLocalFile(i).Filename)!));
|
||||
}
|
||||
@@ -450,7 +450,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
ulong istreamSize = (ulong)(inputStream.Length);
|
||||
|
||||
DateTime dt = DateTime.Now;
|
||||
if (UseDates && !string.IsNullOrWhiteSpace(baseFile.Date) && DateTime.TryParse(baseFile.Date.Replace('\\', '/'), out dt))
|
||||
if (UseDates && !string.IsNullOrEmpty(baseFile.Date) && DateTime.TryParse(baseFile.Date.Replace('\\', '/'), out dt))
|
||||
{
|
||||
long msDosDateTime = DateTimeHelper.ConvertToMsDosTimeFormat(dt);
|
||||
TimeStamps ts = new() { ModTime = msDosDateTime };
|
||||
@@ -524,7 +524,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
ulong istreamSize = (ulong)(inputStream.Length);
|
||||
|
||||
DateTime dt = DateTime.Now;
|
||||
if (UseDates && !string.IsNullOrWhiteSpace(baseFile.Date) && DateTime.TryParse(baseFile.Date.Replace('\\', '/'), out dt))
|
||||
if (UseDates && !string.IsNullOrEmpty(baseFile.Date) && DateTime.TryParse(baseFile.Date.Replace('\\', '/'), out dt))
|
||||
{
|
||||
long msDosDateTime = DateTimeHelper.ConvertToMsDosTimeFormat(dt);
|
||||
TimeStamps ts = new() { ModTime = msDosDateTime };
|
||||
@@ -666,7 +666,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
ulong istreamSize = (ulong)(new FileInfo(inputFiles[index]).Length);
|
||||
|
||||
DateTime dt = DateTime.Now;
|
||||
if (UseDates && !string.IsNullOrWhiteSpace(baseFiles[index].Date) && DateTime.TryParse(baseFiles[index].Date?.Replace('\\', '/'), out dt))
|
||||
if (UseDates && !string.IsNullOrEmpty(baseFiles[index].Date) && DateTime.TryParse(baseFiles[index].Date?.Replace('\\', '/'), out dt))
|
||||
{
|
||||
long msDosDateTime = DateTimeHelper.ConvertToMsDosTimeFormat(dt);
|
||||
TimeStamps ts = new() { ModTime = msDosDateTime };
|
||||
@@ -750,7 +750,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
ulong istreamSize = (ulong)(new FileInfo(inputFiles[-index - 1]).Length);
|
||||
|
||||
DateTime dt = DateTime.Now;
|
||||
if (UseDates && !string.IsNullOrWhiteSpace(baseFiles[-index - 1].Date) && DateTime.TryParse(baseFiles[-index - 1].Date?.Replace('\\', '/'), out dt))
|
||||
if (UseDates && !string.IsNullOrEmpty(baseFiles[-index - 1].Date) && DateTime.TryParse(baseFiles[-index - 1].Date?.Replace('\\', '/'), out dt))
|
||||
{
|
||||
long msDosDateTime = DateTimeHelper.ConvertToMsDosTimeFormat(dt);
|
||||
TimeStamps ts = new() { ModTime = msDosDateTime };
|
||||
|
||||
@@ -201,7 +201,9 @@ namespace SabreTools.FileTypes
|
||||
// Read the first bytes of the file and get the magic number
|
||||
BinaryReader br = new(File.OpenRead(input));
|
||||
byte[] magic = br.ReadBytes(8);
|
||||
#if NET40_OR_GREATER
|
||||
br.Dispose();
|
||||
#endif
|
||||
|
||||
// Now try to match it to a known signature
|
||||
if (magic.StartsWith(SevenZipSignature))
|
||||
@@ -300,10 +302,17 @@ namespace SabreTools.FileTypes
|
||||
|
||||
// Get the info in the proper manner
|
||||
BaseFile? baseFile;
|
||||
#if NETFRAMEWORK
|
||||
if (fileType == FileType.AaruFormat && (asFiles & TreatAsFile.AaruFormat) == 0)
|
||||
baseFile = AaruFormat.Create(inputStream);
|
||||
else if (fileType == FileType.CHD && (asFiles & TreatAsFile.CHD) == 0)
|
||||
baseFile = CHDFile.Create(inputStream);
|
||||
#else
|
||||
if (fileType == FileType.AaruFormat && !asFiles.HasFlag(TreatAsFile.AaruFormat))
|
||||
baseFile = AaruFormat.Create(inputStream);
|
||||
else if (fileType == FileType.CHD && !asFiles.HasFlag(TreatAsFile.CHD))
|
||||
baseFile = CHDFile.Create(inputStream);
|
||||
#endif
|
||||
else
|
||||
baseFile = GetInfo(inputStream, hashes: hashes, keepReadOpen: false);
|
||||
|
||||
@@ -340,6 +349,22 @@ namespace SabreTools.FileTypes
|
||||
// Get a list of hashers to run over the buffer
|
||||
List<Hasher> hashers = [];
|
||||
|
||||
#if NETFRAMEWORK
|
||||
if ((hashes & Hash.CRC) != 0)
|
||||
hashers.Add(new Hasher(Hash.CRC));
|
||||
if ((hashes & Hash.MD5) != 0)
|
||||
hashers.Add(new Hasher(Hash.MD5));
|
||||
if ((hashes & Hash.SHA1) != 0)
|
||||
hashers.Add(new Hasher(Hash.SHA1));
|
||||
if ((hashes & Hash.SHA256) != 0)
|
||||
hashers.Add(new Hasher(Hash.SHA256));
|
||||
if ((hashes & Hash.SHA384) != 0)
|
||||
hashers.Add(new Hasher(Hash.SHA384));
|
||||
if ((hashes & Hash.SHA512) != 0)
|
||||
hashers.Add(new Hasher(Hash.SHA512));
|
||||
if ((hashes & Hash.SpamSum) != 0)
|
||||
hashers.Add(new Hasher(Hash.SpamSum));
|
||||
#else
|
||||
if (hashes.HasFlag(Hash.CRC))
|
||||
hashers.Add(new Hasher(Hash.CRC));
|
||||
if (hashes.HasFlag(Hash.MD5))
|
||||
@@ -354,6 +379,7 @@ namespace SabreTools.FileTypes
|
||||
hashers.Add(new Hasher(Hash.SHA512));
|
||||
if (hashes.HasFlag(Hash.SpamSum))
|
||||
hashers.Add(new Hasher(Hash.SpamSum));
|
||||
#endif
|
||||
|
||||
// Initialize the hashing helpers
|
||||
int buffersize = 3 * 1024 * 1024;
|
||||
@@ -376,7 +402,16 @@ namespace SabreTools.FileTypes
|
||||
{
|
||||
// Run hashes in parallel
|
||||
if (current > 0)
|
||||
#if NET452_OR_GREATER || NETCOREAPP
|
||||
Parallel.ForEach(hashers, Globals.ParallelOptions, h => h.Process(buffer, current));
|
||||
#elif NET40_OR_GREATER
|
||||
Parallel.ForEach(hashers, h => h.Process(buffer, current));
|
||||
#else
|
||||
foreach (var h in hashers)
|
||||
{
|
||||
h.Process(buffer, current);
|
||||
}
|
||||
#endif
|
||||
|
||||
// Load the next buffer
|
||||
refsize -= current;
|
||||
@@ -391,12 +426,30 @@ namespace SabreTools.FileTypes
|
||||
}
|
||||
|
||||
// Finalize all hashing helpers
|
||||
#if NET452_OR_GREATER || NETCOREAPP
|
||||
Parallel.ForEach(hashers, Globals.ParallelOptions, h => h.Terminate());
|
||||
#elif NET40_OR_GREATER
|
||||
Parallel.ForEach(hashers, h => h.Terminate());
|
||||
#else
|
||||
foreach (var h in hashers)
|
||||
{
|
||||
h.Terminate();
|
||||
}
|
||||
#endif
|
||||
|
||||
// Get the results
|
||||
BaseFile baseFile = new()
|
||||
{
|
||||
Size = size,
|
||||
#if NETFRAMEWORK
|
||||
CRC = (hashes & Hash.CRC) != 0 ? hashers.First(h => h.HashType == Hash.CRC).GetHash() : null,
|
||||
MD5 = (hashes & Hash.MD5) != 0 ? hashers.First(h => h.HashType == Hash.MD5).GetHash() : null,
|
||||
SHA1 = (hashes & Hash.SHA1) != 0 ? hashers.First(h => h.HashType == Hash.SHA1).GetHash() : null,
|
||||
SHA256 = (hashes & Hash.SHA256) != 0 ? hashers.First(h => h.HashType == Hash.SHA256).GetHash() : null,
|
||||
SHA384 = (hashes & Hash.SHA384) != 0 ? hashers.First(h => h.HashType == Hash.SHA384).GetHash() : null,
|
||||
SHA512 = (hashes & Hash.SHA512) != 0 ? hashers.First(h => h.HashType == Hash.SHA512).GetHash() : null,
|
||||
SpamSum = (hashes & Hash.SpamSum) != 0 ? hashers.First(h => h.HashType == Hash.SpamSum).GetHash() : null,
|
||||
#else
|
||||
CRC = hashes.HasFlag(Hash.CRC) ? hashers.First(h => h.HashType == Hash.CRC).GetHash() : null,
|
||||
MD5 = hashes.HasFlag(Hash.MD5) ? hashers.First(h => h.HashType == Hash.MD5).GetHash() : null,
|
||||
SHA1 = hashes.HasFlag(Hash.SHA1) ? hashers.First(h => h.HashType == Hash.SHA1).GetHash() : null,
|
||||
@@ -404,6 +457,7 @@ namespace SabreTools.FileTypes
|
||||
SHA384 = hashes.HasFlag(Hash.SHA384) ? hashers.First(h => h.HashType == Hash.SHA384).GetHash() : null,
|
||||
SHA512 = hashes.HasFlag(Hash.SHA512) ? hashers.First(h => h.HashType == Hash.SHA512).GetHash() : null,
|
||||
SpamSum = hashes.HasFlag(Hash.SpamSum) ? hashers.First(h => h.HashType == Hash.SpamSum).GetHash() : null,
|
||||
#endif
|
||||
};
|
||||
|
||||
// Dispose of the hashers
|
||||
|
||||
@@ -94,7 +94,11 @@ namespace SabreTools.FileTypes.CHD
|
||||
uint parsedLength = 0;
|
||||
uint parsedVersion = 0;
|
||||
|
||||
#if NET20 || NET35 || NET40
|
||||
using (BinaryReader br = new(stream, Encoding.Default))
|
||||
#else
|
||||
using (BinaryReader br = new(stream, Encoding.Default, true))
|
||||
#endif
|
||||
{
|
||||
parsedTag = br.ReadChars(8);
|
||||
parsedLength = br.ReadUInt32BigEndian();
|
||||
|
||||
@@ -60,7 +60,11 @@ namespace SabreTools.FileTypes.CHD
|
||||
{
|
||||
CHDFileV1 chd = new();
|
||||
|
||||
#if NET20 || NET35 || NET40
|
||||
using (BinaryReader br = new(stream, Encoding.Default))
|
||||
#else
|
||||
using (BinaryReader br = new(stream, Encoding.Default, true))
|
||||
#endif
|
||||
{
|
||||
chd.tag = br.ReadChars(8);
|
||||
chd.length = br.ReadUInt32BigEndian();
|
||||
|
||||
@@ -61,7 +61,11 @@ namespace SabreTools.FileTypes.CHD
|
||||
{
|
||||
CHDFileV2 chd = new();
|
||||
|
||||
using (BinaryReader br = new(stream, Encoding.Default, true))
|
||||
#if NET20 || NET35 || NET40
|
||||
using (var br = new BinaryReader(stream, Encoding.Default))
|
||||
#else
|
||||
using (var br = new BinaryReader(stream, Encoding.Default, true))
|
||||
#endif
|
||||
{
|
||||
chd.tag = br.ReadChars(8);
|
||||
chd.length = br.ReadUInt32BigEndian();
|
||||
|
||||
@@ -65,7 +65,11 @@ namespace SabreTools.FileTypes.CHD
|
||||
{
|
||||
CHDFileV3 chd = new();
|
||||
|
||||
using (BinaryReader br = new(stream, Encoding.Default, true))
|
||||
#if NET20 || NET35 || NET40
|
||||
using (var br = new BinaryReader(stream, Encoding.Default))
|
||||
#else
|
||||
using (var br = new BinaryReader(stream, Encoding.Default, true))
|
||||
#endif
|
||||
{
|
||||
chd.tag = br.ReadChars(8);
|
||||
chd.length = br.ReadUInt32BigEndian();
|
||||
|
||||
@@ -65,7 +65,11 @@ namespace SabreTools.FileTypes.CHD
|
||||
{
|
||||
CHDFileV4 chd = new();
|
||||
|
||||
#if NET20 || NET35 || NET40
|
||||
using (BinaryReader br = new(stream, Encoding.Default))
|
||||
#else
|
||||
using (BinaryReader br = new(stream, Encoding.Default, true))
|
||||
#endif
|
||||
{
|
||||
chd.tag = br.ReadChars(8);
|
||||
chd.length = br.ReadUInt32BigEndian();
|
||||
|
||||
@@ -64,7 +64,11 @@ namespace SabreTools.FileTypes.CHD
|
||||
{
|
||||
CHDFileV5 chd = new CHDFileV5();
|
||||
|
||||
#if NET20 || NET35 || NET40
|
||||
using (BinaryReader br = new BinaryReader(stream, Encoding.Default))
|
||||
#else
|
||||
using (BinaryReader br = new BinaryReader(stream, Encoding.Default, true))
|
||||
#endif
|
||||
{
|
||||
chd.tag = br.ReadChars(8);
|
||||
chd.length = br.ReadUInt32BigEndian();
|
||||
|
||||
@@ -32,7 +32,10 @@ namespace Compress
|
||||
{
|
||||
if (enc != null)
|
||||
return;
|
||||
|
||||
#if NET462_OR_GREATER || NETCOREAPP
|
||||
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
|
||||
#endif
|
||||
enc = Encoding.GetEncoding(437);
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,9 @@ using Compress.SevenZip.Structure;
|
||||
using Compress.Support.Compression.BZip2;
|
||||
using Compress.Support.Compression.LZMA;
|
||||
using Compress.Support.Compression.PPmd;
|
||||
#if NET462_OR_GREATER || NETCOREAPP
|
||||
using Compress.Support.Compression.zStd;
|
||||
#endif
|
||||
using Compress.Support.Filters;
|
||||
using FileStream = RVIO.FileStream;
|
||||
|
||||
@@ -163,9 +165,11 @@ namespace Compress.SevenZip
|
||||
case DecompressType.BCJ2:
|
||||
coder.DecoderStream = new BCJ2Filter(inputCoders[0], inputCoders[1], inputCoders[2], inputCoders[3]);
|
||||
break;
|
||||
#if NET462_OR_GREATER || NETCOREAPP
|
||||
case DecompressType.ZSTD:
|
||||
coder.DecoderStream =new zStdSharp(inputCoders[0]);
|
||||
coder.DecoderStream = new zStdSharp(inputCoders[0]);
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
return ZipReturn.ZipDecodeError;
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace Compress.SevenZip
|
||||
ZipStatus = ZipStatus.TrrntZip;
|
||||
}
|
||||
|
||||
private bool IsRomVault7Z(long testBaseOffset,ulong testHeaderPos,ulong testHeaderLength,uint testHeaderCRC)
|
||||
private bool IsRomVault7Z(long testBaseOffset, ulong testHeaderPos, ulong testHeaderLength, uint testHeaderCRC)
|
||||
{
|
||||
long length = _zipFs.Length;
|
||||
if (length < 32)
|
||||
@@ -52,7 +52,11 @@ namespace Compress.SevenZip
|
||||
uint headerCRC;
|
||||
ulong headerOffset; // is location of header in file
|
||||
ulong headerSize;
|
||||
#if NET20 || NET35 || NET40
|
||||
using (BinaryReader br = new(_zipFs, Encoding.UTF8))
|
||||
#else
|
||||
using (BinaryReader br = new(_zipFs, Encoding.UTF8, true))
|
||||
#endif
|
||||
{
|
||||
headerCRC = br.ReadUInt32();
|
||||
headerOffset = br.ReadUInt64();
|
||||
@@ -62,7 +66,7 @@ namespace Compress.SevenZip
|
||||
if (headerCRC != testHeaderCRC)
|
||||
return false;
|
||||
|
||||
if (headerOffset != testHeaderPos+(ulong)testBaseOffset)
|
||||
if (headerOffset != testHeaderPos + (ulong)testBaseOffset)
|
||||
return false;
|
||||
|
||||
return headerSize == testHeaderLength;
|
||||
|
||||
@@ -57,7 +57,11 @@ namespace Compress.SevenZip
|
||||
_signatureHeader = new SignatureHeader();
|
||||
_header = new Header();
|
||||
|
||||
#if NET20 || NET35 || NET40
|
||||
using (BinaryWriter bw = new(_zipFs, Encoding.UTF8))
|
||||
#else
|
||||
using (BinaryWriter bw = new(_zipFs, Encoding.UTF8, true))
|
||||
#endif
|
||||
{
|
||||
_signatureHeader.Write(bw);
|
||||
}
|
||||
@@ -179,6 +183,7 @@ namespace Compress.SevenZip
|
||||
_compressStream = lzs;
|
||||
break;
|
||||
|
||||
#if NET462_OR_GREATER || NETCOREAPP
|
||||
case SevenZipCompressType.zstd:
|
||||
|
||||
ZstdSharp.CompressionStream zss = new(_zipFs, 19);
|
||||
@@ -186,6 +191,7 @@ namespace Compress.SevenZip
|
||||
newStream.Properties = new byte[] { 1, 5, 19, 0, 0 };
|
||||
_compressStream = zss;
|
||||
break;
|
||||
#endif
|
||||
|
||||
case SevenZipCompressType.uncompressed:
|
||||
newStream.Method = new byte[] { 0 };
|
||||
|
||||
@@ -130,7 +130,11 @@ namespace Compress.SevenZip
|
||||
byte[] newHeaderByte;
|
||||
using (Stream headerMem = new MemoryStream())
|
||||
{
|
||||
#if NET20 || NET35 || NET40
|
||||
using BinaryWriter headerBw = new(headerMem, Encoding.UTF8);
|
||||
#else
|
||||
using BinaryWriter headerBw = new(headerMem, Encoding.UTF8, true);
|
||||
#endif
|
||||
_header.WriteHeader(headerBw);
|
||||
|
||||
newHeaderByte = new byte[headerMem.Length];
|
||||
@@ -140,7 +144,7 @@ namespace Compress.SevenZip
|
||||
|
||||
uint mainHeaderCRC = CRC.CalculateDigest(newHeaderByte, 0, (uint)newHeaderByte.Length);
|
||||
|
||||
#region Header Compression
|
||||
#region Header Compression
|
||||
long packedHeaderPos = _zipFs.Position;
|
||||
LzmaEncoderProperties ep = new(true, GetDictionarySizeFromUncompressedSize((ulong)newHeaderByte.Length), 64);
|
||||
LzmaStream lzs = new(ep, false, _zipFs);
|
||||
@@ -177,7 +181,11 @@ namespace Compress.SevenZip
|
||||
|
||||
using (Stream headerMem = new MemoryStream())
|
||||
{
|
||||
#if NET20 || NET35 || NET40
|
||||
using BinaryWriter bw = new(headerMem, Encoding.UTF8);
|
||||
#else
|
||||
using BinaryWriter bw = new(headerMem, Encoding.UTF8, true);
|
||||
#endif
|
||||
bw.Write((byte)HeaderProperty.kEncodedHeader);
|
||||
streamsInfo.WriteHeader(bw);
|
||||
|
||||
@@ -186,10 +194,13 @@ namespace Compress.SevenZip
|
||||
headerMem.Read(newHeaderByte, 0, newHeaderByte.Length);
|
||||
}
|
||||
mainHeaderCRC = CRC.CalculateDigest(newHeaderByte, 0, (uint)newHeaderByte.Length);
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#if NET20 || NET35 || NET40
|
||||
using (BinaryWriter bw = new(_zipFs, Encoding.UTF8))
|
||||
#else
|
||||
using (BinaryWriter bw = new(_zipFs, Encoding.UTF8, true))
|
||||
#endif
|
||||
{
|
||||
ulong headerPosition = (ulong)_zipFs.Position + 32; //tzip header is 32 bytes
|
||||
WriteRomVault7Zip(bw, headerPosition, (ulong)newHeaderByte.Length, mainHeaderCRC);
|
||||
|
||||
@@ -98,7 +98,11 @@ namespace Compress.SevenZip.Structure
|
||||
byte[] namebyte;
|
||||
using (MemoryStream nameMem = new())
|
||||
{
|
||||
#if NET20 || NET35 || NET40
|
||||
using BinaryWriter nameBw = new(nameMem, Encoding.UTF8);
|
||||
#else
|
||||
using BinaryWriter nameBw = new(nameMem, Encoding.UTF8, true);
|
||||
#endif
|
||||
nameBw.Write((byte)0); //not external
|
||||
foreach (string name in Names)
|
||||
{
|
||||
|
||||
@@ -49,7 +49,11 @@ namespace Compress.SevenZip.Structure
|
||||
{
|
||||
header = null;
|
||||
|
||||
#if NET20 || NET35 || NET40
|
||||
using BinaryReader br = new(stream, Encoding.UTF8);
|
||||
#else
|
||||
using BinaryReader br = new(stream, Encoding.UTF8, true);
|
||||
#endif
|
||||
HeaderProperty hp = (HeaderProperty)br.ReadByte();
|
||||
switch (hp)
|
||||
{
|
||||
|
||||
@@ -20,7 +20,11 @@ namespace Compress.SevenZip.Structure
|
||||
|
||||
public bool Read(Stream stream)
|
||||
{
|
||||
#if NET20 || NET35 || NET40
|
||||
using BinaryReader br = new(stream, Encoding.UTF8);
|
||||
#else
|
||||
using BinaryReader br = new(stream, Encoding.UTF8, true);
|
||||
#endif
|
||||
byte[] signatureBytes = br.ReadBytes(6);
|
||||
if (!signatureBytes.Compare(Signature))
|
||||
{
|
||||
@@ -82,7 +86,11 @@ namespace Compress.SevenZip.Structure
|
||||
byte[] sigHeaderBytes;
|
||||
using (MemoryStream sigHeaderMem = new())
|
||||
{
|
||||
#if NET20 || NET35 || NET40
|
||||
using BinaryWriter sigHeaderBw = new(sigHeaderMem, Encoding.UTF8);
|
||||
#else
|
||||
using BinaryWriter sigHeaderBw = new(sigHeaderMem, Encoding.UTF8, true);
|
||||
#endif
|
||||
sigHeaderBw.Write((ulong)((long)headerpos - BaseOffset)); //NextHeaderOffset
|
||||
sigHeaderBw.Write(headerLength); //NextHeaderSize
|
||||
sigHeaderBw.Write(headerCRC); //NextHeaderCRC
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.IO;
|
||||
#if NET462_OR_GREATER || NETCOREAPP
|
||||
using System.IO;
|
||||
|
||||
namespace Compress.Support.Compression.zStd
|
||||
{
|
||||
@@ -62,3 +63,4 @@ namespace Compress.Support.Compression.zStd
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -72,7 +72,7 @@ namespace Compress.Support.Utils
|
||||
MessageCallBack?.Invoke($"Extracting {filenameOut}");
|
||||
string fOut = Path.Combine(outDir, filenameOut.Replace('/', '\\'));
|
||||
string dOut = Path.GetDirectoryName(fOut);
|
||||
if (!string.IsNullOrWhiteSpace(dOut) && !Directory.Exists(dOut))
|
||||
if (!string.IsNullOrEmpty(dOut) && !Directory.Exists(dOut))
|
||||
Directory.CreateDirectory(dOut);
|
||||
|
||||
int errorCode = FileStream.OpenFileWrite(fOut, out Stream sWrite);
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace Compress.ThreadReaders
|
||||
|
||||
public ThreadCRC()
|
||||
{
|
||||
crc=new CRC();
|
||||
crc = new CRC();
|
||||
_waitEvent = new AutoResetEvent(false);
|
||||
_outEvent = new AutoResetEvent(false);
|
||||
_finished = false;
|
||||
@@ -31,8 +31,10 @@ namespace Compress.ThreadReaders
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
#if NET40_OR_GREATER
|
||||
_waitEvent.Dispose();
|
||||
_outEvent.Dispose();
|
||||
#endif
|
||||
}
|
||||
|
||||
private void MainLoop()
|
||||
@@ -45,7 +47,7 @@ namespace Compress.ThreadReaders
|
||||
break;
|
||||
}
|
||||
|
||||
crc.SlurpBlock(_buffer,0,_size);
|
||||
crc.SlurpBlock(_buffer, 0, _size);
|
||||
|
||||
_outEvent.Set();
|
||||
}
|
||||
|
||||
@@ -79,7 +79,11 @@ namespace Compress.ZipFile
|
||||
public void BreakTrrntZip(string filename)
|
||||
{
|
||||
_zipFs = new FileStream(filename, FileMode.Open, FileAccess.ReadWrite);
|
||||
using (BinaryReader zipBr = new BinaryReader(_zipFs,Encoding.UTF8,true))
|
||||
#if NET20 || NET35 || NET40
|
||||
using (var zipBr = new BinaryReader(_zipFs,Encoding.UTF8))
|
||||
#else
|
||||
using (var zipBr = new BinaryReader(_zipFs,Encoding.UTF8,true))
|
||||
#endif
|
||||
{
|
||||
_zipFs.Position = _zipFs.Length - 22;
|
||||
byte[] fileComment = zipBr.ReadBytes(22);
|
||||
|
||||
@@ -56,7 +56,11 @@ namespace Compress.ZipFile
|
||||
|
||||
private ZipReturn EndOfCentralDirRead()
|
||||
{
|
||||
#if NET20 || NET35 || NET40
|
||||
using BinaryReader zipBr = new(_zipFs, Encoding.UTF8);
|
||||
#else
|
||||
using BinaryReader zipBr = new(_zipFs, Encoding.UTF8, true);
|
||||
#endif
|
||||
uint thisSignature = zipBr.ReadUInt32();
|
||||
if (thisSignature != EndOfCentralDirSignature)
|
||||
{
|
||||
@@ -105,7 +109,11 @@ namespace Compress.ZipFile
|
||||
|
||||
private void EndOfCentralDirWrite()
|
||||
{
|
||||
#if NET20 || NET35 || NET40
|
||||
using BinaryWriter bw = new(_zipFs, Encoding.UTF8);
|
||||
#else
|
||||
using BinaryWriter bw = new(_zipFs, Encoding.UTF8, true);
|
||||
#endif
|
||||
bw.Write(EndOfCentralDirSignature);
|
||||
bw.Write((ushort)0); // NumberOfThisDisk
|
||||
bw.Write((ushort)0); // NumberOfThisDiskCenterDir
|
||||
@@ -122,7 +130,11 @@ namespace Compress.ZipFile
|
||||
|
||||
private ZipReturn Zip64EndOfCentralDirRead()
|
||||
{
|
||||
#if NET20 || NET35 || NET40
|
||||
using BinaryReader zipBr = new(_zipFs, Encoding.UTF8);
|
||||
#else
|
||||
using BinaryReader zipBr = new(_zipFs, Encoding.UTF8, true);
|
||||
#endif
|
||||
uint thisSignature = zipBr.ReadUInt32();
|
||||
if (thisSignature != Zip64EndOfCentralDirSignature)
|
||||
{
|
||||
@@ -174,7 +186,11 @@ namespace Compress.ZipFile
|
||||
|
||||
private void Zip64EndOfCentralDirWrite()
|
||||
{
|
||||
#if NET20 || NET35 || NET40
|
||||
using BinaryWriter bw = new(_zipFs, Encoding.UTF8);
|
||||
#else
|
||||
using BinaryWriter bw = new(_zipFs, Encoding.UTF8, true);
|
||||
#endif
|
||||
bw.Write(Zip64EndOfCentralDirSignature);
|
||||
bw.Write((ulong)44); // Size of zip64 end of central directory record
|
||||
bw.Write((ushort)45); // version made by
|
||||
@@ -191,7 +207,11 @@ namespace Compress.ZipFile
|
||||
|
||||
private ZipReturn Zip64EndOfCentralDirectoryLocatorRead()
|
||||
{
|
||||
#if NET20 || NET35 || NET40
|
||||
using BinaryReader zipBr = new(_zipFs, Encoding.UTF8);
|
||||
#else
|
||||
using BinaryReader zipBr = new(_zipFs, Encoding.UTF8, true);
|
||||
#endif
|
||||
uint thisSignature = zipBr.ReadUInt32();
|
||||
if (thisSignature != Zip64EndOfCentralDirectoryLocator)
|
||||
{
|
||||
@@ -217,7 +237,11 @@ namespace Compress.ZipFile
|
||||
|
||||
private void Zip64EndOfCentralDirectoryLocatorWrite()
|
||||
{
|
||||
#if NET20 || NET35 || NET40
|
||||
using BinaryWriter bw = new(_zipFs, Encoding.UTF8);
|
||||
#else
|
||||
using BinaryWriter bw = new(_zipFs, Encoding.UTF8, true);
|
||||
#endif
|
||||
bw.Write(Zip64EndOfCentralDirectoryLocator);
|
||||
bw.Write((uint)0); // number of the disk with the start of the zip64 end of central directory
|
||||
bw.Write(_endOfCentralDir64); // relative offset of the zip64 end of central directory record
|
||||
|
||||
@@ -55,7 +55,11 @@ namespace Compress.ZipFile
|
||||
{
|
||||
try
|
||||
{
|
||||
#if NET20 || NET35 || NET40
|
||||
using BinaryReader br = new(zipFs, Encoding.UTF8);
|
||||
#else
|
||||
using BinaryReader br = new(zipFs, Encoding.UTF8, true);
|
||||
#endif
|
||||
uint thisSignature = br.ReadUInt32();
|
||||
if (thisSignature != CentralDirectoryHeaderSignature)
|
||||
{
|
||||
@@ -182,7 +186,11 @@ namespace Compress.ZipFile
|
||||
|
||||
internal void CentralDirectoryWrite(Stream crcStream)
|
||||
{
|
||||
#if NET20 || NET35 || NET40
|
||||
using BinaryWriter bw = new(crcStream, Encoding.UTF8);
|
||||
#else
|
||||
using BinaryWriter bw = new(crcStream, Encoding.UTF8, true);
|
||||
#endif
|
||||
|
||||
ZipExtraFieldWrite zefw = new();
|
||||
SetStatus(LocalFileStatus.Zip64,
|
||||
@@ -238,7 +246,11 @@ namespace Compress.ZipFile
|
||||
|
||||
try
|
||||
{
|
||||
#if NET20 || NET35 || NET40
|
||||
using (BinaryReader br = new(zipFs, Encoding.UTF8))
|
||||
#else
|
||||
using (BinaryReader br = new(zipFs, Encoding.UTF8, true))
|
||||
#endif
|
||||
{
|
||||
|
||||
SetStatus(LocalFileStatus.TrrntZip);
|
||||
@@ -368,7 +380,11 @@ namespace Compress.ZipFile
|
||||
|
||||
try
|
||||
{
|
||||
#if NET20 || NET35 || NET40
|
||||
using BinaryReader br = new(zipFs, Encoding.UTF8);
|
||||
#else
|
||||
using BinaryReader br = new(zipFs, Encoding.UTF8, true);
|
||||
#endif
|
||||
SetStatus(LocalFileStatus.TrrntZip);
|
||||
|
||||
zipFs.Position = (long)RelativeOffsetOfLocalHeader;
|
||||
@@ -431,7 +447,11 @@ namespace Compress.ZipFile
|
||||
|
||||
private void LocalFileHeaderWrite(Stream zipFs)
|
||||
{
|
||||
#if NET20 || NET35 || NET40
|
||||
using BinaryWriter bw = new(zipFs, Encoding.UTF8);
|
||||
#else
|
||||
using BinaryWriter bw = new(zipFs, Encoding.UTF8, true);
|
||||
#endif
|
||||
ZipExtraFieldWrite zefw = new();
|
||||
bool zip64 = zefw.Zip64(UncompressedSize, _compressedSize, RelativeOffsetOfLocalHeader, false,
|
||||
out uint headerUnCompressedSize, out uint headerCompressedSize,
|
||||
@@ -505,7 +525,11 @@ namespace Compress.ZipFile
|
||||
long posNow = zipFs.Position;
|
||||
|
||||
zipFs.Seek((long)RelativeOffsetOfLocalHeader + 14, SeekOrigin.Begin);
|
||||
#if NET20 || NET35 || NET40
|
||||
using (BinaryWriter bw = new(zipFs, Encoding.UTF8))
|
||||
#else
|
||||
using (BinaryWriter bw = new(zipFs, Encoding.UTF8, true))
|
||||
#endif
|
||||
{
|
||||
WriteCRC(bw, CRC);
|
||||
bw.Write(headerCompressedSize);
|
||||
@@ -524,7 +548,11 @@ namespace Compress.ZipFile
|
||||
|
||||
internal void LocalFileHeaderFake(ulong filePosition, ulong uncompressedSize, ulong compressedSize, byte[] crc32, MemoryStream ms)
|
||||
{
|
||||
#if NET20 || NET35 || NET40
|
||||
using BinaryWriter bw = new(ms, Encoding.UTF8);
|
||||
#else
|
||||
using BinaryWriter bw = new(ms, Encoding.UTF8, true);
|
||||
#endif
|
||||
RelativeOffsetOfLocalHeader = filePosition;
|
||||
SetStatus(LocalFileStatus.TrrntZip);
|
||||
UncompressedSize = uncompressedSize;
|
||||
@@ -634,11 +662,13 @@ namespace Compress.ZipFile
|
||||
break;
|
||||
}
|
||||
|
||||
#if NET462_OR_GREATER || NETCOREAPP
|
||||
case 20:
|
||||
case 93:
|
||||
readStream = new ZstdSharp.DecompressionStream(zipFs);
|
||||
streamSize = UncompressedSize;
|
||||
break;
|
||||
#endif
|
||||
|
||||
case 98:
|
||||
{
|
||||
@@ -675,10 +705,12 @@ namespace Compress.ZipFile
|
||||
{
|
||||
writeStream = zipFs;
|
||||
}
|
||||
#if NET462_OR_GREATER || NETCOREAPP
|
||||
else if (compressionMethod == 93)
|
||||
{
|
||||
writeStream = new ZstdSharp.CompressionStream(zipFs, 19);
|
||||
}
|
||||
#endif
|
||||
else if (compressionMethod == 8)
|
||||
{
|
||||
writeStream = new ZlibBaseStream(zipFs, CompressionMode.Compress, CompressionLevel.BestCompression, ZlibStreamFlavor.DEFLATE, true);
|
||||
@@ -712,7 +744,11 @@ namespace Compress.ZipFile
|
||||
private void FixFileForZip64(Stream zipFs, int oldExtraFieldLength, int newExtraFieldLength)
|
||||
{
|
||||
long posNow = zipFs.Position;
|
||||
#if NET20 || NET35 || NET40
|
||||
using (BinaryWriter bw = new(zipFs, Encoding.UTF8))
|
||||
#else
|
||||
using (BinaryWriter bw = new(zipFs, Encoding.UTF8, true))
|
||||
#endif
|
||||
{
|
||||
zipFs.Seek((long)RelativeOffsetOfLocalHeader + 4, SeekOrigin.Begin);
|
||||
ushort versionNeededToExtract = 45;
|
||||
|
||||
@@ -90,7 +90,7 @@ namespace Compress.gZip
|
||||
ZipFileClose();
|
||||
return ZipReturn.ZipErrorOpeningFile;
|
||||
}
|
||||
catch(Exception)
|
||||
catch (Exception)
|
||||
{
|
||||
ZipFileClose();
|
||||
return ZipReturn.ZipErrorReadingFile;
|
||||
@@ -111,7 +111,11 @@ namespace Compress.gZip
|
||||
|
||||
private ZipReturn ZipFileReadHeaders()
|
||||
{
|
||||
#if NET20 || NET35 || NET40
|
||||
using BinaryReader zipBr = new(_zipFs, Encoding.UTF8);
|
||||
#else
|
||||
using BinaryReader zipBr = new(_zipFs, Encoding.UTF8, true);
|
||||
#endif
|
||||
|
||||
byte ID1 = zipBr.ReadByte();
|
||||
byte ID2 = zipBr.ReadByte();
|
||||
@@ -316,7 +320,11 @@ namespace Compress.gZip
|
||||
|
||||
public ZipReturn ZipFileOpenWriteStream(bool raw, bool trrntzip, string filename, ulong unCompressedSize, ushort compressionMethod, out Stream stream, TimeStamps dateTime)
|
||||
{
|
||||
#if NET20 || NET35 || NET40
|
||||
using (BinaryWriter zipBw = new(_zipFs, Encoding.UTF8))
|
||||
#else
|
||||
using (BinaryWriter zipBw = new(_zipFs, Encoding.UTF8, true))
|
||||
#endif
|
||||
{
|
||||
UnCompressedSize = unCompressedSize;
|
||||
|
||||
@@ -422,7 +430,11 @@ namespace Compress.gZip
|
||||
|
||||
CompressedSize = (ulong)(_zipFs.Position - dataStartPos);
|
||||
|
||||
#if NET20 || NET35 || NET40
|
||||
using (BinaryWriter zipBw = new(_zipFs, Encoding.UTF8))
|
||||
#else
|
||||
using (BinaryWriter zipBw = new(_zipFs, Encoding.UTF8, true))
|
||||
#endif
|
||||
{
|
||||
|
||||
zipBw.Write(crc32[3]);
|
||||
|
||||
@@ -190,7 +190,7 @@ namespace SabreTools.FileTypes
|
||||
string? match = files.Where(s => s.EndsWith(entryName)).FirstOrDefault();
|
||||
|
||||
// If we had a file, copy that over to the new name
|
||||
if (!string.IsNullOrWhiteSpace(match))
|
||||
if (!string.IsNullOrEmpty(match))
|
||||
{
|
||||
realentry = match;
|
||||
File.Copy(match, Path.Combine(outDir, entryName));
|
||||
@@ -232,9 +232,19 @@ namespace SabreTools.FileTypes
|
||||
string? match = files.Where(s => s.EndsWith(entryName)).FirstOrDefault();
|
||||
|
||||
// If we had a file, copy that over to the new name
|
||||
if (!string.IsNullOrWhiteSpace(match))
|
||||
if (!string.IsNullOrEmpty(match))
|
||||
{
|
||||
#if NET20 || NET35
|
||||
var tempStream = File.OpenRead(match);
|
||||
byte[] buffer = new byte[32768];
|
||||
int read;
|
||||
while ((read = tempStream.Read(buffer, 0, buffer.Length)) > 0)
|
||||
{
|
||||
ms.Write(buffer, 0, read);
|
||||
}
|
||||
#else
|
||||
File.OpenRead(match).CopyTo(ms);
|
||||
#endif
|
||||
realentry = match;
|
||||
}
|
||||
}
|
||||
@@ -264,14 +274,22 @@ namespace SabreTools.FileTypes
|
||||
if (_children == null || _children.Count == 0)
|
||||
{
|
||||
_children = [];
|
||||
#if NETFRAMEWORK
|
||||
foreach (string file in Directory.GetFiles(this.Filename, "*"))
|
||||
#else
|
||||
foreach (string file in Directory.EnumerateFiles(this.Filename, "*", SearchOption.TopDirectoryOnly))
|
||||
#endif
|
||||
{
|
||||
BaseFile? nf = GetInfo(file, hashes: this.AvailableHashes);
|
||||
if (nf != null)
|
||||
_children.Add(nf);
|
||||
}
|
||||
|
||||
#if NETFRAMEWORK
|
||||
foreach (string dir in Directory.GetDirectories(this.Filename, "*"))
|
||||
#else
|
||||
foreach (string dir in Directory.EnumerateDirectories(this.Filename, "*", SearchOption.TopDirectoryOnly))
|
||||
#endif
|
||||
{
|
||||
Folder fl = new(dir);
|
||||
_children.Add(fl);
|
||||
@@ -337,7 +355,11 @@ namespace SabreTools.FileTypes
|
||||
if (writeToParent)
|
||||
fileName = Path.Combine(outDir, TextHelper.RemovePathUnsafeCharacters(baseFile.Filename) ?? string.Empty);
|
||||
else
|
||||
#if NET20 || NET35
|
||||
fileName = Path.Combine(Path.Combine(outDir, TextHelper.RemovePathUnsafeCharacters(baseFile.Parent) ?? string.Empty), TextHelper.RemovePathUnsafeCharacters(baseFile.Filename) ?? string.Empty);
|
||||
#else
|
||||
fileName = Path.Combine(outDir, TextHelper.RemovePathUnsafeCharacters(baseFile.Parent) ?? string.Empty, TextHelper.RemovePathUnsafeCharacters(baseFile.Filename) ?? string.Empty);
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
@@ -365,7 +387,7 @@ namespace SabreTools.FileTypes
|
||||
|
||||
outputStream.Dispose();
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(baseFile.Date))
|
||||
if (!string.IsNullOrEmpty(baseFile.Date))
|
||||
File.SetCreationTime(fileName, DateTime.Parse(baseFile.Date));
|
||||
|
||||
success = true;
|
||||
|
||||
@@ -358,7 +358,11 @@ namespace RVIO
|
||||
catch (Exception e)
|
||||
{
|
||||
stream = null;
|
||||
#if NET462_OR_GREATER || NETCOREAPP
|
||||
return e.HResult;
|
||||
#else
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -372,7 +376,11 @@ namespace RVIO
|
||||
catch (Exception e)
|
||||
{
|
||||
stream = null;
|
||||
#if NET462_OR_GREATER || NETCOREAPP
|
||||
return e.HResult;
|
||||
#else
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,23 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
|
||||
<!-- Assembly Properties -->
|
||||
<TargetFrameworks>net20;net35;net40;net452;net462;net472;net48;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0</TargetFrameworks>
|
||||
<RuntimeIdentifiers>win-x86;win-x64;win-arm64;linux-x64;linux-arm64;osx-x64</RuntimeIdentifiers>
|
||||
<CheckEolTargetFramework>false</CheckEolTargetFramework>
|
||||
<IncludeSourceRevisionInInformationalVersion>false</IncludeSourceRevisionInInformationalVersion>
|
||||
<LangVersion>latest</LangVersion>
|
||||
<Nullable>enable</Nullable>
|
||||
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
|
||||
<!-- <TreatWarningsAsErrors>true</TreatWarningsAsErrors> --> <!-- Can't be enabled because of external code -->
|
||||
<Version>1.1.2</Version>
|
||||
|
||||
<!-- Package Properties -->
|
||||
<Authors>Matt Nadareski</Authors>
|
||||
<Copyright>Copyright (c)2016-2024 Matt Nadareski</Copyright>
|
||||
<PackageProjectUrl>https://github.com/SabreTools/</PackageProjectUrl>
|
||||
<RepositoryUrl>https://github.com/SabreTools/SabreTools</RepositoryUrl>
|
||||
<RepositoryType>git</RepositoryType>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@@ -14,11 +27,15 @@
|
||||
<ProjectReference Include="..\SabreTools.Skippers\SabreTools.Skippers.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="SabreTools.IO" Version="1.3.0" />
|
||||
<!-- Support for old .NET versions -->
|
||||
<ItemGroup Condition="!$(TargetFramework.StartsWith(`net2`)) AND !$(TargetFramework.StartsWith(`net3`)) AND !$(TargetFramework.StartsWith(`net40`)) AND !$(TargetFramework.StartsWith(`net452`))">
|
||||
<PackageReference Include="SharpCompress" Version="0.34.2" />
|
||||
<PackageReference Include="System.Text.Encoding.CodePages" Version="8.0.0" />
|
||||
<PackageReference Include="ZstdSharp.Port" Version="0.7.4" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="SabreTools.IO" Version="1.3.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -232,7 +232,13 @@ namespace SabreTools.Filtering
|
||||
// First we want to get a mapping for all games to description
|
||||
ConcurrentDictionary<string, string> concurrentDictionary = new();
|
||||
ConcurrentDictionary<string, string> mapping = concurrentDictionary;
|
||||
#if NET452_OR_GREATER || NETCOREAPP
|
||||
Parallel.ForEach(datFile.Items.Keys, Globals.ParallelOptions, key =>
|
||||
#elif NET40_OR_GREATER
|
||||
Parallel.ForEach(datFile.Items.Keys, key =>
|
||||
#else
|
||||
foreach (var key in datFile.Items.Keys)
|
||||
#endif
|
||||
{
|
||||
var items = datFile.Items[key];
|
||||
if (items == null)
|
||||
@@ -243,10 +249,20 @@ namespace SabreTools.Filtering
|
||||
// If the key mapping doesn't exist, add it
|
||||
mapping.TryAdd(item.Machine.Name!, item.Machine.Description!.Replace('/', '_').Replace("\"", "''").Replace(":", " -"));
|
||||
}
|
||||
#if NET40_OR_GREATER || NETCOREAPP
|
||||
});
|
||||
#else
|
||||
}
|
||||
#endif
|
||||
|
||||
// Now we loop through every item and update accordingly
|
||||
#if NET452_OR_GREATER || NETCOREAPP
|
||||
Parallel.ForEach(datFile.Items.Keys, Globals.ParallelOptions, key =>
|
||||
#elif NET40_OR_GREATER
|
||||
Parallel.ForEach(datFile.Items.Keys, key =>
|
||||
#else
|
||||
foreach (var key in datFile.Items.Keys)
|
||||
#endif
|
||||
{
|
||||
var items = datFile.Items[key];
|
||||
if (items == null)
|
||||
@@ -278,7 +294,11 @@ namespace SabreTools.Filtering
|
||||
// Replace the old list of roms with the new one
|
||||
datFile.Items.Remove(key);
|
||||
datFile.Items.AddRange(key, newItems);
|
||||
#if NET40_OR_GREATER || NETCOREAPP
|
||||
});
|
||||
#else
|
||||
}
|
||||
#endif
|
||||
}
|
||||
catch (Exception ex) when (!throwOnError)
|
||||
{
|
||||
@@ -379,7 +399,13 @@ namespace SabreTools.Filtering
|
||||
datFile.Header.Type = "SuperDAT";
|
||||
|
||||
// For each rom, we want to update the game to be "<game name>/<rom name>"
|
||||
#if NET452_OR_GREATER || NETCOREAPP
|
||||
Parallel.ForEach(datFile.Items.Keys, Globals.ParallelOptions, key =>
|
||||
#elif NET40_OR_GREATER
|
||||
Parallel.ForEach(datFile.Items.Keys, key =>
|
||||
#else
|
||||
foreach (var key in datFile.Items.Keys)
|
||||
#endif
|
||||
{
|
||||
var items = datFile.Items[key];
|
||||
if (items == null)
|
||||
@@ -389,7 +415,11 @@ namespace SabreTools.Filtering
|
||||
{
|
||||
SetOneRomPerGame(items[i]);
|
||||
}
|
||||
#if NET40_OR_GREATER || NETCOREAPP
|
||||
});
|
||||
#else
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -419,7 +449,13 @@ namespace SabreTools.Filtering
|
||||
string pattern = @"([0-9]{2}\.[0-9]{2}\.[0-9]{2}-)(.*?-.*?)";
|
||||
|
||||
// Now process all of the roms
|
||||
#if NET452_OR_GREATER || NETCOREAPP
|
||||
Parallel.ForEach(datFile.Items.Keys, Globals.ParallelOptions, key =>
|
||||
#elif NET40_OR_GREATER
|
||||
Parallel.ForEach(datFile.Items.Keys, key =>
|
||||
#else
|
||||
foreach (var key in datFile.Items.Keys)
|
||||
#endif
|
||||
{
|
||||
var items = datFile.Items[key];
|
||||
if (items == null)
|
||||
@@ -439,7 +475,11 @@ namespace SabreTools.Filtering
|
||||
|
||||
datFile.Items.Remove(key);
|
||||
datFile.Items.AddRange(key, items);
|
||||
#if NET40_OR_GREATER || NETCOREAPP
|
||||
});
|
||||
#else
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -111,7 +111,13 @@ namespace SabreTools.Filtering
|
||||
// Remove DatItem and Machine fields
|
||||
if (DatItemRemover != null && (DatItemRemover.MachineFields.Any() || DatItemRemover.DatItemFields.Any()))
|
||||
{
|
||||
#if NET452_OR_GREATER || NETCOREAPP
|
||||
Parallel.ForEach(datFile.Items.Keys, Globals.ParallelOptions, key =>
|
||||
#elif NET40_OR_GREATER
|
||||
Parallel.ForEach(datFile.Items.Keys, key =>
|
||||
#else
|
||||
foreach (var key in datFile.Items.Keys)
|
||||
#endif
|
||||
{
|
||||
ConcurrentList<DatItem>? items = datFile.Items[key];
|
||||
if (items == null)
|
||||
@@ -124,7 +130,11 @@ namespace SabreTools.Filtering
|
||||
|
||||
datFile.Items.Remove(key);
|
||||
datFile.Items.AddRange(key, items);
|
||||
#if NET40_OR_GREATER || NETCOREAPP
|
||||
});
|
||||
#else
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
watch.Stop();
|
||||
|
||||
@@ -284,17 +284,25 @@ namespace SabreTools.Skippers
|
||||
}
|
||||
finally
|
||||
{
|
||||
#if NET40_OR_GREATER
|
||||
// If we're not keeping the read stream open, dispose of the binary reader
|
||||
if (!keepReadOpen)
|
||||
{
|
||||
#if NET40_OR_GREATER
|
||||
br?.Dispose();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
// If we're not keeping the write stream open, dispose of the binary reader
|
||||
if (!keepWriteOpen)
|
||||
{
|
||||
#if NET40_OR_GREATER
|
||||
bw?.Dispose();
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,7 +97,11 @@ namespace SabreTools.Features
|
||||
Parallel.ForEach(typeDats.Keys, Globals.ParallelOptions, itemType =>
|
||||
{
|
||||
Writer.Write(typeDats[itemType], OutputDir);
|
||||
#if NET40_OR_GREATER || NETCOREAPP
|
||||
});
|
||||
#else
|
||||
}
|
||||
#endif
|
||||
|
||||
watch.Stop();
|
||||
}
|
||||
@@ -139,7 +143,11 @@ namespace SabreTools.Features
|
||||
Parallel.ForEach(sizedDats, Globals.ParallelOptions, sizedDat =>
|
||||
{
|
||||
Writer.Write(sizedDat, OutputDir);
|
||||
#if NET40_OR_GREATER || NETCOREAPP
|
||||
});
|
||||
#else
|
||||
}
|
||||
#endif
|
||||
|
||||
watch.Stop();
|
||||
}
|
||||
@@ -155,7 +163,11 @@ namespace SabreTools.Features
|
||||
Parallel.ForEach(typeDats.Keys, Globals.ParallelOptions, itemType =>
|
||||
{
|
||||
Writer.Write(typeDats[itemType], OutputDir);
|
||||
#if NET40_OR_GREATER || NETCOREAPP
|
||||
});
|
||||
#else
|
||||
}
|
||||
#endif
|
||||
|
||||
watch.Stop();
|
||||
}
|
||||
|
||||
@@ -175,7 +175,11 @@ namespace SabreTools.Features
|
||||
|
||||
// Try to output the file, overwriting only if it's not in the current directory
|
||||
Writer.Write(datFile, realOutDir, overwrite: GetBoolean(features, InplaceValue));
|
||||
#if NET40_OR_GREATER || NETCOREAPP
|
||||
});
|
||||
#else
|
||||
}
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -308,7 +312,11 @@ namespace SabreTools.Features
|
||||
// Finally output the diffed DatFile
|
||||
string interOutDir = inputPath.GetOutputPath(OutputDir, GetBoolean(features, InplaceValue));
|
||||
Writer.Write(repDat, interOutDir, overwrite: GetBoolean(features, InplaceValue));
|
||||
#if NET40_OR_GREATER || NETCOREAPP
|
||||
});
|
||||
#else
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// Output DATs after replacing fields from a base DatFile
|
||||
@@ -339,7 +347,11 @@ namespace SabreTools.Features
|
||||
// Finally output the replaced DatFile
|
||||
string interOutDir = inputPath.GetOutputPath(OutputDir, GetBoolean(features, InplaceValue));
|
||||
Writer.Write(repDat, interOutDir, overwrite: GetBoolean(features, InplaceValue));
|
||||
#if NET40_OR_GREATER || NETCOREAPP
|
||||
});
|
||||
#else
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// Merge all input files and write
|
||||
|
||||
Reference in New Issue
Block a user