mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Perform mass cleanup
This is cleanup based on both new .NET functionality (in 6 and 7) as well as a ton of simplifications and things that were missed that were caught due to the cleanup.
This commit is contained in:
@@ -9,8 +9,8 @@ namespace SabreTools.Core
|
||||
/// </summary>
|
||||
public class ConcurrentList<T> : ICollection<T>, IEnumerable<T>, IEnumerable, IList<T>, IReadOnlyCollection<T>, IReadOnlyList<T>, ICollection, IList
|
||||
{
|
||||
private List<T> _list = new List<T>();
|
||||
private object _lock = new object();
|
||||
private List<T> _list = new();
|
||||
private readonly object _lock = new();
|
||||
|
||||
public T this[int index]
|
||||
{
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace SabreTools.Core
|
||||
/// <summary>
|
||||
/// ParallelOptions object for use in parallel operations
|
||||
/// </summary>
|
||||
public static ParallelOptions ParallelOptions => new ParallelOptions()
|
||||
public static ParallelOptions ParallelOptions => new()
|
||||
{
|
||||
MaxDegreeOfParallelism = MaxThreads
|
||||
};
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace NaturalSort
|
||||
table = new Dictionary<string, string[]>();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
public void Dispose()
|
||||
{
|
||||
table.Clear();
|
||||
table = null;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -92,7 +92,7 @@ namespace SabreTools.Core.Tools
|
||||
/// </summary>
|
||||
public void Terminate()
|
||||
{
|
||||
byte[] emptyBuffer = new byte[0];
|
||||
byte[] emptyBuffer = Array.Empty<byte>();
|
||||
switch (HashType)
|
||||
{
|
||||
case Hash.CRC:
|
||||
@@ -118,23 +118,17 @@ namespace SabreTools.Core.Tools
|
||||
/// </summary>
|
||||
public byte[] GetHash()
|
||||
{
|
||||
switch (HashType)
|
||||
return HashType switch
|
||||
{
|
||||
case Hash.CRC:
|
||||
return BitConverter.GetBytes((_hasher as OptimizedCRC.OptimizedCRC).Value).Reverse().ToArray();
|
||||
|
||||
case Hash.MD5:
|
||||
case Hash.SHA1:
|
||||
case Hash.SHA256:
|
||||
case Hash.SHA384:
|
||||
case Hash.SHA512:
|
||||
return (_hasher as HashAlgorithm).Hash;
|
||||
|
||||
case Hash.SpamSum:
|
||||
return (_hasher as SpamSumContext).Final();
|
||||
}
|
||||
|
||||
return null;
|
||||
Hash.CRC => BitConverter.GetBytes((_hasher as OptimizedCRC.OptimizedCRC).Value).Reverse().ToArray(),
|
||||
Hash.MD5 => (_hasher as HashAlgorithm).Hash,
|
||||
Hash.SHA1 => (_hasher as HashAlgorithm).Hash,
|
||||
Hash.SHA256 => (_hasher as HashAlgorithm).Hash,
|
||||
Hash.SHA384 => (_hasher as HashAlgorithm).Hash,
|
||||
Hash.SHA512 => (_hasher as HashAlgorithm).Hash,
|
||||
Hash.SpamSum => (_hasher as SpamSumContext).Final(),
|
||||
_ => null,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -182,26 +182,24 @@ namespace SabreTools.Core.Tools
|
||||
string ext = Path.GetExtension(path).TrimStart('.').ToLowerInvariant();
|
||||
|
||||
// Check against the list of known DAT extensions
|
||||
switch (ext)
|
||||
return ext switch
|
||||
{
|
||||
case "csv":
|
||||
case "dat":
|
||||
case "json":
|
||||
case "md5":
|
||||
case "sfv":
|
||||
case "sha1":
|
||||
case "sha256":
|
||||
case "sha384":
|
||||
case "sha512":
|
||||
case "spamsum":
|
||||
case "ssv":
|
||||
case "tsv":
|
||||
case "txt":
|
||||
case "xml":
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
"csv" => true,
|
||||
"dat" => true,
|
||||
"json" => true,
|
||||
"md5" => true,
|
||||
"sfv" => true,
|
||||
"sha1" => true,
|
||||
"sha256" => true,
|
||||
"sha384" => true,
|
||||
"sha512" => true,
|
||||
"spamsum" => true,
|
||||
"ssv" => true,
|
||||
"tsv" => true,
|
||||
"txt" => true,
|
||||
"xml" => true,
|
||||
_ => false,
|
||||
};
|
||||
}
|
||||
|
||||
/// Indicates whether the specified array is null or has a length of zero
|
||||
@@ -213,7 +211,7 @@ namespace SabreTools.Core.Tools
|
||||
{
|
||||
return array == null || array.Length == 0;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Remove all chars that are considered path unsafe
|
||||
/// </summary>
|
||||
@@ -224,7 +222,7 @@ namespace SabreTools.Core.Tools
|
||||
List<char> invalidPath = Path.GetInvalidPathChars().ToList();
|
||||
return new string(s.Where(c => !invalidPath.Contains(c)).ToArray());
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Returns if the first byte array starts with the second array
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user