mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-04 18:26:39 +02:00
.NET 8 Upgrade Silenced Errors Fix (#30469)
* [Dev][Build] .NET 8 Upgrade Silenced errors first fix. * [Dev][Build] .NET 8 Upgrade Silenced errors. CA1859 * [Dev][Build] .NET 8 Upgrade Silenced errors. CA1854. * [Dev][Build] .NET 8 Upgrade Silenced errors. CA1860 * [Dev][Build] .NET 8 Upgrade Silenced errors. CA1861 * [Dev][Build] .NET 8 Upgrade Silenced errors. CA1862 * [Dev][Build] .NET 8 Upgrade Silenced errors. CA1863 * [Dev][Build] .NET 8 Upgrade Silenced errors. CA1864 * [Dev][Build] .NET 8 Upgrade Silenced errors. CA1865 * [Dev][Build] .NET 8 Upgrade Silenced errors. CA2208 * [Dev][Build] .NET 8 Upgrade Silenced errors. CS9191 * [Dev][Build] .NET 8 Upgrade Silenced errors. Spell check * [Dev][Build] .NET 8 Upgrade Silenced errors. Spell check * [Dev][Build] .NET 8 Upgrade Silenced errors. - CompositeFormat variables used more than once in the same file were assigned to a single variable. - GetProcessesByName logic fix. - String comparion fix. - ArgumentOutOfRangeException message change. * [Dev][Build] .NET 8 Upgrade Silenced errors. - Null check added. - static readonly CompositeFormat added for all fields.
This commit is contained in:
@@ -26,13 +26,15 @@ namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
Name = ModuleName;
|
||||
}
|
||||
|
||||
private static readonly JsonSerializerOptions _serializerOptions = new JsonSerializerOptions
|
||||
{
|
||||
WriteIndented = true,
|
||||
};
|
||||
|
||||
public virtual void Save(ISettingsUtils settingsUtils)
|
||||
{
|
||||
// Save settings to file
|
||||
var options = new JsonSerializerOptions
|
||||
{
|
||||
WriteIndented = true,
|
||||
};
|
||||
var options = _serializerOptions;
|
||||
|
||||
ArgumentNullException.ThrowIfNull(settingsUtils);
|
||||
|
||||
|
||||
@@ -13,6 +13,11 @@ namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
{
|
||||
public const string ModuleName = "ColorPicker";
|
||||
|
||||
private static readonly JsonSerializerOptions _serializerOptions = new JsonSerializerOptions
|
||||
{
|
||||
WriteIndented = true,
|
||||
};
|
||||
|
||||
[JsonPropertyName("properties")]
|
||||
public ColorPickerPropertiesVersion1 Properties { get; set; }
|
||||
|
||||
@@ -26,10 +31,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
public virtual void Save(ISettingsUtils settingsUtils)
|
||||
{
|
||||
// Save settings to file
|
||||
var options = new JsonSerializerOptions
|
||||
{
|
||||
WriteIndented = true,
|
||||
};
|
||||
var options = _serializerOptions;
|
||||
|
||||
ArgumentNullException.ThrowIfNull(settingsUtils);
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System.Collections.Concurrent;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
@@ -9,6 +10,8 @@ namespace Microsoft.PowerToys.Settings.UI.Library.CustomAction
|
||||
{
|
||||
public class SendCustomAction
|
||||
{
|
||||
private static readonly ConcurrentDictionary<string, JsonSerializerOptions> OptionsCache = new ConcurrentDictionary<string, JsonSerializerOptions>();
|
||||
|
||||
private readonly string moduleName;
|
||||
|
||||
public SendCustomAction(string moduleName)
|
||||
@@ -21,7 +24,13 @@ namespace Microsoft.PowerToys.Settings.UI.Library.CustomAction
|
||||
|
||||
public string ToJsonString()
|
||||
{
|
||||
var jsonSerializerOptions = new JsonSerializerOptions
|
||||
var jsonSerializerOptions = OptionsCache.GetOrAdd(moduleName, CreateOptionsForModuleName);
|
||||
return JsonSerializer.Serialize(this, jsonSerializerOptions);
|
||||
}
|
||||
|
||||
private JsonSerializerOptions CreateOptionsForModuleName(string moduleName)
|
||||
{
|
||||
return new JsonSerializerOptions
|
||||
{
|
||||
PropertyNamingPolicy = new CustomNamePolicy((propertyName) =>
|
||||
{
|
||||
@@ -29,8 +38,6 @@ namespace Microsoft.PowerToys.Settings.UI.Library.CustomAction
|
||||
return propertyName.Equals("ModuleAction", System.StringComparison.Ordinal) ? moduleName : propertyName;
|
||||
}),
|
||||
};
|
||||
|
||||
return JsonSerializer.Serialize(this, jsonSerializerOptions);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,11 @@ namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
{
|
||||
public const string ModuleName = "EnvironmentVariables";
|
||||
|
||||
private static readonly JsonSerializerOptions _serializerOptions = new JsonSerializerOptions
|
||||
{
|
||||
WriteIndented = true,
|
||||
};
|
||||
|
||||
[JsonPropertyName("properties")]
|
||||
public EnvironmentVariablesProperties Properties { get; set; }
|
||||
|
||||
@@ -26,10 +31,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
public virtual void Save(ISettingsUtils settingsUtils)
|
||||
{
|
||||
// Save settings to file
|
||||
var options = new JsonSerializerOptions
|
||||
{
|
||||
WriteIndented = true,
|
||||
};
|
||||
var options = _serializerOptions;
|
||||
|
||||
ArgumentNullException.ThrowIfNull(settingsUtils);
|
||||
|
||||
|
||||
@@ -14,6 +14,12 @@ namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
public const string ModuleName = "Hosts";
|
||||
|
||||
[JsonPropertyName("properties")]
|
||||
|
||||
private static readonly JsonSerializerOptions _serializerOptions = new JsonSerializerOptions
|
||||
{
|
||||
WriteIndented = true,
|
||||
};
|
||||
|
||||
public HostsProperties Properties { get; set; }
|
||||
|
||||
public HostsSettings()
|
||||
@@ -26,10 +32,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
public virtual void Save(ISettingsUtils settingsUtils)
|
||||
{
|
||||
// Save settings to file
|
||||
var options = new JsonSerializerOptions
|
||||
{
|
||||
WriteIndented = true,
|
||||
};
|
||||
var options = _serializerOptions;
|
||||
|
||||
ArgumentNullException.ThrowIfNull(settingsUtils);
|
||||
|
||||
|
||||
@@ -13,6 +13,11 @@ namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
{
|
||||
public const string ModuleName = "Image Resizer";
|
||||
|
||||
private static readonly JsonSerializerOptions _serializerOptions = new JsonSerializerOptions
|
||||
{
|
||||
WriteIndented = true,
|
||||
};
|
||||
|
||||
[JsonPropertyName("properties")]
|
||||
public ImageResizerProperties Properties { get; set; }
|
||||
|
||||
@@ -31,10 +36,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
|
||||
public override string ToJsonString()
|
||||
{
|
||||
var options = new JsonSerializerOptions
|
||||
{
|
||||
WriteIndented = true,
|
||||
};
|
||||
var options = _serializerOptions;
|
||||
return JsonSerializer.Serialize(this, options);
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,11 @@ namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
{
|
||||
public class ImageResizerSizes
|
||||
{
|
||||
private static readonly JsonSerializerOptions _serializerOptions = new JsonSerializerOptions
|
||||
{
|
||||
WriteIndented = true,
|
||||
};
|
||||
|
||||
// Suppressing this warning because removing the setter breaks
|
||||
// deserialization with System.Text.Json. This affects the UI display.
|
||||
// See: https://github.com/dotnet/runtime/issues/30258
|
||||
@@ -28,10 +33,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
|
||||
public string ToJsonString()
|
||||
{
|
||||
var options = new JsonSerializerOptions
|
||||
{
|
||||
WriteIndented = true,
|
||||
};
|
||||
var options = _serializerOptions;
|
||||
return JsonSerializer.Serialize(this, options);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,11 @@ namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
{
|
||||
public const string ModuleName = "MouseJump";
|
||||
|
||||
private static readonly JsonSerializerOptions _serializerOptions = new JsonSerializerOptions
|
||||
{
|
||||
WriteIndented = true,
|
||||
};
|
||||
|
||||
[JsonPropertyName("properties")]
|
||||
public MouseJumpProperties Properties { get; set; }
|
||||
|
||||
@@ -26,10 +31,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
public void Save(ISettingsUtils settingsUtils)
|
||||
{
|
||||
// Save settings to file
|
||||
var options = new JsonSerializerOptions
|
||||
{
|
||||
WriteIndented = true,
|
||||
};
|
||||
var options = _serializerOptions;
|
||||
|
||||
ArgumentNullException.ThrowIfNull(settingsUtils);
|
||||
|
||||
|
||||
@@ -14,6 +14,13 @@ namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
{
|
||||
public const string ModuleName = "MouseWithoutBorders";
|
||||
|
||||
private static readonly JsonSerializerOptions _serializerOptions = new JsonSerializerOptions
|
||||
{
|
||||
WriteIndented = true,
|
||||
MaxDepth = 0,
|
||||
IncludeFields = true,
|
||||
};
|
||||
|
||||
[JsonPropertyName("properties")]
|
||||
public MouseWithoutBordersProperties Properties { get; set; }
|
||||
|
||||
@@ -91,12 +98,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
public virtual void Save(ISettingsUtils settingsUtils)
|
||||
{
|
||||
// Save settings to file
|
||||
var options = new JsonSerializerOptions
|
||||
{
|
||||
WriteIndented = true,
|
||||
MaxDepth = 0,
|
||||
IncludeFields = true,
|
||||
};
|
||||
var options = _serializerOptions;
|
||||
|
||||
ArgumentNullException.ThrowIfNull(settingsUtils);
|
||||
|
||||
|
||||
@@ -13,6 +13,11 @@ namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
{
|
||||
public const string ModuleName = "PastePlain";
|
||||
|
||||
private static readonly JsonSerializerOptions _serializerOptions = new JsonSerializerOptions
|
||||
{
|
||||
WriteIndented = true,
|
||||
};
|
||||
|
||||
[JsonPropertyName("properties")]
|
||||
public PastePlainProperties Properties { get; set; }
|
||||
|
||||
@@ -26,10 +31,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
public virtual void Save(ISettingsUtils settingsUtils)
|
||||
{
|
||||
// Save settings to file
|
||||
var options = new JsonSerializerOptions
|
||||
{
|
||||
WriteIndented = true,
|
||||
};
|
||||
var options = _serializerOptions;
|
||||
|
||||
ArgumentNullException.ThrowIfNull(settingsUtils);
|
||||
|
||||
|
||||
@@ -14,6 +14,11 @@ namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
public const string ModuleName = "Peek";
|
||||
public const string ModuleVersion = "0.0.1";
|
||||
|
||||
private static readonly JsonSerializerOptions _serializerOptions = new JsonSerializerOptions
|
||||
{
|
||||
WriteIndented = true,
|
||||
};
|
||||
|
||||
[JsonPropertyName("properties")]
|
||||
public PeekProperties Properties { get; set; }
|
||||
|
||||
@@ -37,10 +42,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
public virtual void Save(ISettingsUtils settingsUtils)
|
||||
{
|
||||
// Save settings to file
|
||||
var options = new JsonSerializerOptions
|
||||
{
|
||||
WriteIndented = true,
|
||||
};
|
||||
var options = _serializerOptions;
|
||||
|
||||
ArgumentNullException.ThrowIfNull(settingsUtils);
|
||||
|
||||
|
||||
@@ -14,6 +14,12 @@ namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
{
|
||||
public const string ModuleName = "PowerToys Run";
|
||||
|
||||
private static readonly JsonSerializerOptions _serializerOptions = new JsonSerializerOptions
|
||||
{
|
||||
WriteIndented = true,
|
||||
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
|
||||
};
|
||||
|
||||
[JsonPropertyName("properties")]
|
||||
public PowerLauncherProperties Properties { get; set; }
|
||||
|
||||
@@ -30,11 +36,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
public virtual void Save(ISettingsUtils settingsUtils)
|
||||
{
|
||||
// Save settings to file
|
||||
var options = new JsonSerializerOptions
|
||||
{
|
||||
WriteIndented = true,
|
||||
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
|
||||
};
|
||||
var options = _serializerOptions;
|
||||
|
||||
ArgumentNullException.ThrowIfNull(settingsUtils);
|
||||
|
||||
|
||||
@@ -13,6 +13,11 @@ namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
{
|
||||
public const string ModuleName = "TextExtractor";
|
||||
|
||||
private static readonly JsonSerializerOptions _serializerOptions = new JsonSerializerOptions
|
||||
{
|
||||
WriteIndented = true,
|
||||
};
|
||||
|
||||
[JsonPropertyName("properties")]
|
||||
public PowerOcrProperties Properties { get; set; }
|
||||
|
||||
@@ -26,10 +31,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
public virtual void Save(ISettingsUtils settingsUtils)
|
||||
{
|
||||
// Save settings to file
|
||||
var options = new JsonSerializerOptions
|
||||
{
|
||||
WriteIndented = true,
|
||||
};
|
||||
var options = _serializerOptions;
|
||||
|
||||
ArgumentNullException.ThrowIfNull(settingsUtils);
|
||||
|
||||
|
||||
@@ -29,6 +29,11 @@ namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
|
||||
public DateTime LastBackupStartTime { get; set; }
|
||||
|
||||
private static readonly JsonSerializerOptions _serializerOptions = new JsonSerializerOptions
|
||||
{
|
||||
WriteIndented = true,
|
||||
};
|
||||
|
||||
private SettingsBackupAndRestoreUtils()
|
||||
{
|
||||
LastBackupStartTime = DateTime.MinValue;
|
||||
@@ -378,7 +383,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
return settingsBackupAndRestoreDir;
|
||||
}
|
||||
|
||||
private IList<string> GetBackupSettingsFiles(string settingsBackupAndRestoreDir)
|
||||
private List<string> GetBackupSettingsFiles(string settingsBackupAndRestoreDir)
|
||||
{
|
||||
return Directory.GetFiles(settingsBackupAndRestoreDir, "settings_*.ptb", SearchOption.TopDirectoryOnly).ToList().Where(f => Regex.IsMatch(f, "settings_(\\d{1,19}).ptb")).ToList();
|
||||
}
|
||||
@@ -745,7 +750,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
UnchangedFiles = skippedSettingsFiles.Keys.ToList(),
|
||||
};
|
||||
|
||||
var manifest = JsonSerializer.Serialize(manifestData, new JsonSerializerOptions() { WriteIndented = true });
|
||||
var manifest = JsonSerializer.Serialize(manifestData, _serializerOptions);
|
||||
|
||||
if (!dryRun)
|
||||
{
|
||||
@@ -993,7 +998,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
public static string Normalize(string json)
|
||||
{
|
||||
var doc1 = JsonNormalizer.Deserialize(json);
|
||||
var newJson1 = JsonSerializer.Serialize(doc1, new JsonSerializerOptions { WriteIndented = true });
|
||||
var newJson1 = JsonSerializer.Serialize(doc1, _serializerOptions);
|
||||
return newJson1;
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,12 @@ namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
private readonly IFile _file;
|
||||
private readonly ISettingsPath _settingsPath;
|
||||
|
||||
private static readonly JsonSerializerOptions _serializerOptions = new JsonSerializerOptions
|
||||
{
|
||||
MaxDepth = 0,
|
||||
IncludeFields = true,
|
||||
};
|
||||
|
||||
public SettingsUtils()
|
||||
: this(new FileSystem())
|
||||
{
|
||||
@@ -151,7 +157,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
// The file itself did write the content correctly but something is off with the actual end of the file, hence the 0x00 bug
|
||||
var jsonSettingsString = _file.ReadAllText(_settingsPath.GetSettingsPath(powertoyFolderName, fileName)).Trim('\0');
|
||||
|
||||
var options = new JsonSerializerOptions { MaxDepth = 0, IncludeFields = true };
|
||||
var options = _serializerOptions;
|
||||
return JsonSerializer.Deserialize<T>(jsonSettingsString, options);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user