More code analysis suppression

This commit is contained in:
Terry MacDonald 2021-01-28 22:20:00 +13:00
parent 88bd1a71fa
commit 0f38881709
10 changed files with 48 additions and 64 deletions

View File

@ -64,7 +64,6 @@ namespace DesktopNotifications
/// under Desktop Bridge. Call this upon application startup, before calling any other APIs. /// under Desktop Bridge. Call this upon application startup, before calling any other APIs.
/// </summary> /// </summary>
/// <param name="aumid">An AUMID that uniquely identifies your application.</param> /// <param name="aumid">An AUMID that uniquely identifies your application.</param>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1004:GenericMethodsShouldProvideTypeParameter")]
public static void RegisterAumidAndComServer<T>(string aumid) public static void RegisterAumidAndComServer<T>(string aumid)
where T : NotificationActivator 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. /// Registers the activator type as a COM server client so that Windows can launch your activator.
/// </summary> /// </summary>
/// <typeparam name="T">Your implementation of NotificationActivator. Must have GUID and ComVisible attributes on class.</typeparam> /// <typeparam name="T">Your implementation of NotificationActivator. Must have GUID and ComVisible attributes on class.</typeparam>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1004:GenericMethodsShouldProvideTypeParameter")]
public static void RegisterActivator<T>() public static void RegisterActivator<T>()
where T : NotificationActivator, new() 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 // 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; var uuid = typeof(T).GUID;
//uint _cookie; #pragma warning disable IDE0059 // Unnecessary assignment of a value
CoRegisterClassObject(uuid, new NotificationActivatorClassFactory<T>(), CLSCTX_LOCAL_SERVER, CoRegisterClassObject(uuid, new NotificationActivatorClassFactory<T>(), CLSCTX_LOCAL_SERVER,
REGCLS_MULTIPLEUSE, out uint _cookie); REGCLS_MULTIPLEUSE, out uint _cookie);
#pragma warning restore IDE0059 // Unnecessary assignment of a value
_registeredActivator = true; _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() private static void EnsureRegistered()
{ {
// If not registered AUMID yet // If not registered AUMID yet

View File

@ -136,7 +136,6 @@ namespace DisplayMagician.GameLibraries
} }
} }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")]
public bool CopyInto(SteamGame steamGame) public bool CopyInto(SteamGame steamGame)
{ {
if (!(steamGame is SteamGame)) if (!(steamGame is SteamGame))

View File

@ -224,8 +224,6 @@ namespace DisplayMagician.GameLibraries
} }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")]
public static bool ContainsSteamGame(SteamGame steamGame) public static bool ContainsSteamGame(SteamGame steamGame)
{ {
if (!(steamGame is SteamGame)) if (!(steamGame is SteamGame))

View File

@ -137,7 +137,6 @@ namespace DisplayMagician.GameLibraries
} }
}*/ }*/
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")]
public bool CopyTo(UplayGame uplayGame) public bool CopyTo(UplayGame uplayGame)
{ {
if (!(uplayGame is UplayGame)) if (!(uplayGame is UplayGame))

View File

@ -280,10 +280,10 @@ namespace DisplayMagician
[DllImport("user32")] [DllImport("user32")]
public static extern int DestroyIcon(IntPtr hIcon); public static extern int DestroyIcon(IntPtr hIcon);
public struct pair public struct Pair
{ {
public System.Drawing.Icon icon { get; set; } public System.Drawing.Icon Icon { get; set; }
public IntPtr iconHandleToDestroy { set; get; } public IntPtr IconHandleToDestroy { set; get; }
} }

View File

@ -1753,7 +1753,7 @@ namespace DisplayMagician
public void ReplaceShortcutIconInCache() public void ReplaceShortcutIconInCache()
{ {
string newShortcutIconFilename = ""; string newShortcutIconFilename;
if (_category == ShortcutCategory.Application) if (_category == ShortcutCategory.Application)
{ {
// Work out the name of the shortcut we'll save. // Work out the name of the shortcut we'll save.
@ -1852,8 +1852,6 @@ namespace DisplayMagician
return bm; 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) 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 programName = Path.GetFileNameWithoutExtension(ExecutableNameAndPath);
string shortcutDescription = string.Empty; string shortcutDescription = string.Empty;
string shortcutIconFileName = string.Empty; string shortcutIconFileName;
var shortcutArgs = new List<string> var shortcutArgs = new List<string>
{ {

View File

@ -322,7 +322,9 @@ namespace DisplayMagician
if (!string.IsNullOrWhiteSpace(json)) if (!string.IsNullOrWhiteSpace(json))
{ {
#pragma warning disable IDE0059 // Unnecessary assignment of a value
List<ShortcutItem> shortcuts = new List<ShortcutItem>(); List<ShortcutItem> shortcuts = new List<ShortcutItem>();
#pragma warning restore IDE0059 // Unnecessary assignment of a value
try try
{ {
_allShortcuts = JsonConvert.DeserializeObject<List<ShortcutItem>>(json, new JsonSerializerSettings _allShortcuts = JsonConvert.DeserializeObject<List<ShortcutItem>>(json, new JsonSerializerSettings

View File

@ -548,11 +548,11 @@ namespace DisplayMagician.UIForms
{ {
if (_loadedShortcut) if (_loadedShortcut)
_isUnsaved = true; _isUnsaved = true;
suggestShortcutName(); SuggestShortcutName();
enableSaveButtonIfValid(); EnableSaveButtonIfValid();
} }
private bool canEnableSaveButton() private bool CanEnableSaveButton()
{ {
if ((txt_shortcut_save_name.Text.Length > 0) && if ((txt_shortcut_save_name.Text.Length > 0) &&
_profileToUse is ProfileItem && _profileToUse is ProfileItem &&
@ -564,16 +564,16 @@ namespace DisplayMagician.UIForms
return false; return false;
} }
private void enableSaveButtonIfValid() private void EnableSaveButtonIfValid()
{ {
if (canEnableSaveButton()) if (CanEnableSaveButton())
btn_save.Enabled = true; btn_save.Enabled = true;
else else
btn_save.Enabled = false; btn_save.Enabled = false;
} }
private void suggestShortcutName() private void SuggestShortcutName()
{ {
if (_autoName && _profileToUse is ProfileItem) if (_autoName && _profileToUse is ProfileItem)
{ {
@ -1047,7 +1047,7 @@ namespace DisplayMagician.UIForms
_isUnsaved = false; _isUnsaved = false;
// Finally enable the save button if it's still valid // Finally enable the save button if it's still valid
enableSaveButtonIfValid(); EnableSaveButtonIfValid();
} }
@ -1065,8 +1065,8 @@ namespace DisplayMagician.UIForms
// Disable the Game Panel // Disable the Game Panel
p_game.Enabled = false; p_game.Enabled = false;
suggestShortcutName(); SuggestShortcutName();
enableSaveButtonIfValid(); EnableSaveButtonIfValid();
} }
} }
@ -1085,8 +1085,8 @@ namespace DisplayMagician.UIForms
// Disable the Standalone Panel // Disable the Standalone Panel
p_standalone.Enabled = false; p_standalone.Enabled = false;
suggestShortcutName(); SuggestShortcutName();
enableSaveButtonIfValid(); EnableSaveButtonIfValid();
} }
} }
@ -1105,8 +1105,8 @@ namespace DisplayMagician.UIForms
// Disable the Game Panel // Disable the Game Panel
p_game.Enabled = false; p_game.Enabled = false;
suggestShortcutName(); SuggestShortcutName();
enableSaveButtonIfValid(); EnableSaveButtonIfValid();
} }
} }
@ -1208,8 +1208,8 @@ namespace DisplayMagician.UIForms
} }
} }
suggestShortcutName(); SuggestShortcutName();
enableSaveButtonIfValid(); EnableSaveButtonIfValid();
} }
@ -1224,8 +1224,8 @@ namespace DisplayMagician.UIForms
} }
} }
suggestShortcutName(); SuggestShortcutName();
enableSaveButtonIfValid(); EnableSaveButtonIfValid();
} }
@ -1286,7 +1286,7 @@ namespace DisplayMagician.UIForms
ilv_saved_profiles.ResumeLayout(); ilv_saved_profiles.ResumeLayout();
} }
enableSaveButtonIfValid(); EnableSaveButtonIfValid();
} }
private void btn_back_Click(object sender, EventArgs e) private void btn_back_Click(object sender, EventArgs e)
@ -1361,7 +1361,7 @@ namespace DisplayMagician.UIForms
_isUnsaved = true; _isUnsaved = true;
rb_switch_display_permanent.Checked = false; rb_switch_display_permanent.Checked = false;
suggestShortcutName(); SuggestShortcutName();
} }
} }
@ -1372,7 +1372,7 @@ namespace DisplayMagician.UIForms
if (_loadedShortcut) if (_loadedShortcut)
_isUnsaved = true; _isUnsaved = true;
rb_switch_display_temp.Checked = false; rb_switch_display_temp.Checked = false;
suggestShortcutName(); SuggestShortcutName();
} }
} }
@ -1380,7 +1380,7 @@ namespace DisplayMagician.UIForms
{ {
if (_loadedShortcut) if (_loadedShortcut)
_isUnsaved = true; _isUnsaved = true;
enableSaveButtonIfValid(); EnableSaveButtonIfValid();
} }
private void ShortcutForm_FormClosing(object sender, FormClosingEventArgs e) 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) 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) private void txt_shortcut_save_name_Click(object sender, EventArgs e)
@ -1424,13 +1424,13 @@ namespace DisplayMagician.UIForms
if (cb_autosuggest.Checked) if (cb_autosuggest.Checked)
{ {
_autoName = true; _autoName = true;
suggestShortcutName(); SuggestShortcutName();
} }
else else
_autoName = false; _autoName = false;
} }
private string get_exe_file() private string getExeFile()
{ {
string textToReturn = ""; string textToReturn = "";
if (dialog_open.ShowDialog(this) == DialogResult.OK) if (dialog_open.ShowDialog(this) == DialogResult.OK)
@ -1453,22 +1453,22 @@ namespace DisplayMagician.UIForms
} }
private void btn_start_program1_Click(object sender, EventArgs e) 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) 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) 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) 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) private void cb_start_program1_CheckedChanged(object sender, EventArgs e)

