[fxcop] Wox.Infrastructure (#7590)

* CA1052: Static holder types should be Static or NotInheritable

* CA1041: Provide ObsoleteAttribute message

* CA1062: Validate arguments of public methods

* CA1304: Specify CultureInfo / CA1305: Specify IFormatProvider / CA1307: Specify StringComparison for clarity

* CA1802: Use Literals Where Appropriate

* CA1820: Test for empty strings using string length

* CA1707: Identifiers should not contain underscores

* CA1805: Do not initialize unnecessarily.

* CA1822: Mark members as static

* CA2227: Collection properties should be read only

* CA1054: URI parameters should not be strings

* CA1031: Do not catch general exception types

* CA1060: Move P/Invokes to NativeMethods class

* CA1308: Normalize strings to uppercase

* CA2000: Dispose objects before losing scope / CA2234: Pass System.Uri objects instead of strings

* CA2234: Pass System.Uri objects instead of strings

* CA1044: Properties should not be write only

* CA1716: Identifiers should not match keywords

* CA2007: Do not directly await a Task

* CA2007: Do not directly await a Task (Suppressed)

* CA5350: Do Not Use Weak Cryptographic Algorithms (Suppressed)

* CA1724: Type names should not match namespaces (renamed Settings.cs to PowerToysRunSettings.cs)

* CA1033: Interface methods should be callable by child types (Added sealed modifier to class)

* CA1724: Type names should not match namespaces (Renamed Plugin.cs to RunPlugin.cs)

* CA1724: Type names should not match namespaces (Renamed Http.cs to HttpClient.cs)

* CA5364: Do not use deprecated security protocols (Remove unused code)

* Enabled FxCopAnalyzer for Wox.Infrastructure

* fixed comment

* Addressed comments

- Changed Ordinal to InvariantCulture
- Added comments
- Removed unused obsolete code
- Removed unused method (CA2007: Do not directly await a Task)

* Addressed comments - fixed justification for CA1031 suppression

* Addressed comments - Fixed justification for CA1031 suppression in Wox.Core/Wox.Plugin
This commit is contained in:
Avneet Kaur
2020-10-29 17:52:35 -07:00
committed by GitHub
parent 5015642b6d
commit ec8ead8183
41 changed files with 293 additions and 227 deletions

View File

@@ -6,13 +6,15 @@ using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Text;
using Microsoft.Win32;
using Wox.Plugin;
using Wox.Plugin.Logger;
namespace Wox.Infrastructure.Exception
{
public class ExceptionFormatter
public static class ExceptionFormatter
{
public static string FormatException(System.Exception exception)
{
@@ -110,6 +112,7 @@ namespace Wox.Infrastructure.Exception
}
// http://msdn.microsoft.com/en-us/library/hh925568%28v=vs.110%29.aspx
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "Suppressing this to enable FxCop. We are logging the exception, and going forward general exceptions should not be caught")]
private static List<string> GetFrameworkVersionFromRegistry()
{
try
@@ -119,25 +122,28 @@ namespace Wox.Infrastructure.Exception
{
foreach (string versionKeyName in ndpKey.GetSubKeyNames())
{
if (versionKeyName.StartsWith("v"))
// Using InvariantCulture since this is internal and involves version key
if (versionKeyName.StartsWith("v", StringComparison.InvariantCulture))
{
RegistryKey versionKey = ndpKey.OpenSubKey(versionKeyName);
string name = (string)versionKey.GetValue("Version", string.Empty);
string sp = versionKey.GetValue("SP", string.Empty).ToString();
string install = versionKey.GetValue("Install", string.Empty).ToString();
if (install != string.Empty)
if (!string.IsNullOrEmpty(install))
{
if (sp != string.Empty && install == "1")
if (!string.IsNullOrEmpty(sp) && install == "1")
{
result.Add(string.Format("{0} {1} SP{2}", versionKeyName, name, sp));
// Using InvariantCulture since this is internal
result.Add(string.Format(CultureInfo.InvariantCulture, "{0} {1} SP{2}", versionKeyName, name, sp));
}
else
{
result.Add(string.Format("{0} {1}", versionKeyName, name));
// Using InvariantCulture since this is internal
result.Add(string.Format(CultureInfo.InvariantCulture, "{0} {1}", versionKeyName, name));
}
}
if (name != string.Empty)
if (!string.IsNullOrEmpty(name))
{
continue;
}
@@ -146,21 +152,23 @@ namespace Wox.Infrastructure.Exception
{
RegistryKey subKey = versionKey.OpenSubKey(subKeyName);
name = (string)subKey.GetValue("Version", string.Empty);
if (name != string.Empty)
if (!string.IsNullOrEmpty(name))
{
sp = subKey.GetValue("SP", string.Empty).ToString();
}
install = subKey.GetValue("Install", string.Empty).ToString();
if (install != string.Empty)
if (!string.IsNullOrEmpty(install))
{
if (sp != string.Empty && install == "1")
if (!string.IsNullOrEmpty(sp) && install == "1")
{
result.Add(string.Format("{0} {1} {2} SP{3}", versionKeyName, subKeyName, name, sp));
// Using InvariantCulture since this is internal
result.Add(string.Format(CultureInfo.InvariantCulture, "{0} {1} {2} SP{3}", versionKeyName, subKeyName, name, sp));
}
else if (install == "1")
{
result.Add(string.Format("{0} {1} {2}", versionKeyName, subKeyName, name));
// Using InvariantCulture since this is internal
result.Add(string.Format(CultureInfo.InvariantCulture, "{0} {1} {2}", versionKeyName, subKeyName, name));
}
}
}
@@ -191,8 +199,9 @@ namespace Wox.Infrastructure.Exception
return result;
}
catch (System.Exception)
catch (System.Exception e)
{
Log.Exception("Could not get framework version from registry", e, MethodBase.GetCurrentMethod().DeclaringType);
return new List<string>();
}
}