[PTRun][WindowsSettings] Enable analyzer and fix warnings (#16942)

This commit is contained in:
CleanCodeDeveloper
2022-03-10 17:00:28 +01:00
committed by GitHub
parent 94391775c8
commit 0d3aa3a187
4 changed files with 10 additions and 7 deletions

View File

@@ -40,7 +40,7 @@ namespace Microsoft.PowerToys.Run.Plugin.WindowsSettings.Helper
using var stream = assembly.GetManifestResourceStream(resourceName); using var stream = assembly.GetManifestResourceStream(resourceName);
if (stream is null) if (stream is null)
{ {
throw new Exception("stream is null"); throw new ArgumentNullException(nameof(stream), "stream is null");
} }
var options = new JsonSerializerOptions(); var options = new JsonSerializerOptions();

View File

@@ -4,6 +4,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Globalization;
using System.Linq; using System.Linq;
using Microsoft.PowerToys.Run.Plugin.WindowsSettings.Properties; using Microsoft.PowerToys.Run.Plugin.WindowsSettings.Properties;
using Wox.Plugin.Logger; using Wox.Plugin.Logger;
@@ -31,7 +32,7 @@ namespace Microsoft.PowerToys.Run.Plugin.WindowsSettings.Helper
// Translate Name // Translate Name
if (!string.IsNullOrWhiteSpace(settings.Name)) if (!string.IsNullOrWhiteSpace(settings.Name))
{ {
var name = Resources.ResourceManager.GetString(settings.Name); var name = Resources.ResourceManager.GetString(settings.Name, CultureInfo.CurrentUICulture);
if (string.IsNullOrEmpty(name)) if (string.IsNullOrEmpty(name))
{ {
Log.Warn($"Resource string for [{settings.Name}] not found", typeof(TranslationHelper)); Log.Warn($"Resource string for [{settings.Name}] not found", typeof(TranslationHelper));
@@ -43,7 +44,7 @@ namespace Microsoft.PowerToys.Run.Plugin.WindowsSettings.Helper
// Translate Type (App) // Translate Type (App)
if (!string.IsNullOrWhiteSpace(settings.Type)) if (!string.IsNullOrWhiteSpace(settings.Type))
{ {
var type = Resources.ResourceManager.GetString(settings.Type); var type = Resources.ResourceManager.GetString(settings.Type, CultureInfo.CurrentUICulture);
if (string.IsNullOrEmpty(type)) if (string.IsNullOrEmpty(type))
{ {
Log.Warn($"Resource string for [{settings.Type}] not found", typeof(TranslationHelper)); Log.Warn($"Resource string for [{settings.Type}] not found", typeof(TranslationHelper));
@@ -64,7 +65,7 @@ namespace Microsoft.PowerToys.Run.Plugin.WindowsSettings.Helper
continue; continue;
} }
var translatedArea = Resources.ResourceManager.GetString(area); var translatedArea = Resources.ResourceManager.GetString(area, CultureInfo.CurrentUICulture);
if (string.IsNullOrEmpty(translatedArea)) if (string.IsNullOrEmpty(translatedArea))
{ {
Log.Warn($"Resource string for [{area}] not found", typeof(TranslationHelper)); Log.Warn($"Resource string for [{area}] not found", typeof(TranslationHelper));
@@ -88,7 +89,7 @@ namespace Microsoft.PowerToys.Run.Plugin.WindowsSettings.Helper
continue; continue;
} }
var translatedAltName = Resources.ResourceManager.GetString(altName); var translatedAltName = Resources.ResourceManager.GetString(altName, CultureInfo.CurrentUICulture);
if (string.IsNullOrEmpty(translatedAltName)) if (string.IsNullOrEmpty(translatedAltName))
{ {
Log.Warn($"Resource string for [{altName}] not found", typeof(TranslationHelper)); Log.Warn($"Resource string for [{altName}] not found", typeof(TranslationHelper));
@@ -103,7 +104,7 @@ namespace Microsoft.PowerToys.Run.Plugin.WindowsSettings.Helper
// Translate Note // Translate Note
if (!string.IsNullOrWhiteSpace(settings.Note)) if (!string.IsNullOrWhiteSpace(settings.Note))
{ {
var note = Resources.ResourceManager.GetString(settings.Note); var note = Resources.ResourceManager.GetString(settings.Note, CultureInfo.CurrentUICulture);
if (string.IsNullOrEmpty(note)) if (string.IsNullOrEmpty(note))
{ {
Log.Warn($"Resource string for [{settings.Note}] not found", typeof(TranslationHelper)); Log.Warn($"Resource string for [{settings.Note}] not found", typeof(TranslationHelper));

View File

@@ -134,7 +134,7 @@ namespace Microsoft.PowerToys.Run.Plugin.WindowsSettings
// Search for Area only on queries with action char. // Search for Area only on queries with action char.
if (area.Contains(query.Search.Replace(":", string.Empty), StringComparison.CurrentCultureIgnoreCase) if (area.Contains(query.Search.Replace(":", string.Empty), StringComparison.CurrentCultureIgnoreCase)
&& query.Search.EndsWith(":")) && query.Search.EndsWith(":", StringComparison.CurrentCultureIgnoreCase))
{ {
return true; return true;
} }

View File

@@ -15,6 +15,8 @@
<UseWindowsForms>true</UseWindowsForms> <UseWindowsForms>true</UseWindowsForms>
<NeutralLanguage>en-US</NeutralLanguage> <NeutralLanguage>en-US</NeutralLanguage>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<AnalysisMode>Recommended</AnalysisMode>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">