mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Fix Sort multiple outputs
This commit is contained in:
@@ -2686,28 +2686,7 @@ namespace SabreTools.Library.DatFiles
|
||||
return;
|
||||
|
||||
// Set the deletion variables
|
||||
bool usedExternally, usedInternally = false;
|
||||
|
||||
// Scan the file externally
|
||||
|
||||
// TODO: All instances of Hash.DeepHashes should be made into 0x0 eventually
|
||||
BaseFile externalFileInfo = FileExtensions.GetInfo(
|
||||
file,
|
||||
omitFromScan: (quickScan ? Hash.SecureHashes : Hash.DeepHashes),
|
||||
header: Header.HeaderSkipper,
|
||||
asFiles: asFiles);
|
||||
|
||||
DatItem externalDatItem = null;
|
||||
if (externalFileInfo.Type == FileType.AaruFormat)
|
||||
externalDatItem = new Media(externalFileInfo);
|
||||
else if (externalFileInfo.Type == FileType.CHD)
|
||||
externalDatItem = new Disk(externalFileInfo);
|
||||
else if (externalFileInfo.Type == FileType.None)
|
||||
externalDatItem = new Rom(externalFileInfo);
|
||||
|
||||
usedExternally = RebuildIndividualFile(externalDatItem, file, outDir, date, inverse, outputFormat, updateDat, null /* isZip */);
|
||||
|
||||
// Scan the file internally
|
||||
bool usedExternally = false, usedInternally = false;
|
||||
|
||||
// Create an empty list of BaseFile for archive entries
|
||||
List<BaseFile> entries = null;
|
||||
@@ -2726,7 +2705,7 @@ namespace SabreTools.Library.DatFiles
|
||||
entries = archive.GetChildren(omitFromScan: (quickScan ? Hash.SecureHashes : Hash.DeepHashes), date: date);
|
||||
}
|
||||
|
||||
// If the entries list is null, we encountered an error and should scan exteranlly
|
||||
// If the entries list is null, we encountered an error or have a file and should scan externally
|
||||
if (entries == null && File.Exists(file))
|
||||
{
|
||||
// TODO: All instances of Hash.DeepHashes should be made into 0x0 eventually
|
||||
|
||||
@@ -328,15 +328,11 @@ namespace SabreTools.Library.FileTypes
|
||||
|
||||
// If either input is null or empty, return
|
||||
if (inputStream == null || rom == null || rom.Name == null)
|
||||
{
|
||||
return success;
|
||||
}
|
||||
|
||||
// If the stream is not readable, return
|
||||
if (!inputStream.CanRead)
|
||||
{
|
||||
return success;
|
||||
}
|
||||
|
||||
// Set internal variables
|
||||
FileStream outputStream = null;
|
||||
@@ -352,9 +348,7 @@ namespace SabreTools.Library.FileTypes
|
||||
{
|
||||
// If the full output path doesn't exist, create it
|
||||
if (!Directory.Exists(Path.GetDirectoryName(fileName)))
|
||||
{
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(fileName));
|
||||
}
|
||||
|
||||
// Overwrite output files by default
|
||||
outputStream = FileExtensions.TryCreate(fileName);
|
||||
@@ -372,15 +366,14 @@ namespace SabreTools.Library.FileTypes
|
||||
outputStream.Write(ibuffer, 0, ilen);
|
||||
outputStream.Flush();
|
||||
}
|
||||
|
||||
outputStream.Dispose();
|
||||
|
||||
if (rom.ItemType == ItemType.Rom)
|
||||
{
|
||||
if (date && !string.IsNullOrWhiteSpace((rom as Rom).Date))
|
||||
{
|
||||
File.SetCreationTime(fileName, DateTime.Parse((rom as Rom).Date));
|
||||
}
|
||||
}
|
||||
|
||||
success = true;
|
||||
}
|
||||
@@ -392,7 +385,6 @@ namespace SabreTools.Library.FileTypes
|
||||
}
|
||||
finally
|
||||
{
|
||||
inputStream.Dispose();
|
||||
outputStream?.Dispose();
|
||||
}
|
||||
|
||||
|
||||
@@ -491,6 +491,7 @@ namespace SabreTools.Library.FileTypes
|
||||
ds.Write(ibuffer, 0, ilen);
|
||||
ds.Flush();
|
||||
}
|
||||
|
||||
ds.Dispose();
|
||||
|
||||
// Now write the standard footer
|
||||
@@ -500,7 +501,6 @@ namespace SabreTools.Library.FileTypes
|
||||
// Dispose of everything
|
||||
sw.Dispose();
|
||||
outputStream.Dispose();
|
||||
inputStream.Dispose();
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@@ -438,15 +438,11 @@ namespace SabreTools.Library.FileTypes
|
||||
|
||||
// If either input is null or empty, return
|
||||
if (inputStream == null || rom == null || rom.Name == null)
|
||||
{
|
||||
return success;
|
||||
}
|
||||
|
||||
// If the stream is not readable, return
|
||||
if (!inputStream.CanRead)
|
||||
{
|
||||
return success;
|
||||
}
|
||||
|
||||
// Seek to the beginning of the stream
|
||||
inputStream.Seek(0, SeekOrigin.Begin);
|
||||
@@ -464,9 +460,7 @@ namespace SabreTools.Library.FileTypes
|
||||
{
|
||||
// If the full output path doesn't exist, create it
|
||||
if (!Directory.Exists(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))
|
||||
@@ -496,7 +490,7 @@ namespace SabreTools.Library.FileTypes
|
||||
writeStream.Write(ibuffer, 0, ilen);
|
||||
writeStream.Flush();
|
||||
}
|
||||
inputStream.Dispose();
|
||||
|
||||
zipFile.ZipFileCloseWriteStream(Utilities.StringToByteArray(rom.CRC));
|
||||
}
|
||||
|
||||
@@ -572,7 +566,6 @@ namespace SabreTools.Library.FileTypes
|
||||
writeStream.Flush();
|
||||
}
|
||||
|
||||
inputStream.Dispose();
|
||||
zipFile.ZipFileCloseWriteStream(Utilities.StringToByteArray(rom.CRC));
|
||||
}
|
||||
|
||||
@@ -611,14 +604,12 @@ namespace SabreTools.Library.FileTypes
|
||||
}
|
||||
finally
|
||||
{
|
||||
inputStream?.Dispose();
|
||||
}
|
||||
|
||||
// If the old file exists, delete it and replace
|
||||
if (File.Exists(archiveFileName))
|
||||
{
|
||||
FileExtensions.TryDelete(archiveFileName);
|
||||
}
|
||||
|
||||
File.Move(tempFile, archiveFileName);
|
||||
|
||||
return true;
|
||||
|
||||
@@ -313,15 +313,11 @@ namespace SabreTools.Library.FileTypes
|
||||
|
||||
// If either input is null or empty, return
|
||||
if (inputStream == null || rom == null || rom.Name == null)
|
||||
{
|
||||
return success;
|
||||
}
|
||||
|
||||
// If the stream is not readable, return
|
||||
if (!inputStream.CanRead)
|
||||
{
|
||||
return success;
|
||||
}
|
||||
|
||||
// Get the output archive name from the first rebuild rom
|
||||
string archiveFileName = Path.Combine(outDir, Sanitizer.RemovePathUnsafeCharacters(rom.Machine.Name) + (rom.Machine.Name.EndsWith(".tar") ? string.Empty : ".tar"));
|
||||
@@ -334,9 +330,7 @@ namespace SabreTools.Library.FileTypes
|
||||
{
|
||||
// If the full output path doesn't exist, create it
|
||||
if (!Directory.Exists(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))
|
||||
@@ -344,9 +338,7 @@ namespace SabreTools.Library.FileTypes
|
||||
// Get temporary date-time if possible
|
||||
DateTime? usableDate = null;
|
||||
if (date && !string.IsNullOrWhiteSpace(rom.Date) && DateTime.TryParse(rom.Date.Replace('\\', '/'), out DateTime dt))
|
||||
{
|
||||
usableDate = dt;
|
||||
}
|
||||
|
||||
// Copy the input stream to the output
|
||||
inputStream.Seek(0, SeekOrigin.Begin);
|
||||
@@ -367,9 +359,7 @@ namespace SabreTools.Library.FileTypes
|
||||
|
||||
// If the old one doesn't contain the new file, then add it
|
||||
if (!entries.Contains(rom.Name.Replace('\\', '/')))
|
||||
{
|
||||
inputIndexMap.Add(rom.Name.Replace('\\', '/'), -1);
|
||||
}
|
||||
|
||||
// Then add all of the old entries to it too
|
||||
for (int i = 0; i < entries.Count; i++)
|
||||
@@ -397,9 +387,7 @@ namespace SabreTools.Library.FileTypes
|
||||
// Get temporary date-time if possible
|
||||
DateTime? usableDate = null;
|
||||
if (date && !string.IsNullOrWhiteSpace(rom.Date) && DateTime.TryParse(rom.Date.Replace('\\', '/'), out DateTime dt))
|
||||
{
|
||||
usableDate = dt;
|
||||
}
|
||||
|
||||
// If we have the input file, add it now
|
||||
if (index < 0)
|
||||
@@ -435,16 +423,14 @@ namespace SabreTools.Library.FileTypes
|
||||
}
|
||||
finally
|
||||
{
|
||||
inputStream.Dispose();
|
||||
tarFile.Dispose();
|
||||
oldTarFile.Dispose();
|
||||
}
|
||||
|
||||
// If the old file exists, delete it and replace
|
||||
if (File.Exists(archiveFileName))
|
||||
{
|
||||
FileExtensions.TryDelete(archiveFileName);
|
||||
}
|
||||
|
||||
File.Move(tempFile, archiveFileName);
|
||||
|
||||
return success;
|
||||
|
||||
@@ -373,7 +373,6 @@ namespace SabreTools.Library.FileTypes
|
||||
|
||||
// Dispose of everything
|
||||
outputStream.Dispose();
|
||||
inputStream.Dispose();
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@@ -443,15 +443,11 @@ namespace SabreTools.Library.FileTypes
|
||||
|
||||
// If either input is null or empty, return
|
||||
if (inputStream == null || rom == null || rom.Name == null)
|
||||
{
|
||||
return success;
|
||||
}
|
||||
|
||||
// If the stream is not readable, return
|
||||
if (!inputStream.CanRead)
|
||||
{
|
||||
return success;
|
||||
}
|
||||
|
||||
// Seek to the beginning of the stream
|
||||
inputStream.Seek(0, SeekOrigin.Begin);
|
||||
@@ -469,9 +465,7 @@ namespace SabreTools.Library.FileTypes
|
||||
{
|
||||
// If the full output path doesn't exist, create it
|
||||
if (!Directory.Exists(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))
|
||||
@@ -501,7 +495,7 @@ namespace SabreTools.Library.FileTypes
|
||||
writeStream.Write(ibuffer, 0, ilen);
|
||||
writeStream.Flush();
|
||||
}
|
||||
inputStream.Dispose();
|
||||
|
||||
zipFile.ZipFileCloseWriteStream(Utilities.StringToByteArray(rom.CRC));
|
||||
}
|
||||
|
||||
@@ -521,9 +515,7 @@ namespace SabreTools.Library.FileTypes
|
||||
|
||||
// If the old one doesn't contain the new file, then add it
|
||||
if (!oldZipFileContents.Contains(rom.Name.Replace('\\', '/')))
|
||||
{
|
||||
inputIndexMap.Add(rom.Name.Replace('\\', '/'), -1);
|
||||
}
|
||||
|
||||
// Then add all of the old entries to it too
|
||||
for (int i = 0; i < oldZipFile.LocalFilesCount(); i++)
|
||||
@@ -577,7 +569,6 @@ namespace SabreTools.Library.FileTypes
|
||||
writeStream.Flush();
|
||||
}
|
||||
|
||||
inputStream.Dispose();
|
||||
zipFile.ZipFileCloseWriteStream(Utilities.StringToByteArray(rom.CRC));
|
||||
}
|
||||
|
||||
@@ -617,14 +608,12 @@ namespace SabreTools.Library.FileTypes
|
||||
}
|
||||
finally
|
||||
{
|
||||
inputStream?.Dispose();
|
||||
}
|
||||
|
||||
// If the old file exists, delete it and replace
|
||||
if (File.Exists(archiveFileName))
|
||||
{
|
||||
FileExtensions.TryDelete(archiveFileName);
|
||||
}
|
||||
|
||||
File.Move(tempFile, archiveFileName);
|
||||
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user