Use collection expression syntax.

This commit is contained in:
2024-11-12 06:39:06 +00:00
parent dda17fc1f9
commit cd66743990
16 changed files with 64 additions and 53 deletions

View File

@@ -113,7 +113,7 @@ public static class Base32
if(base32String == null) return null;
// Check if empty
if(base32String == string.Empty) return new byte[0];
if(base32String == string.Empty) return [];
// Convert to upper-case
string base32StringUpperCase = base32String.ToUpperInvariant();

View File

@@ -60,7 +60,7 @@ public sealed class Md5Context : IChecksum
/// <summary>Returns a byte array of the hash value.</summary>
public byte[] Final()
{
_provider.TransformFinalBlock(new byte[0], 0, 0);
_provider.TransformFinalBlock([], 0, 0);
return _provider.Hash;
}
@@ -69,7 +69,7 @@ public sealed class Md5Context : IChecksum
/// <summary>Returns a hexadecimal representation of the hash value.</summary>
public string End()
{
_provider.TransformFinalBlock(new byte[0], 0, 0);
_provider.TransformFinalBlock([], 0, 0);
var md5Output = new StringBuilder();
foreach(byte h in _provider.Hash) md5Output.Append(h.ToString("x2"));

View File

@@ -60,7 +60,7 @@ public sealed class Sha1Context : IChecksum
/// <summary>Returns a byte array of the hash value.</summary>
public byte[] Final()
{
_provider.TransformFinalBlock(new byte[0], 0, 0);
_provider.TransformFinalBlock([], 0, 0);
return _provider.Hash;
}
@@ -69,7 +69,7 @@ public sealed class Sha1Context : IChecksum
/// <summary>Returns a hexadecimal representation of the hash value.</summary>
public string End()
{
_provider.TransformFinalBlock(new byte[0], 0, 0);
_provider.TransformFinalBlock([], 0, 0);
var sha1Output = new StringBuilder();
foreach(byte h in _provider.Hash) sha1Output.Append(h.ToString("x2"));

View File

@@ -60,7 +60,7 @@ public sealed class Sha256Context : IChecksum
/// <summary>Returns a byte array of the hash value.</summary>
public byte[] Final()
{
_provider.TransformFinalBlock(new byte[0], 0, 0);
_provider.TransformFinalBlock([], 0, 0);
return _provider.Hash;
}
@@ -69,7 +69,7 @@ public sealed class Sha256Context : IChecksum
/// <summary>Returns a hexadecimal representation of the hash value.</summary>
public string End()
{
_provider.TransformFinalBlock(new byte[0], 0, 0);
_provider.TransformFinalBlock([], 0, 0);
var sha256Output = new StringBuilder();
foreach(byte h in _provider.Hash) sha256Output.Append(h.ToString("x2"));

View File

@@ -60,7 +60,7 @@ public sealed class Sha384Context : IChecksum
/// <summary>Returns a byte array of the hash value.</summary>
public byte[] Final()
{
_provider.TransformFinalBlock(new byte[0], 0, 0);
_provider.TransformFinalBlock([], 0, 0);
return _provider.Hash;
}
@@ -69,7 +69,7 @@ public sealed class Sha384Context : IChecksum
/// <summary>Returns a hexadecimal representation of the hash value.</summary>
public string End()
{
_provider.TransformFinalBlock(new byte[0], 0, 0);
_provider.TransformFinalBlock([], 0, 0);
var sha384Output = new StringBuilder();
foreach(byte h in _provider.Hash) sha384Output.Append(h.ToString("x2"));

View File

@@ -60,7 +60,7 @@ public sealed class Sha512Context : IChecksum
/// <summary>Returns a byte array of the hash value.</summary>
public byte[] Final()
{
_provider.TransformFinalBlock(new byte[0], 0, 0);
_provider.TransformFinalBlock([], 0, 0);
return _provider.Hash;
}
@@ -69,7 +69,7 @@ public sealed class Sha512Context : IChecksum
/// <summary>Returns a hexadecimal representation of the hash value.</summary>
public string End()
{
_provider.TransformFinalBlock(new byte[0], 0, 0);
_provider.TransformFinalBlock([], 0, 0);
var sha512Output = new StringBuilder();
foreach(byte h in _provider.Hash) sha512Output.Append(h.ToString("x2"));

View File

@@ -60,12 +60,12 @@ public sealed class SpamSumContext : IChecksum
//"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
readonly byte[] _b64 =
{
[
0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, 0x51, 0x52,
0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A,
0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0x30, 0x31,
0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x2B, 0x2F
};
];
FuzzyState _self;

View File

@@ -415,19 +415,19 @@ public class Winfsp : FileSystemBase
ConcurrentDictionary<string, CachedMedia> cachedMachineMedias =
_vfs.GetMediasFromMachine(node.MachineId);
node.Children = new List<FileEntry>
{
new()
node.Children =
[
new FileEntry
{
FileName = ".",
Info = node.Info
},
new()
new FileEntry
{
FileName = "..",
Info = node.ParentInfo
}
};
];
node.Children.AddRange(cachedMachineFiles.Select(file => new FileEntry
{
@@ -485,19 +485,19 @@ public class Winfsp : FileSystemBase
{
ConcurrentDictionary<string, CachedMachine> machines = _vfs.GetMachinesFromRomSet(node.RomSetId);
node.Children = new List<FileEntry>
{
new()
node.Children =
[
new FileEntry
{
FileName = ".",
Info = node.Info
},
new()
new FileEntry
{
FileName = "..",
Info = node.ParentInfo
}
};
];
node.Children.AddRange(machines.Select(machine => new FileEntry
{
@@ -512,7 +512,7 @@ public class Winfsp : FileSystemBase
}
else
{
node.Children = new List<FileEntry>();
node.Children = [];
node.Children.AddRange(_vfs.GetRootEntries()
.Select(e => new FileEntry

View File

@@ -479,41 +479,41 @@ public sealed class DatImporter
? ctx.Files
.FromSqlRaw($"SELECT DISTINCT f.* FROM Files AS f, [{tmpRomCrc32Table}] AS t WHERE f.Crc32 = t.Crc32 AND f.Size = t.Size")
.ToList()
: new List<DbFile>();
: [];
List<DbFile> pendingFilesByMd5List = romsHaveMd5
? ctx.Files
.FromSqlRaw($"SELECT DISTINCT f.* FROM Files AS f, [{tmpRomMd5Table}] AS t WHERE f.Md5 = t.Md5 AND f.Size = t.Size")
.ToList()
: new List<DbFile>();
: [];
List<DbFile> pendingFilesBySha1List =
romsHaveSha1
? ctx.Files
.FromSqlRaw($"SELECT DISTINCT f.* FROM Files AS f, [{tmpRomSha1Table}] AS t WHERE f.Sha1 = t.Sha1 AND f.Size = t.Size")
.ToList()
: new List<DbFile>();
: [];
List<DbFile> pendingFilesBySha256List =
romsHaveSha256
? ctx.Files
.FromSqlRaw($"SELECT DISTINCT f.* FROM Files AS f, [{tmpRomSha256Table}] AS t WHERE f.Sha256 = t.Sha256 AND f.Size = t.Size")
.ToList()
: new List<DbFile>();
: [];
List<DbFile> pendingFilesBySha384List =
romsHaveSha384
? ctx.Files
.FromSqlRaw($"SELECT DISTINCT f.* FROM Files AS f, [{tmpRomSha384Table}] AS t WHERE f.Sha384 = t.Sha384 AND f.Size = t.Size")
.ToList()
: new List<DbFile>();
: [];
List<DbFile> pendingFilesBySha512List =
romsHaveSha512
? ctx.Files
.FromSqlRaw($"SELECT DISTINCT f.* FROM Files AS f, [{tmpRomSha512Table}] AS t WHERE f.Sha512 = t.Sha512 AND f.Size = t.Size")
.ToList()
: new List<DbFile>();
: [];
Dictionary<string, DbDisk> pendingDisksByMd5 =
disksHaveMd5
@@ -756,40 +756,52 @@ public sealed class DatImporter
if(file == null && hashCollision)
{
if(rom.GetStringFieldValue(SabreTools.Models.Metadata.Rom.SHA512Key) != null)
{
file = pendingFiles.FirstOrDefault(f => f.Sha512 ==
rom.GetStringFieldValue(SabreTools.Models.Metadata.Rom
.SHA512Key) &&
f.Size == uSize);
}
if(file == null && rom.GetStringFieldValue(SabreTools.Models.Metadata.Rom.SHA384Key) != null)
{
file = pendingFiles.FirstOrDefault(f => f.Sha384 ==
rom.GetStringFieldValue(SabreTools.Models.Metadata.Rom
.SHA384Key) &&
f.Size == uSize);
}
if(file == null && rom.GetStringFieldValue(SabreTools.Models.Metadata.Rom.SHA256Key) != null)
{
file = pendingFiles.FirstOrDefault(f => f.Sha256 ==
rom.GetStringFieldValue(SabreTools.Models.Metadata.Rom
.SHA256Key) &&
f.Size == uSize);
}
if(file == null && rom.GetStringFieldValue(SabreTools.Models.Metadata.Rom.SHA1Key) != null)
{
file = pendingFiles.FirstOrDefault(f => f.Sha1 ==
rom.GetStringFieldValue(SabreTools.Models.Metadata.Rom
.SHA1Key) &&
f.Size == uSize);
}
if(file == null && rom.GetStringFieldValue(SabreTools.Models.Metadata.Rom.MD5Key) != null)
{
file = pendingFiles.FirstOrDefault(f => f.Md5 ==
rom.GetStringFieldValue(SabreTools.Models.Metadata.Rom
.MD5Key) &&
f.Size == uSize);
}
if(file == null && rom.GetStringFieldValue(SabreTools.Models.Metadata.Rom.CRCKey) != null)
{
file = pendingFiles.FirstOrDefault(f => f.Crc32 ==
rom.GetStringFieldValue(SabreTools.Models.Metadata.Rom
.CRCKey) &&
f.Size == uSize);
}
}
if(file == null)
@@ -991,12 +1003,16 @@ public sealed class DatImporter
DbDisk dbDisk = null;
if(disk.GetStringFieldValue(SabreTools.Models.Metadata.Disk.SHA1Key) != null && dbDisk == null)
{
pendingDisksBySha1.TryGetValue(disk.GetStringFieldValue(SabreTools.Models.Metadata.Disk.SHA1Key),
out dbDisk);
}
if(disk.GetStringFieldValue(SabreTools.Models.Metadata.Disk.MD5Key) != null && dbDisk == null)
{
pendingDisksByMd5.TryGetValue(disk.GetStringFieldValue(SabreTools.Models.Metadata.Disk.MD5Key),
out dbDisk);
}
if(dbDisk == null)
{
@@ -1115,17 +1131,23 @@ public sealed class DatImporter
DbMedia dbMedia = null;
if(media.GetStringFieldValue(SabreTools.Models.Metadata.Media.SHA256Key) != null && dbMedia == null)
{
pendingMediasBySha256.TryGetValue(media.GetStringFieldValue(SabreTools.Models.Metadata.Media
.SHA256Key),
out dbMedia);
}
if(media.GetStringFieldValue(SabreTools.Models.Metadata.Media.SHA1Key) != null && dbMedia == null)
{
pendingMediasBySha1.TryGetValue(media.GetStringFieldValue(SabreTools.Models.Metadata.Media.SHA1Key),
out dbMedia);
}
if(media.GetStringFieldValue(SabreTools.Models.Metadata.Media.MD5Key) != null && dbMedia == null)
{
pendingMediasByMd5.TryGetValue(media.GetStringFieldValue(SabreTools.Models.Metadata.Media.MD5Key),
out dbMedia);
}
// TODO: SpamSum
if(dbMedia == null)

View File

@@ -45,9 +45,9 @@ public class FileImporter
_pendingMediasBySha256 = new Dictionary<string, DbMedia>();
_pendingMediasBySha1 = new Dictionary<string, DbMedia>();
_pendingMediasByMd5 = new Dictionary<string, DbMedia>();
_newFiles = new List<DbFile>();
_newDisks = new List<DbDisk>();
_newMedias = new List<DbMedia>();
_newFiles = [];
_newDisks = [];
_newMedias = [];
_onlyKnown = onlyKnown;
_deleteAfterImport = deleteAfterImport;
_position = 0;

View File

@@ -52,11 +52,7 @@ public static class Version
{
Assembly assembly = typeof(GCSettings).Assembly;
string[] assemblyPath = assembly.Location.Split(new[]
{
'/', '\\'
},
StringSplitOptions.RemoveEmptyEntries);
string[] assemblyPath = assembly.Location.Split(['/', '\\'], StringSplitOptions.RemoveEmptyEntries);
int netCoreAppIndex = Array.IndexOf(assemblyPath, "Microsoft.NETCore.App");

View File

@@ -56,7 +56,7 @@ public sealed class AboutViewModel : ViewModelBase
LicenseCommand = ReactiveCommand.Create(ExecuteLicenseCommand);
CloseCommand = ReactiveCommand.Create(ExecuteCloseCommand);
Assemblies = new ObservableCollection<AssemblyModel>();
Assemblies = [];
// TODO: They do not load in time
Task.Run(() =>

View File

@@ -70,7 +70,7 @@ public sealed class ImportDatFolderViewModel : ViewModelBase
FolderPath = folderPath;
_allFilesChecked = false;
_recursiveChecked = true;
ImportResults = new ObservableCollection<ImportDatFolderItem>();
ImportResults = [];
CloseCommand = ReactiveCommand.Create(ExecuteCloseCommand);
StartCommand = ReactiveCommand.Create(ExecuteStartCommand);
}

View File

@@ -68,7 +68,7 @@ public sealed class ImportRomFolderViewModel : ViewModelBase
_removeFilesChecked = false;
_knownOnlyChecked = true;
_recurseArchivesChecked = Settings.Settings.UnArUsable;
ImportResults = new ObservableCollection<ImportRomItem>();
ImportResults = [];
CloseCommand = ReactiveCommand.Create(ExecuteCloseCommand);
StartCommand = ReactiveCommand.Create(ExecuteStartCommand);
IsReady = true;

View File

@@ -162,21 +162,14 @@ public class MainWindowViewModel : ViewModelBase
dlgOpen.Filters.Add(new FileDialogFilter
{
Extensions = new List<string>
{
"dat",
"xml"
},
Name = Localization.DatFilesDialogLabel
Extensions = ["dat", "xml"],
Name = Localization.DatFilesDialogLabel
});
dlgOpen.Filters.Add(new FileDialogFilter
{
Extensions = new List<string>
{
"*"
},
Name = Localization.AllFilesDialogLabel
Extensions = ["*"],
Name = Localization.AllFilesDialogLabel
});
string[] result = await dlgOpen.ShowAsync(_view);

View File

@@ -57,7 +57,7 @@ public sealed class UpdateStatsViewModel : ViewModelBase
CloseCommand = ReactiveCommand.Create(ExecuteCloseCommand);
IndeterminateProgress = true;
ProgressVisible = false;
RomSets = new ObservableCollection<RomSetModel>();
RomSets = [];
}
public string Title => Localization.UpdateStatsTitle;