mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Enable nullability everywhere
This commit is contained in:
@@ -16,7 +16,7 @@ namespace SabreTools.FileTypes.Aaru
|
||||
#region Header
|
||||
|
||||
protected ulong Identifier; // 'AARUFRMT' (0x544D524655524141)
|
||||
protected string Application; // Name of application that created image
|
||||
protected string? Application; // Name of application that created image
|
||||
protected byte ImageMajorVersion; // Image format major version
|
||||
protected byte ImageMinorVersion; // Image format minor version
|
||||
protected byte ApplicationMajorVersion; // Major version of application that created image
|
||||
@@ -30,8 +30,8 @@ namespace SabreTools.FileTypes.Aaru
|
||||
|
||||
#region Internal Values
|
||||
|
||||
protected IndexHeader IndexHeader;
|
||||
protected IndexEntry[] IndexEntries;
|
||||
protected IndexHeader? IndexHeader;
|
||||
protected IndexEntry[]? IndexEntries;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -51,7 +51,7 @@ namespace SabreTools.FileTypes.Aaru
|
||||
/// Create a new AaruFormat from an input file
|
||||
/// </summary>
|
||||
/// <param name="filename">Filename respresenting the AaruFormat file</param>
|
||||
public static AaruFormat Create(string filename)
|
||||
public static AaruFormat? Create(string filename)
|
||||
{
|
||||
using FileStream fs = File.OpenRead(filename);
|
||||
return Create(fs);
|
||||
@@ -61,7 +61,7 @@ namespace SabreTools.FileTypes.Aaru
|
||||
/// Create a new AaruFormat from an input stream
|
||||
/// </summary>
|
||||
/// <param name="aarustream">Stream representing the AaruFormat file</param>
|
||||
public static AaruFormat Create(Stream aarustream)
|
||||
public static AaruFormat? Create(Stream aarustream)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -72,7 +72,7 @@ namespace SabreTools.FileTypes.Aaru
|
||||
return null;
|
||||
|
||||
// Read and retrun the current AaruFormat
|
||||
AaruFormat generated = Deserialize(aarustream);
|
||||
AaruFormat? generated = Deserialize(aarustream);
|
||||
if (generated != null)
|
||||
generated.Type = FileType.AaruFormat;
|
||||
|
||||
@@ -113,7 +113,7 @@ namespace SabreTools.FileTypes.Aaru
|
||||
/// </summary>
|
||||
/// <param name="stream">AaruFormat file as a stream</param>
|
||||
/// <returns>Populated AaruFormat file, null on failure</returns>
|
||||
public static AaruFormat Deserialize(Stream stream)
|
||||
public static AaruFormat? Deserialize(Stream stream)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -183,7 +183,7 @@ namespace SabreTools.FileTypes.Aaru
|
||||
// Read through each and pick out the ones we care about
|
||||
for (byte entry = 0; entry < checksumHeader.entries; entry++)
|
||||
{
|
||||
ChecksumEntry checksumEntry = ChecksumEntry.Deserialize(stream);
|
||||
ChecksumEntry? checksumEntry = ChecksumEntry.Deserialize(stream);
|
||||
if (checksumEntry == null)
|
||||
continue;
|
||||
|
||||
|
||||
@@ -16,18 +16,18 @@ namespace SabreTools.FileTypes.Aaru
|
||||
/// <summary>Length in bytes of checksum that follows this structure</summary>
|
||||
public uint length;
|
||||
/// <summary>Checksum that follows this structure</summary>
|
||||
public byte[] checksum;
|
||||
public byte[]? checksum;
|
||||
|
||||
/// <summary>
|
||||
/// Read a stream as an v
|
||||
/// </summary>
|
||||
/// <param name="stream">ChecksumEntry as a stream</param>
|
||||
/// <returns>Populated ChecksumEntry, null on failure</returns>
|
||||
public static ChecksumEntry Deserialize(Stream stream)
|
||||
public static ChecksumEntry? Deserialize(Stream stream)
|
||||
{
|
||||
ChecksumEntry checksumEntry = new ChecksumEntry();
|
||||
var checksumEntry = new ChecksumEntry();
|
||||
|
||||
using (BinaryReader br = new BinaryReader(stream, Encoding.Default, true))
|
||||
using (var br = new BinaryReader(stream, Encoding.Default, true))
|
||||
{
|
||||
checksumEntry.type = (AaruChecksumAlgorithm)br.ReadByte();
|
||||
checksumEntry.length = br.ReadUInt32();
|
||||
|
||||
@@ -23,9 +23,9 @@ namespace SabreTools.FileTypes.Aaru
|
||||
/// <returns>Populated IndexHeader, null on failure</returns>
|
||||
public static IndexHeader Deserialize(Stream stream)
|
||||
{
|
||||
IndexHeader indexHeader = new IndexHeader();
|
||||
var indexHeader = new IndexHeader();
|
||||
|
||||
using (BinaryReader br = new BinaryReader(stream, Encoding.Default, true))
|
||||
using (var br = new BinaryReader(stream, Encoding.Default, true))
|
||||
{
|
||||
indexHeader.identifier = (AaruBlockType)br.ReadUInt32();
|
||||
indexHeader.entries = br.ReadUInt16();
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
1C-1F CRC hash
|
||||
20-27 Int64 size (mirrored)
|
||||
*/
|
||||
private readonly static byte[] TorrentGZHeader = new byte[] { 0x1f, 0x8b, 0x08, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x00 };
|
||||
private readonly static byte[] TorrentGZHeader = [0x1f, 0x8b, 0x08, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x00];
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -80,6 +80,10 @@ namespace SabreTools.FileTypes.Archives
|
||||
{
|
||||
bool encounteredErrors = true;
|
||||
|
||||
// If we have an invalid file
|
||||
if (this.Filename == null)
|
||||
return true;
|
||||
|
||||
try
|
||||
{
|
||||
// Create the temp directory
|
||||
@@ -114,15 +118,15 @@ namespace SabreTools.FileTypes.Archives
|
||||
logger.Error(ex);
|
||||
encounteredErrors = true;
|
||||
}
|
||||
|
||||
|
||||
return encounteredErrors;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override string CopyToFile(string entryName, string outDir)
|
||||
public override string? CopyToFile(string entryName, string outDir)
|
||||
{
|
||||
// Try to extract a stream using the given information
|
||||
(MemoryStream ms, string realEntry) = CopyToStream(entryName);
|
||||
(MemoryStream? ms, string? realEntry) = CopyToStream(entryName);
|
||||
|
||||
// If the memory stream and the entry name are both non-null, we write to file
|
||||
if (ms != null && realEntry != null)
|
||||
@@ -130,7 +134,9 @@ namespace SabreTools.FileTypes.Archives
|
||||
realEntry = Path.Combine(outDir, realEntry);
|
||||
|
||||
// Create the output subfolder now
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(realEntry));
|
||||
string? dir = Path.GetDirectoryName(realEntry);
|
||||
if (dir != null)
|
||||
Directory.CreateDirectory(dir);
|
||||
|
||||
// Now open and write the file if possible
|
||||
FileStream fs = File.Create(realEntry);
|
||||
@@ -160,10 +166,14 @@ namespace SabreTools.FileTypes.Archives
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override (MemoryStream, string) CopyToStream(string entryName)
|
||||
public override (MemoryStream?, string?) CopyToStream(string entryName)
|
||||
{
|
||||
MemoryStream ms = new();
|
||||
string realEntry;
|
||||
MemoryStream? ms = new();
|
||||
string? realEntry;
|
||||
|
||||
// If we have an invalid file
|
||||
if (this.Filename == null)
|
||||
return (null, null);
|
||||
|
||||
try
|
||||
{
|
||||
@@ -201,15 +211,19 @@ namespace SabreTools.FileTypes.Archives
|
||||
#region Information
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override List<BaseFile> GetChildren()
|
||||
public override List<BaseFile>? GetChildren()
|
||||
{
|
||||
// If we have an invalid file
|
||||
if (this.Filename == null)
|
||||
return null;
|
||||
|
||||
if (_children == null || _children.Count == 0)
|
||||
{
|
||||
_children = new List<BaseFile>();
|
||||
_children = [];
|
||||
|
||||
string gamename = Path.GetFileNameWithoutExtension(this.Filename);
|
||||
|
||||
BaseFile possibleTgz = GetTorrentGZFileInfo();
|
||||
BaseFile? possibleTgz = GetTorrentGZFileInfo();
|
||||
|
||||
// If it was, then add it to the outputs and continue
|
||||
if (possibleTgz != null && possibleTgz.Filename != null)
|
||||
@@ -227,7 +241,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
if (this.AvailableHashes == Hash.CRC)
|
||||
{
|
||||
gzipEntryRom.Filename = gamename;
|
||||
|
||||
|
||||
using BinaryReader br = new(File.OpenRead(this.Filename));
|
||||
br.BaseStream.Seek(-8, SeekOrigin.End);
|
||||
gzipEntryRom.CRC = br.ReadBytesBigEndian(4);
|
||||
@@ -265,7 +279,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
public override List<string> GetEmptyFolders()
|
||||
{
|
||||
// GZip files don't contain directories
|
||||
return new List<string>();
|
||||
return [];
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
@@ -328,13 +342,11 @@ namespace SabreTools.FileTypes.Archives
|
||||
/// Retrieve file information for a single torrent GZ file
|
||||
/// </summary>
|
||||
/// <returns>Populated DatItem object if success, empty one on error</returns>
|
||||
public BaseFile GetTorrentGZFileInfo()
|
||||
public BaseFile? GetTorrentGZFileInfo()
|
||||
{
|
||||
// Check for the file existing first
|
||||
if (!File.Exists(this.Filename))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
string datum = Path.GetFileName(this.Filename).ToLowerInvariant();
|
||||
long filesize = new FileInfo(this.Filename).Length;
|
||||
@@ -383,10 +395,9 @@ namespace SabreTools.FileTypes.Archives
|
||||
}
|
||||
correct &= (header[i] == TorrentGZHeader[i]);
|
||||
}
|
||||
|
||||
if (!correct)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// Now convert the data and get the right position
|
||||
long extractedsize = (long)headersz;
|
||||
@@ -410,7 +421,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
#region Writing
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool Write(string inputFile, string outDir, BaseFile baseFile = null)
|
||||
public override bool Write(string inputFile, string outDir, BaseFile? baseFile = null)
|
||||
{
|
||||
// Check that the input file exists
|
||||
if (!File.Exists(inputFile))
|
||||
@@ -426,12 +437,12 @@ namespace SabreTools.FileTypes.Archives
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool Write(Stream inputStream, string outDir, BaseFile baseFile = null)
|
||||
public override bool Write(Stream? inputStream, string outDir, BaseFile? baseFile = null)
|
||||
{
|
||||
bool success = false;
|
||||
|
||||
// If the stream is not readable, return
|
||||
if (!inputStream.CanRead)
|
||||
if (inputStream == null || !inputStream.CanRead)
|
||||
return success;
|
||||
|
||||
// Make sure the output directory exists
|
||||
@@ -444,11 +455,11 @@ namespace SabreTools.FileTypes.Archives
|
||||
baseFile = GetInfo(inputStream, keepReadOpen: true);
|
||||
|
||||
// Get the output file name
|
||||
string outfile = Path.Combine(outDir, Utilities.GetDepotPath(TextHelper.ByteArrayToString(baseFile.SHA1), Depth));
|
||||
string outfile = Path.Combine(outDir, Utilities.GetDepotPath(TextHelper.ByteArrayToString(baseFile.SHA1), Depth) ?? string.Empty);
|
||||
|
||||
// Check to see if the folder needs to be created
|
||||
if (!Directory.Exists(Path.GetDirectoryName(outfile)))
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(outfile));
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(outfile)!);
|
||||
|
||||
// If the output file exists, don't try to write again
|
||||
if (!File.Exists(outfile))
|
||||
@@ -461,8 +472,8 @@ namespace SabreTools.FileTypes.Archives
|
||||
|
||||
// Write standard header and TGZ info
|
||||
byte[] data = TorrentGZHeader
|
||||
.Concat(baseFile.MD5) // MD5
|
||||
.Concat(baseFile.CRC) // CRC
|
||||
.Concat(baseFile.MD5!) // MD5
|
||||
.Concat(baseFile.CRC!) // CRC
|
||||
.ToArray();
|
||||
sw.Write(data);
|
||||
sw.Write((ulong)(baseFile.Size ?? 0)); // Long size (Unsigned, Mirrored)
|
||||
@@ -482,7 +493,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
ds.Dispose();
|
||||
|
||||
// Now write the standard footer
|
||||
sw.Write(baseFile.CRC.Reverse().ToArray());
|
||||
sw.Write(baseFile.CRC!.Reverse().ToArray());
|
||||
sw.Write((uint)(baseFile.Size ?? 0));
|
||||
|
||||
// Dispose of everything
|
||||
@@ -494,7 +505,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool Write(List<string> inputFiles, string outDir, List<BaseFile> baseFile)
|
||||
public override bool Write(List<string> inputFiles, string outDir, List<BaseFile>? baseFile)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@@ -81,19 +81,19 @@ namespace SabreTools.FileTypes.Archives
|
||||
#region Writing
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool Write(string inputFile, string outDir, BaseFile baseFile)
|
||||
public override bool Write(string inputFile, string outDir, BaseFile? baseFile)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool Write(Stream inputStream, string outDir, BaseFile baseFile)
|
||||
public override bool Write(Stream? inputStream, string outDir, BaseFile? baseFile)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool Write(List<string> inputFiles, string outDir, List<BaseFile> baseFiles)
|
||||
public override bool Write(List<string> inputFiles, string outDir, List<BaseFile>? baseFiles)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@@ -81,19 +81,19 @@ namespace SabreTools.FileTypes.Archives
|
||||
#region Writing
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool Write(string inputFile, string outDir, BaseFile rom)
|
||||
public override bool Write(string inputFile, string outDir, BaseFile? rom)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool Write(Stream inputStream, string outDir, BaseFile rom)
|
||||
public override bool Write(Stream? inputStream, string outDir, BaseFile? rom)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool Write(List<string> inputFiles, string outDir, List<BaseFile> baseFiles)
|
||||
public override bool Write(List<string> inputFiles, string outDir, List<BaseFile>? baseFiles)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@@ -47,6 +47,10 @@ namespace SabreTools.FileTypes.Archives
|
||||
{
|
||||
bool encounteredErrors = true;
|
||||
|
||||
// If we have an invalid file
|
||||
if (this.Filename == null)
|
||||
return true;
|
||||
|
||||
try
|
||||
{
|
||||
// Create the temp directory
|
||||
@@ -81,10 +85,10 @@ namespace SabreTools.FileTypes.Archives
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override string CopyToFile(string entryName, string outDir)
|
||||
public override string? CopyToFile(string entryName, string outDir)
|
||||
{
|
||||
// Try to extract a stream using the given information
|
||||
(MemoryStream ms, string realEntry) = CopyToStream(entryName);
|
||||
(MemoryStream? ms, string? realEntry) = CopyToStream(entryName);
|
||||
|
||||
// If the memory stream and the entry name are both non-null, we write to file
|
||||
if (ms != null && realEntry != null)
|
||||
@@ -92,7 +96,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
realEntry = Path.Combine(outDir, realEntry);
|
||||
|
||||
// Create the output subfolder now
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(realEntry));
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(realEntry) ?? string.Empty);
|
||||
|
||||
// Now open and write the file if possible
|
||||
FileStream fs = File.Create(realEntry);
|
||||
@@ -122,10 +126,14 @@ namespace SabreTools.FileTypes.Archives
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override (MemoryStream, string) CopyToStream(string entryName)
|
||||
public override (MemoryStream?, string?) CopyToStream(string entryName)
|
||||
{
|
||||
MemoryStream ms = new();
|
||||
string realEntry = null;
|
||||
MemoryStream? ms = new();
|
||||
string? realEntry = null;
|
||||
|
||||
// If we have an invalid file
|
||||
if (this.Filename == null)
|
||||
return (null, null);
|
||||
|
||||
try
|
||||
{
|
||||
@@ -156,10 +164,14 @@ namespace SabreTools.FileTypes.Archives
|
||||
#region Information
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override List<BaseFile> GetChildren()
|
||||
public override List<BaseFile>? GetChildren()
|
||||
{
|
||||
List<BaseFile> found = new();
|
||||
string gamename = Path.GetFileNameWithoutExtension(this.Filename);
|
||||
// If we have an invalid file
|
||||
if (this.Filename == null)
|
||||
return null;
|
||||
|
||||
List<BaseFile> found = [];
|
||||
string? gamename = Path.GetFileNameWithoutExtension(this.Filename);
|
||||
|
||||
try
|
||||
{
|
||||
@@ -204,13 +216,17 @@ namespace SabreTools.FileTypes.Archives
|
||||
/// <inheritdoc/>
|
||||
public override List<string> GetEmptyFolders()
|
||||
{
|
||||
List<string> empties = new();
|
||||
List<string> empties = [];
|
||||
|
||||
// If we have an invalid file
|
||||
if (this.Filename == null)
|
||||
return empties;
|
||||
|
||||
try
|
||||
{
|
||||
SharpCompress.Archives.Rar.RarArchive ra = SharpCompress.Archives.Rar.RarArchive.Open(this.Filename, new ReaderOptions { LeaveStreamOpen = false });
|
||||
List<RarArchiveEntry> rarEntries = ra.Entries.OrderBy(e => e.Key, new NaturalSort.NaturalReversedComparer()).ToList();
|
||||
string lastRarEntry = null;
|
||||
string? lastRarEntry = null;
|
||||
foreach (RarArchiveEntry entry in rarEntries)
|
||||
{
|
||||
if (entry != null)
|
||||
@@ -248,20 +264,20 @@ namespace SabreTools.FileTypes.Archives
|
||||
#region Writing
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool Write(string inputFile, string outDir, BaseFile baseFile)
|
||||
public override bool Write(string inputFile, string outDir, BaseFile? baseFile)
|
||||
{
|
||||
// Get the file stream for the file and write out
|
||||
return Write(File.OpenRead(inputFile), outDir, baseFile);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool Write(Stream inputStream, string outDir, BaseFile baseFile)
|
||||
public override bool Write(Stream? inputStream, string outDir, BaseFile? baseFile)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool Write(List<string> inputFiles, string outDir, List<BaseFile> roms)
|
||||
public override bool Write(List<string> inputFiles, string outDir, List<BaseFile>? roms)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@@ -25,9 +25,42 @@ namespace SabreTools.FileTypes.Archives
|
||||
06-07 ArchiveVersion (0x00, 0x03)
|
||||
The rest is unknown
|
||||
*/
|
||||
private readonly static byte[] Torrent7ZipHeader = new byte[] { 0x37, 0x7a, 0xbc, 0xaf, 0x27, 0x1c, 0x00, 0x03 };
|
||||
private readonly static byte[] Torrent7ZipSignature = new byte[] { 0xa9, 0xa9, 0x9f, 0xd1, 0x57, 0x08, 0xa9, 0xd7, 0xea, 0x29, 0x64, 0xb2,
|
||||
0x36, 0x1b, 0x83, 0x52, 0x33, 0x00, 0x74, 0x6f, 0x72, 0x72, 0x65, 0x6e, 0x74, 0x37, 0x7a, 0x5f, 0x30, 0x2e, 0x39, 0x62, 0x65, 0x74, 0x61 };
|
||||
private readonly static byte[] Torrent7ZipHeader = [0x37, 0x7a, 0xbc, 0xaf, 0x27, 0x1c, 0x00, 0x03];
|
||||
private readonly static byte[] Torrent7ZipSignature = [0xa9,
|
||||
0xa9,
|
||||
0x9f,
|
||||
0xd1,
|
||||
0x57,
|
||||
0x08,
|
||||
0xa9,
|
||||
0xd7,
|
||||
0xea,
|
||||
0x29,
|
||||
0x64,
|
||||
0xb2,
|
||||
0x36,
|
||||
0x1b,
|
||||
0x83,
|
||||
0x52,
|
||||
0x33,
|
||||
0x00,
|
||||
0x74,
|
||||
0x6f,
|
||||
0x72,
|
||||
0x72,
|
||||
0x65,
|
||||
0x6e,
|
||||
0x74,
|
||||
0x37,
|
||||
0x7a,
|
||||
0x5f,
|
||||
0x30,
|
||||
0x2e,
|
||||
0x39,
|
||||
0x62,
|
||||
0x65,
|
||||
0x74,
|
||||
0x61];
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -63,6 +96,10 @@ namespace SabreTools.FileTypes.Archives
|
||||
{
|
||||
bool encounteredErrors = true;
|
||||
|
||||
// If we have an invalid file
|
||||
if (this.Filename == null)
|
||||
return true;
|
||||
|
||||
try
|
||||
{
|
||||
// Create the temp directory
|
||||
@@ -83,7 +120,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
|
||||
// Create the rest of the path, if needed
|
||||
if (!string.IsNullOrWhiteSpace(Path.GetDirectoryName(zf.GetLocalFile(i).Filename)))
|
||||
Directory.CreateDirectory(Path.Combine(outDir, 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
|
||||
if (zf.GetLocalFile(i).Filename.EndsWith(Path.DirectorySeparatorChar.ToString())
|
||||
@@ -144,10 +181,10 @@ namespace SabreTools.FileTypes.Archives
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override string CopyToFile(string entryName, string outDir)
|
||||
public override string? CopyToFile(string entryName, string outDir)
|
||||
{
|
||||
// Try to extract a stream using the given information
|
||||
(MemoryStream ms, string realEntry) = CopyToStream(entryName);
|
||||
(MemoryStream? ms, string? realEntry) = CopyToStream(entryName);
|
||||
|
||||
// If the memory stream and the entry name are both non-null, we write to file
|
||||
if (ms != null && realEntry != null)
|
||||
@@ -155,7 +192,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
realEntry = Path.Combine(outDir, realEntry);
|
||||
|
||||
// Create the output subfolder now
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(realEntry));
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(realEntry)!);
|
||||
|
||||
// Now open and write the file if possible
|
||||
FileStream fs = File.Create(realEntry);
|
||||
@@ -185,10 +222,14 @@ namespace SabreTools.FileTypes.Archives
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override (MemoryStream, string) CopyToStream(string entryName)
|
||||
public override (MemoryStream?, string?) CopyToStream(string entryName)
|
||||
{
|
||||
MemoryStream ms = new();
|
||||
string realEntry = null;
|
||||
MemoryStream? ms = new();
|
||||
string? realEntry = null;
|
||||
|
||||
// If we have an invalid file
|
||||
if (this.Filename == null)
|
||||
return (null, null);
|
||||
|
||||
try
|
||||
{
|
||||
@@ -254,10 +295,15 @@ namespace SabreTools.FileTypes.Archives
|
||||
#region Information
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override List<BaseFile> GetChildren()
|
||||
public override List<BaseFile>? GetChildren()
|
||||
{
|
||||
List<BaseFile> found = new();
|
||||
string gamename = Path.GetFileNameWithoutExtension(this.Filename);
|
||||
List<BaseFile> found = [];
|
||||
|
||||
// If we have an invalid file
|
||||
if (this.Filename == null)
|
||||
return null;
|
||||
|
||||
string? gamename = Path.GetFileNameWithoutExtension(this.Filename);
|
||||
|
||||
try
|
||||
{
|
||||
@@ -327,7 +373,11 @@ namespace SabreTools.FileTypes.Archives
|
||||
/// <inheritdoc/>
|
||||
public override List<string> GetEmptyFolders()
|
||||
{
|
||||
List<string> empties = new();
|
||||
List<string> empties = [];
|
||||
|
||||
// If we have an invalid file
|
||||
if (this.Filename == null)
|
||||
return empties;
|
||||
|
||||
try
|
||||
{
|
||||
@@ -338,14 +388,14 @@ namespace SabreTools.FileTypes.Archives
|
||||
throw new Exception(CompressUtils.ZipErrorMessageText(zr));
|
||||
}
|
||||
|
||||
List<(string, bool)> zipEntries = new();
|
||||
List<(string, bool)> zipEntries = [];
|
||||
for (int i = 0; i < zf.LocalFilesCount(); i++)
|
||||
{
|
||||
zipEntries.Add((zf.GetLocalFile(i).Filename, zf.GetLocalFile(i).IsDirectory));
|
||||
}
|
||||
|
||||
zipEntries = zipEntries.OrderBy(p => p.Item1, new NaturalReversedComparer()).ToList();
|
||||
string lastZipEntry = null;
|
||||
string? lastZipEntry = null;
|
||||
foreach ((string, bool) entry in zipEntries)
|
||||
{
|
||||
// If the current is a superset of last, we skip it
|
||||
@@ -375,6 +425,10 @@ namespace SabreTools.FileTypes.Archives
|
||||
/// <inheritdoc/>
|
||||
public override bool IsTorrent()
|
||||
{
|
||||
// If we have an invalid file
|
||||
if (this.Filename == null)
|
||||
return false;
|
||||
|
||||
SevenZ zf = new();
|
||||
ZipReturn zr = zf.ZipFileOpen(this.Filename, -1, true);
|
||||
if (zr != ZipReturn.ZipGood)
|
||||
@@ -390,14 +444,14 @@ namespace SabreTools.FileTypes.Archives
|
||||
#region Writing
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool Write(string inputFile, string outDir, BaseFile baseFile)
|
||||
public override bool Write(string inputFile, string outDir, BaseFile? baseFile)
|
||||
{
|
||||
// Get the file stream for the file and write out
|
||||
return Write(File.OpenRead(inputFile), outDir, baseFile);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool Write(Stream inputStream, string outDir, BaseFile baseFile)
|
||||
public override bool Write(Stream? inputStream, string outDir, BaseFile? baseFile)
|
||||
{
|
||||
bool success = false;
|
||||
string tempFile = Path.Combine(outDir, $"tmp{Guid.NewGuid()}");
|
||||
@@ -414,10 +468,10 @@ namespace SabreTools.FileTypes.Archives
|
||||
inputStream.Seek(0, SeekOrigin.Begin);
|
||||
|
||||
// Get the output archive name from the first rebuild rom
|
||||
string archiveFileName = Path.Combine(outDir, TextHelper.RemovePathUnsafeCharacters(baseFile.Parent) + (baseFile.Parent.EndsWith(".7z") ? string.Empty : ".7z"));
|
||||
string archiveFileName = Path.Combine(outDir, TextHelper.RemovePathUnsafeCharacters(baseFile.Parent) + (baseFile.Parent?.EndsWith(".7z") ?? false ? string.Empty : ".7z"));
|
||||
|
||||
// Set internal variables
|
||||
Stream writeStream = null;
|
||||
Stream? writeStream = null;
|
||||
SevenZ oldZipFile = new();
|
||||
SevenZ zipFile = new();
|
||||
ZipReturn zipReturn = ZipReturn.ZipGood;
|
||||
@@ -426,7 +480,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
{
|
||||
// If the full output path doesn't exist, create it
|
||||
if (!Directory.Exists(Path.GetDirectoryName(archiveFileName)))
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(archiveFileName));
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(archiveFileName)!);
|
||||
|
||||
// If the archive doesn't exist, create it and put the single file
|
||||
if (!File.Exists(archiveFileName))
|
||||
@@ -450,15 +504,18 @@ namespace SabreTools.FileTypes.Archives
|
||||
}
|
||||
|
||||
// Copy the input stream to the output
|
||||
byte[] ibuffer = new byte[_bufferSize];
|
||||
int ilen;
|
||||
while ((ilen = inputStream.Read(ibuffer, 0, _bufferSize)) > 0)
|
||||
if (writeStream != null)
|
||||
{
|
||||
writeStream.Write(ibuffer, 0, ilen);
|
||||
writeStream.Flush();
|
||||
byte[] ibuffer = new byte[_bufferSize];
|
||||
int ilen;
|
||||
while ((ilen = inputStream.Read(ibuffer, 0, _bufferSize)) > 0)
|
||||
{
|
||||
writeStream.Write(ibuffer, 0, ilen);
|
||||
writeStream.Flush();
|
||||
}
|
||||
}
|
||||
|
||||
zipFile.ZipFileCloseWriteStream(baseFile.CRC);
|
||||
zipFile.ZipFileCloseWriteStream(baseFile.CRC!);
|
||||
}
|
||||
|
||||
// Otherwise, sort the input files and write out in the correct order
|
||||
@@ -468,7 +525,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
oldZipFile.ZipFileOpen(archiveFileName, -1, true);
|
||||
|
||||
// Map all inputs to index
|
||||
Dictionary<string, int> inputIndexMap = new();
|
||||
Dictionary<string, int> inputIndexMap = [];
|
||||
var oldZipFileContents = new List<string>();
|
||||
for (int i = 0; i < oldZipFile.LocalFilesCount(); i++)
|
||||
{
|
||||
@@ -498,7 +555,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
zipFile.ZipFileCreate(tempFile);
|
||||
|
||||
// Get the order for the entries with the new file
|
||||
List<string> keys = inputIndexMap.Keys.ToList();
|
||||
List<string> keys = [.. inputIndexMap.Keys];
|
||||
keys.Sort(CompressUtils.TrrntZipStringCompare);
|
||||
|
||||
// Copy over all files to the new archive
|
||||
@@ -526,15 +583,18 @@ namespace SabreTools.FileTypes.Archives
|
||||
}
|
||||
|
||||
// Copy the input stream to the output
|
||||
byte[] ibuffer = new byte[_bufferSize];
|
||||
int ilen;
|
||||
while ((ilen = inputStream.Read(ibuffer, 0, _bufferSize)) > 0)
|
||||
if (writeStream != null)
|
||||
{
|
||||
writeStream.Write(ibuffer, 0, ilen);
|
||||
writeStream.Flush();
|
||||
byte[] ibuffer = new byte[_bufferSize];
|
||||
int ilen;
|
||||
while ((ilen = inputStream.Read(ibuffer, 0, _bufferSize)) > 0)
|
||||
{
|
||||
writeStream.Write(ibuffer, 0, ilen);
|
||||
writeStream.Flush();
|
||||
}
|
||||
}
|
||||
|
||||
zipFile.ZipFileCloseWriteStream(baseFile.CRC);
|
||||
zipFile.ZipFileCloseWriteStream(baseFile.CRC!);
|
||||
}
|
||||
|
||||
// Otherwise, copy the file from the old archive
|
||||
@@ -545,12 +605,15 @@ namespace SabreTools.FileTypes.Archives
|
||||
zipFile.ZipFileOpenWriteStream(false, true, oldZipFile.GetLocalFile(index).Filename, istreamSize, 0, out writeStream, null);
|
||||
|
||||
// Copy the input stream to the output
|
||||
byte[] ibuffer = new byte[_bufferSize];
|
||||
int ilen;
|
||||
while ((ilen = zreadStream.Read(ibuffer, 0, _bufferSize)) > 0)
|
||||
if (writeStream != null)
|
||||
{
|
||||
writeStream.Write(ibuffer, 0, ilen);
|
||||
writeStream.Flush();
|
||||
byte[] ibuffer = new byte[_bufferSize];
|
||||
int ilen;
|
||||
while ((ilen = zreadStream.Read(ibuffer, 0, _bufferSize)) > 0)
|
||||
{
|
||||
writeStream.Write(ibuffer, 0, ilen);
|
||||
writeStream.Flush();
|
||||
}
|
||||
}
|
||||
|
||||
oldZipFile.ZipFileCloseReadStream();
|
||||
@@ -584,7 +647,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool Write(List<string> inputFiles, string outDir, List<BaseFile> baseFiles)
|
||||
public override bool Write(List<string> inputFiles, string outDir, List<BaseFile>? baseFiles)
|
||||
{
|
||||
bool success = false;
|
||||
string tempFile = Path.Combine(outDir, $"tmp{Guid.NewGuid()}");
|
||||
@@ -611,10 +674,10 @@ namespace SabreTools.FileTypes.Archives
|
||||
}
|
||||
|
||||
// Get the output archive name from the first rebuild rom
|
||||
string archiveFileName = Path.Combine(outDir, TextHelper.RemovePathUnsafeCharacters(baseFiles[0].Parent) + (baseFiles[0].Parent.EndsWith(".7z") ? string.Empty : ".7z"));
|
||||
string archiveFileName = Path.Combine(outDir, TextHelper.RemovePathUnsafeCharacters(baseFiles[0].Parent) + (baseFiles[0].Parent?.EndsWith(".7z") ?? false ? string.Empty : ".7z"));
|
||||
|
||||
// Set internal variables
|
||||
Stream writeStream = null;
|
||||
Stream? writeStream = null;
|
||||
SevenZ oldZipFile = new();
|
||||
SevenZ zipFile = new();
|
||||
ZipReturn zipReturn = ZipReturn.ZipGood;
|
||||
@@ -623,9 +686,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
{
|
||||
// If the full output path doesn't exist, create it
|
||||
if (!Directory.Exists(Path.GetDirectoryName(archiveFileName)))
|
||||
{
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(archiveFileName));
|
||||
}
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(archiveFileName)!);
|
||||
|
||||
// If the archive doesn't exist, create it and put the single file
|
||||
if (!File.Exists(archiveFileName))
|
||||
@@ -633,14 +694,14 @@ namespace SabreTools.FileTypes.Archives
|
||||
zipReturn = zipFile.ZipFileCreate(tempFile);
|
||||
|
||||
// Map all inputs to index
|
||||
Dictionary<string, int> inputIndexMap = new();
|
||||
Dictionary<string, int> inputIndexMap = [];
|
||||
for (int i = 0; i < inputFiles.Count; i++)
|
||||
{
|
||||
inputIndexMap.Add(baseFiles[i].Filename.Replace('\\', '/'), i);
|
||||
inputIndexMap.Add(baseFiles[i]?.Filename?.Replace('\\', '/') ?? string.Empty, i);
|
||||
}
|
||||
|
||||
// Sort the keys in TZIP order
|
||||
List<string> keys = inputIndexMap.Keys.ToList();
|
||||
List<string> keys = [.. inputIndexMap.Keys];
|
||||
keys.Sort(CompressUtils.TrrntZipStringCompare);
|
||||
|
||||
// Now add all of the files in order
|
||||
@@ -651,18 +712,18 @@ namespace SabreTools.FileTypes.Archives
|
||||
|
||||
// Open the input file for reading
|
||||
Stream freadStream = File.OpenRead(inputFiles[index]);
|
||||
ulong istreamSize = (ulong)(new FileInfo(inputFiles[index]).Length);
|
||||
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.IsNullOrWhiteSpace(baseFiles[index].Date) && DateTime.TryParse(baseFiles[index].Date?.Replace('\\', '/'), out dt))
|
||||
{
|
||||
long msDosDateTime = DateTimeHelper.ConvertToMsDosTimeFormat(dt);
|
||||
TimeStamps ts = new() { ModTime = msDosDateTime };
|
||||
zipFile.ZipFileOpenWriteStream(false, false, baseFiles[index].Filename.Replace('\\', '/'), istreamSize, 0, out writeStream, ts);
|
||||
zipFile.ZipFileOpenWriteStream(false, false, baseFiles[index].Filename!.Replace('\\', '/')!, istreamSize, 0, out writeStream, ts);
|
||||
}
|
||||
else
|
||||
{
|
||||
zipFile.ZipFileOpenWriteStream(false, true, baseFiles[index].Filename.Replace('\\', '/'), istreamSize, 0, out writeStream, null);
|
||||
zipFile.ZipFileOpenWriteStream(false, true, baseFiles[index].Filename!.Replace('\\', '/'), istreamSize, 0, out writeStream, null);
|
||||
}
|
||||
|
||||
// Copy the input stream to the output
|
||||
@@ -670,12 +731,12 @@ namespace SabreTools.FileTypes.Archives
|
||||
int ilen;
|
||||
while ((ilen = freadStream.Read(ibuffer, 0, _bufferSize)) > 0)
|
||||
{
|
||||
writeStream.Write(ibuffer, 0, ilen);
|
||||
writeStream!.Write(ibuffer, 0, ilen);
|
||||
writeStream.Flush();
|
||||
}
|
||||
|
||||
freadStream.Dispose();
|
||||
zipFile.ZipFileCloseWriteStream(baseFiles[index].CRC);
|
||||
zipFile.ZipFileCloseWriteStream(baseFiles[index].CRC!);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -696,12 +757,12 @@ namespace SabreTools.FileTypes.Archives
|
||||
}
|
||||
|
||||
// If the old one contains the new file, then just skip out
|
||||
if (oldZipFileContents.Contains(baseFiles[i].Filename.Replace('\\', '/')))
|
||||
if (oldZipFileContents.Contains(baseFiles[i].Filename!.Replace('\\', '/')))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
inputIndexMap.Add(baseFiles[i].Filename.Replace('\\', '/'), -(i + 1));
|
||||
inputIndexMap.Add(baseFiles[i].Filename!.Replace('\\', '/'), -(i + 1));
|
||||
}
|
||||
|
||||
// Then add all of the old entries to it too
|
||||
@@ -738,15 +799,15 @@ 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.IsNullOrWhiteSpace(baseFiles[-index - 1].Date) && DateTime.TryParse(baseFiles[-index - 1].Date?.Replace('\\', '/'), out dt))
|
||||
{
|
||||
long msDosDateTime = DateTimeHelper.ConvertToMsDosTimeFormat(dt);
|
||||
TimeStamps ts = new() { ModTime = msDosDateTime };
|
||||
zipFile.ZipFileOpenWriteStream(false, false, baseFiles[-index - 1].Filename.Replace('\\', '/'), istreamSize, 0, out writeStream, ts);
|
||||
zipFile.ZipFileOpenWriteStream(false, false, baseFiles[-index - 1].Filename!.Replace('\\', '/'), istreamSize, 0, out writeStream, ts);
|
||||
}
|
||||
else
|
||||
{
|
||||
zipFile.ZipFileOpenWriteStream(false, true, baseFiles[-index - 1].Filename.Replace('\\', '/'), istreamSize, 0, out writeStream, null);
|
||||
zipFile.ZipFileOpenWriteStream(false, true, baseFiles[-index - 1].Filename!.Replace('\\', '/'), istreamSize, 0, out writeStream, null);
|
||||
}
|
||||
|
||||
// Copy the input stream to the output
|
||||
@@ -754,11 +815,11 @@ namespace SabreTools.FileTypes.Archives
|
||||
int ilen;
|
||||
while ((ilen = freadStream.Read(ibuffer, 0, _bufferSize)) > 0)
|
||||
{
|
||||
writeStream.Write(ibuffer, 0, ilen);
|
||||
writeStream!.Write(ibuffer, 0, ilen);
|
||||
writeStream.Flush();
|
||||
}
|
||||
freadStream.Dispose();
|
||||
zipFile.ZipFileCloseWriteStream(baseFiles[-index - 1].CRC);
|
||||
zipFile.ZipFileCloseWriteStream(baseFiles[-index - 1].CRC!);
|
||||
}
|
||||
|
||||
// Otherwise, copy the file from the old archive
|
||||
@@ -773,7 +834,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
int ilen;
|
||||
while ((ilen = zreadStream.Read(ibuffer, 0, _bufferSize)) > 0)
|
||||
{
|
||||
writeStream.Write(ibuffer, 0, ilen);
|
||||
writeStream!.Write(ibuffer, 0, ilen);
|
||||
writeStream.Flush();
|
||||
}
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
Directory.CreateDirectory(outDir);
|
||||
|
||||
// Extract all files to the temp directory
|
||||
TarArchive ta = TarArchive.Open(this.Filename);
|
||||
TarArchive ta = TarArchive.Open(this.Filename!);
|
||||
foreach (TarArchiveEntry entry in ta.Entries)
|
||||
{
|
||||
entry.WriteToDirectory(outDir, new ExtractionOptions { PreserveFileTime = true, ExtractFullPath = true, Overwrite = true });
|
||||
@@ -86,10 +86,10 @@ namespace SabreTools.FileTypes.Archives
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override string CopyToFile(string entryName, string outDir)
|
||||
public override string? CopyToFile(string entryName, string outDir)
|
||||
{
|
||||
// Try to extract a stream using the given information
|
||||
(MemoryStream ms, string realEntry) = CopyToStream(entryName);
|
||||
(MemoryStream? ms, string? realEntry) = CopyToStream(entryName);
|
||||
|
||||
// If the memory stream and the entry name are both non-null, we write to file
|
||||
if (ms != null && realEntry != null)
|
||||
@@ -97,7 +97,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
realEntry = Path.Combine(outDir, realEntry);
|
||||
|
||||
// Create the output subfolder now
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(realEntry));
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(realEntry)!);
|
||||
|
||||
// Now open and write the file if possible
|
||||
FileStream fs = File.Create(realEntry);
|
||||
@@ -127,14 +127,14 @@ namespace SabreTools.FileTypes.Archives
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override (MemoryStream, string) CopyToStream(string entryName)
|
||||
public override (MemoryStream?, string?) CopyToStream(string entryName)
|
||||
{
|
||||
MemoryStream ms = new();
|
||||
string realEntry = null;
|
||||
MemoryStream? ms = new();
|
||||
string? realEntry = null;
|
||||
|
||||
try
|
||||
{
|
||||
TarArchive ta = TarArchive.Open(this.Filename, new ReaderOptions { LeaveStreamOpen = false, });
|
||||
TarArchive ta = TarArchive.Open(this.Filename!, new ReaderOptions { LeaveStreamOpen = false, });
|
||||
foreach (TarArchiveEntry entry in ta.Entries)
|
||||
{
|
||||
if (entry != null && !entry.IsDirectory && entry.Key.Contains(entryName))
|
||||
@@ -161,14 +161,14 @@ namespace SabreTools.FileTypes.Archives
|
||||
#region Information
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override List<BaseFile> GetChildren()
|
||||
public override List<BaseFile>? GetChildren()
|
||||
{
|
||||
List<BaseFile> found = new();
|
||||
string gamename = Path.GetFileNameWithoutExtension(this.Filename);
|
||||
string? gamename = Path.GetFileNameWithoutExtension(this.Filename);
|
||||
|
||||
try
|
||||
{
|
||||
TarArchive ta = TarArchive.Open(File.OpenRead(this.Filename));
|
||||
TarArchive ta = TarArchive.Open(File.OpenRead(this.Filename!));
|
||||
foreach (TarArchiveEntry entry in ta.Entries.Where(e => e != null && !e.IsDirectory))
|
||||
{
|
||||
// Create a blank item for the entry
|
||||
@@ -213,9 +213,9 @@ namespace SabreTools.FileTypes.Archives
|
||||
|
||||
try
|
||||
{
|
||||
TarArchive ta = TarArchive.Open(this.Filename, new ReaderOptions { LeaveStreamOpen = false });
|
||||
TarArchive ta = TarArchive.Open(this.Filename!, new ReaderOptions { LeaveStreamOpen = false });
|
||||
List<TarArchiveEntry> tarEntries = ta.Entries.OrderBy(e => e.Key, new NaturalSort.NaturalReversedComparer()).ToList();
|
||||
string lastTarEntry = null;
|
||||
string? lastTarEntry = null;
|
||||
foreach (TarArchiveEntry entry in tarEntries)
|
||||
{
|
||||
if (entry != null)
|
||||
@@ -253,14 +253,14 @@ namespace SabreTools.FileTypes.Archives
|
||||
#region Writing
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool Write(string inputFile, string outDir, BaseFile baseFile)
|
||||
public override bool Write(string inputFile, string outDir, BaseFile? baseFile)
|
||||
{
|
||||
// Get the file stream for the file and write out
|
||||
return Write(File.OpenRead(inputFile), outDir, baseFile);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool Write(Stream inputStream, string outDir, BaseFile baseFile)
|
||||
public override bool Write(Stream? inputStream, string outDir, BaseFile? baseFile)
|
||||
{
|
||||
bool success = false;
|
||||
string tempFile = Path.Combine(outDir, $"tmp{Guid.NewGuid()}");
|
||||
@@ -274,7 +274,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
return success;
|
||||
|
||||
// Get the output archive name from the first rebuild rom
|
||||
string archiveFileName = Path.Combine(outDir, TextHelper.RemovePathUnsafeCharacters(baseFile.Parent) + (baseFile.Parent.EndsWith(".tar") ? string.Empty : ".tar"));
|
||||
string archiveFileName = Path.Combine(outDir, TextHelper.RemovePathUnsafeCharacters(baseFile.Parent) + (baseFile.Parent!.EndsWith(".tar") ? string.Empty : ".tar"));
|
||||
|
||||
// Set internal variables
|
||||
TarArchive oldTarFile = TarArchive.Create();
|
||||
@@ -284,7 +284,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
{
|
||||
// If the full output path doesn't exist, create it
|
||||
if (!Directory.Exists(Path.GetDirectoryName(archiveFileName)))
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(archiveFileName));
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(archiveFileName)!);
|
||||
|
||||
// If the archive doesn't exist, create it and put the single file
|
||||
if (!File.Exists(archiveFileName))
|
||||
@@ -391,7 +391,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool Write(List<string> inputFiles, string outDir, List<BaseFile> baseFiles)
|
||||
public override bool Write(List<string> inputFiles, string outDir, List<BaseFile>? baseFiles)
|
||||
{
|
||||
bool success = false;
|
||||
string tempFile = Path.Combine(outDir, $"tmp{Guid.NewGuid()}");
|
||||
@@ -418,7 +418,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
}
|
||||
|
||||
// Get the output archive name from the first rebuild rom
|
||||
string archiveFileName = Path.Combine(outDir, TextHelper.RemovePathUnsafeCharacters(baseFiles[0].Parent) + (baseFiles[0].Parent.EndsWith(".tar") ? string.Empty : ".tar"));
|
||||
string archiveFileName = Path.Combine(outDir, TextHelper.RemovePathUnsafeCharacters(baseFiles[0].Parent) + (baseFiles[0].Parent!.EndsWith(".tar") ? string.Empty : ".tar"));
|
||||
|
||||
// Set internal variables
|
||||
TarArchive oldTarFile = TarArchive.Create();
|
||||
@@ -429,7 +429,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
// If the full output path doesn't exist, create it
|
||||
if (!Directory.Exists(Path.GetDirectoryName(archiveFileName)))
|
||||
{
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(archiveFileName));
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(archiveFileName)!);
|
||||
}
|
||||
|
||||
// If the archive doesn't exist, create it and put the single file
|
||||
@@ -439,7 +439,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
Dictionary<string, int> inputIndexMap = new();
|
||||
for (int i = 0; i < inputFiles.Count; i++)
|
||||
{
|
||||
inputIndexMap.Add(baseFiles[i].Filename.Replace('\\', '/'), i);
|
||||
inputIndexMap.Add(baseFiles[i].Filename!.Replace('\\', '/'), i);
|
||||
}
|
||||
|
||||
// Sort the keys in TZIP order
|
||||
@@ -454,11 +454,11 @@ 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.IsNullOrWhiteSpace(baseFiles[index].Date) && DateTime.TryParse(baseFiles[index].Date?.Replace('\\', '/'), out DateTime dt))
|
||||
usableDate = dt;
|
||||
|
||||
// Copy the input stream to the output
|
||||
tarFile.AddEntry(baseFiles[index].Filename, File.OpenRead(inputFiles[index]), size: baseFiles[index].Size ?? 0, modified: usableDate);
|
||||
tarFile.AddEntry(baseFiles[index].Filename!, File.OpenRead(inputFiles[index]), size: baseFiles[index].Size ?? 0, modified: usableDate);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -476,12 +476,12 @@ namespace SabreTools.FileTypes.Archives
|
||||
for (int i = 0; i < inputFiles.Count; i++)
|
||||
{
|
||||
// If the old one contains the new file, then just skip out
|
||||
if (entries.Contains(baseFiles[i].Filename.Replace('\\', '/')))
|
||||
if (entries.Contains(baseFiles[i].Filename!.Replace('\\', '/')))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
inputIndexMap.Add(baseFiles[i].Filename.Replace('\\', '/'), -(i + 1));
|
||||
inputIndexMap.Add(baseFiles[i].Filename!.Replace('\\', '/'), -(i + 1));
|
||||
}
|
||||
|
||||
// Then add all of the old entries to it too
|
||||
@@ -512,11 +512,11 @@ 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.IsNullOrWhiteSpace(baseFiles[-index - 1].Date) && DateTime.TryParse(baseFiles[-index - 1].Date?.Replace('\\', '/'), out DateTime dt))
|
||||
usableDate = dt;
|
||||
|
||||
// Copy the input file to the output
|
||||
tarFile.AddEntry(baseFiles[-index - 1].Filename, File.OpenRead(inputFiles[-index - 1]), size: baseFiles[-index - 1].Size ?? 0, modified: usableDate);
|
||||
tarFile.AddEntry(baseFiles[-index - 1].Filename!, File.OpenRead(inputFiles[-index - 1]), size: baseFiles[-index - 1].Size ?? 0, modified: usableDate);
|
||||
}
|
||||
|
||||
// Otherwise, copy the file from the old archive
|
||||
|
||||
@@ -75,8 +75,8 @@ namespace SabreTools.FileTypes.Archives
|
||||
Directory.CreateDirectory(outDir);
|
||||
|
||||
// Decompress the _filename stream
|
||||
FileStream outstream = File.Create(Path.Combine(outDir, Path.GetFileNameWithoutExtension(this.Filename)));
|
||||
var xz = new XZStream(File.OpenRead(this.Filename));
|
||||
FileStream outstream = File.Create(Path.Combine(outDir, Path.GetFileNameWithoutExtension(this.Filename)!));
|
||||
var xz = new XZStream(File.OpenRead(this.Filename!));
|
||||
xz.CopyTo(outstream);
|
||||
|
||||
// Dispose of the streams
|
||||
@@ -105,10 +105,10 @@ namespace SabreTools.FileTypes.Archives
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override string CopyToFile(string entryName, string outDir)
|
||||
public override string? CopyToFile(string entryName, string outDir)
|
||||
{
|
||||
// Try to extract a stream using the given information
|
||||
(MemoryStream ms, string realEntry) = CopyToStream(entryName);
|
||||
(MemoryStream? ms, string? realEntry) = CopyToStream(entryName);
|
||||
|
||||
// If the memory stream and the entry name are both non-null, we write to file
|
||||
if (ms != null && realEntry != null)
|
||||
@@ -116,7 +116,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
realEntry = Path.Combine(outDir, realEntry);
|
||||
|
||||
// Create the output subfolder now
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(realEntry));
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(realEntry)!);
|
||||
|
||||
// Now open and write the file if possible
|
||||
FileStream fs = File.Create(realEntry);
|
||||
@@ -146,16 +146,16 @@ namespace SabreTools.FileTypes.Archives
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override (MemoryStream, string) CopyToStream(string entryName)
|
||||
public override (MemoryStream?, string?) CopyToStream(string entryName)
|
||||
{
|
||||
MemoryStream ms = new();
|
||||
string realEntry;
|
||||
MemoryStream? ms = new();
|
||||
string? realEntry;
|
||||
|
||||
try
|
||||
{
|
||||
// Decompress the _filename stream
|
||||
realEntry = Path.GetFileNameWithoutExtension(this.Filename);
|
||||
var xz = new XZStream(File.OpenRead(this.Filename));
|
||||
var xz = new XZStream(File.OpenRead(this.Filename!));
|
||||
|
||||
// Write the file out
|
||||
byte[] xbuffer = new byte[_bufferSize];
|
||||
@@ -185,15 +185,15 @@ namespace SabreTools.FileTypes.Archives
|
||||
#region Information
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override List<BaseFile> GetChildren()
|
||||
public override List<BaseFile>? GetChildren()
|
||||
{
|
||||
if (_children == null || _children.Count == 0)
|
||||
{
|
||||
_children = new List<BaseFile>();
|
||||
|
||||
string gamename = Path.GetFileNameWithoutExtension(this.Filename);
|
||||
string? gamename = Path.GetFileNameWithoutExtension(this.Filename);
|
||||
|
||||
BaseFile possibleTxz = GetTorrentXZFileInfo();
|
||||
BaseFile? possibleTxz = GetTorrentXZFileInfo();
|
||||
|
||||
// If it was, then add it to the outputs and continue
|
||||
if (possibleTxz != null && possibleTxz.Filename != null)
|
||||
@@ -212,7 +212,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
{
|
||||
xzEntryRom.Filename = gamename;
|
||||
|
||||
using BinaryReader br = new(File.OpenRead(this.Filename));
|
||||
using BinaryReader br = new(File.OpenRead(this.Filename!));
|
||||
br.BaseStream.Seek(-8, SeekOrigin.End);
|
||||
xzEntryRom.CRC = br.ReadBytesBigEndian(4);
|
||||
xzEntryRom.Size = br.ReadInt32BigEndian();
|
||||
@@ -220,7 +220,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
// Otherwise, use the stream directly
|
||||
else
|
||||
{
|
||||
var xzStream = new XZStream(File.OpenRead(this.Filename));
|
||||
var xzStream = new XZStream(File.OpenRead(this.Filename!));
|
||||
xzEntryRom = GetInfo(xzStream, hashes: this.AvailableHashes);
|
||||
xzEntryRom.Filename = gamename;
|
||||
xzStream.Dispose();
|
||||
@@ -245,7 +245,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
public override List<string> GetEmptyFolders()
|
||||
{
|
||||
// XZ files don't contain directories
|
||||
return new List<string>();
|
||||
return [];
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
@@ -271,7 +271,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
/// Retrieve file information for a single torrent XZ file
|
||||
/// </summary>
|
||||
/// <returns>Populated DatItem object if success, empty one on error</returns>
|
||||
public BaseFile GetTorrentXZFileInfo()
|
||||
public BaseFile? GetTorrentXZFileInfo()
|
||||
{
|
||||
// Check for the file existing first
|
||||
if (!File.Exists(this.Filename))
|
||||
@@ -302,7 +302,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
#region Writing
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool Write(string inputFile, string outDir, BaseFile baseFile)
|
||||
public override bool Write(string inputFile, string outDir, BaseFile? baseFile)
|
||||
{
|
||||
// Check that the input file exists
|
||||
if (!File.Exists(inputFile))
|
||||
@@ -318,12 +318,12 @@ namespace SabreTools.FileTypes.Archives
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool Write(Stream inputStream, string outDir, BaseFile baseFile)
|
||||
public override bool Write(Stream? inputStream, string outDir, BaseFile? baseFile)
|
||||
{
|
||||
bool success = false;
|
||||
|
||||
// If the stream is not readable, return
|
||||
if (!inputStream.CanRead)
|
||||
if (inputStream == null || !inputStream.CanRead)
|
||||
return success;
|
||||
|
||||
// Make sure the output directory exists
|
||||
@@ -336,12 +336,12 @@ namespace SabreTools.FileTypes.Archives
|
||||
baseFile = GetInfo(inputStream, keepReadOpen: true);
|
||||
|
||||
// Get the output file name
|
||||
string outfile = Path.Combine(outDir, Utilities.GetDepotPath(TextHelper.ByteArrayToString(baseFile.SHA1), Depth));
|
||||
string outfile = Path.Combine(outDir, Utilities.GetDepotPath(TextHelper.ByteArrayToString(baseFile.SHA1), Depth)!);
|
||||
outfile = outfile.Replace(".gz", ".xz");
|
||||
|
||||
// Check to see if the folder needs to be created
|
||||
if (!Directory.Exists(Path.GetDirectoryName(outfile)))
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(outfile));
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(outfile)!);
|
||||
|
||||
// If the output file exists, don't try to write again
|
||||
if (!File.Exists(outfile))
|
||||
@@ -358,7 +358,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool Write(List<string> inputFiles, string outDir, List<BaseFile> baseFiles)
|
||||
public override bool Write(List<string> inputFiles, string outDir, List<BaseFile>? baseFiles)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@@ -81,19 +81,19 @@ namespace SabreTools.FileTypes.Archives
|
||||
#region Writing
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool Write(string inputFile, string outDir, BaseFile baseFile)
|
||||
public override bool Write(string inputFile, string outDir, BaseFile? baseFile)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool Write(Stream inputStream, string outDir, BaseFile baseFile)
|
||||
public override bool Write(Stream? inputStream, string outDir, BaseFile? baseFile)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool Write(List<string> inputFiles, string outDir, List<BaseFile> baseFiles)
|
||||
public override bool Write(List<string> inputFiles, string outDir, List<BaseFile>? baseFiles)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
|
||||
// Extract all files to the temp directory
|
||||
Zip zf = new();
|
||||
ZipReturn zr = zf.ZipFileOpen(this.Filename, -1, true);
|
||||
ZipReturn zr = zf.ZipFileOpen(this.Filename!, -1, true);
|
||||
if (zr != ZipReturn.ZipGood)
|
||||
{
|
||||
throw new Exception(CompressUtils.ZipErrorMessageText(zr));
|
||||
@@ -88,12 +88,12 @@ namespace SabreTools.FileTypes.Archives
|
||||
for (int i = 0; i < zf.LocalFilesCount() && zr == ZipReturn.ZipGood; i++)
|
||||
{
|
||||
// Open the read stream
|
||||
zr = zf.ZipFileOpenReadStream(i, false, out Stream readStream, out ulong streamsize, out ushort cm);
|
||||
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)))
|
||||
{
|
||||
Directory.CreateDirectory(Path.Combine(outDir, 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
|
||||
@@ -111,7 +111,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
if (streamsize < _bufferSize)
|
||||
{
|
||||
byte[] ibuffer = new byte[streamsize];
|
||||
int ilen = readStream.Read(ibuffer, 0, (int)streamsize);
|
||||
int ilen = readStream!.Read(ibuffer, 0, (int)streamsize);
|
||||
writeStream.Write(ibuffer, 0, ilen);
|
||||
writeStream.Flush();
|
||||
}
|
||||
@@ -121,7 +121,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
int realBufferSize = (streamsize < _bufferSize ? (int)streamsize : _bufferSize);
|
||||
byte[] ibuffer = new byte[realBufferSize];
|
||||
int ilen;
|
||||
while ((ilen = readStream.Read(ibuffer, 0, realBufferSize)) > 0)
|
||||
while ((ilen = readStream!.Read(ibuffer, 0, realBufferSize)) > 0)
|
||||
{
|
||||
writeStream.Write(ibuffer, 0, ilen);
|
||||
writeStream.Flush();
|
||||
@@ -155,10 +155,10 @@ namespace SabreTools.FileTypes.Archives
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override string CopyToFile(string entryName, string outDir)
|
||||
public override string? CopyToFile(string entryName, string outDir)
|
||||
{
|
||||
// Try to extract a stream using the given information
|
||||
(MemoryStream ms, string realEntry) = CopyToStream(entryName);
|
||||
(MemoryStream? ms, string? realEntry) = CopyToStream(entryName);
|
||||
|
||||
// If the memory stream and the entry name are both non-null, we write to file
|
||||
if (ms != null && realEntry != null)
|
||||
@@ -166,7 +166,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
realEntry = Path.Combine(outDir, realEntry);
|
||||
|
||||
// Create the output subfolder now
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(realEntry));
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(realEntry)!);
|
||||
|
||||
// Now open and write the file if possible
|
||||
FileStream fs = File.Create(realEntry);
|
||||
@@ -196,15 +196,15 @@ namespace SabreTools.FileTypes.Archives
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override (MemoryStream, string) CopyToStream(string entryName)
|
||||
public override (MemoryStream?, string?) CopyToStream(string entryName)
|
||||
{
|
||||
MemoryStream ms = new();
|
||||
string realEntry = null;
|
||||
MemoryStream? ms = new();
|
||||
string? realEntry = null;
|
||||
|
||||
try
|
||||
{
|
||||
Zip zf = new();
|
||||
ZipReturn zr = zf.ZipFileOpen(this.Filename, -1, true);
|
||||
ZipReturn zr = zf.ZipFileOpen(this.Filename!, -1, true);
|
||||
if (zr != ZipReturn.ZipGood)
|
||||
{
|
||||
throw new Exception(CompressUtils.ZipErrorMessageText(zr));
|
||||
@@ -216,13 +216,13 @@ namespace SabreTools.FileTypes.Archives
|
||||
{
|
||||
// Open the read stream
|
||||
realEntry = zf.GetLocalFile(i).Filename;
|
||||
zr = zf.ZipFileOpenReadStream(i, false, out Stream readStream, out ulong streamsize, out ushort cm);
|
||||
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
|
||||
if (streamsize < _bufferSize)
|
||||
{
|
||||
byte[] ibuffer = new byte[streamsize];
|
||||
int ilen = readStream.Read(ibuffer, 0, (int)streamsize);
|
||||
int ilen = readStream!.Read(ibuffer, 0, (int)streamsize);
|
||||
ms.Write(ibuffer, 0, ilen);
|
||||
ms.Flush();
|
||||
}
|
||||
@@ -233,13 +233,13 @@ namespace SabreTools.FileTypes.Archives
|
||||
int ilen;
|
||||
while (streamsize > _bufferSize)
|
||||
{
|
||||
ilen = readStream.Read(ibuffer, 0, _bufferSize);
|
||||
ilen = readStream!.Read(ibuffer, 0, _bufferSize);
|
||||
ms.Write(ibuffer, 0, ilen);
|
||||
ms.Flush();
|
||||
streamsize -= _bufferSize;
|
||||
}
|
||||
|
||||
ilen = readStream.Read(ibuffer, 0, (int)streamsize);
|
||||
ilen = readStream!.Read(ibuffer, 0, (int)streamsize);
|
||||
ms.Write(ibuffer, 0, ilen);
|
||||
ms.Flush();
|
||||
}
|
||||
@@ -265,15 +265,15 @@ namespace SabreTools.FileTypes.Archives
|
||||
#region Information
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override List<BaseFile> GetChildren()
|
||||
public override List<BaseFile>? GetChildren()
|
||||
{
|
||||
List<BaseFile> found = new();
|
||||
string gamename = Path.GetFileNameWithoutExtension(this.Filename);
|
||||
string? gamename = Path.GetFileNameWithoutExtension(this.Filename);
|
||||
|
||||
try
|
||||
{
|
||||
Zip zf = new();
|
||||
ZipReturn zr = zf.ZipFileOpen(this.Filename, -1, true);
|
||||
ZipReturn zr = zf.ZipFileOpen(this.Filename!, -1, true);
|
||||
if (zr != ZipReturn.ZipGood)
|
||||
{
|
||||
throw new Exception(CompressUtils.ZipErrorMessageText(zr));
|
||||
@@ -291,7 +291,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
}
|
||||
|
||||
// Open the read stream
|
||||
zr = zf.ZipFileOpenReadStream(i, false, out Stream readStream, out ulong streamsize, out ushort cm);
|
||||
zr = zf.ZipFileOpenReadStream(i, false, out Stream? readStream, out ulong streamsize, out ushort cm);
|
||||
|
||||
// If we get a read error, log it and continue
|
||||
if (zr != ZipReturn.ZipGood)
|
||||
@@ -339,12 +339,12 @@ namespace SabreTools.FileTypes.Archives
|
||||
/// <inheritdoc/>
|
||||
public override List<string> GetEmptyFolders()
|
||||
{
|
||||
List<string> empties = new();
|
||||
List<string> empties = [];
|
||||
|
||||
try
|
||||
{
|
||||
Zip zf = new();
|
||||
ZipReturn zr = zf.ZipFileOpen(this.Filename, -1, true);
|
||||
ZipReturn zr = zf.ZipFileOpen(this.Filename!, -1, true);
|
||||
if (zr != ZipReturn.ZipGood)
|
||||
{
|
||||
throw new Exception(CompressUtils.ZipErrorMessageText(zr));
|
||||
@@ -357,7 +357,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
}
|
||||
|
||||
zipEntries = zipEntries.OrderBy(p => p.Item1, new NaturalReversedComparer()).ToList();
|
||||
string lastZipEntry = null;
|
||||
string? lastZipEntry = null;
|
||||
foreach ((string, bool) entry in zipEntries)
|
||||
{
|
||||
// If the current is a superset of last, we skip it
|
||||
@@ -388,7 +388,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
public override bool IsTorrent()
|
||||
{
|
||||
Zip zf = new();
|
||||
ZipReturn zr = zf.ZipFileOpen(this.Filename, -1, true);
|
||||
ZipReturn zr = zf.ZipFileOpen(this.Filename!, -1, true);
|
||||
if (zr != ZipReturn.ZipGood)
|
||||
{
|
||||
throw new Exception(CompressUtils.ZipErrorMessageText(zr));
|
||||
@@ -402,14 +402,14 @@ namespace SabreTools.FileTypes.Archives
|
||||
#region Writing
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool Write(string inputFile, string outDir, BaseFile baseFile)
|
||||
public override bool Write(string inputFile, string outDir, BaseFile? baseFile)
|
||||
{
|
||||
// Get the file stream for the file and write out
|
||||
return Write(File.OpenRead(inputFile), outDir, baseFile);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool Write(Stream inputStream, string outDir, BaseFile baseFile)
|
||||
public override bool Write(Stream? inputStream, string outDir, BaseFile? baseFile)
|
||||
{
|
||||
bool success = false;
|
||||
string tempFile = Path.Combine(outDir, $"tmp{Guid.NewGuid()}");
|
||||
@@ -426,10 +426,10 @@ namespace SabreTools.FileTypes.Archives
|
||||
inputStream.Seek(0, SeekOrigin.Begin);
|
||||
|
||||
// Get the output archive name from the first rebuild rom
|
||||
string archiveFileName = Path.Combine(outDir, TextHelper.RemovePathUnsafeCharacters(baseFile.Parent) + (baseFile.Parent.EndsWith(".zip") ? string.Empty : ".zip"));
|
||||
string archiveFileName = Path.Combine(outDir, TextHelper.RemovePathUnsafeCharacters(baseFile.Parent) + (baseFile.Parent!.EndsWith(".zip") ? string.Empty : ".zip"));
|
||||
|
||||
// Set internal variables
|
||||
Stream writeStream = null;
|
||||
Stream? writeStream = null;
|
||||
Zip oldZipFile = new();
|
||||
Zip zipFile = new();
|
||||
ZipReturn zipReturn = ZipReturn.ZipGood;
|
||||
@@ -438,7 +438,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
{
|
||||
// If the full output path doesn't exist, create it
|
||||
if (!Directory.Exists(Path.GetDirectoryName(archiveFileName)))
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(archiveFileName));
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(archiveFileName)!);
|
||||
|
||||
// If the archive doesn't exist, create it and put the single file
|
||||
if (!File.Exists(archiveFileName))
|
||||
@@ -466,11 +466,11 @@ namespace SabreTools.FileTypes.Archives
|
||||
int ilen;
|
||||
while ((ilen = inputStream.Read(ibuffer, 0, _bufferSize)) > 0)
|
||||
{
|
||||
writeStream.Write(ibuffer, 0, ilen);
|
||||
writeStream!.Write(ibuffer, 0, ilen);
|
||||
writeStream.Flush();
|
||||
}
|
||||
|
||||
zipFile.ZipFileCloseWriteStream(baseFile.CRC);
|
||||
zipFile.ZipFileCloseWriteStream(baseFile.CRC!);
|
||||
}
|
||||
|
||||
// Otherwise, sort the input files and write out in the correct order
|
||||
@@ -540,18 +540,18 @@ namespace SabreTools.FileTypes.Archives
|
||||
int ilen;
|
||||
while ((ilen = inputStream.Read(ibuffer, 0, _bufferSize)) > 0)
|
||||
{
|
||||
writeStream.Write(ibuffer, 0, ilen);
|
||||
writeStream!.Write(ibuffer, 0, ilen);
|
||||
writeStream.Flush();
|
||||
}
|
||||
|
||||
zipFile.ZipFileCloseWriteStream(baseFile.CRC);
|
||||
zipFile.ZipFileCloseWriteStream(baseFile.CRC!);
|
||||
}
|
||||
|
||||
// Otherwise, copy the file from the old archive
|
||||
else
|
||||
{
|
||||
// Instantiate the streams
|
||||
oldZipFile.ZipFileOpenReadStream(index, false, out Stream zreadStream, out ulong istreamSize, out ushort icompressionMethod);
|
||||
oldZipFile.ZipFileOpenReadStream(index, false, out Stream? zreadStream, out ulong istreamSize, out ushort icompressionMethod);
|
||||
long msDosDateTime = oldZipFile.GetLocalFile(index).LastModified;
|
||||
TimeStamps ts = new() { ModTime = msDosDateTime };
|
||||
zipFile.ZipFileOpenWriteStream(false, true, oldZipFile.GetLocalFile(index).Filename, istreamSize, (ushort)CompressionMethod.Deflated, out writeStream, ts);
|
||||
@@ -559,9 +559,9 @@ namespace SabreTools.FileTypes.Archives
|
||||
// Copy the input stream to the output
|
||||
byte[] ibuffer = new byte[_bufferSize];
|
||||
int ilen;
|
||||
while ((ilen = zreadStream.Read(ibuffer, 0, _bufferSize)) > 0)
|
||||
while ((ilen = zreadStream!.Read(ibuffer, 0, _bufferSize)) > 0)
|
||||
{
|
||||
writeStream.Write(ibuffer, 0, ilen);
|
||||
writeStream!.Write(ibuffer, 0, ilen);
|
||||
writeStream.Flush();
|
||||
}
|
||||
|
||||
@@ -596,7 +596,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool Write(List<string> inputFiles, string outDir, List<BaseFile> baseFiles)
|
||||
public override bool Write(List<string> inputFiles, string outDir, List<BaseFile>? baseFiles)
|
||||
{
|
||||
bool success = false;
|
||||
string tempFile = Path.Combine(outDir, $"tmp{Guid.NewGuid()}");
|
||||
@@ -623,10 +623,10 @@ namespace SabreTools.FileTypes.Archives
|
||||
}
|
||||
|
||||
// Get the output archive name from the first rebuild rom
|
||||
string archiveFileName = Path.Combine(outDir, TextHelper.RemovePathUnsafeCharacters(baseFiles[0].Parent) + (baseFiles[0].Parent.EndsWith(".zip") ? string.Empty : ".zip"));
|
||||
string archiveFileName = Path.Combine(outDir, TextHelper.RemovePathUnsafeCharacters(baseFiles[0].Parent) + (baseFiles[0].Parent!.EndsWith(".zip") ? string.Empty : ".zip"));
|
||||
|
||||
// Set internal variables
|
||||
Stream writeStream = null;
|
||||
Stream? writeStream = null;
|
||||
Zip oldZipFile = new();
|
||||
Zip zipFile = new();
|
||||
ZipReturn zipReturn = ZipReturn.ZipGood;
|
||||
@@ -636,7 +636,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
// If the full output path doesn't exist, create it
|
||||
if (!Directory.Exists(Path.GetDirectoryName(archiveFileName)))
|
||||
{
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(archiveFileName));
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(archiveFileName)!);
|
||||
}
|
||||
|
||||
// If the archive doesn't exist, create it and put the single file
|
||||
@@ -648,7 +648,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
Dictionary<string, int> inputIndexMap = new();
|
||||
for (int i = 0; i < inputFiles.Count; i++)
|
||||
{
|
||||
inputIndexMap.Add(baseFiles[i].Filename.Replace('\\', '/'), i);
|
||||
inputIndexMap.Add(baseFiles[i].Filename!.Replace('\\', '/'), i);
|
||||
}
|
||||
|
||||
// Sort the keys in TZIP order
|
||||
@@ -666,15 +666,15 @@ 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.IsNullOrWhiteSpace(baseFiles[index].Date) && DateTime.TryParse(baseFiles[index].Date?.Replace('\\', '/'), out dt))
|
||||
{
|
||||
long msDosDateTime = DateTimeHelper.ConvertToMsDosTimeFormat(dt);
|
||||
TimeStamps ts = new() { ModTime = msDosDateTime };
|
||||
zipFile.ZipFileOpenWriteStream(false, false, baseFiles[index].Filename.Replace('\\', '/'), istreamSize, (ushort)CompressionMethod.Deflated, out writeStream, ts);
|
||||
zipFile.ZipFileOpenWriteStream(false, false, baseFiles[index].Filename!.Replace('\\', '/'), istreamSize, (ushort)CompressionMethod.Deflated, out writeStream, ts);
|
||||
}
|
||||
else
|
||||
{
|
||||
zipFile.ZipFileOpenWriteStream(false, true, baseFiles[index].Filename.Replace('\\', '/'), istreamSize, (ushort)CompressionMethod.Deflated, out writeStream, null);
|
||||
zipFile.ZipFileOpenWriteStream(false, true, baseFiles[index].Filename!.Replace('\\', '/'), istreamSize, (ushort)CompressionMethod.Deflated, out writeStream, null);
|
||||
}
|
||||
|
||||
// Copy the input stream to the output
|
||||
@@ -682,12 +682,12 @@ namespace SabreTools.FileTypes.Archives
|
||||
int ilen;
|
||||
while ((ilen = freadStream.Read(ibuffer, 0, _bufferSize)) > 0)
|
||||
{
|
||||
writeStream.Write(ibuffer, 0, ilen);
|
||||
writeStream!.Write(ibuffer, 0, ilen);
|
||||
writeStream.Flush();
|
||||
}
|
||||
|
||||
freadStream.Dispose();
|
||||
zipFile.ZipFileCloseWriteStream(baseFiles[index].CRC);
|
||||
zipFile.ZipFileCloseWriteStream(baseFiles[index].CRC!);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -708,12 +708,12 @@ namespace SabreTools.FileTypes.Archives
|
||||
}
|
||||
|
||||
// If the old one contains the new file, then just skip out
|
||||
if (oldZipFileContents.Contains(baseFiles[i].Filename.Replace('\\', '/')))
|
||||
if (oldZipFileContents.Contains(baseFiles[i].Filename!.Replace('\\', '/')))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
inputIndexMap.Add(baseFiles[i].Filename.Replace('\\', '/'), -(i + 1));
|
||||
inputIndexMap.Add(baseFiles[i].Filename!.Replace('\\', '/'), -(i + 1));
|
||||
}
|
||||
|
||||
// Then add all of the old entries to it too
|
||||
@@ -750,15 +750,15 @@ 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.IsNullOrWhiteSpace(baseFiles[-index - 1].Date) && DateTime.TryParse(baseFiles[-index - 1].Date?.Replace('\\', '/'), out dt))
|
||||
{
|
||||
long msDosDateTime = DateTimeHelper.ConvertToMsDosTimeFormat(dt);
|
||||
TimeStamps ts = new() { ModTime = msDosDateTime };
|
||||
zipFile.ZipFileOpenWriteStream(false, false, baseFiles[-index - 1].Filename.Replace('\\', '/'), istreamSize, (ushort)CompressionMethod.Deflated, out writeStream, ts);
|
||||
zipFile.ZipFileOpenWriteStream(false, false, baseFiles[-index - 1].Filename!.Replace('\\', '/'), istreamSize, (ushort)CompressionMethod.Deflated, out writeStream, ts);
|
||||
}
|
||||
else
|
||||
{
|
||||
zipFile.ZipFileOpenWriteStream(false, true, baseFiles[-index - 1].Filename.Replace('\\', '/'), istreamSize, (ushort)CompressionMethod.Deflated, out writeStream, null);
|
||||
zipFile.ZipFileOpenWriteStream(false, true, baseFiles[-index - 1].Filename!.Replace('\\', '/'), istreamSize, (ushort)CompressionMethod.Deflated, out writeStream, null);
|
||||
}
|
||||
|
||||
// Copy the input stream to the output
|
||||
@@ -766,18 +766,18 @@ namespace SabreTools.FileTypes.Archives
|
||||
int ilen;
|
||||
while ((ilen = freadStream.Read(ibuffer, 0, _bufferSize)) > 0)
|
||||
{
|
||||
writeStream.Write(ibuffer, 0, ilen);
|
||||
writeStream!.Write(ibuffer, 0, ilen);
|
||||
writeStream.Flush();
|
||||
}
|
||||
freadStream.Dispose();
|
||||
zipFile.ZipFileCloseWriteStream(baseFiles[-index - 1].CRC);
|
||||
zipFile.ZipFileCloseWriteStream(baseFiles[-index - 1].CRC!);
|
||||
}
|
||||
|
||||
// Otherwise, copy the file from the old archive
|
||||
else
|
||||
{
|
||||
// Instantiate the streams
|
||||
oldZipFile.ZipFileOpenReadStream(index, false, out Stream zreadStream, out ulong istreamSize, out ushort icompressionMethod);
|
||||
oldZipFile.ZipFileOpenReadStream(index, false, out Stream? zreadStream, out ulong istreamSize, out ushort icompressionMethod);
|
||||
long msDosDateTime = oldZipFile.GetLocalFile(index).LastModified;
|
||||
TimeStamps ts = new() { ModTime = msDosDateTime };
|
||||
zipFile.ZipFileOpenWriteStream(false, true, oldZipFile.GetLocalFile(index).Filename, istreamSize, (ushort)CompressionMethod.Deflated, out writeStream, ts);
|
||||
@@ -785,9 +785,9 @@ namespace SabreTools.FileTypes.Archives
|
||||
// Copy the input stream to the output
|
||||
byte[] ibuffer = new byte[_bufferSize];
|
||||
int ilen;
|
||||
while ((ilen = zreadStream.Read(ibuffer, 0, _bufferSize)) > 0)
|
||||
while ((ilen = zreadStream!.Read(ibuffer, 0, _bufferSize)) > 0)
|
||||
{
|
||||
writeStream.Write(ibuffer, 0, ilen);
|
||||
writeStream!.Write(ibuffer, 0, ilen);
|
||||
writeStream.Flush();
|
||||
}
|
||||
|
||||
|
||||
@@ -81,19 +81,19 @@ namespace SabreTools.FileTypes.Archives
|
||||
#region Writing
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool Write(string inputFile, string outDir, BaseFile baseFile)
|
||||
public override bool Write(string inputFile, string outDir, BaseFile? baseFile)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool Write(Stream inputStream, string outDir, BaseFile baseFile)
|
||||
public override bool Write(Stream? inputStream, string outDir, BaseFile? baseFile)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool Write(List<string> inputFiles, string outDir, List<BaseFile> baseFiles)
|
||||
public override bool Write(List<string> inputFiles, string outDir, List<BaseFile>? baseFiles)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@@ -49,9 +49,9 @@ namespace SabreTools.FileTypes
|
||||
/// </summary>
|
||||
/// <param name="input">Name of the file to create the archive from</param>
|
||||
/// <returns>Archive object representing the inputs</returns>
|
||||
public static BaseArchive Create(string input)
|
||||
public static BaseArchive? Create(string input)
|
||||
{
|
||||
BaseArchive archive = null;
|
||||
BaseArchive? archive = null;
|
||||
|
||||
// First get the archive type
|
||||
FileType? at = GetFileType(input);
|
||||
@@ -97,7 +97,7 @@ namespace SabreTools.FileTypes
|
||||
/// </summary>
|
||||
/// <param name="archiveType">SharpCompress.Common.ArchiveType representing the archive to create</param>
|
||||
/// <returns>Archive object representing the inputs</returns>
|
||||
public static BaseArchive Create(FileType archiveType)
|
||||
public static BaseArchive? Create(FileType archiveType)
|
||||
{
|
||||
return archiveType switch
|
||||
{
|
||||
@@ -118,17 +118,17 @@ namespace SabreTools.FileTypes
|
||||
public override abstract bool CopyAll(string outDir);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override abstract string CopyToFile(string entryName, string outDir);
|
||||
public override abstract string? CopyToFile(string entryName, string outDir);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override abstract (MemoryStream, string) CopyToStream(string entryName);
|
||||
public override abstract (MemoryStream?, string?) CopyToStream(string entryName);
|
||||
|
||||
#endregion
|
||||
|
||||
#region Information
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override abstract List<BaseFile> GetChildren();
|
||||
public override abstract List<BaseFile>? GetChildren();
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override abstract List<string> GetEmptyFolders();
|
||||
@@ -143,13 +143,13 @@ namespace SabreTools.FileTypes
|
||||
#region Writing
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override abstract bool Write(string inputFile, string outDir, BaseFile baseFile);
|
||||
public override abstract bool Write(string inputFile, string outDir, BaseFile? baseFile);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override abstract bool Write(Stream inputStream, string outDir, BaseFile baseFile);
|
||||
public override abstract bool Write(Stream? inputStream, string outDir, BaseFile? baseFile);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override abstract bool Write(List<string> inputFiles, string outDir, List<BaseFile> baseFiles);
|
||||
public override abstract bool Write(List<string> inputFiles, string outDir, List<BaseFile>? baseFiles);
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
@@ -53,17 +53,17 @@ namespace SabreTools.FileTypes
|
||||
/// <summary>
|
||||
/// Filename or path to the file
|
||||
/// </summary>
|
||||
public string Filename { get; set; }
|
||||
public string? Filename { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Direct parent of the file
|
||||
/// </summary>
|
||||
public string Parent { get; set; }
|
||||
public string? Parent { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Date stamp of the file
|
||||
/// </summary>
|
||||
public string Date { get; set; }
|
||||
public string? Date { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Optional size of the file
|
||||
@@ -78,37 +78,37 @@ namespace SabreTools.FileTypes
|
||||
/// <summary>
|
||||
/// CRC32 hash of the file
|
||||
/// </summary>
|
||||
public byte[] CRC { get; set; } = null;
|
||||
public byte[]? CRC { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// MD5 hash of the file
|
||||
/// </summary>
|
||||
public byte[] MD5 { get; set; } = null;
|
||||
public byte[]? MD5 { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// SHA-1 hash of the file
|
||||
/// </summary>
|
||||
public byte[] SHA1 { get; set; } = null;
|
||||
public byte[]? SHA1 { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// SHA-256 hash of the file
|
||||
/// </summary>
|
||||
public byte[] SHA256 { get; set; } = null;
|
||||
public byte[]? SHA256 { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// SHA-384 hash of the file
|
||||
/// </summary>
|
||||
public byte[] SHA384 { get; set; } = null;
|
||||
public byte[]? SHA384 { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// SHA-512 hash of the file
|
||||
/// </summary>
|
||||
public byte[] SHA512 { get; set; } = null;
|
||||
public byte[]? SHA512 { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// SpamSum fuzzy hash of the file
|
||||
/// </summary>
|
||||
public byte[] SpamSum { get; set; } = null;
|
||||
public byte[]? SpamSum { get; set; } = null;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -132,7 +132,7 @@ namespace SabreTools.FileTypes
|
||||
|
||||
if (getHashes)
|
||||
{
|
||||
BaseFile temp = GetInfo(this.Filename, hashes: this.AvailableHashes);
|
||||
BaseFile? temp = GetInfo(this.Filename, hashes: this.AvailableHashes);
|
||||
if (temp != null)
|
||||
{
|
||||
this.Parent = temp.Parent;
|
||||
@@ -270,7 +270,7 @@ namespace SabreTools.FileTypes
|
||||
/// <param name="hashes">Hashes to include in the information</param>
|
||||
/// <param name="asFiles">TreatAsFiles representing special format scanning</param>
|
||||
/// <returns>Populated BaseFile object if success, empty one on error</returns>
|
||||
public static BaseFile GetInfo(string input, string header = null, Hash hashes = Hash.Standard, TreatAsFile asFiles = 0x00)
|
||||
public static BaseFile? GetInfo(string input, string? header = null, Hash hashes = Hash.Standard, TreatAsFile asFiles = 0x00)
|
||||
{
|
||||
// Add safeguard if file doesn't exist
|
||||
if (!File.Exists(input))
|
||||
@@ -299,7 +299,7 @@ namespace SabreTools.FileTypes
|
||||
}
|
||||
|
||||
// Get the info in the proper manner
|
||||
BaseFile baseFile;
|
||||
BaseFile? baseFile;
|
||||
if (fileType == FileType.AaruFormat && !asFiles.HasFlag(TreatAsFile.AaruFormat))
|
||||
baseFile = AaruFormat.Create(inputStream);
|
||||
else if (fileType == FileType.CHD && !asFiles.HasFlag(TreatAsFile.CHD))
|
||||
@@ -311,7 +311,7 @@ namespace SabreTools.FileTypes
|
||||
inputStream?.Dispose();
|
||||
|
||||
// Add unique data from the file
|
||||
baseFile.Filename = Path.GetFileName(input);
|
||||
baseFile!.Filename = Path.GetFileName(input);
|
||||
baseFile.Date = new FileInfo(input).LastWriteTime.ToString("yyyy/MM/dd HH:mm:ss");
|
||||
|
||||
return baseFile;
|
||||
@@ -325,8 +325,12 @@ namespace SabreTools.FileTypes
|
||||
/// <param name="hashes">Hashes to include in the information</param>
|
||||
/// <param name="keepReadOpen">True if the underlying read stream should be kept open, false otherwise</param>
|
||||
/// <returns>Populated BaseFile object if success, empty one on error</returns>
|
||||
public static BaseFile GetInfo(Stream input, long size = -1, Hash hashes = Hash.Standard, bool keepReadOpen = false)
|
||||
public static BaseFile GetInfo(Stream? input, long size = -1, Hash hashes = Hash.Standard, bool keepReadOpen = false)
|
||||
{
|
||||
// If we have no stream
|
||||
if (input == null)
|
||||
return new BaseFile();
|
||||
|
||||
// If we want to automatically set the size
|
||||
if (size == -1)
|
||||
size = input.Length;
|
||||
@@ -334,7 +338,7 @@ namespace SabreTools.FileTypes
|
||||
try
|
||||
{
|
||||
// Get a list of hashers to run over the buffer
|
||||
List<Hasher> hashers = new();
|
||||
List<Hasher> hashers = [];
|
||||
|
||||
if (hashes.HasFlag(Hash.CRC))
|
||||
hashers.Add(new Hasher(Hash.CRC));
|
||||
@@ -429,7 +433,7 @@ namespace SabreTools.FileTypes
|
||||
private static bool HasValidArchiveExtension(string path)
|
||||
{
|
||||
// Get the extension from the path, if possible
|
||||
string ext = path.GetNormalizedExtension();
|
||||
string? ext = path.GetNormalizedExtension();
|
||||
|
||||
// Check against the list of known archive extensions
|
||||
return ext switch
|
||||
|
||||
@@ -34,7 +34,7 @@ namespace SabreTools.FileTypes.CHD
|
||||
/// Create a new CHDFile from an input file
|
||||
/// </summary>
|
||||
/// <param name="filename">Filename respresenting the CHD file</param>
|
||||
public static CHDFile Create(string filename)
|
||||
public static CHDFile? Create(string filename)
|
||||
{
|
||||
using FileStream fs = File.OpenRead(filename);
|
||||
return Create(fs);
|
||||
@@ -44,7 +44,7 @@ namespace SabreTools.FileTypes.CHD
|
||||
/// Create a new CHDFile from an input stream
|
||||
/// </summary>
|
||||
/// <param name="chdstream">Stream representing the CHD file</param>
|
||||
public static CHDFile Create(Stream chdstream)
|
||||
public static CHDFile? Create(Stream chdstream)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -58,7 +58,7 @@ namespace SabreTools.FileTypes.CHD
|
||||
return null;
|
||||
|
||||
// Read and retrun the current CHD
|
||||
CHDFile generated = ReadAsVersion(chdstream, version);
|
||||
CHDFile? generated = ReadAsVersion(chdstream, version);
|
||||
if (generated != null)
|
||||
generated.Type = FileType.CHD;
|
||||
|
||||
@@ -130,7 +130,7 @@ namespace SabreTools.FileTypes.CHD
|
||||
/// <param name="stream">CHD file as a stream</param>
|
||||
/// <param name="version">CHD version to parse</param>
|
||||
/// <returns>Populated CHD file, null on failure</returns>
|
||||
private static CHDFile ReadAsVersion(Stream stream, uint version)
|
||||
private static CHDFile? ReadAsVersion(Stream stream, uint version)
|
||||
{
|
||||
return version switch
|
||||
{
|
||||
|
||||
@@ -14,11 +14,11 @@ namespace Compress
|
||||
|
||||
ZipReturn ZipFileOpen(string newFilename, long timestamp = -1, bool readHeaders = true);
|
||||
|
||||
ZipReturn ZipFileOpen(Stream inStream);
|
||||
ZipReturn ZipFileOpen(Stream? inStream);
|
||||
void ZipFileClose();
|
||||
|
||||
ZipReturn ZipFileOpenReadStream(int index, out Stream stream, out ulong streamSize);
|
||||
ZipReturn ZipFileOpenWriteStream(bool raw, bool trrntzip, string filename, ulong uncompressedSize, ushort compressionMethod, out Stream stream, TimeStamps dateTime = null);
|
||||
ZipReturn ZipFileOpenReadStream(int index, out Stream? stream, out ulong streamSize);
|
||||
ZipReturn ZipFileOpenWriteStream(bool raw, bool trrntzip, string filename, ulong uncompressedSize, ushort compressionMethod, out Stream? stream, TimeStamps? dateTime = null);
|
||||
ZipReturn ZipFileCloseReadStream();
|
||||
|
||||
|
||||
|
||||
@@ -10,19 +10,19 @@ namespace Compress.SevenZip
|
||||
{
|
||||
public partial class SevenZ
|
||||
{
|
||||
private Stream _compressStream;
|
||||
private Stream? _compressStream;
|
||||
|
||||
public class outStreams
|
||||
{
|
||||
public SevenZipCompressType compType;
|
||||
public byte[] Method;
|
||||
public byte[] Properties;
|
||||
public byte[]? Method;
|
||||
public byte[]? Properties;
|
||||
public ulong packedStart;
|
||||
public ulong packedSize;
|
||||
public List<UnpackedStreamInfo> unpackedStreams;
|
||||
public List<UnpackedStreamInfo>? unpackedStreams;
|
||||
}
|
||||
|
||||
public List<outStreams> _packedOutStreams;
|
||||
public List<outStreams>? _packedOutStreams;
|
||||
|
||||
public ZipReturn ZipFileCreate(string newFilename)
|
||||
{
|
||||
@@ -133,8 +133,8 @@ namespace Compress.SevenZip
|
||||
|
||||
|
||||
|
||||
UnpackedStreamInfo unpackedStreamInfo;
|
||||
public ZipReturn ZipFileOpenWriteStream(bool raw, bool trrntzip, string filename, ulong uncompressedSize, ushort compressionMethod, out Stream stream, TimeStamps dateTime)
|
||||
UnpackedStreamInfo? unpackedStreamInfo;
|
||||
public ZipReturn ZipFileOpenWriteStream(bool raw, bool trrntzip, string filename, ulong uncompressedSize, ushort compressionMethod, out Stream? stream, TimeStamps? dateTime)
|
||||
{
|
||||
// check if we are writing a directory
|
||||
if (uncompressedSize == 0 && filename.Substring(filename.Length - 1, 1) == "/")
|
||||
|
||||
@@ -13,9 +13,9 @@ namespace Compress.ZipFile
|
||||
{
|
||||
private readonly List<ZipLocalFile> _localFiles = new();
|
||||
|
||||
private FileInfo _zipFileInfo;
|
||||
private FileInfo? _zipFileInfo;
|
||||
|
||||
private Stream _zipFs;
|
||||
private Stream? _zipFs;
|
||||
|
||||
private uint _localFilesCount;
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace Compress.ZipFile
|
||||
{
|
||||
}
|
||||
|
||||
internal ZipLocalFile(string filename, TimeStamps dateTime = null)
|
||||
internal ZipLocalFile(string filename, TimeStamps? dateTime = null)
|
||||
{
|
||||
SetStatus(LocalFileStatus.Zip64, false);
|
||||
GeneralPurposeBitFlag = 2; // Maximum Compression Deflating
|
||||
@@ -231,8 +231,11 @@ namespace Compress.ZipFile
|
||||
bw.Write(_extraField, 0, extraFieldLength);
|
||||
// No File Comment
|
||||
}
|
||||
internal ZipReturn LocalFileHeaderRead(Stream zipFs)
|
||||
internal ZipReturn LocalFileHeaderRead(Stream? zipFs)
|
||||
{
|
||||
if (zipFs == null)
|
||||
return ZipReturn.ZipErrorFileNotFound;
|
||||
|
||||
try
|
||||
{
|
||||
using (BinaryReader br = new(zipFs, Encoding.UTF8, true))
|
||||
@@ -358,8 +361,11 @@ namespace Compress.ZipFile
|
||||
}
|
||||
}
|
||||
|
||||
internal ZipReturn LocalFileHeaderReadQuick(Stream zipFs)
|
||||
internal ZipReturn LocalFileHeaderReadQuick(Stream? zipFs)
|
||||
{
|
||||
if (zipFs == null)
|
||||
return ZipReturn.ZipErrorOpeningFile;
|
||||
|
||||
try
|
||||
{
|
||||
using BinaryReader br = new(zipFs, Encoding.UTF8, true);
|
||||
@@ -568,12 +574,16 @@ namespace Compress.ZipFile
|
||||
|
||||
bw.Write(_extraField);
|
||||
}
|
||||
internal ZipReturn LocalFileOpenReadStream(Stream zipFs, bool raw, out Stream readStream, out ulong streamSize, out ushort compressionMethod)
|
||||
internal ZipReturn LocalFileOpenReadStream(Stream? zipFs, bool raw, out Stream? readStream, out ulong streamSize, out ushort compressionMethod)
|
||||
{
|
||||
streamSize = 0;
|
||||
compressionMethod = _compressionMethod;
|
||||
|
||||
readStream = null;
|
||||
|
||||
if (zipFs == null)
|
||||
return ZipReturn.ZipErrorFileNotFound;
|
||||
|
||||
zipFs.Seek((long)_dataLocation, SeekOrigin.Begin);
|
||||
|
||||
switch (_compressionMethod)
|
||||
@@ -644,7 +654,7 @@ namespace Compress.ZipFile
|
||||
return readStream == null ? ZipReturn.ZipErrorGettingDataStream : ZipReturn.ZipGood;
|
||||
}
|
||||
|
||||
internal ZipReturn LocalFileOpenWriteStream(Stream zipFs, bool raw, ulong uncompressedSize, ushort compressionMethod, out Stream writeStream)
|
||||
internal ZipReturn LocalFileOpenWriteStream(Stream? zipFs, bool raw, ulong uncompressedSize, ushort compressionMethod, out Stream? writeStream)
|
||||
{
|
||||
UncompressedSize = uncompressedSize;
|
||||
_compressedSize = 0;
|
||||
@@ -678,10 +688,10 @@ namespace Compress.ZipFile
|
||||
return writeStream == null ? ZipReturn.ZipErrorGettingDataStream : ZipReturn.ZipGood;
|
||||
}
|
||||
|
||||
internal ZipReturn LocalFileCloseWriteStream(Stream zipFs, byte[] crc32)
|
||||
internal ZipReturn LocalFileCloseWriteStream(Stream? zipFs, byte[] crc32)
|
||||
{
|
||||
|
||||
_compressedSize = (ulong)zipFs.Position - _dataLocation;
|
||||
_compressedSize = (ulong)zipFs!.Position - _dataLocation;
|
||||
|
||||
if (_compressedSize == 0 && UncompressedSize == 0)
|
||||
{
|
||||
@@ -734,8 +744,11 @@ namespace Compress.ZipFile
|
||||
}
|
||||
}
|
||||
|
||||
internal static void LocalFileAddZeroLengthFile(Stream zipFs)
|
||||
internal static void LocalFileAddZeroLengthFile(Stream? zipFs)
|
||||
{
|
||||
if (zipFs == null)
|
||||
return;
|
||||
|
||||
zipFs.WriteByte(03);
|
||||
zipFs.WriteByte(00);
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ namespace Compress.ZipFile
|
||||
}
|
||||
|
||||
|
||||
public ZipReturn ZipFileOpen(Stream inStream)
|
||||
public ZipReturn ZipFileOpen(Stream? inStream)
|
||||
{
|
||||
ZipFileClose();
|
||||
ZipStatus = ZipStatus.None;
|
||||
|
||||
@@ -4,12 +4,12 @@ namespace Compress.ZipFile
|
||||
{
|
||||
public partial class Zip
|
||||
{
|
||||
public ZipReturn ZipFileOpenReadStream(int index, out Stream stream, out ulong streamSize)
|
||||
public ZipReturn ZipFileOpenReadStream(int index, out Stream? stream, out ulong streamSize)
|
||||
{
|
||||
return ZipFileOpenReadStream(index, false, out stream, out streamSize, out ushort _);
|
||||
}
|
||||
|
||||
public ZipReturn ZipFileOpenReadStream(int index, bool raw, out Stream stream, out ulong streamSize, out ushort compressionMethod)
|
||||
public ZipReturn ZipFileOpenReadStream(int index, bool raw, out Stream? stream, out ulong streamSize, out ushort compressionMethod)
|
||||
{
|
||||
ZipFileCloseReadStream();
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace Compress.ZipFile
|
||||
return zRet;
|
||||
}
|
||||
|
||||
public ZipReturn ZipFileOpenReadStreamQuick(ulong pos, bool raw, out Stream stream, out ulong streamSize, out ushort compressionMethod)
|
||||
public ZipReturn ZipFileOpenReadStreamQuick(ulong pos, bool raw, out Stream? stream, out ulong streamSize, out ushort compressionMethod)
|
||||
{
|
||||
ZipFileCloseReadStream();
|
||||
|
||||
|
||||
@@ -43,6 +43,9 @@ namespace Compress.ZipFile
|
||||
{
|
||||
bool lTrrntzip = true;
|
||||
|
||||
if (_zipFs == null)
|
||||
return;
|
||||
|
||||
_centralDirStart = (ulong)_zipFs.Position;
|
||||
|
||||
using (CrcCalculatorStream crcCs = new CrcCalculatorStream(_zipFs, true))
|
||||
@@ -79,7 +82,7 @@ namespace Compress.ZipFile
|
||||
_zipFs.Flush();
|
||||
_zipFs.Close();
|
||||
_zipFs.Dispose();
|
||||
_zipFileInfo = new FileInfo(_zipFileInfo.FullName);
|
||||
_zipFileInfo = new FileInfo(_zipFileInfo?.FullName ?? string.Empty);
|
||||
ZipOpen = ZipOpenType.Closed;
|
||||
}
|
||||
|
||||
@@ -98,9 +101,9 @@ namespace Compress.ZipFile
|
||||
}
|
||||
break;
|
||||
case ZipOpenType.OpenWrite:
|
||||
_zipFs.Flush();
|
||||
_zipFs.Close();
|
||||
_zipFs.Dispose();
|
||||
_zipFs?.Flush();
|
||||
_zipFs?.Close();
|
||||
_zipFs?.Dispose();
|
||||
if (_zipFileInfo != null)
|
||||
RVIO.File.Delete(_zipFileInfo.FullName);
|
||||
_zipFileInfo = null;
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace Compress.ZipFile
|
||||
{
|
||||
public partial class Zip
|
||||
{
|
||||
private Stream _compressionStream;
|
||||
private Stream? _compressionStream;
|
||||
|
||||
/*
|
||||
raw is true if we are just going to copy the raw data stream from the source to the destination zip file
|
||||
@@ -20,7 +20,7 @@ namespace Compress.ZipFile
|
||||
if raw is false then compressionMthod must be 0,8 or 93 (zstd)
|
||||
*/
|
||||
|
||||
public ZipReturn ZipFileOpenWriteStream(bool raw, bool trrntzip, string filename, ulong uncompressedSize, ushort compressionMethod, out Stream stream, TimeStamps timeStamp = null)
|
||||
public ZipReturn ZipFileOpenWriteStream(bool raw, bool trrntzip, string filename, ulong uncompressedSize, ushort compressionMethod, out Stream? stream, TimeStamps? timeStamp = null)
|
||||
{
|
||||
stream = null;
|
||||
if (ZipOpen != ZipOpenType.OpenWrite)
|
||||
@@ -108,7 +108,7 @@ namespace Compress.ZipFile
|
||||
}
|
||||
|
||||
_localFiles.RemoveAt(fileCount - 1);
|
||||
_zipFs.Position = (long)_localFiles[fileCount - 1].RelativeOffsetOfLocalHeader;
|
||||
_zipFs!.Position = (long)_localFiles[fileCount - 1].RelativeOffsetOfLocalHeader;
|
||||
return ZipReturn.ZipGood;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace SabreTools.FileTypes
|
||||
{
|
||||
#region Protected instance variables
|
||||
|
||||
protected List<BaseFile> _children;
|
||||
protected List<BaseFile>? _children;
|
||||
|
||||
/// <summary>
|
||||
/// Logging object
|
||||
@@ -68,7 +68,7 @@ namespace SabreTools.FileTypes
|
||||
/// </summary>
|
||||
/// <param name="outputFormat">OutputFormat representing the archive to create</param>
|
||||
/// <returns>Archive object representing the inputs</returns>
|
||||
public static Folder Create(OutputFormat outputFormat)
|
||||
public static Folder? Create(OutputFormat outputFormat)
|
||||
{
|
||||
return outputFormat switch
|
||||
{
|
||||
@@ -101,6 +101,10 @@ namespace SabreTools.FileTypes
|
||||
/// <returns>True if the extraction was a success, false otherwise</returns>
|
||||
public virtual bool CopyAll(string outDir)
|
||||
{
|
||||
// If we have an invalid filename
|
||||
if (this.Filename == null)
|
||||
return false;
|
||||
|
||||
// Copy all files from the current folder to the output directory recursively
|
||||
try
|
||||
{
|
||||
@@ -164,9 +168,13 @@ namespace SabreTools.FileTypes
|
||||
/// <param name="entryName">Name of the entry to be extracted</param>
|
||||
/// <param name="outDir">Output directory for archive extraction</param>
|
||||
/// <returns>Name of the extracted file, null on error</returns>
|
||||
public virtual string CopyToFile(string entryName, string outDir)
|
||||
public virtual string? CopyToFile(string entryName, string outDir)
|
||||
{
|
||||
string realentry = null;
|
||||
string? realentry = null;
|
||||
|
||||
// If we have an invalid filename
|
||||
if (this.Filename == null)
|
||||
return null;
|
||||
|
||||
// Copy single file from the current folder to the output directory, if exists
|
||||
try
|
||||
@@ -179,7 +187,7 @@ namespace SabreTools.FileTypes
|
||||
List<string> files = PathTool.GetFilesOrdered(this.Filename);
|
||||
|
||||
// Now sort through to find the first file that matches
|
||||
string match = files.Where(s => s.EndsWith(entryName)).FirstOrDefault();
|
||||
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))
|
||||
@@ -202,10 +210,14 @@ namespace SabreTools.FileTypes
|
||||
/// </summary>
|
||||
/// <param name="entryName">Name of the entry to be extracted</param>
|
||||
/// <returns>MemoryStream representing the entry, null on error</returns>
|
||||
public virtual (MemoryStream, string) CopyToStream(string entryName)
|
||||
public virtual (MemoryStream?, string?) CopyToStream(string entryName)
|
||||
{
|
||||
MemoryStream ms = new();
|
||||
string realentry = null;
|
||||
string? realentry = null;
|
||||
|
||||
// If we have an invalid filename
|
||||
if (this.Filename == null)
|
||||
return (null, null);
|
||||
|
||||
// Copy single file from the current folder to the output directory, if exists
|
||||
try
|
||||
@@ -217,7 +229,7 @@ namespace SabreTools.FileTypes
|
||||
List<string> files = PathTool.GetFilesOrdered(this.Filename);
|
||||
|
||||
// Now sort through to find the first file that matches
|
||||
string match = files.Where(s => s.EndsWith(entryName)).FirstOrDefault();
|
||||
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))
|
||||
@@ -243,15 +255,20 @@ namespace SabreTools.FileTypes
|
||||
/// Generate a list of immediate children from the current folder
|
||||
/// </summary>
|
||||
/// <returns>List of BaseFile objects representing the found data</returns>
|
||||
public virtual List<BaseFile> GetChildren()
|
||||
public virtual List<BaseFile>? GetChildren()
|
||||
{
|
||||
// If we have an invalid filename
|
||||
if (this.Filename == null)
|
||||
return null;
|
||||
|
||||
if (_children == null || _children.Count == 0)
|
||||
{
|
||||
_children = new List<BaseFile>();
|
||||
_children = [];
|
||||
foreach (string file in Directory.EnumerateFiles(this.Filename, "*", SearchOption.TopDirectoryOnly))
|
||||
{
|
||||
BaseFile nf = GetInfo(file, hashes: this.AvailableHashes);
|
||||
_children.Add(nf);
|
||||
BaseFile? nf = GetInfo(file, hashes: this.AvailableHashes);
|
||||
if (nf != null)
|
||||
_children.Add(nf);
|
||||
}
|
||||
|
||||
foreach (string dir in Directory.EnumerateDirectories(this.Filename, "*", SearchOption.TopDirectoryOnly))
|
||||
@@ -269,7 +286,7 @@ namespace SabreTools.FileTypes
|
||||
/// </summary>
|
||||
/// <param name="input">Input file to get data from</param>
|
||||
/// <returns>List of empty folders in the folder</returns>
|
||||
public virtual List<string> GetEmptyFolders()
|
||||
public virtual List<string>? GetEmptyFolders()
|
||||
{
|
||||
return this.Filename.ListEmpty();
|
||||
}
|
||||
@@ -286,7 +303,7 @@ namespace SabreTools.FileTypes
|
||||
/// <param name="baseFile">BaseFile representing the new information</param>
|
||||
/// <returns>True if the write was a success, false otherwise</returns>
|
||||
/// <remarks>This works for now, but it can be sped up by using Ionic.Zip or another zlib wrapper that allows for header values built-in. See edc's code.</remarks>
|
||||
public virtual bool Write(string inputFile, string outDir, BaseFile baseFile)
|
||||
public virtual bool Write(string inputFile, string outDir, BaseFile? baseFile)
|
||||
{
|
||||
FileStream fs = File.OpenRead(inputFile);
|
||||
return Write(fs, outDir, baseFile);
|
||||
@@ -300,7 +317,7 @@ namespace SabreTools.FileTypes
|
||||
/// <param name="baseFile">BaseFile representing the new information</param>
|
||||
/// <returns>True if the write was a success, false otherwise</returns>
|
||||
/// <remarks>This works for now, but it can be sped up by using Ionic.Zip or another zlib wrapper that allows for header values built-in. See edc's code.</remarks>
|
||||
public virtual bool Write(Stream inputStream, string outDir, BaseFile baseFile)
|
||||
public virtual bool Write(Stream? inputStream, string outDir, BaseFile? baseFile)
|
||||
{
|
||||
bool success = false;
|
||||
|
||||
@@ -313,20 +330,21 @@ namespace SabreTools.FileTypes
|
||||
return success;
|
||||
|
||||
// Set internal variables
|
||||
FileStream outputStream = null;
|
||||
FileStream? outputStream = null;
|
||||
|
||||
// Get the output folder name from the first rebuild rom
|
||||
string fileName;
|
||||
if (writeToParent)
|
||||
fileName = Path.Combine(outDir, TextHelper.RemovePathUnsafeCharacters(baseFile.Filename));
|
||||
fileName = Path.Combine(outDir, TextHelper.RemovePathUnsafeCharacters(baseFile.Filename) ?? string.Empty);
|
||||
else
|
||||
fileName = Path.Combine(outDir, TextHelper.RemovePathUnsafeCharacters(baseFile.Parent), TextHelper.RemovePathUnsafeCharacters(baseFile.Filename));
|
||||
fileName = Path.Combine(outDir, TextHelper.RemovePathUnsafeCharacters(baseFile.Parent) ?? string.Empty, TextHelper.RemovePathUnsafeCharacters(baseFile.Filename) ?? string.Empty);
|
||||
|
||||
try
|
||||
{
|
||||
// If the full output path doesn't exist, create it
|
||||
if (!Directory.Exists(Path.GetDirectoryName(fileName)))
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(fileName));
|
||||
string? dir = Path.GetDirectoryName(fileName);
|
||||
if (dir != null && !Directory.Exists(dir))
|
||||
Directory.CreateDirectory(dir);
|
||||
|
||||
// Overwrite output files by default
|
||||
outputStream = File.Create(fileName);
|
||||
@@ -373,7 +391,7 @@ namespace SabreTools.FileTypes
|
||||
/// <param name="outDir">Output directory to build to</param>
|
||||
/// <param name="baseFiles">BaseFiles representing the new information</param>
|
||||
/// <returns>True if the inputs were written properly, false otherwise</returns>
|
||||
public virtual bool Write(List<string> inputFiles, string outDir, List<BaseFile> baseFiles)
|
||||
public virtual bool Write(List<string> inputFiles, string outDir, List<BaseFile>? baseFiles)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@@ -243,15 +243,15 @@ namespace RVIO
|
||||
}
|
||||
}
|
||||
|
||||
public static StreamWriter CreateText(string filename)
|
||||
public static StreamWriter? CreateText(string filename)
|
||||
{
|
||||
int errorCode = FileStream.OpenFileWrite(filename, out Stream fStream);
|
||||
return errorCode != 0 ? null : new StreamWriter(fStream);
|
||||
int errorCode = FileStream.OpenFileWrite(filename, out Stream? fStream);
|
||||
return errorCode != 0 ? null : new StreamWriter(fStream!);
|
||||
}
|
||||
public static StreamReader OpenText(string filename, Encoding Enc)
|
||||
public static StreamReader? OpenText(string filename, Encoding Enc)
|
||||
{
|
||||
int errorCode = FileStream.OpenFileRead(filename, out Stream fStream);
|
||||
return errorCode != 0 ? null : new StreamReader(fStream, Enc);
|
||||
int errorCode = FileStream.OpenFileRead(filename, out Stream? fStream);
|
||||
return errorCode != 0 ? null : new StreamReader(fStream!, Enc);
|
||||
}
|
||||
|
||||
public static string ReadAllText(string filename)
|
||||
@@ -332,7 +332,7 @@ namespace RVIO
|
||||
{
|
||||
return System.IO.Path.GetFileName(path);
|
||||
}
|
||||
public static string GetDirectoryName(string path)
|
||||
public static string? GetDirectoryName(string path)
|
||||
{
|
||||
return System.IO.Path.GetDirectoryName(path);
|
||||
|
||||
@@ -342,13 +342,13 @@ namespace RVIO
|
||||
|
||||
public static class FileStream
|
||||
{
|
||||
public static Stream OpenFileRead(string path, out int result)
|
||||
public static Stream? OpenFileRead(string path, out int result)
|
||||
{
|
||||
result = OpenFileRead(path, out Stream stream);
|
||||
result = OpenFileRead(path, out Stream? stream);
|
||||
return stream;
|
||||
}
|
||||
|
||||
public static int OpenFileRead(string path, out Stream stream)
|
||||
public static int OpenFileRead(string path, out Stream? stream)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -362,7 +362,7 @@ namespace RVIO
|
||||
}
|
||||
}
|
||||
|
||||
public static int OpenFileWrite(string path, out Stream stream)
|
||||
public static int OpenFileWrite(string path, out Stream? stream)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
|
||||
<LangVersion>latest</LangVersion>
|
||||
<Nullable>enable</Nullable>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
<!-- <TreatWarningsAsErrors>true</TreatWarningsAsErrors> --> <!-- Can't be enabled because of external code -->
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@@ -15,10 +15,10 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="SabreTools.IO" Version="1.2.0" />
|
||||
<PackageReference Include="SharpCompress" Version="0.34.1" />
|
||||
<PackageReference Include="SabreTools.IO" Version="1.3.0" />
|
||||
<PackageReference Include="SharpCompress" Version="0.34.2" />
|
||||
<PackageReference Include="System.Text.Encoding.CodePages" Version="8.0.0" />
|
||||
<PackageReference Include="ZstdSharp.Port" Version="0.7.3" />
|
||||
<PackageReference Include="ZstdSharp.Port" Version="0.7.4" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
Reference in New Issue
Block a user