mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-08 04:07:40 +02:00
[Wox.Infrastructure] Enable analyzer and fix warnings (#16996)
This commit is contained in:
committed by
GitHub
parent
7365ba14d0
commit
561882c2f1
@@ -28,7 +28,7 @@ namespace Wox.Infrastructure
|
|||||||
{
|
{
|
||||||
if (obj == null)
|
if (obj == null)
|
||||||
{
|
{
|
||||||
throw new NullReferenceException();
|
throw new ArgumentNullException(nameof(obj));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -40,7 +40,7 @@ namespace Wox.Infrastructure
|
|||||||
{
|
{
|
||||||
if (obj == null)
|
if (obj == null)
|
||||||
{
|
{
|
||||||
throw new NullReferenceException();
|
throw new ArgumentNullException(nameof(obj));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,9 +16,9 @@ namespace Wox.Infrastructure.Image
|
|||||||
{
|
{
|
||||||
[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")]
|
[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")]
|
||||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Security", "CA5350:Do Not Use Weak Cryptographic Algorithms", Justification = "Level of protection needed for the image data does not require a security guarantee")]
|
[System.Diagnostics.CodeAnalysis.SuppressMessage("Security", "CA5350:Do Not Use Weak Cryptographic Algorithms", Justification = "Level of protection needed for the image data does not require a security guarantee")]
|
||||||
public string GetHashFromImage(ImageSource imageSource)
|
public string GetHashFromImage(ImageSource image)
|
||||||
{
|
{
|
||||||
if (!(imageSource is BitmapSource image))
|
if (!(image is BitmapSource bitmapSource))
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -30,7 +30,7 @@ namespace Wox.Infrastructure.Image
|
|||||||
// PngBitmapEncoder enc2 = new PngBitmapEncoder();
|
// PngBitmapEncoder enc2 = new PngBitmapEncoder();
|
||||||
// enc2.Frames.Add(BitmapFrame.Create(tt));
|
// enc2.Frames.Add(BitmapFrame.Create(tt));
|
||||||
var enc = new JpegBitmapEncoder();
|
var enc = new JpegBitmapEncoder();
|
||||||
var bitmapFrame = BitmapFrame.Create(image);
|
var bitmapFrame = BitmapFrame.Create(bitmapSource);
|
||||||
bitmapFrame.Freeze();
|
bitmapFrame.Freeze();
|
||||||
enc.Frames.Add(bitmapFrame);
|
enc.Frames.Add(bitmapFrame);
|
||||||
enc.Save(outStream);
|
enc.Save(outStream);
|
||||||
|
|||||||
@@ -123,7 +123,7 @@ namespace Wox.Infrastructure.Image
|
|||||||
return hBitmap;
|
return hBitmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new COMException($"Error while extracting thumbnail for {fileName}", Marshal.GetExceptionForHR((int)hr));
|
throw new InvalidComObjectException($"Error while extracting thumbnail for {fileName}", Marshal.GetExceptionForHR((int)hr));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,12 +29,12 @@ namespace Wox.Infrastructure.Storage
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetList(IList<T> items)
|
public void SetList(IList<T> list)
|
||||||
{
|
{
|
||||||
// enforce that internal representation
|
// enforce that internal representation
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_items = new ConcurrentDictionary<int, T>(items.ToDictionary(i => i.GetHashCode()));
|
_items = new ConcurrentDictionary<int, T>(list.ToDictionary(i => i.GetHashCode()));
|
||||||
}
|
}
|
||||||
catch (ArgumentException e)
|
catch (ArgumentException e)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ namespace Wox.Infrastructure.Storage
|
|||||||
suffix = jsonSuffix;
|
suffix = jsonSuffix;
|
||||||
}
|
}
|
||||||
|
|
||||||
string filePath = associatedFilePath.Substring(0, associatedFilePath.Length - suffix.Length) + "_version.txt";
|
string filePath = string.Concat(associatedFilePath.AsSpan(0, associatedFilePath.Length - suffix.Length), "_version.txt");
|
||||||
return filePath;
|
return filePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -101,7 +101,9 @@ namespace Wox.Infrastructure
|
|||||||
{
|
{
|
||||||
var fullStringToCompare = fullStringToCompareWithoutCase[compareStringIndex].ToString();
|
var fullStringToCompare = fullStringToCompareWithoutCase[compareStringIndex].ToString();
|
||||||
var querySubstring = currentQuerySubstring[currentQuerySubstringCharacterIndex].ToString();
|
var querySubstring = currentQuerySubstring[currentQuerySubstringCharacterIndex].ToString();
|
||||||
|
#pragma warning disable CA1309 // Use ordinal string comparison (We are looking for a fuzzy match here)
|
||||||
compareResult = string.Compare(fullStringToCompare, querySubstring, CultureInfo.CurrentCulture, CompareOptions.IgnoreCase | CompareOptions.IgnoreNonSpace) != 0;
|
compareResult = string.Compare(fullStringToCompare, querySubstring, CultureInfo.CurrentCulture, CompareOptions.IgnoreCase | CompareOptions.IgnoreNonSpace) != 0;
|
||||||
|
#pragma warning restore CA1309 // Use ordinal string comparison
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -262,12 +264,13 @@ namespace Wox.Infrastructure
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Using CurrentCultureIgnoreCase since this relates to queries input by user
|
#pragma warning disable CA1309 // Use ordinal string comparison (Using CurrentCultureIgnoreCase since this relates to queries input by user)
|
||||||
if (string.Equals(query, stringToCompare, StringComparison.CurrentCultureIgnoreCase))
|
if (string.Equals(query, stringToCompare, StringComparison.CurrentCultureIgnoreCase))
|
||||||
{
|
{
|
||||||
var bonusForExactMatch = 10;
|
var bonusForExactMatch = 10;
|
||||||
score += bonusForExactMatch;
|
score += bonusForExactMatch;
|
||||||
}
|
}
|
||||||
|
#pragma warning restore CA1309 // Use ordinal string comparison
|
||||||
|
|
||||||
return score;
|
return score;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,8 @@
|
|||||||
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
|
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
|
||||||
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
|
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
|
||||||
<Platforms>x64</Platforms>
|
<Platforms>x64</Platforms>
|
||||||
|
<EnableNETAnalyzers>true</EnableNETAnalyzers>
|
||||||
|
<AnalysisMode>Recommended</AnalysisMode>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
|
|||||||
Reference in New Issue
Block a user