From 0f38881709ad5d677b5e9dfbdf9e426f70134d9a Mon Sep 17 00:00:00 2001 From: Terry MacDonald Date: Thu, 28 Jan 2021 22:20:00 +1300 Subject: [PATCH] More code analysis suppression --- .../DesktopNotificationManagerCompat.cs | 6 +- DisplayMagician/GameLibraries/SteamGame.cs | 1 - DisplayMagician/GameLibraries/SteamLibrary.cs | 2 - DisplayMagician/GameLibraries/UplayGame.cs | 1 - DisplayMagician/IconFromFile.cs | 6 +- DisplayMagician/ShortcutItem.cs | 6 +- DisplayMagician/ShortcutRepository.cs | 2 + DisplayMagician/UIForms/ShortcutForm.cs | 56 +++++++++---------- DisplayMagicianShared/ProfileItem.cs | 12 +--- DisplayMagicianShared/ProfileRepository.cs | 20 +++---- 10 files changed, 48 insertions(+), 64 deletions(-) diff --git a/DisplayMagician/DesktopNotificationManagerCompat.cs b/DisplayMagician/DesktopNotificationManagerCompat.cs index 393e71c..e0a5d65 100644 --- a/DisplayMagician/DesktopNotificationManagerCompat.cs +++ b/DisplayMagician/DesktopNotificationManagerCompat.cs @@ -64,7 +64,6 @@ namespace DesktopNotifications /// under Desktop Bridge. Call this upon application startup, before calling any other APIs. /// /// An AUMID that uniquely identifies your application. - [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1004:GenericMethodsShouldProvideTypeParameter")] public static void RegisterAumidAndComServer(string aumid) where T : NotificationActivator { @@ -128,15 +127,15 @@ namespace DesktopNotifications /// Registers the activator type as a COM server client so that Windows can launch your activator. /// /// Your implementation of NotificationActivator. Must have GUID and ComVisible attributes on class. - [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1004:GenericMethodsShouldProvideTypeParameter")] public static void RegisterActivator() where T : NotificationActivator, new() { // Big thanks to FrecherxDachs for figuring out the following code which works in .NET Core 3: https://github.com/FrecherxDachs/UwpNotificationNetCoreTest var uuid = typeof(T).GUID; - //uint _cookie; +#pragma warning disable IDE0059 // Unnecessary assignment of a value CoRegisterClassObject(uuid, new NotificationActivatorClassFactory(), CLSCTX_LOCAL_SERVER, REGCLS_MULTIPLEUSE, out uint _cookie); +#pragma warning restore IDE0059 // Unnecessary assignment of a value _registeredActivator = true; } @@ -229,7 +228,6 @@ namespace DesktopNotifications } } - [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA2204:Literals should be spelled correctly", MessageId = "RegisterAumidAndComServer")] private static void EnsureRegistered() { // If not registered AUMID yet diff --git a/DisplayMagician/GameLibraries/SteamGame.cs b/DisplayMagician/GameLibraries/SteamGame.cs index 760f8fc..0ab3d7a 100644 --- a/DisplayMagician/GameLibraries/SteamGame.cs +++ b/DisplayMagician/GameLibraries/SteamGame.cs @@ -136,7 +136,6 @@ namespace DisplayMagician.GameLibraries } } - [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")] public bool CopyInto(SteamGame steamGame) { if (!(steamGame is SteamGame)) diff --git a/DisplayMagician/GameLibraries/SteamLibrary.cs b/DisplayMagician/GameLibraries/SteamLibrary.cs index e290476..20ac4b8 100644 --- a/DisplayMagician/GameLibraries/SteamLibrary.cs +++ b/DisplayMagician/GameLibraries/SteamLibrary.cs @@ -224,8 +224,6 @@ namespace DisplayMagician.GameLibraries } - - [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")] public static bool ContainsSteamGame(SteamGame steamGame) { if (!(steamGame is SteamGame)) diff --git a/DisplayMagician/GameLibraries/UplayGame.cs b/DisplayMagician/GameLibraries/UplayGame.cs index 31d11d2..b546e39 100644 --- a/DisplayMagician/GameLibraries/UplayGame.cs +++ b/DisplayMagician/GameLibraries/UplayGame.cs @@ -137,7 +137,6 @@ namespace DisplayMagician.GameLibraries } }*/ - [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")] public bool CopyTo(UplayGame uplayGame) { if (!(uplayGame is UplayGame)) diff --git a/DisplayMagician/IconFromFile.cs b/DisplayMagician/IconFromFile.cs index 4f7f271..d11bb0d 100644 --- a/DisplayMagician/IconFromFile.cs +++ b/DisplayMagician/IconFromFile.cs @@ -280,10 +280,10 @@ namespace DisplayMagician [DllImport("user32")] public static extern int DestroyIcon(IntPtr hIcon); - public struct pair + public struct Pair { - public System.Drawing.Icon icon { get; set; } - public IntPtr iconHandleToDestroy { set; get; } + public System.Drawing.Icon Icon { get; set; } + public IntPtr IconHandleToDestroy { set; get; } } diff --git a/DisplayMagician/ShortcutItem.cs b/DisplayMagician/ShortcutItem.cs index 8af36a8..a055a98 100644 --- a/DisplayMagician/ShortcutItem.cs +++ b/DisplayMagician/ShortcutItem.cs @@ -1753,7 +1753,7 @@ namespace DisplayMagician public void ReplaceShortcutIconInCache() { - string newShortcutIconFilename = ""; + string newShortcutIconFilename; if (_category == ShortcutCategory.Application) { // Work out the name of the shortcut we'll save. @@ -1852,8 +1852,6 @@ namespace DisplayMagician return bm; } - - [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")] public Bitmap ToBitmapOverlay(Bitmap originalBitmap, Bitmap overlayBitmap, int width, int height, PixelFormat format = PixelFormat.Format32bppArgb) { @@ -2040,7 +2038,7 @@ namespace DisplayMagician { string programName = Path.GetFileNameWithoutExtension(ExecutableNameAndPath); string shortcutDescription = string.Empty; - string shortcutIconFileName = string.Empty; + string shortcutIconFileName; var shortcutArgs = new List { diff --git a/DisplayMagician/ShortcutRepository.cs b/DisplayMagician/ShortcutRepository.cs index 46d6ea2..35558ac 100644 --- a/DisplayMagician/ShortcutRepository.cs +++ b/DisplayMagician/ShortcutRepository.cs @@ -322,7 +322,9 @@ namespace DisplayMagician if (!string.IsNullOrWhiteSpace(json)) { +#pragma warning disable IDE0059 // Unnecessary assignment of a value List shortcuts = new List(); +#pragma warning restore IDE0059 // Unnecessary assignment of a value try { _allShortcuts = JsonConvert.DeserializeObject>(json, new JsonSerializerSettings diff --git a/DisplayMagician/UIForms/ShortcutForm.cs b/DisplayMagician/UIForms/ShortcutForm.cs index 585e056..0d26374 100644 --- a/DisplayMagician/UIForms/ShortcutForm.cs +++ b/DisplayMagician/UIForms/ShortcutForm.cs @@ -548,11 +548,11 @@ namespace DisplayMagician.UIForms { if (_loadedShortcut) _isUnsaved = true; - suggestShortcutName(); - enableSaveButtonIfValid(); + SuggestShortcutName(); + EnableSaveButtonIfValid(); } - private bool canEnableSaveButton() + private bool CanEnableSaveButton() { if ((txt_shortcut_save_name.Text.Length > 0) && _profileToUse is ProfileItem && @@ -564,16 +564,16 @@ namespace DisplayMagician.UIForms return false; } - private void enableSaveButtonIfValid() + private void EnableSaveButtonIfValid() { - if (canEnableSaveButton()) + if (CanEnableSaveButton()) btn_save.Enabled = true; else btn_save.Enabled = false; } - private void suggestShortcutName() + private void SuggestShortcutName() { if (_autoName && _profileToUse is ProfileItem) { @@ -1047,7 +1047,7 @@ namespace DisplayMagician.UIForms _isUnsaved = false; // Finally enable the save button if it's still valid - enableSaveButtonIfValid(); + EnableSaveButtonIfValid(); } @@ -1065,8 +1065,8 @@ namespace DisplayMagician.UIForms // Disable the Game Panel p_game.Enabled = false; - suggestShortcutName(); - enableSaveButtonIfValid(); + SuggestShortcutName(); + EnableSaveButtonIfValid(); } } @@ -1085,8 +1085,8 @@ namespace DisplayMagician.UIForms // Disable the Standalone Panel p_standalone.Enabled = false; - suggestShortcutName(); - enableSaveButtonIfValid(); + SuggestShortcutName(); + EnableSaveButtonIfValid(); } } @@ -1105,8 +1105,8 @@ namespace DisplayMagician.UIForms // Disable the Game Panel p_game.Enabled = false; - suggestShortcutName(); - enableSaveButtonIfValid(); + SuggestShortcutName(); + EnableSaveButtonIfValid(); } } @@ -1208,8 +1208,8 @@ namespace DisplayMagician.UIForms } } - suggestShortcutName(); - enableSaveButtonIfValid(); + SuggestShortcutName(); + EnableSaveButtonIfValid(); } @@ -1224,8 +1224,8 @@ namespace DisplayMagician.UIForms } } - suggestShortcutName(); - enableSaveButtonIfValid(); + SuggestShortcutName(); + EnableSaveButtonIfValid(); } @@ -1286,7 +1286,7 @@ namespace DisplayMagician.UIForms ilv_saved_profiles.ResumeLayout(); } - enableSaveButtonIfValid(); + EnableSaveButtonIfValid(); } private void btn_back_Click(object sender, EventArgs e) @@ -1361,7 +1361,7 @@ namespace DisplayMagician.UIForms _isUnsaved = true; rb_switch_display_permanent.Checked = false; - suggestShortcutName(); + SuggestShortcutName(); } } @@ -1372,7 +1372,7 @@ namespace DisplayMagician.UIForms if (_loadedShortcut) _isUnsaved = true; rb_switch_display_temp.Checked = false; - suggestShortcutName(); + SuggestShortcutName(); } } @@ -1380,7 +1380,7 @@ namespace DisplayMagician.UIForms { if (_loadedShortcut) _isUnsaved = true; - enableSaveButtonIfValid(); + EnableSaveButtonIfValid(); } private void ShortcutForm_FormClosing(object sender, FormClosingEventArgs e) @@ -1406,7 +1406,7 @@ namespace DisplayMagician.UIForms private void btn_exe_to_start_Click(object sender, EventArgs e) { - txt_executable.Text = get_exe_file(); + txt_executable.Text = getExeFile(); } private void txt_shortcut_save_name_Click(object sender, EventArgs e) @@ -1424,13 +1424,13 @@ namespace DisplayMagician.UIForms if (cb_autosuggest.Checked) { _autoName = true; - suggestShortcutName(); + SuggestShortcutName(); } else _autoName = false; } - private string get_exe_file() + private string getExeFile() { string textToReturn = ""; if (dialog_open.ShowDialog(this) == DialogResult.OK) @@ -1453,22 +1453,22 @@ namespace DisplayMagician.UIForms } private void btn_start_program1_Click(object sender, EventArgs e) { - txt_start_program1.Text = get_exe_file(); + txt_start_program1.Text = getExeFile(); } private void btn_start_program2_Click(object sender, EventArgs e) { - txt_start_program2.Text = get_exe_file(); + txt_start_program2.Text = getExeFile(); } private void btn_start_program3_Click(object sender, EventArgs e) { - txt_start_program3.Text = get_exe_file(); + txt_start_program3.Text = getExeFile(); } private void btn_start_program4_Click(object sender, EventArgs e) { - txt_start_program4.Text = get_exe_file(); + txt_start_program4.Text = getExeFile(); } private void cb_start_program1_CheckedChanged(object sender, EventArgs e) diff --git a/DisplayMagicianShared/ProfileItem.cs b/DisplayMagicianShared/ProfileItem.cs index 405bf23..6f6c0c4 100644 --- a/DisplayMagicianShared/ProfileItem.cs +++ b/DisplayMagicianShared/ProfileItem.cs @@ -30,7 +30,7 @@ namespace DisplayMagicianShared //private static List _unavailableDisplays; internal static string AppDataPath = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "DisplayMagician"); - private static string uuidV4Regex = @"(?im)^[{(]?[0-9A-F]{8}[-]?(?:[0-9A-F]{4}[-]?){3}[0-9A-F]{12}[)}]?$"; + private static readonly string uuidV4Regex = @"(?im)^[{(]?[0-9A-F]{8}[-]?(?:[0-9A-F]{4}[-]?){3}[0-9A-F]{12}[)}]?$"; private string _uuid = ""; //private Version _version; @@ -380,16 +380,6 @@ namespace DisplayMagicianShared return (Name ?? Language.UN_TITLED_PROFILE); } - private static string GetValidFilename(string uncheckedFilename) - { - string invalid = new string(System.IO.Path.GetInvalidFileNameChars()) + new string(System.IO.Path.GetInvalidPathChars()); - foreach (char c in invalid) - { - uncheckedFilename = uncheckedFilename.Replace(c.ToString(), ""); - } - return uncheckedFilename; - } - public int CompareTo(object obj) { if (!(obj is ProfileItem)) throw new ArgumentException("Object to CompareTo is not a Shortcut"); ; diff --git a/DisplayMagicianShared/ProfileRepository.cs b/DisplayMagicianShared/ProfileRepository.cs index 5ce3ae8..72702bb 100644 --- a/DisplayMagicianShared/ProfileRepository.cs +++ b/DisplayMagicianShared/ProfileRepository.cs @@ -29,8 +29,8 @@ namespace DisplayMagicianShared public static string AppDataPath = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "DisplayMagician"); public static string AppIconPath = System.IO.Path.Combine(AppDataPath, $"Icons"); public static string AppDisplayMagicianIconFilename = System.IO.Path.Combine(AppIconPath, @"DisplayMagician.ico"); - private static string AppProfileStoragePath = System.IO.Path.Combine(AppDataPath, $"Profiles"); - private static string _profileStorageJsonFileName = System.IO.Path.Combine(AppProfileStoragePath, $"DisplayProfiles_{_version.ToString(2)}.json"); + private static readonly string AppProfileStoragePath = System.IO.Path.Combine(AppDataPath, $"Profiles"); + private static readonly string _profileStorageJsonFileName = System.IO.Path.Combine(AppProfileStoragePath, $"DisplayProfiles_{_version.ToString(2)}.json"); #endregion @@ -614,10 +614,10 @@ namespace DisplayMagicianShared Debug.WriteLine($"ADCSF : {attachedDisplay.CurrentSetting.Frequency}"); Debug.WriteLine($"ADCSIE : {attachedDisplay.CurrentSetting.IsEnable}"); Debug.WriteLine($"ADCSII : {attachedDisplay.CurrentSetting.IsInterlaced}"); - Debug.WriteLine($"ADCSO : {attachedDisplay.CurrentSetting.Orientation.ToString()}"); - Debug.WriteLine($"ADCSOSM : {attachedDisplay.CurrentSetting.OutputScalingMode.ToString()}"); - Debug.WriteLine($"ADCSP : {attachedDisplay.CurrentSetting.Position.ToString()}"); - Debug.WriteLine($"ADCSR : {attachedDisplay.CurrentSetting.Resolution.ToString()}"); + Debug.WriteLine($"ADCSO : {attachedDisplay.CurrentSetting.Orientation}"); + Debug.WriteLine($"ADCSOSM : {attachedDisplay.CurrentSetting.OutputScalingMode}"); + Debug.WriteLine($"ADCSP : {attachedDisplay.CurrentSetting.Position}"); + Debug.WriteLine($"ADCSR : {attachedDisplay.CurrentSetting.Resolution}"); Debug.WriteLine($"DP : {displayAdapter.DevicePath}"); Debug.WriteLine($"DK : {displayAdapter.DeviceKey}"); Debug.WriteLine($"DN : {displayAdapter.DeviceName}"); @@ -749,10 +749,10 @@ namespace DisplayMagicianShared Debug.WriteLine($"ADCSF : {attachedDisplay.CurrentSetting.Frequency}"); Debug.WriteLine($"ADCSIE : {attachedDisplay.CurrentSetting.IsEnable}"); Debug.WriteLine($"ADCSII : {attachedDisplay.CurrentSetting.IsInterlaced}"); - Debug.WriteLine($"ADCSO : {attachedDisplay.CurrentSetting.Orientation.ToString()}"); - Debug.WriteLine($"ADCSOSM : {attachedDisplay.CurrentSetting.OutputScalingMode.ToString()}"); - Debug.WriteLine($"ADCSP : {attachedDisplay.CurrentSetting.Position.ToString()}"); - Debug.WriteLine($"ADCSR : {attachedDisplay.CurrentSetting.Resolution.ToString()}"); + Debug.WriteLine($"ADCSO : {attachedDisplay.CurrentSetting.Orientation}"); + Debug.WriteLine($"ADCSOSM : {attachedDisplay.CurrentSetting.OutputScalingMode}"); + Debug.WriteLine($"ADCSP : {attachedDisplay.CurrentSetting.Position}"); + Debug.WriteLine($"ADCSR : {attachedDisplay.CurrentSetting.Resolution}"); Debug.WriteLine($"DP : {displayAdapter.DevicePath}"); Debug.WriteLine($"DK : {displayAdapter.DeviceKey}"); Debug.WriteLine($"DN : {displayAdapter.DeviceName}");