mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Fix Sort
This commit is contained in:
@@ -1908,7 +1908,7 @@ namespace SabreTools.Library.DatFiles
|
||||
});
|
||||
|
||||
// Now find all folders that are empty, if we are supposed to
|
||||
if (!(Header.OutputDepot?.IsActive ?? false) && addBlanks)
|
||||
if (Header.OutputDepot?.IsActive != true && addBlanks)
|
||||
{
|
||||
List<string> empties = DirectoryExtensions.ListEmpty(basePath);
|
||||
Parallel.ForEach(empties, Globals.ParallelOptions, dir =>
|
||||
@@ -1979,7 +1979,7 @@ namespace SabreTools.Library.DatFiles
|
||||
bool copyFiles)
|
||||
{
|
||||
// Special case for if we are in Depot mode (all names are supposed to be SHA-1 hashes)
|
||||
if (Header.OutputDepot?.IsActive ?? false)
|
||||
if (Header.OutputDepot?.IsActive == true)
|
||||
{
|
||||
GZipArchive gzarc = new GZipArchive(item);
|
||||
BaseFile baseFile = gzarc.GetTorrentGZFileInfo();
|
||||
@@ -2980,11 +2980,7 @@ namespace SabreTools.Library.DatFiles
|
||||
/// <param name="quickScan">True to enable external scanning of archives, false otherwise</param>
|
||||
/// <param name="asFiles">TreatAsFiles representing CHD and Archive scanning</param>
|
||||
/// <returns>True if verification was a success, false otherwise</returns>
|
||||
public bool VerifyGeneric(
|
||||
List<string> inputs,
|
||||
bool hashOnly = false,
|
||||
bool quickScan = false,
|
||||
TreatAsFiles asFiles = 0x00)
|
||||
public bool VerifyGeneric(List<string> inputs, bool hashOnly, bool quickScan, TreatAsFiles asFiles = 0x00)
|
||||
{
|
||||
bool success = true;
|
||||
|
||||
@@ -2996,12 +2992,14 @@ namespace SabreTools.Library.DatFiles
|
||||
PopulateFromDir(input, quickScan ? Hash.SecureHashes : Hash.DeepHashes, asFiles: asFiles);
|
||||
}
|
||||
|
||||
// If we are checking hashes only, essentially diff the inputs
|
||||
// Force bucketing according to the flags
|
||||
Items.SetBucketedBy(Field.NULL);
|
||||
if (hashOnly)
|
||||
{
|
||||
// First we need to bucket and dedupe by hash to get duplicates
|
||||
Items.BucketBy(Field.DatItem_CRC, DedupeType.Full);
|
||||
else
|
||||
Items.BucketBy(Field.Machine_Name, DedupeType.Full);
|
||||
|
||||
// Then mark items for removal
|
||||
var keys = Items.SortedKeys.ToList();
|
||||
foreach (string key in keys)
|
||||
{
|
||||
@@ -3016,26 +3014,6 @@ namespace SabreTools.Library.DatFiles
|
||||
// Set the list back, just in case
|
||||
Items[key] = items;
|
||||
}
|
||||
}
|
||||
// If we are checking full names, get only files found in directory
|
||||
else
|
||||
{
|
||||
var keys = Items.SortedKeys.ToList();
|
||||
foreach (string key in keys)
|
||||
{
|
||||
List<DatItem> items = Items[key];
|
||||
List<DatItem> newItems = DatItem.Merge(items);
|
||||
for (int i = 0; i < newItems.Count; i++)
|
||||
{
|
||||
// Unmatched items will have a source ID of 99, remove all others
|
||||
if (newItems[i].Source.Index != 99)
|
||||
newItems[i].Remove = true;
|
||||
}
|
||||
|
||||
// Set the list back, just in case
|
||||
Items[key] = newItems;
|
||||
}
|
||||
}
|
||||
|
||||
// Set fixdat headers in case of writing out
|
||||
Header.FileName = $"fixDAT_{Header.FileName}";
|
||||
@@ -3618,7 +3596,7 @@ namespace SabreTools.Library.DatFiles
|
||||
string post = CreatePrefixPostfix(item, false);
|
||||
|
||||
// If we're in Depot mode, take care of that instead
|
||||
if (Header.OutputDepot?.IsActive ?? false)
|
||||
if (Header.OutputDepot?.IsActive == true)
|
||||
{
|
||||
if (item.ItemType == ItemType.Disk)
|
||||
{
|
||||
|
||||
@@ -373,6 +373,27 @@ namespace SabreTools.Library.DatFiles
|
||||
return items[key].Remove(value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reset a key from the file dictionary if it exists
|
||||
/// </summary>
|
||||
/// <param name="key">Key in the dictionary to reset</param>
|
||||
public bool Reset(string key)
|
||||
{
|
||||
// If the key doesn't exist, return
|
||||
if (!ContainsKey(key))
|
||||
return false;
|
||||
|
||||
// Remove the statistics first
|
||||
foreach (DatItem item in items[key])
|
||||
{
|
||||
RemoveItemStatistics(item);
|
||||
}
|
||||
|
||||
// Remove the key from the dictionary
|
||||
items[key] = new List<DatItem>();
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Override the internal Field value
|
||||
/// </summary>
|
||||
@@ -658,10 +679,11 @@ namespace SabreTools.Library.DatFiles
|
||||
// Set the sorted type
|
||||
mergedBy = dedupeType;
|
||||
|
||||
Parallel.ForEach(Keys, Globals.ParallelOptions, key =>
|
||||
List<string> keys = Keys.ToList();
|
||||
Parallel.ForEach(keys, Globals.ParallelOptions, key =>
|
||||
{
|
||||
// Get the possibly unsorted list
|
||||
List<DatItem> sortedlist = this[key];
|
||||
List<DatItem> sortedlist = this[key].ToList();
|
||||
|
||||
// Sort the list of items to be consistent
|
||||
DatItem.Sort(ref sortedlist, false);
|
||||
@@ -671,14 +693,15 @@ namespace SabreTools.Library.DatFiles
|
||||
sortedlist = DatItem.Merge(sortedlist);
|
||||
|
||||
// Add the list back to the dictionary
|
||||
Remove(key);
|
||||
Reset(key);
|
||||
AddRange(key, sortedlist);
|
||||
});
|
||||
}
|
||||
// If the merge type is the same, we want to sort the dictionary to be consistent
|
||||
else
|
||||
{
|
||||
Parallel.ForEach(Keys, Globals.ParallelOptions, key =>
|
||||
List<string> keys = Keys.ToList();
|
||||
Parallel.ForEach(keys, Globals.ParallelOptions, key =>
|
||||
{
|
||||
// Get the possibly unsorted list
|
||||
List<DatItem> sortedlist = this[key];
|
||||
@@ -811,9 +834,12 @@ namespace SabreTools.Library.DatFiles
|
||||
/// </summary>
|
||||
private void ClearEmpty()
|
||||
{
|
||||
var keys = items.Keys.ToList();
|
||||
var keys = items.Keys.Where(k => k != null).ToList();
|
||||
foreach (string key in keys)
|
||||
{
|
||||
if (!items.ContainsKey(key))
|
||||
continue;
|
||||
|
||||
if (items[key] == null || items[key].Count == 0)
|
||||
items.Remove(key);
|
||||
}
|
||||
|
||||
@@ -136,7 +136,7 @@ namespace SabreTools.Library.DatFiles
|
||||
ProcessItemName(datItem, false, forceRomName: false);
|
||||
|
||||
// Romba mode automatically uses item name
|
||||
if ((Header.OutputDepot?.IsActive ?? false) || Header.UseRomName)
|
||||
if (Header.OutputDepot?.IsActive == true || Header.UseRomName)
|
||||
{
|
||||
sw.Write($"{datItem.Name}\n");
|
||||
}
|
||||
|
||||
@@ -1211,7 +1211,7 @@ namespace SabreTools.Library.DatItems
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sort a list of File objects by SystemID, SourceID, Game, and Name (in order)
|
||||
/// Sort a list of File objects by SourceID, Game, and Name (in order)
|
||||
/// </summary>
|
||||
/// <param name="roms">List of File objects representing the roms to be sorted</param>
|
||||
/// <param name="norename">True if files are not renamed, false otherwise</param>
|
||||
|
||||
@@ -321,8 +321,7 @@ namespace Compress.ZipFile.ZLib
|
||||
|
||||
public override System.Int64 Seek(System.Int64 offset, System.IO.SeekOrigin origin)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
//_outStream.Seek(offset, origin);
|
||||
return _stream.Seek(offset, origin);
|
||||
}
|
||||
public override void SetLength(System.Int64 value)
|
||||
{
|
||||
|
||||
@@ -70,7 +70,7 @@ namespace SabreTools.Library.FileTypes
|
||||
{
|
||||
// Validate that this is actually a valid AaruFormat (by magic string alone)
|
||||
bool validated = ValidateHeader(aarustream);
|
||||
aarustream.Seek(-8, SeekOrigin.Current); // Seek back to start
|
||||
aarustream.SeekIfPossible(); // Seek back to start
|
||||
if (!validated)
|
||||
return null;
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ namespace SabreTools.Library.FileTypes
|
||||
{
|
||||
// Read the standard CHD headers
|
||||
(char[] tag, uint length, uint version) = GetHeaderValues(chdstream);
|
||||
chdstream.Seek(-16, SeekOrigin.Current); // Seek back to start
|
||||
chdstream.SeekIfPossible(); // Seek back to start
|
||||
|
||||
// Validate that this is actually a valid CHD
|
||||
uint validatedVersion = ValidateHeader(tag, length, version);
|
||||
|
||||
@@ -231,7 +231,7 @@ namespace SabreTools.Library.FileTypes
|
||||
var gz = new gZip();
|
||||
ZipReturn ret = gz.ZipFileOpen(this.Filename);
|
||||
ret = gz.ZipFileOpenReadStream(0, out Stream gzstream, out ulong streamSize);
|
||||
BaseFile gzipEntryRom = gzstream.GetInfo(omitFromScan: omitFromScan);
|
||||
BaseFile gzipEntryRom = gzstream.GetInfo(omitFromScan: omitFromScan, asFiles: TreatAsFiles.AaruFormats | TreatAsFiles.CHDs);
|
||||
gzipEntryRom.Filename = gz.Filename(0);
|
||||
gzipEntryRom.Parent = gamename;
|
||||
gzipEntryRom.Date = (date && gz.TimeStamp > 0 ? gz.TimeStamp.ToString() : null);
|
||||
|
||||
@@ -204,7 +204,7 @@ namespace SabreTools.Library.FileTypes
|
||||
else
|
||||
{
|
||||
Stream entryStream = entry.OpenEntryStream();
|
||||
BaseFile rarEntryRom = entryStream.GetInfo(size: entry.Size, omitFromScan: omitFromScan);
|
||||
BaseFile rarEntryRom = entryStream.GetInfo(size: entry.Size, omitFromScan: omitFromScan, asFiles: TreatAsFiles.AaruFormats | TreatAsFiles.CHDs);
|
||||
rarEntryRom.Filename = entry.Key;
|
||||
rarEntryRom.Parent = gamename;
|
||||
rarEntryRom.Date = entry.LastModifiedTime?.ToString("yyyy/MM/dd hh:mm:ss");
|
||||
|
||||
@@ -316,7 +316,7 @@ namespace SabreTools.Library.FileTypes
|
||||
// Otherwise, use the stream directly
|
||||
else
|
||||
{
|
||||
BaseFile zipEntryRom = readStream.GetInfo(size: (long)zf.UncompressedSize(i), omitFromScan: omitFromScan, keepReadOpen: true);
|
||||
BaseFile zipEntryRom = readStream.GetInfo(size: (long)zf.UncompressedSize(i), omitFromScan: omitFromScan, keepReadOpen: true, asFiles: TreatAsFiles.AaruFormats | TreatAsFiles.CHDs);
|
||||
zipEntryRom.Filename = zf.Filename(i);
|
||||
zipEntryRom.Parent = gamename;
|
||||
found.Add(zipEntryRom);
|
||||
|
||||
@@ -209,7 +209,7 @@ namespace SabreTools.Library.FileTypes
|
||||
else
|
||||
{
|
||||
Stream entryStream = entry.OpenEntryStream();
|
||||
BaseFile tarEntryRom = entryStream.GetInfo(size: entry.Size, omitFromScan: omitFromScan);
|
||||
BaseFile tarEntryRom = entryStream.GetInfo(size: entry.Size, omitFromScan: omitFromScan, asFiles: TreatAsFiles.AaruFormats | TreatAsFiles.CHDs);
|
||||
tarEntryRom.Filename = entry.Key;
|
||||
tarEntryRom.Parent = gamename;
|
||||
tarEntryRom.Date = entry.LastModifiedTime?.ToString("yyyy/MM/dd hh:mm:ss");
|
||||
|
||||
@@ -221,7 +221,7 @@ namespace SabreTools.Library.FileTypes
|
||||
else
|
||||
{
|
||||
var xzStream = new XZStream(File.OpenRead(this.Filename));
|
||||
BaseFile xzEntryRom = xzStream.GetInfo(omitFromScan: omitFromScan);
|
||||
BaseFile xzEntryRom = xzStream.GetInfo(omitFromScan: omitFromScan, asFiles: TreatAsFiles.AaruFormats | TreatAsFiles.CHDs);
|
||||
xzEntryRom.Filename = gamename;
|
||||
xzEntryRom.Parent = gamename;
|
||||
_children.Add(xzEntryRom);
|
||||
|
||||
@@ -319,7 +319,7 @@ namespace SabreTools.Library.FileTypes
|
||||
// Otherwise, use the stream directly
|
||||
else
|
||||
{
|
||||
BaseFile zipEntryRom = readStream.GetInfo(size: (long)zf.UncompressedSize(i), omitFromScan: omitFromScan, keepReadOpen: true);
|
||||
BaseFile zipEntryRom = readStream.GetInfo(size: (long)zf.UncompressedSize(i), omitFromScan: omitFromScan, keepReadOpen: true, asFiles: TreatAsFiles.AaruFormats | TreatAsFiles.CHDs);
|
||||
zipEntryRom.Filename = zf.Filename(i);
|
||||
zipEntryRom.Parent = gamename;
|
||||
string convertedDate = zf.LastModified(i).ToString("yyyy/MM/dd hh:mm:ss");
|
||||
|
||||
@@ -209,17 +209,20 @@ namespace SabreTools.Library.IO
|
||||
/// </summary>
|
||||
/// <param name="input">Input stream to try seeking on</param>
|
||||
/// <param name="offset">Optional offset to seek to</param>
|
||||
private static long SeekIfPossible(this Stream input, long offset = 0)
|
||||
{
|
||||
if (input.CanSeek)
|
||||
public static long SeekIfPossible(this Stream input, long offset = 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (input.CanSeek)
|
||||
{
|
||||
if (offset < 0)
|
||||
return input.Seek(offset, SeekOrigin.End);
|
||||
else if (offset >= 0)
|
||||
return input.Seek(offset, SeekOrigin.Begin);
|
||||
}
|
||||
|
||||
return input.Position;
|
||||
}
|
||||
catch (NotSupportedException)
|
||||
{
|
||||
Globals.Logger.Verbose("Stream does not support seeking to starting offset. Stream position not changed");
|
||||
@@ -228,9 +231,8 @@ namespace SabreTools.Library.IO
|
||||
{
|
||||
Globals.Logger.Warning("Stream does not support seeking to starting offset. Stream position not changed");
|
||||
}
|
||||
}
|
||||
|
||||
return input.Position;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,13 +68,17 @@ namespace SabreTools.Features
|
||||
bool updateDat = GetBoolean(features, UpdateDatValue);
|
||||
var outputFormat = GetOutputFormat(features);
|
||||
|
||||
// If we have TorrentGzip output and the romba flag, update
|
||||
if ((Header.OutputDepot?.IsActive ?? false) && outputFormat == OutputFormat.TorrentGzip)
|
||||
// If we have the romba flag
|
||||
if (Header.OutputDepot?.IsActive == true)
|
||||
{
|
||||
// Update TorrentGzip output
|
||||
if (outputFormat == OutputFormat.TorrentGzip)
|
||||
outputFormat = OutputFormat.TorrentGzipRomba;
|
||||
|
||||
// If we hae TorrentXZ output and the romba flag, update
|
||||
if ((Header.OutputDepot?.IsActive ?? false) && outputFormat == OutputFormat.TorrentXZ)
|
||||
// Update TorrentXz output
|
||||
else if (outputFormat == OutputFormat.TorrentXZ)
|
||||
outputFormat = OutputFormat.TorrentXZRomba;
|
||||
}
|
||||
|
||||
// Get a list of files from the input datfiles
|
||||
var datfiles = GetList(features, DatListValue);
|
||||
|
||||
Reference in New Issue
Block a user