From 6e334df42fa8532e63aaf624ed1508f8bbb7d936 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Thu, 10 Sep 2020 23:30:07 -0700 Subject: [PATCH] Cleanup now that .NET 4.6.2 is gone --- DICUI.Avalonia/MainWindow.axaml.cs | 24 +++++---- DICUI.Library/Data/BaseParameters.cs | 2 +- DICUI.Library/Utilities/DumpEnvironment.cs | 16 +++--- DICUI.Library/Web/RedumpWebClient.cs | 63 +++++++++++----------- DICUI/ViewModels.cs | 2 +- DICUI/Windows/LogWindow.xaml.cs | 12 ++--- DICUI/Windows/MainWindow.xaml.cs | 19 ++++--- 7 files changed, 69 insertions(+), 69 deletions(-) diff --git a/DICUI.Avalonia/MainWindow.axaml.cs b/DICUI.Avalonia/MainWindow.axaml.cs index cbb5f672..88fc7767 100644 --- a/DICUI.Avalonia/MainWindow.axaml.cs +++ b/DICUI.Avalonia/MainWindow.axaml.cs @@ -123,16 +123,15 @@ namespace DICUI.Avalonia private void CacheCurrentDiscType() { // Get the drive letter from the selected item - var drive = this.Find("DriveLetterComboBox").SelectedItem as Drive; - if (drive == null) - return; - - // Get the current media type - if (!UIOptions.SkipMediaTypeDetection) + if (this.Find("DriveLetterComboBox").SelectedItem is Drive drive) { - ViewModels.LoggerViewModel.VerboseLog("Trying to detect media type for drive {0}.. ", drive.Letter); - CurrentMediaType = Validators.GetMediaType(drive); - ViewModels.LoggerViewModel.VerboseLogLn(CurrentMediaType == null ? "unable to detect." : ("detected " + CurrentMediaType.LongName() + ".")); + // Get the current media type + if (!UIOptions.SkipMediaTypeDetection) + { + ViewModels.LoggerViewModel.VerboseLog("Trying to detect media type for drive {0}.. ", drive.Letter); + CurrentMediaType = Validators.GetMediaType(drive); + ViewModels.LoggerViewModel.VerboseLogLn(CurrentMediaType == null ? "unable to detect." : ("detected " + CurrentMediaType.LongName() + ".")); + } } } @@ -328,8 +327,11 @@ namespace DICUI.Avalonia .ToList() ); - Systems = new List(); - Systems.Add(new KnownSystemComboBoxItem(KnownSystem.NONE)); + Systems = new List() + { + new KnownSystemComboBoxItem(KnownSystem.NONE), + }; + foreach (var group in mapping) { Systems.Add(new KnownSystemComboBoxItem(group.Key)); diff --git a/DICUI.Library/Data/BaseParameters.cs b/DICUI.Library/Data/BaseParameters.cs index 514d5e55..409623b5 100644 --- a/DICUI.Library/Data/BaseParameters.cs +++ b/DICUI.Library/Data/BaseParameters.cs @@ -304,7 +304,7 @@ namespace DICUI.Data /// True if it's a valid bool, false otherwise protected static bool IsValidBool(string parameter) { - return bool.TryParse(parameter, out bool temp); + return bool.TryParse(parameter, out bool _); } /// diff --git a/DICUI.Library/Utilities/DumpEnvironment.cs b/DICUI.Library/Utilities/DumpEnvironment.cs index 0e64ebd7..a04d48c9 100644 --- a/DICUI.Library/Utilities/DumpEnvironment.cs +++ b/DICUI.Library/Utilities/DumpEnvironment.cs @@ -730,7 +730,7 @@ namespace DICUI.Utilities string[] splitData = info.TracksAndWriteOffsets.ClrMameProData.Split('\n'); foreach (string hashData in splitData) { - if (GetISOHashValues(hashData, out long size, out string crc32, out string md5, out string sha1)) + if (GetISOHashValues(hashData, out long _, out string _, out string _, out string sha1)) { List newIds = wc.ListSearchResults(sha1); if (info.MatchedIDs.Any()) @@ -774,7 +774,7 @@ namespace DICUI.Utilities case MediaType.HDDVD: case MediaType.BluRay: // If we have a single-layer disc - if (info.SizeAndChecksums.Layerbreak == default(long)) + if (info.SizeAndChecksums.Layerbreak == default) { info.CommonDiscInfo.MasteringRingFirstLayerDataSide = (AddPlaceholders ? Template.RequiredIfExistsValue : ""); info.CommonDiscInfo.MasteringSIDCodeFirstLayerDataSide = (AddPlaceholders ? Template.RequiredIfExistsValue : ""); @@ -812,7 +812,7 @@ namespace DICUI.Utilities case MediaType.NintendoWiiOpticalDisc: // If we have a single-layer disc - if (info.SizeAndChecksums.Layerbreak == default(long)) + if (info.SizeAndChecksums.Layerbreak == default) { info.CommonDiscInfo.MasteringRingFirstLayerDataSide = (AddPlaceholders ? Template.RequiredIfExistsValue : ""); info.CommonDiscInfo.MasteringSIDCodeFirstLayerDataSide = (AddPlaceholders ? Template.RequiredIfExistsValue : ""); @@ -1050,7 +1050,7 @@ namespace DICUI.Utilities output.Add(""); output.Add("\tRingcode Information:"); // If we have a dual-layer disc - if (info.SizeAndChecksums.Layerbreak != default(long)) + if (info.SizeAndChecksums.Layerbreak != default) { AddIfExists(output, "Inner " + Template.MasteringRingField, info.CommonDiscInfo.MasteringRingFirstLayerDataSide, 2); AddIfExists(output, "Inner " + Template.MasteringSIDField, info.CommonDiscInfo.MasteringSIDCodeFirstLayerDataSide, 2); @@ -1143,7 +1143,7 @@ namespace DICUI.Utilities else { output.Add(""); output.Add("Size & Checksum:"); - AddIfExists(output, Template.LayerbreakField, (info.SizeAndChecksums.Layerbreak == default(long) ? null : info.SizeAndChecksums.Layerbreak.ToString()), 1); + AddIfExists(output, Template.LayerbreakField, (info.SizeAndChecksums.Layerbreak == default ? null : info.SizeAndChecksums.Layerbreak.ToString()), 1); AddIfExists(output, Template.SizeField, info.SizeAndChecksums.Size.ToString(), 1); AddIfExists(output, Template.CRC32Field, info.SizeAndChecksums.CRC32, 1); AddIfExists(output, Template.MD5Field, info.SizeAndChecksums.MD5, 1); @@ -1252,19 +1252,19 @@ namespace DICUI.Utilities switch (mediaType) { case MediaType.DVD: - if (layerbreak != default(long)) + if (layerbreak != default) return $"{mediaType.LongName()}-9"; else return $"{mediaType.LongName()}-5"; case MediaType.BluRay: - if (layerbreak != default(long)) + if (layerbreak != default) return $"{mediaType.LongName()}-50"; else return $"{mediaType.LongName()}-25"; case MediaType.UMD: - if (layerbreak != default(long)) + if (layerbreak != default) return $"{mediaType.LongName()}-DL"; else return $"{mediaType.LongName()}-SL"; diff --git a/DICUI.Library/Web/RedumpWebClient.cs b/DICUI.Library/Web/RedumpWebClient.cs index cee4a9b4..a4352fd6 100644 --- a/DICUI.Library/Web/RedumpWebClient.cs +++ b/DICUI.Library/Web/RedumpWebClient.cs @@ -19,17 +19,17 @@ namespace DICUI.Web /// /// Regex matching the added field on a disc page /// - private Regex addedRegex = new Regex(@"Added(.*?)"); + private readonly Regex addedRegex = new Regex(@"Added(.*?)"); /// /// Regex matching the barcode field on a disc page /// - private Regex barcodeRegex = new Regex(@"Barcode(.*?)"); + private readonly Regex barcodeRegex = new Regex(@"Barcode(.*?)"); /// /// Regex matching the BCA field on a disc page /// - private Regex bcaRegex = new Regex(@"

BCA .*?/>

" + private readonly Regex bcaRegex = new Regex(@"

BCA .*?/>

" + "RowContentsASCII" + "(?.*?)(?.*?)(?.*?)" + "(?.*?)(?.*?)(?.*?)" @@ -39,82 +39,82 @@ namespace DICUI.Web /// /// Regex matching the category field on a disc page /// - private Regex categoryRegex = new Regex(@"Category(.*?)"); + private readonly Regex categoryRegex = new Regex(@"Category(.*?)"); /// /// Regex matching the comments field on a disc page /// - private Regex commentsRegex = new Regex(@"Comments(.*?)"); + private readonly Regex commentsRegex = new Regex(@"Comments(.*?)"); /// /// Regex matching the contents field on a disc page /// - private Regex contentsRegex = new Regex(@"Contents(.*?)"); + private readonly Regex contentsRegex = new Regex(@"Contents(.*?)"); /// /// Regex matching individual disc links on a results page /// - private Regex discRegex = new Regex(@""); + private readonly Regex discRegex = new Regex(@""); /// /// Regex matching the disc number or letter field on a disc page /// - private Regex discNumberLetterRegex = new Regex(@"\((.*?)\)"); + private readonly Regex discNumberLetterRegex = new Regex(@"\((.*?)\)"); /// /// Regex matching the dumpers on a disc page /// - private Regex dumpersRegex = new Regex(@""); + private readonly Regex dumpersRegex = new Regex(@""); /// /// Regex matching the edition field on a disc page /// - private Regex editionRegex = new Regex(@"Edition(.*?)"); + private readonly Regex editionRegex = new Regex(@"Edition(.*?)"); /// /// Regex matching the error count field on a disc page /// - private Regex errorCountRegex = new Regex(@"Errors count(.*?)"); + private readonly Regex errorCountRegex = new Regex(@"Errors count(.*?)"); /// /// Regex matching the foreign title field on a disc page /// - private Regex foreignTitleRegex = new Regex(@"

(.*?)

"); + private readonly Regex foreignTitleRegex = new Regex(@"

(.*?)

"); /// /// Regex matching the "full match" ID list from a WIP disc page /// - private Regex fullMatchRegex = new Regex(@"full match ids: (.*?)"); + private readonly Regex fullMatchRegex = new Regex(@"full match ids: (.*?)"); /// /// Regex matching the languages field on a disc page /// - private Regex languagesRegex = new Regex(@"\s*"); + private readonly Regex languagesRegex = new Regex(@"\s*"); /// /// Regex matching the last modified field on a disc page /// - private Regex lastModifiedRegex = new Regex(@"Last modified(.*?)"); + private readonly Regex lastModifiedRegex = new Regex(@"Last modified(.*?)"); /// /// Regex matching the media field on a disc page /// - private Regex mediaRegex = new Regex(@"Media(.*?)"); + private readonly Regex mediaRegex = new Regex(@"Media(.*?)"); /// /// Regex matching individual WIP disc links on a results page /// - private Regex newDiscRegex = new Regex(@"
"); + private readonly Regex newDiscRegex = new Regex(@""); /// /// Regex matching the "partial match" ID list from a WIP disc page /// - private Regex partialMatchRegex = new Regex(@"partial match ids: (.*?)"); + private readonly Regex partialMatchRegex = new Regex(@"partial match ids: (.*?)"); /// /// Regex matching the PVD field on a disc page /// - private Regex pvdRegex = new Regex(@"

Primary Volume Descriptor (PVD)

" + private readonly Regex pvdRegex = new Regex(@"

Primary Volume Descriptor (PVD)

" + @"Record / EntryContentsDateTimeGMT" + @"Creation(?.*?)(?.*?)(?.*?)(?.*?)" + @"Modification(?.*?)(?.*?)(?.*?)(?.*?)" @@ -124,57 +124,57 @@ namespace DICUI.Web /// /// Regex matching the region field on a disc page /// - private Regex regionRegex = new Regex(@"Region
"); + private readonly Regex regionRegex = new Regex(@"Region"); /// /// Regex matching a double-layer disc ringcode information /// - private Regex ringCodeDoubleRegex = new Regex(@""); // Varies based on available fields, like Addtional Mould + private readonly Regex ringCodeDoubleRegex = new Regex(@""); // Varies based on available fields, like Addtional Mould /// /// Regex matching a single-layer disc ringcode information /// - private Regex ringCodeSingleRegex = new Regex(@""); // Varies based on available fields, like Addtional Mould + private readonly Regex ringCodeSingleRegex = new Regex(@""); // Varies based on available fields, like Addtional Mould /// /// Regex matching the serial field on a disc page /// - private Regex serialRegex = new Regex(@"Serial(.*?)"); + private readonly Regex serialRegex = new Regex(@"Serial(.*?)"); /// /// Regex matching the system field on a disc page /// - private Regex systemRegex = new Regex(@"System"); + private readonly Regex systemRegex = new Regex(@"System"); /// /// Regex matching the title field on a disc page /// - private Regex titleRegex = new Regex(@"

(.*?)

"); + private readonly Regex titleRegex = new Regex(@"

(.*?)

"); /// /// Regex matching the current nonce token for login /// - private Regex tokenRegex = new Regex(@""); + private readonly Regex tokenRegex = new Regex(@""); /// /// Regex matching a single track on a disc page /// - private Regex trackRegex = new Regex(@"(?.*?)(?.*?)(?.*?)(?.*?)(?.*?)(?.*?)(?.*?)(?.*?)(?.*?)"); + private readonly Regex trackRegex = new Regex(@"(?.*?)(?.*?)(?.*?)(?.*?)(?.*?)(?.*?)(?.*?)(?.*?)(?.*?)"); /// /// Regex matching the track count on a disc page /// - private Regex trackCountRegex = new Regex(@"Number of tracks(.*?)"); + private readonly Regex trackCountRegex = new Regex(@"Number of tracks(.*?)"); /// /// Regex matching the version field on a disc page /// - private Regex versionRegex = new Regex(@"Version(.*?)"); + private readonly Regex versionRegex = new Regex(@"Version(.*?)"); /// /// Regex matching the write offset field on a disc page /// - private Regex writeOffsetRegex = new Regex(@"Write offset(.*?)"); + private readonly Regex writeOffsetRegex = new Regex(@"Write offset(.*?)"); #endregion @@ -294,8 +294,7 @@ namespace DICUI.Web protected override WebRequest GetWebRequest(Uri address) { WebRequest request = base.GetWebRequest(address); - HttpWebRequest webRequest = request as HttpWebRequest; - if (webRequest != null) + if (request is HttpWebRequest webRequest) { webRequest.CookieContainer = m_container; } diff --git a/DICUI/ViewModels.cs b/DICUI/ViewModels.cs index b723ccfc..c214c6df 100644 --- a/DICUI/ViewModels.cs +++ b/DICUI/ViewModels.cs @@ -6,7 +6,7 @@ namespace DICUI { public class OptionsViewModel { - private UIOptions _uiOptions; + private readonly UIOptions _uiOptions; #region Internal Program diff --git a/DICUI/Windows/LogWindow.xaml.cs b/DICUI/Windows/LogWindow.xaml.cs index 240d0883..e70fcc5f 100644 --- a/DICUI/Windows/LogWindow.xaml.cs +++ b/DICUI/Windows/LogWindow.xaml.cs @@ -23,11 +23,11 @@ namespace DICUI.Windows [DllImport("user32.dll")] private static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong); - private MainWindow _mainWindow; + private readonly MainWindow _mainWindow; - private FlowDocument _document; - private Paragraph _paragraph; - private List _matchers; + private readonly FlowDocument _document; + private readonly Paragraph _paragraph; + private readonly List _matchers; volatile Process _process; @@ -370,9 +370,9 @@ namespace DICUI.Windows { foreach (var inline in _paragraph.Inlines) { - if (inline is Run) + if (inline is Run run) { - tw.Write(((Run)(inline)).Text); + tw.Write(run.Text); } } } diff --git a/DICUI/Windows/MainWindow.xaml.cs b/DICUI/Windows/MainWindow.xaml.cs index 668f9851..5262d904 100644 --- a/DICUI/Windows/MainWindow.xaml.cs +++ b/DICUI/Windows/MainWindow.xaml.cs @@ -64,7 +64,7 @@ namespace DICUI.Windows /// /// Current attached LogWindow /// - private LogWindow logWindow; + private readonly LogWindow logWindow; /// /// Currently attached OptionsWindow @@ -122,16 +122,15 @@ namespace DICUI.Windows private void CacheCurrentDiscType() { // Get the drive letter from the selected item - var drive = DriveLetterComboBox.SelectedItem as Drive; - if (drive == null) - return; - - // Get the current media type - if (!UIOptions.SkipMediaTypeDetection) + if (DriveLetterComboBox.SelectedItem is Drive drive) { - ViewModels.LoggerViewModel.VerboseLog("Trying to detect media type for drive {0}.. ", drive.Letter); - CurrentMediaType = Validators.GetMediaType(drive); - ViewModels.LoggerViewModel.VerboseLogLn(CurrentMediaType == null ? "unable to detect." : ("detected " + CurrentMediaType.LongName() + ".")); + // Get the current media type + if (!UIOptions.SkipMediaTypeDetection) + { + ViewModels.LoggerViewModel.VerboseLog("Trying to detect media type for drive {0}.. ", drive.Letter); + CurrentMediaType = Validators.GetMediaType(drive); + ViewModels.LoggerViewModel.VerboseLogLn(CurrentMediaType == null ? "unable to detect." : ("detected " + CurrentMediaType.LongName() + ".")); + } } }