mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Use simpler names for archive Write methods
This commit is contained in:
@@ -406,29 +406,29 @@ namespace SabreTools.FileTypes.Archives
|
|||||||
#region Writing
|
#region Writing
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public override bool Write(string inputFile, string outDir, BaseFile? baseFile = null)
|
public override bool Write(string file, string outDir, BaseFile? baseFile = null)
|
||||||
{
|
{
|
||||||
// Check that the input file exists
|
// Check that the input file exists
|
||||||
if (!File.Exists(inputFile))
|
if (!File.Exists(file))
|
||||||
{
|
{
|
||||||
_logger.Warning($"File '{inputFile}' does not exist!");
|
_logger.Warning($"File '{file}' does not exist!");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
inputFile = Path.GetFullPath(inputFile);
|
file = Path.GetFullPath(file);
|
||||||
|
|
||||||
// Get the file stream for the file and write out
|
// Get the file stream for the file and write out
|
||||||
using Stream inputStream = File.Open(inputFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
using Stream inputStream = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
||||||
return Write(inputStream, outDir, baseFile);
|
return Write(inputStream, outDir, baseFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public override bool Write(Stream? inputStream, string outDir, BaseFile? baseFile = null)
|
public override bool Write(Stream? stream, string outDir, BaseFile? baseFile = null)
|
||||||
{
|
{
|
||||||
bool success = false;
|
bool success = false;
|
||||||
|
|
||||||
// If the stream is not readable, return
|
// If the stream is not readable, return
|
||||||
if (inputStream == null || !inputStream.CanRead)
|
if (stream == null || !stream.CanRead)
|
||||||
return success;
|
return success;
|
||||||
|
|
||||||
// Make sure the output directory exists
|
// Make sure the output directory exists
|
||||||
@@ -438,7 +438,7 @@ namespace SabreTools.FileTypes.Archives
|
|||||||
outDir = Path.GetFullPath(outDir);
|
outDir = Path.GetFullPath(outDir);
|
||||||
|
|
||||||
// Now get the Rom info for the file so we have hashes and size
|
// Now get the Rom info for the file so we have hashes and size
|
||||||
baseFile = FileTypeTool.GetInfo(inputStream, _hashTypes, keepReadOpen: true);
|
baseFile = FileTypeTool.GetInfo(stream, _hashTypes, keepReadOpen: true);
|
||||||
|
|
||||||
// Get the output file name
|
// Get the output file name
|
||||||
string outfile = Path.Combine(outDir, Utilities.GetDepotPath(baseFile.SHA1, Depth) ?? string.Empty);
|
string outfile = Path.Combine(outDir, Utilities.GetDepotPath(baseFile.SHA1, Depth) ?? string.Empty);
|
||||||
@@ -467,7 +467,7 @@ namespace SabreTools.FileTypes.Archives
|
|||||||
// Copy the input stream to the output
|
// Copy the input stream to the output
|
||||||
byte[] ibuffer = new byte[_bufferSize];
|
byte[] ibuffer = new byte[_bufferSize];
|
||||||
int ilen;
|
int ilen;
|
||||||
while ((ilen = inputStream.Read(ibuffer, 0, _bufferSize)) > 0)
|
while ((ilen = stream.Read(ibuffer, 0, _bufferSize)) > 0)
|
||||||
{
|
{
|
||||||
ds.Write(ibuffer, 0, ilen);
|
ds.Write(ibuffer, 0, ilen);
|
||||||
ds.Flush();
|
ds.Flush();
|
||||||
@@ -490,7 +490,7 @@ namespace SabreTools.FileTypes.Archives
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public override bool Write(List<string> inputFiles, string outDir, List<BaseFile>? baseFile)
|
public override bool Write(List<string> files, string outDir, List<BaseFile>? baseFile)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -292,30 +292,30 @@ namespace SabreTools.FileTypes.Archives
|
|||||||
#region Writing
|
#region Writing
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public override bool Write(string inputFile, string outDir, BaseFile? baseFile)
|
public override bool Write(string file, string outDir, BaseFile? baseFile)
|
||||||
{
|
{
|
||||||
// Check that the input file exists
|
// Check that the input file exists
|
||||||
if (!File.Exists(inputFile))
|
if (!File.Exists(file))
|
||||||
{
|
{
|
||||||
_logger.Warning($"File '{inputFile}' does not exist!");
|
_logger.Warning($"File '{file}' does not exist!");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
inputFile = Path.GetFullPath(inputFile);
|
file = Path.GetFullPath(file);
|
||||||
|
|
||||||
// Get the file stream for the file and write out
|
// Get the file stream for the file and write out
|
||||||
using Stream inputStream = File.Open(inputFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
using Stream inputStream = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
||||||
return Write(inputStream, outDir, baseFile);
|
return Write(inputStream, outDir, baseFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public override bool Write(Stream? inputStream, string outDir, BaseFile? baseFile)
|
public override bool Write(Stream? stream, string outDir, BaseFile? baseFile)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public override bool Write(List<string> inputFiles, string outDir, List<BaseFile>? roms)
|
public override bool Write(List<string> files, string outDir, List<BaseFile>? roms)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -376,39 +376,39 @@ namespace SabreTools.FileTypes.Archives
|
|||||||
#region Writing
|
#region Writing
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public override bool Write(string inputFile, string outDir, BaseFile? baseFile)
|
public override bool Write(string file, string outDir, BaseFile? baseFile)
|
||||||
{
|
{
|
||||||
// Check that the input file exists
|
// Check that the input file exists
|
||||||
if (!File.Exists(inputFile))
|
if (!File.Exists(file))
|
||||||
{
|
{
|
||||||
_logger.Warning($"File '{inputFile}' does not exist!");
|
_logger.Warning($"File '{file}' does not exist!");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
inputFile = Path.GetFullPath(inputFile);
|
file = Path.GetFullPath(file);
|
||||||
|
|
||||||
// Get the file stream for the file and write out
|
// Get the file stream for the file and write out
|
||||||
using Stream inputStream = File.Open(inputFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
using Stream inputStream = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
||||||
return Write(inputStream, outDir, baseFile);
|
return Write(inputStream, outDir, baseFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public override bool Write(Stream? inputStream, string outDir, BaseFile? baseFile)
|
public override bool Write(Stream? stream, string outDir, BaseFile? baseFile)
|
||||||
{
|
{
|
||||||
bool success = false;
|
bool success = false;
|
||||||
string tempFile = Path.Combine(outDir, $"tmp{Guid.NewGuid()}");
|
string tempFile = Path.Combine(outDir, $"tmp{Guid.NewGuid()}");
|
||||||
|
|
||||||
// If either input is null or empty, return
|
// If either input is null or empty, return
|
||||||
if (inputStream == null || baseFile == null || baseFile.Filename == null)
|
if (stream == null || baseFile == null || baseFile.Filename == null)
|
||||||
return success;
|
return success;
|
||||||
|
|
||||||
// If the stream is not readable, return
|
// If the stream is not readable, return
|
||||||
if (!inputStream.CanRead)
|
if (!stream.CanRead)
|
||||||
return success;
|
return success;
|
||||||
|
|
||||||
// Seek to the beginning of the stream
|
// Seek to the beginning of the stream
|
||||||
if (inputStream.CanSeek)
|
if (stream.CanSeek)
|
||||||
inputStream.Seek(0, SeekOrigin.Begin);
|
stream.Seek(0, SeekOrigin.Begin);
|
||||||
|
|
||||||
// Get the output archive name from the first rebuild rom
|
// Get the output archive name from the first rebuild rom
|
||||||
string archiveFileName = Path.Combine(outDir, TextHelper.RemovePathUnsafeCharacters(baseFile.Parent) + (baseFile.Parent?.EndsWith(".7z") ?? false ? string.Empty : ".7z"));
|
string archiveFileName = Path.Combine(outDir, TextHelper.RemovePathUnsafeCharacters(baseFile.Parent) + (baseFile.Parent?.EndsWith(".7z") ?? false ? string.Empty : ".7z"));
|
||||||
@@ -428,13 +428,13 @@ namespace SabreTools.FileTypes.Archives
|
|||||||
// If the archive doesn't exist, create it and put the single file
|
// If the archive doesn't exist, create it and put the single file
|
||||||
if (!File.Exists(archiveFileName))
|
if (!File.Exists(archiveFileName))
|
||||||
{
|
{
|
||||||
if (inputStream.CanSeek)
|
if (stream.CanSeek)
|
||||||
inputStream.Seek(0, SeekOrigin.Begin);
|
stream.Seek(0, SeekOrigin.Begin);
|
||||||
|
|
||||||
zipReturn = zipFile.ZipFileCreate(tempFile);
|
zipReturn = zipFile.ZipFileCreate(tempFile);
|
||||||
|
|
||||||
// Open the input file for reading
|
// Open the input file for reading
|
||||||
ulong istreamSize = (ulong)(inputStream.Length);
|
ulong istreamSize = (ulong)(stream.Length);
|
||||||
|
|
||||||
DateTime dt = DateTime.Now;
|
DateTime dt = DateTime.Now;
|
||||||
if (_realDates && !string.IsNullOrEmpty(baseFile.Date) && DateTime.TryParse(baseFile.Date!.Replace('\\', '/'), out dt))
|
if (_realDates && !string.IsNullOrEmpty(baseFile.Date) && DateTime.TryParse(baseFile.Date!.Replace('\\', '/'), out dt))
|
||||||
@@ -453,7 +453,7 @@ namespace SabreTools.FileTypes.Archives
|
|||||||
{
|
{
|
||||||
byte[] ibuffer = new byte[_bufferSize];
|
byte[] ibuffer = new byte[_bufferSize];
|
||||||
int ilen;
|
int ilen;
|
||||||
while ((ilen = inputStream.Read(ibuffer, 0, _bufferSize)) > 0)
|
while ((ilen = stream.Read(ibuffer, 0, _bufferSize)) > 0)
|
||||||
{
|
{
|
||||||
writeStream.Write(ibuffer, 0, ilen);
|
writeStream.Write(ibuffer, 0, ilen);
|
||||||
writeStream.Flush();
|
writeStream.Flush();
|
||||||
@@ -511,7 +511,7 @@ namespace SabreTools.FileTypes.Archives
|
|||||||
if (index < 0)
|
if (index < 0)
|
||||||
{
|
{
|
||||||
// Open the input file for reading
|
// Open the input file for reading
|
||||||
ulong istreamSize = (ulong)(inputStream.Length);
|
ulong istreamSize = (ulong)(stream.Length);
|
||||||
|
|
||||||
DateTime dt = DateTime.Now;
|
DateTime dt = DateTime.Now;
|
||||||
if (_realDates && !string.IsNullOrEmpty(baseFile.Date) && DateTime.TryParse(baseFile.Date!.Replace('\\', '/'), out dt))
|
if (_realDates && !string.IsNullOrEmpty(baseFile.Date) && DateTime.TryParse(baseFile.Date!.Replace('\\', '/'), out dt))
|
||||||
@@ -530,7 +530,7 @@ namespace SabreTools.FileTypes.Archives
|
|||||||
{
|
{
|
||||||
byte[] ibuffer = new byte[_bufferSize];
|
byte[] ibuffer = new byte[_bufferSize];
|
||||||
int ilen;
|
int ilen;
|
||||||
while ((ilen = inputStream.Read(ibuffer, 0, _bufferSize)) > 0)
|
while ((ilen = stream.Read(ibuffer, 0, _bufferSize)) > 0)
|
||||||
{
|
{
|
||||||
writeStream.Write(ibuffer, 0, ilen);
|
writeStream.Write(ibuffer, 0, ilen);
|
||||||
writeStream.Flush();
|
writeStream.Flush();
|
||||||
@@ -590,21 +590,21 @@ namespace SabreTools.FileTypes.Archives
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public override bool Write(List<string> inputFiles, string outDir, List<BaseFile>? baseFiles)
|
public override bool Write(List<string> files, string outDir, List<BaseFile>? baseFiles)
|
||||||
{
|
{
|
||||||
bool success = false;
|
bool success = false;
|
||||||
string tempFile = Path.Combine(outDir, $"tmp{Guid.NewGuid()}");
|
string tempFile = Path.Combine(outDir, $"tmp{Guid.NewGuid()}");
|
||||||
|
|
||||||
// If either list of roms is null or empty, return
|
// If either list of roms is null or empty, return
|
||||||
if (inputFiles == null || baseFiles == null || inputFiles.Count == 0 || baseFiles.Count == 0)
|
if (files == null || baseFiles == null || files.Count == 0 || baseFiles.Count == 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// If the number of inputs is less than the number of available roms, return
|
// If the number of inputs is less than the number of available roms, return
|
||||||
if (inputFiles.Count < baseFiles.Count)
|
if (files.Count < baseFiles.Count)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// If one of the files doesn't exist, return
|
// If one of the files doesn't exist, return
|
||||||
foreach (string file in inputFiles)
|
foreach (string file in files)
|
||||||
{
|
{
|
||||||
if (!File.Exists(file))
|
if (!File.Exists(file))
|
||||||
return false;
|
return false;
|
||||||
@@ -632,7 +632,7 @@ namespace SabreTools.FileTypes.Archives
|
|||||||
|
|
||||||
// Map all inputs to index
|
// Map all inputs to index
|
||||||
Dictionary<string, int> inputIndexMap = [];
|
Dictionary<string, int> inputIndexMap = [];
|
||||||
for (int i = 0; i < inputFiles.Count; i++)
|
for (int i = 0; i < files.Count; i++)
|
||||||
{
|
{
|
||||||
inputIndexMap.Add(baseFiles[i]?.Filename?.Replace('\\', '/') ?? string.Empty, i);
|
inputIndexMap.Add(baseFiles[i]?.Filename?.Replace('\\', '/') ?? string.Empty, i);
|
||||||
}
|
}
|
||||||
@@ -648,8 +648,8 @@ namespace SabreTools.FileTypes.Archives
|
|||||||
int index = inputIndexMap[key];
|
int index = inputIndexMap[key];
|
||||||
|
|
||||||
// Open the input file for reading
|
// Open the input file for reading
|
||||||
Stream freadStream = File.Open(inputFiles[index], FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
Stream freadStream = File.Open(files[index], FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
||||||
ulong istreamSize = (ulong)new FileInfo(inputFiles[index]).Length;
|
ulong istreamSize = (ulong)new FileInfo(files[index]).Length;
|
||||||
|
|
||||||
DateTime dt = DateTime.Now;
|
DateTime dt = DateTime.Now;
|
||||||
if (_realDates && !string.IsNullOrEmpty(baseFiles[index].Date) && DateTime.TryParse(baseFiles[index].Date?.Replace('\\', '/'), out dt))
|
if (_realDates && !string.IsNullOrEmpty(baseFiles[index].Date) && DateTime.TryParse(baseFiles[index].Date?.Replace('\\', '/'), out dt))
|
||||||
@@ -685,7 +685,7 @@ namespace SabreTools.FileTypes.Archives
|
|||||||
|
|
||||||
// Map all inputs to index
|
// Map all inputs to index
|
||||||
Dictionary<string, int> inputIndexMap = new();
|
Dictionary<string, int> inputIndexMap = new();
|
||||||
for (int i = 0; i < inputFiles.Count; i++)
|
for (int i = 0; i < files.Count; i++)
|
||||||
{
|
{
|
||||||
List<string> oldZipFileContents = [];
|
List<string> oldZipFileContents = [];
|
||||||
for (int j = 0; j < oldZipFile.LocalFilesCount(); j++)
|
for (int j = 0; j < oldZipFile.LocalFilesCount(); j++)
|
||||||
@@ -730,8 +730,8 @@ namespace SabreTools.FileTypes.Archives
|
|||||||
if (index < 0)
|
if (index < 0)
|
||||||
{
|
{
|
||||||
// Open the input file for reading
|
// Open the input file for reading
|
||||||
Stream freadStream = File.Open(inputFiles[-index - 1], FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
Stream freadStream = File.Open(files[-index - 1], FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
||||||
ulong istreamSize = (ulong)(new FileInfo(inputFiles[-index - 1]).Length);
|
ulong istreamSize = (ulong)(new FileInfo(files[-index - 1]).Length);
|
||||||
|
|
||||||
DateTime dt = DateTime.Now;
|
DateTime dt = DateTime.Now;
|
||||||
if (_realDates && !string.IsNullOrEmpty(baseFiles[-index - 1].Date) && DateTime.TryParse(baseFiles[-index - 1].Date?.Replace('\\', '/'), out dt))
|
if (_realDates && !string.IsNullOrEmpty(baseFiles[-index - 1].Date) && DateTime.TryParse(baseFiles[-index - 1].Date?.Replace('\\', '/'), out dt))
|
||||||
|
|||||||
@@ -281,35 +281,35 @@ namespace SabreTools.FileTypes.Archives
|
|||||||
#region Writing
|
#region Writing
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public override bool Write(string inputFile, string outDir, BaseFile? baseFile)
|
public override bool Write(string file, string outDir, BaseFile? baseFile)
|
||||||
{
|
{
|
||||||
// Check that the input file exists
|
// Check that the input file exists
|
||||||
if (!File.Exists(inputFile))
|
if (!File.Exists(file))
|
||||||
{
|
{
|
||||||
_logger.Warning($"File '{inputFile}' does not exist!");
|
_logger.Warning($"File '{file}' does not exist!");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
inputFile = Path.GetFullPath(inputFile);
|
file = Path.GetFullPath(file);
|
||||||
|
|
||||||
// Get the file stream for the file and write out
|
// Get the file stream for the file and write out
|
||||||
using Stream inputStream = File.Open(inputFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
using Stream inputStream = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
||||||
return Write(inputStream, outDir, baseFile);
|
return Write(inputStream, outDir, baseFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public override bool Write(Stream? inputStream, string outDir, BaseFile? baseFile)
|
public override bool Write(Stream? stream, string outDir, BaseFile? baseFile)
|
||||||
{
|
{
|
||||||
#if NET462_OR_GREATER || NETCOREAPP
|
#if NET462_OR_GREATER || NETCOREAPP
|
||||||
bool success = false;
|
bool success = false;
|
||||||
string tempFile = Path.Combine(outDir, $"tmp{Guid.NewGuid()}");
|
string tempFile = Path.Combine(outDir, $"tmp{Guid.NewGuid()}");
|
||||||
|
|
||||||
// If either input is null or empty, return
|
// If either input is null or empty, return
|
||||||
if (inputStream == null || baseFile == null || baseFile.Filename == null)
|
if (stream == null || baseFile == null || baseFile.Filename == null)
|
||||||
return success;
|
return success;
|
||||||
|
|
||||||
// If the stream is not readable, return
|
// If the stream is not readable, return
|
||||||
if (!inputStream.CanRead)
|
if (!stream.CanRead)
|
||||||
return success;
|
return success;
|
||||||
|
|
||||||
// Get the output archive name from the first rebuild rom
|
// Get the output archive name from the first rebuild rom
|
||||||
@@ -334,10 +334,10 @@ namespace SabreTools.FileTypes.Archives
|
|||||||
usableDate = dt;
|
usableDate = dt;
|
||||||
|
|
||||||
// Copy the input stream to the output
|
// Copy the input stream to the output
|
||||||
if (inputStream.CanSeek)
|
if (stream.CanSeek)
|
||||||
inputStream.Seek(0, SeekOrigin.Begin);
|
stream.Seek(0, SeekOrigin.Begin);
|
||||||
|
|
||||||
tarFile.AddEntry(baseFile.Filename, inputStream, size: baseFile.Size ?? 0, modified: usableDate);
|
tarFile.AddEntry(baseFile.Filename, stream, size: baseFile.Size ?? 0, modified: usableDate);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise, sort the input files and write out in the correct order
|
// Otherwise, sort the input files and write out in the correct order
|
||||||
@@ -392,10 +392,10 @@ namespace SabreTools.FileTypes.Archives
|
|||||||
if (index < 0)
|
if (index < 0)
|
||||||
{
|
{
|
||||||
// Copy the input file to the output
|
// Copy the input file to the output
|
||||||
if (inputStream.CanSeek)
|
if (stream.CanSeek)
|
||||||
inputStream.Seek(0, SeekOrigin.Begin);
|
stream.Seek(0, SeekOrigin.Begin);
|
||||||
|
|
||||||
tarFile.AddEntry(baseFile.Filename, inputStream, size: baseFile.Size ?? 0, modified: usableDate);
|
tarFile.AddEntry(baseFile.Filename, stream, size: baseFile.Size ?? 0, modified: usableDate);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise, copy the file from the old archive
|
// Otherwise, copy the file from the old archive
|
||||||
@@ -442,22 +442,22 @@ namespace SabreTools.FileTypes.Archives
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public override bool Write(List<string> inputFiles, string outDir, List<BaseFile>? baseFiles)
|
public override bool Write(List<string> files, string outDir, List<BaseFile>? baseFiles)
|
||||||
{
|
{
|
||||||
#if NET462_OR_GREATER || NETCOREAPP
|
#if NET462_OR_GREATER || NETCOREAPP
|
||||||
bool success = false;
|
bool success = false;
|
||||||
string tempFile = Path.Combine(outDir, $"tmp{Guid.NewGuid()}");
|
string tempFile = Path.Combine(outDir, $"tmp{Guid.NewGuid()}");
|
||||||
|
|
||||||
// If either list of roms is null or empty, return
|
// If either list of roms is null or empty, return
|
||||||
if (inputFiles == null || baseFiles == null || inputFiles.Count == 0 || baseFiles.Count == 0)
|
if (files == null || baseFiles == null || files.Count == 0 || baseFiles.Count == 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// If the number of inputs is less than the number of available roms, return
|
// If the number of inputs is less than the number of available roms, return
|
||||||
if (inputFiles.Count < baseFiles.Count)
|
if (files.Count < baseFiles.Count)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// If one of the files doesn't exist, return
|
// If one of the files doesn't exist, return
|
||||||
foreach (string file in inputFiles)
|
foreach (string file in files)
|
||||||
{
|
{
|
||||||
if (!File.Exists(file))
|
if (!File.Exists(file))
|
||||||
return false;
|
return false;
|
||||||
@@ -481,7 +481,7 @@ namespace SabreTools.FileTypes.Archives
|
|||||||
{
|
{
|
||||||
// Map all inputs to index
|
// Map all inputs to index
|
||||||
Dictionary<string, int> inputIndexMap = new();
|
Dictionary<string, int> inputIndexMap = new();
|
||||||
for (int i = 0; i < inputFiles.Count; i++)
|
for (int i = 0; i < files.Count; i++)
|
||||||
{
|
{
|
||||||
inputIndexMap.Add(baseFiles[i].Filename!.Replace('\\', '/'), i);
|
inputIndexMap.Add(baseFiles[i].Filename!.Replace('\\', '/'), i);
|
||||||
}
|
}
|
||||||
@@ -503,7 +503,7 @@ namespace SabreTools.FileTypes.Archives
|
|||||||
|
|
||||||
// Copy the input stream to the output
|
// Copy the input stream to the output
|
||||||
tarFile.AddEntry(baseFiles[index].Filename!,
|
tarFile.AddEntry(baseFiles[index].Filename!,
|
||||||
File.Open(inputFiles[index], FileMode.Open, FileAccess.Read, FileShare.ReadWrite),
|
File.Open(files[index], FileMode.Open, FileAccess.Read, FileShare.ReadWrite),
|
||||||
size: baseFiles[index].Size ?? 0,
|
size: baseFiles[index].Size ?? 0,
|
||||||
modified: usableDate);
|
modified: usableDate);
|
||||||
}
|
}
|
||||||
@@ -520,7 +520,7 @@ namespace SabreTools.FileTypes.Archives
|
|||||||
|
|
||||||
// Map all inputs to index
|
// Map all inputs to index
|
||||||
var inputIndexMap = new Dictionary<string, int>();
|
var inputIndexMap = new Dictionary<string, int>();
|
||||||
for (int i = 0; i < inputFiles.Count; i++)
|
for (int i = 0; i < files.Count; i++)
|
||||||
{
|
{
|
||||||
// If the old one contains the new file, then just skip out
|
// 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('\\', '/')))
|
||||||
@@ -568,7 +568,7 @@ namespace SabreTools.FileTypes.Archives
|
|||||||
|
|
||||||
// Copy the input file to the output
|
// Copy the input file to the output
|
||||||
tarFile.AddEntry(baseFiles[-index - 1].Filename!,
|
tarFile.AddEntry(baseFiles[-index - 1].Filename!,
|
||||||
File.Open(inputFiles[-index - 1], FileMode.Open, FileAccess.Read, FileShare.ReadWrite),
|
File.Open(files[-index - 1], FileMode.Open, FileAccess.Read, FileShare.ReadWrite),
|
||||||
size: baseFiles[-index - 1].Size ?? 0,
|
size: baseFiles[-index - 1].Size ?? 0,
|
||||||
modified: usableDate);
|
modified: usableDate);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -299,30 +299,30 @@ namespace SabreTools.FileTypes.Archives
|
|||||||
#region Writing
|
#region Writing
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public override bool Write(string inputFile, string outDir, BaseFile? baseFile)
|
public override bool Write(string file, string outDir, BaseFile? baseFile)
|
||||||
{
|
{
|
||||||
// Check that the input file exists
|
// Check that the input file exists
|
||||||
if (!File.Exists(inputFile))
|
if (!File.Exists(file))
|
||||||
{
|
{
|
||||||
_logger.Warning($"File '{inputFile}' does not exist!");
|
_logger.Warning($"File '{file}' does not exist!");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
inputFile = Path.GetFullPath(inputFile);
|
file = Path.GetFullPath(file);
|
||||||
|
|
||||||
// Get the file stream for the file and write out
|
// Get the file stream for the file and write out
|
||||||
using Stream inputStream = File.Open(inputFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
using Stream inputStream = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
||||||
return Write(inputStream, outDir, baseFile);
|
return Write(inputStream, outDir, baseFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public override bool Write(Stream? inputStream, string outDir, BaseFile? baseFile)
|
public override bool Write(Stream? stream, string outDir, BaseFile? baseFile)
|
||||||
{
|
{
|
||||||
#if NET462_OR_GREATER || NETCOREAPP
|
#if NET462_OR_GREATER || NETCOREAPP
|
||||||
bool success = false;
|
bool success = false;
|
||||||
|
|
||||||
// If the stream is not readable, return
|
// If the stream is not readable, return
|
||||||
if (inputStream == null || !inputStream.CanRead)
|
if (stream == null || !stream.CanRead)
|
||||||
return success;
|
return success;
|
||||||
|
|
||||||
// Make sure the output directory exists
|
// Make sure the output directory exists
|
||||||
@@ -332,7 +332,7 @@ namespace SabreTools.FileTypes.Archives
|
|||||||
outDir = Path.GetFullPath(outDir);
|
outDir = Path.GetFullPath(outDir);
|
||||||
|
|
||||||
// Now get the Rom info for the file so we have hashes and size
|
// Now get the Rom info for the file so we have hashes and size
|
||||||
baseFile = FileTypeTool.GetInfo(inputStream, _hashTypes, keepReadOpen: true);
|
baseFile = FileTypeTool.GetInfo(stream, _hashTypes, keepReadOpen: true);
|
||||||
|
|
||||||
// Get the output file name
|
// Get the output file name
|
||||||
string outfile = Path.Combine(outDir, Core.Tools.Utilities.GetDepotPath(baseFile.SHA1, Depth)!);
|
string outfile = Path.Combine(outDir, Core.Tools.Utilities.GetDepotPath(baseFile.SHA1, Depth)!);
|
||||||
@@ -347,7 +347,7 @@ namespace SabreTools.FileTypes.Archives
|
|||||||
{
|
{
|
||||||
// Compress the input stream
|
// Compress the input stream
|
||||||
XZStream outputStream = new(File.Create(outfile));
|
XZStream outputStream = new(File.Create(outfile));
|
||||||
inputStream.CopyTo(outputStream);
|
stream.CopyTo(outputStream);
|
||||||
|
|
||||||
// Dispose of everything
|
// Dispose of everything
|
||||||
outputStream.Dispose();
|
outputStream.Dispose();
|
||||||
@@ -361,7 +361,7 @@ namespace SabreTools.FileTypes.Archives
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public override bool Write(List<string> inputFiles, string outDir, List<BaseFile>? baseFiles)
|
public override bool Write(List<string> files, string outDir, List<BaseFile>? baseFiles)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -554,39 +554,39 @@ namespace SabreTools.FileTypes.Archives
|
|||||||
#region Writing
|
#region Writing
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public override bool Write(string inputFile, string outDir, BaseFile? baseFile)
|
public override bool Write(string file, string outDir, BaseFile? baseFile)
|
||||||
{
|
{
|
||||||
// Check that the input file exists
|
// Check that the input file exists
|
||||||
if (!File.Exists(inputFile))
|
if (!File.Exists(file))
|
||||||
{
|
{
|
||||||
_logger.Warning($"File '{inputFile}' does not exist!");
|
_logger.Warning($"File '{file}' does not exist!");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
inputFile = Path.GetFullPath(inputFile);
|
file = Path.GetFullPath(file);
|
||||||
|
|
||||||
// Get the file stream for the file and write out
|
// Get the file stream for the file and write out
|
||||||
using Stream inputStream = File.Open(inputFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
using Stream inputStream = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
||||||
return Write(inputStream, outDir, baseFile);
|
return Write(inputStream, outDir, baseFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public override bool Write(Stream? inputStream, string outDir, BaseFile? baseFile)
|
public override bool Write(Stream? stream, string outDir, BaseFile? baseFile)
|
||||||
{
|
{
|
||||||
bool success = false;
|
bool success = false;
|
||||||
string tempFile = Path.Combine(outDir, $"tmp{Guid.NewGuid()}");
|
string tempFile = Path.Combine(outDir, $"tmp{Guid.NewGuid()}");
|
||||||
|
|
||||||
// If either input is null or empty, return
|
// If either input is null or empty, return
|
||||||
if (inputStream == null || baseFile == null || baseFile.Filename == null)
|
if (stream == null || baseFile == null || baseFile.Filename == null)
|
||||||
return success;
|
return success;
|
||||||
|
|
||||||
// If the stream is not readable, return
|
// If the stream is not readable, return
|
||||||
if (!inputStream.CanRead)
|
if (!stream.CanRead)
|
||||||
return success;
|
return success;
|
||||||
|
|
||||||
// Seek to the beginning of the stream
|
// Seek to the beginning of the stream
|
||||||
if (inputStream.CanSeek)
|
if (stream.CanSeek)
|
||||||
inputStream.Seek(0, SeekOrigin.Begin);
|
stream.Seek(0, SeekOrigin.Begin);
|
||||||
|
|
||||||
// Get the output archive name from the first rebuild rom
|
// 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"));
|
||||||
@@ -606,13 +606,13 @@ namespace SabreTools.FileTypes.Archives
|
|||||||
// If the archive doesn't exist, create it and put the single file
|
// If the archive doesn't exist, create it and put the single file
|
||||||
if (!File.Exists(archiveFileName))
|
if (!File.Exists(archiveFileName))
|
||||||
{
|
{
|
||||||
if (inputStream.CanSeek)
|
if (stream.CanSeek)
|
||||||
inputStream.Seek(0, SeekOrigin.Begin);
|
stream.Seek(0, SeekOrigin.Begin);
|
||||||
|
|
||||||
zipReturn = zipFile.ZipFileCreate(tempFile);
|
zipReturn = zipFile.ZipFileCreate(tempFile);
|
||||||
|
|
||||||
// Open the input file for reading
|
// Open the input file for reading
|
||||||
ulong istreamSize = (ulong)(inputStream.Length);
|
ulong istreamSize = (ulong)(stream.Length);
|
||||||
|
|
||||||
DateTime dt = DateTime.Now;
|
DateTime dt = DateTime.Now;
|
||||||
if (_realDates && !string.IsNullOrEmpty(baseFile.Date) && DateTime.TryParse(baseFile.Date!.Replace('\\', '/'), out dt))
|
if (_realDates && !string.IsNullOrEmpty(baseFile.Date) && DateTime.TryParse(baseFile.Date!.Replace('\\', '/'), out dt))
|
||||||
@@ -629,7 +629,7 @@ namespace SabreTools.FileTypes.Archives
|
|||||||
// Copy the input stream to the output
|
// Copy the input stream to the output
|
||||||
byte[] ibuffer = new byte[_bufferSize];
|
byte[] ibuffer = new byte[_bufferSize];
|
||||||
int ilen;
|
int ilen;
|
||||||
while ((ilen = inputStream.Read(ibuffer, 0, _bufferSize)) > 0)
|
while ((ilen = stream.Read(ibuffer, 0, _bufferSize)) > 0)
|
||||||
{
|
{
|
||||||
writeStream!.Write(ibuffer, 0, ilen);
|
writeStream!.Write(ibuffer, 0, ilen);
|
||||||
writeStream.Flush();
|
writeStream.Flush();
|
||||||
@@ -686,7 +686,7 @@ namespace SabreTools.FileTypes.Archives
|
|||||||
if (index < 0)
|
if (index < 0)
|
||||||
{
|
{
|
||||||
// Open the input file for reading
|
// Open the input file for reading
|
||||||
ulong istreamSize = (ulong)(inputStream.Length);
|
ulong istreamSize = (ulong)(stream.Length);
|
||||||
|
|
||||||
DateTime dt = DateTime.Now;
|
DateTime dt = DateTime.Now;
|
||||||
if (_realDates && !string.IsNullOrEmpty(baseFile.Date) && DateTime.TryParse(baseFile.Date!.Replace('\\', '/'), out dt))
|
if (_realDates && !string.IsNullOrEmpty(baseFile.Date) && DateTime.TryParse(baseFile.Date!.Replace('\\', '/'), out dt))
|
||||||
@@ -703,7 +703,7 @@ namespace SabreTools.FileTypes.Archives
|
|||||||
// Copy the input stream to the output
|
// Copy the input stream to the output
|
||||||
byte[] ibuffer = new byte[_bufferSize];
|
byte[] ibuffer = new byte[_bufferSize];
|
||||||
int ilen;
|
int ilen;
|
||||||
while ((ilen = inputStream.Read(ibuffer, 0, _bufferSize)) > 0)
|
while ((ilen = stream.Read(ibuffer, 0, _bufferSize)) > 0)
|
||||||
{
|
{
|
||||||
writeStream!.Write(ibuffer, 0, ilen);
|
writeStream!.Write(ibuffer, 0, ilen);
|
||||||
writeStream.Flush();
|
writeStream.Flush();
|
||||||
@@ -761,21 +761,21 @@ namespace SabreTools.FileTypes.Archives
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public override bool Write(List<string> inputFiles, string outDir, List<BaseFile>? baseFiles)
|
public override bool Write(List<string> files, string outDir, List<BaseFile>? baseFiles)
|
||||||
{
|
{
|
||||||
bool success = false;
|
bool success = false;
|
||||||
string tempFile = Path.Combine(outDir, $"tmp{Guid.NewGuid()}");
|
string tempFile = Path.Combine(outDir, $"tmp{Guid.NewGuid()}");
|
||||||
|
|
||||||
// If either list of roms is null or empty, return
|
// If either list of roms is null or empty, return
|
||||||
if (inputFiles == null || baseFiles == null || inputFiles.Count == 0 || baseFiles.Count == 0)
|
if (files == null || baseFiles == null || files.Count == 0 || baseFiles.Count == 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// If the number of inputs is less than the number of available roms, return
|
// If the number of inputs is less than the number of available roms, return
|
||||||
if (inputFiles.Count < baseFiles.Count)
|
if (files.Count < baseFiles.Count)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// If one of the files doesn't exist, return
|
// If one of the files doesn't exist, return
|
||||||
foreach (string file in inputFiles)
|
foreach (string file in files)
|
||||||
{
|
{
|
||||||
if (!File.Exists(file))
|
if (!File.Exists(file))
|
||||||
return false;
|
return false;
|
||||||
@@ -803,7 +803,7 @@ namespace SabreTools.FileTypes.Archives
|
|||||||
|
|
||||||
// Map all inputs to index
|
// Map all inputs to index
|
||||||
Dictionary<string, int> inputIndexMap = new();
|
Dictionary<string, int> inputIndexMap = new();
|
||||||
for (int i = 0; i < inputFiles.Count; i++)
|
for (int i = 0; i < files.Count; i++)
|
||||||
{
|
{
|
||||||
inputIndexMap.Add(baseFiles[i].Filename!.Replace('\\', '/'), i);
|
inputIndexMap.Add(baseFiles[i].Filename!.Replace('\\', '/'), i);
|
||||||
}
|
}
|
||||||
@@ -819,8 +819,8 @@ namespace SabreTools.FileTypes.Archives
|
|||||||
int index = inputIndexMap[key];
|
int index = inputIndexMap[key];
|
||||||
|
|
||||||
// Open the input file for reading
|
// Open the input file for reading
|
||||||
Stream freadStream = File.Open(inputFiles[index], FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
Stream freadStream = File.Open(files[index], FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
||||||
ulong istreamSize = (ulong)(new FileInfo(inputFiles[index]).Length);
|
ulong istreamSize = (ulong)(new FileInfo(files[index]).Length);
|
||||||
|
|
||||||
DateTime dt = DateTime.Now;
|
DateTime dt = DateTime.Now;
|
||||||
if (_realDates && !string.IsNullOrEmpty(baseFiles[index].Date) && DateTime.TryParse(baseFiles[index].Date?.Replace('\\', '/'), out dt))
|
if (_realDates && !string.IsNullOrEmpty(baseFiles[index].Date) && DateTime.TryParse(baseFiles[index].Date?.Replace('\\', '/'), out dt))
|
||||||
@@ -856,7 +856,7 @@ namespace SabreTools.FileTypes.Archives
|
|||||||
|
|
||||||
// Map all inputs to index
|
// Map all inputs to index
|
||||||
Dictionary<string, int> inputIndexMap = new();
|
Dictionary<string, int> inputIndexMap = new();
|
||||||
for (int i = 0; i < inputFiles.Count; i++)
|
for (int i = 0; i < files.Count; i++)
|
||||||
{
|
{
|
||||||
List<string> oldZipFileContents = [];
|
List<string> oldZipFileContents = [];
|
||||||
for (int j = 0; j < oldZipFile.LocalFilesCount(); j++)
|
for (int j = 0; j < oldZipFile.LocalFilesCount(); j++)
|
||||||
@@ -901,8 +901,8 @@ namespace SabreTools.FileTypes.Archives
|
|||||||
if (index < 0)
|
if (index < 0)
|
||||||
{
|
{
|
||||||
// Open the input file for reading
|
// Open the input file for reading
|
||||||
Stream freadStream = File.Open(inputFiles[-index - 1], FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
Stream freadStream = File.Open(files[-index - 1], FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
||||||
ulong istreamSize = (ulong)(new FileInfo(inputFiles[-index - 1]).Length);
|
ulong istreamSize = (ulong)(new FileInfo(files[-index - 1]).Length);
|
||||||
|
|
||||||
DateTime dt = DateTime.Now;
|
DateTime dt = DateTime.Now;
|
||||||
if (_realDates && !string.IsNullOrEmpty(baseFiles[-index - 1].Date) && DateTime.TryParse(baseFiles[-index - 1].Date?.Replace('\\', '/'), out dt))
|
if (_realDates && !string.IsNullOrEmpty(baseFiles[-index - 1].Date) && DateTime.TryParse(baseFiles[-index - 1].Date?.Replace('\\', '/'), out dt))
|
||||||
|
|||||||
@@ -108,13 +108,13 @@ namespace SabreTools.FileTypes
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public abstract bool Write(string inputFile, string outDir, BaseFile? baseFile);
|
public abstract bool Write(string file, string outDir, BaseFile? baseFile);
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public abstract bool Write(Stream? inputStream, string outDir, BaseFile? baseFile);
|
public abstract bool Write(Stream? stream, string outDir, BaseFile? baseFile);
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public abstract bool Write(List<string> inputFiles, string outDir, List<BaseFile>? baseFiles);
|
public abstract bool Write(List<string> files, string outDir, List<BaseFile>? baseFiles);
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -264,7 +264,7 @@ namespace SabreTools.FileTypes
|
|||||||
#region Writing
|
#region Writing
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public bool Write(string inputFile, string outDir, BaseFile? baseFile)
|
public bool Write(string file, string outDir, BaseFile? baseFile)
|
||||||
{
|
{
|
||||||
using Stream inputStream = File.Open(inputFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
using Stream inputStream = File.Open(inputFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
||||||
return Write(inputStream, outDir, baseFile);
|
return Write(inputStream, outDir, baseFile);
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ namespace SabreTools.FileTypes
|
|||||||
/// <param name="outDir">Output directory to build to</param>
|
/// <param name="outDir">Output directory to build to</param>
|
||||||
/// <param name="baseFile">BaseFile representing the new information</param>
|
/// <param name="baseFile">BaseFile representing the new information</param>
|
||||||
/// <returns>True if the write was a success, false otherwise</returns>
|
/// <returns>True if the write was a success, false otherwise</returns>
|
||||||
bool Write(string inputFile, string outDir, BaseFile? baseFile);
|
bool Write(string file, string outDir, BaseFile? baseFile);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Write an input stream to an output folder
|
/// Write an input stream to an output folder
|
||||||
|
|||||||
Reference in New Issue
Block a user