View File

@ -30,7 +30,7 @@ namespace DisplayMagicianShared
//private static List<WindowsDisplayAPI.UnAttachedDisplay> _unavailableDisplays; //private static List<WindowsDisplayAPI.UnAttachedDisplay> _unavailableDisplays;
internal static string AppDataPath = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "DisplayMagician"); 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 string _uuid = "";
//private Version _version; //private Version _version;
@ -380,16 +380,6 @@ namespace DisplayMagicianShared
return (Name ?? Language.UN_TITLED_PROFILE); 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) public int CompareTo(object obj)
{ {
if (!(obj is ProfileItem)) throw new ArgumentException("Object to CompareTo is not a Shortcut"); ; if (!(obj is ProfileItem)) throw new ArgumentException("Object to CompareTo is not a Shortcut"); ;

View File

@ -29,8 +29,8 @@ namespace DisplayMagicianShared
public static string AppDataPath = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "DisplayMagician"); 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 AppIconPath = System.IO.Path.Combine(AppDataPath, $"Icons");
public static string AppDisplayMagicianIconFilename = System.IO.Path.Combine(AppIconPath, @"DisplayMagician.ico"); public static string AppDisplayMagicianIconFilename = System.IO.Path.Combine(AppIconPath, @"DisplayMagician.ico");
private static string AppProfileStoragePath = System.IO.Path.Combine(AppDataPath, $"Profiles"); private static readonly 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 _profileStorageJsonFileName = System.IO.Path.Combine(AppProfileStoragePath, $"DisplayProfiles_{_version.ToString(2)}.json");
#endregion #endregion
@ -614,10 +614,10 @@ namespace DisplayMagicianShared
Debug.WriteLine($"ADCSF : {attachedDisplay.CurrentSetting.Frequency}"); Debug.WriteLine($"ADCSF : {attachedDisplay.CurrentSetting.Frequency}");
Debug.WriteLine($"ADCSIE : {attachedDisplay.CurrentSetting.IsEnable}"); Debug.WriteLine($"ADCSIE : {attachedDisplay.CurrentSetting.IsEnable}");
Debug.WriteLine($"ADCSII : {attachedDisplay.CurrentSetting.IsInterlaced}"); Debug.WriteLine($"ADCSII : {attachedDisplay.CurrentSetting.IsInterlaced}");
Debug.WriteLine($"ADCSO : {attachedDisplay.CurrentSetting.Orientation.ToString()}"); Debug.WriteLine($"ADCSO : {attachedDisplay.CurrentSetting.Orientation}");
Debug.WriteLine($"ADCSOSM : {attachedDisplay.CurrentSetting.OutputScalingMode.ToString()}"); Debug.WriteLine($"ADCSOSM : {attachedDisplay.CurrentSetting.OutputScalingMode}");
Debug.WriteLine($"ADCSP : {attachedDisplay.CurrentSetting.Position.ToString()}"); Debug.WriteLine($"ADCSP : {attachedDisplay.CurrentSetting.Position}");
Debug.WriteLine($"ADCSR : {attachedDisplay.CurrentSetting.Resolution.ToString()}"); Debug.WriteLine($"ADCSR : {attachedDisplay.CurrentSetting.Resolution}");
Debug.WriteLine($"DP : {displayAdapter.DevicePath}"); Debug.WriteLine($"DP : {displayAdapter.DevicePath}");
Debug.WriteLine($"DK : {displayAdapter.DeviceKey}"); Debug.WriteLine($"DK : {displayAdapter.DeviceKey}");
Debug.WriteLine($"DN : {displayAdapter.DeviceName}"); Debug.WriteLine($"DN : {displayAdapter.DeviceName}");
@ -749,10 +749,10 @@ namespace DisplayMagicianShared
Debug.WriteLine($"ADCSF : {attachedDisplay.CurrentSetting.Frequency}"); Debug.WriteLine($"ADCSF : {attachedDisplay.CurrentSetting.Frequency}");
Debug.WriteLine($"ADCSIE : {attachedDisplay.CurrentSetting.IsEnable}"); Debug.WriteLine($"ADCSIE : {attachedDisplay.CurrentSetting.IsEnable}");
Debug.WriteLine($"ADCSII : {attachedDisplay.CurrentSetting.IsInterlaced}"); Debug.WriteLine($"ADCSII : {attachedDisplay.CurrentSetting.IsInterlaced}");
Debug.WriteLine($"ADCSO : {attachedDisplay.CurrentSetting.Orientation.ToString()}"); Debug.WriteLine($"ADCSO : {attachedDisplay.CurrentSetting.Orientation}");
Debug.WriteLine($"ADCSOSM : {attachedDisplay.CurrentSetting.OutputScalingMode.ToString()}"); Debug.WriteLine($"ADCSOSM : {attachedDisplay.CurrentSetting.OutputScalingMode}");
Debug.WriteLine($"ADCSP : {attachedDisplay.CurrentSetting.Position.ToString()}"); Debug.WriteLine($"ADCSP : {attachedDisplay.CurrentSetting.Position}");
Debug.WriteLine($"ADCSR : {attachedDisplay.CurrentSetting.Resolution.ToString()}"); Debug.WriteLine($"ADCSR : {attachedDisplay.CurrentSetting.Resolution}");
Debug.WriteLine($"DP : {displayAdapter.DevicePath}"); Debug.WriteLine($"DP : {displayAdapter.DevicePath}");
Debug.WriteLine($"DK : {displayAdapter.DeviceKey}"); Debug.WriteLine($"DK : {displayAdapter.DeviceKey}");
Debug.WriteLine($"DN : {displayAdapter.DeviceName}"); Debug.WriteLine($"DN : {displayAdapter.DeviceName}");