[Analyzers] Update StyleCop and enable SA1200 (#22707)

* update StyleCop and enable SA1200

* Fix merge issues

* fix build and added using rule
This commit is contained in:
Davide Giacometti
2022-12-18 14:27:14 +01:00
committed by GitHub
parent 617150cf50
commit 6d138e80fb
55 changed files with 338 additions and 371 deletions

View File

@@ -29,14 +29,14 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup Condition="'$(MSBuildProjectExtension)' == '.csproj'"> <ItemGroup Condition="'$(MSBuildProjectExtension)' == '.csproj'">
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118"> <PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.435">
<PrivateAssets>all</PrivateAssets> <PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference> </PackageReference>
<Compile Include="$(MSBuildThisFileDirectory)\src\codeAnalysis\GlobalSuppressions.cs" Link="GlobalSuppressions.cs" /> <Compile Include="$(MSBuildThisFileDirectory)\src\codeAnalysis\GlobalSuppressions.cs" Link="GlobalSuppressions.cs" />
<AdditionalFiles Include="$(MSBuildThisFileDirectory)\src\codeAnalysis\StyleCop.json" Link="StyleCop.json" /> <AdditionalFiles Include="$(MSBuildThisFileDirectory)\src\codeAnalysis\StyleCop.json" Link="StyleCop.json" />
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="7.0.0-preview1.22464.1"> <PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="7.0.0">
<PrivateAssets>all</PrivateAssets> <PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference> </PackageReference>

View File

@@ -8,7 +8,6 @@ dotnet_diagnostic.CA1303.severity = suggestion
# CA1051: Do not declare visible instance fields # CA1051: Do not declare visible instance fields
dotnet_code_quality.ca1051.exclude_structs = true dotnet_code_quality.ca1051.exclude_structs = true
csharp_using_directive_placement = inside_namespace:warning
csharp_prefer_simple_using_statement = true:suggestion csharp_prefer_simple_using_statement = true:suggestion
csharp_prefer_braces = true:silent csharp_prefer_braces = true:silent
csharp_style_namespace_declarations = block_scoped:silent csharp_style_namespace_declarations = block_scoped:silent

View File

@@ -12,7 +12,6 @@ using System.Diagnostics.CodeAnalysis;
[assembly: SuppressMessage("StyleCop.CSharp.ReadabilityRules", "SA1101:PrefixLocalCallsWithThis", Justification = "We follow the C# Core Coding Style which avoids using `this` unless absolutely necessary.")] [assembly: SuppressMessage("StyleCop.CSharp.ReadabilityRules", "SA1101:PrefixLocalCallsWithThis", Justification = "We follow the C# Core Coding Style which avoids using `this` unless absolutely necessary.")]
[assembly: SuppressMessage("StyleCop.CSharp.OrderingRules", "SA1200:UsingDirectivesMustBePlacedWithinNamespace", Justification = "We follow the C# Core Coding Style which puts using statements outside the namespace.")]
[assembly: SuppressMessage("StyleCop.CSharp.OrderingRules", "SA1201:ElementsMustAppearInTheCorrectOrder", Justification = "It is not a priority and have hight impact in code changes.")] [assembly: SuppressMessage("StyleCop.CSharp.OrderingRules", "SA1201:ElementsMustAppearInTheCorrectOrder", Justification = "It is not a priority and have hight impact in code changes.")]
[assembly: SuppressMessage("StyleCop.CSharp.OrderingRules", "SA1202:ElementsMustBeOrderedByAccess", Justification = "It is not a priority and have hight impact in code changes.")] [assembly: SuppressMessage("StyleCop.CSharp.OrderingRules", "SA1202:ElementsMustBeOrderedByAccess", Justification = "It is not a priority and have hight impact in code changes.")]
[assembly: SuppressMessage("StyleCop.CSharp.OrderingRules", "SA1203:ConstantsMustAppearBeforeFields", Justification = "It is not a priority and have hight impact in code changes.")] [assembly: SuppressMessage("StyleCop.CSharp.OrderingRules", "SA1203:ConstantsMustAppearBeforeFields", Justification = "It is not a priority and have hight impact in code changes.")]

View File

@@ -15,7 +15,8 @@
"newlineAtEndOfFile": "require" "newlineAtEndOfFile": "require"
}, },
"orderingRules": { "orderingRules": {
"usingDirectivesPlacement": "outsideNamespace" "usingDirectivesPlacement": "outsideNamespace",
"systemUsingDirectivesFirst": true
} }
} }
} }

View File

@@ -2,13 +2,13 @@
// The Microsoft Corporation licenses this file to you under the MIT license. // The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information. // See the LICENSE file in the project root for more information.
namespace ManagedCommon
{
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Drawing; using System.Drawing;
using System.Globalization; using System.Globalization;
namespace ManagedCommon
{
public static class ColorFormatHelper public static class ColorFormatHelper
{ {
/// <summary> /// <summary>
@@ -16,7 +16,7 @@ namespace ManagedCommon
/// </summary> /// </summary>
/// <param name="color">The <see cref="Color"/> to convert</param> /// <param name="color">The <see cref="Color"/> to convert</param>
/// <returns>The cyan[0..1], magenta[0..1], yellow[0..1] and black key[0..1] of the converted color</returns> /// <returns>The cyan[0..1], magenta[0..1], yellow[0..1] and black key[0..1] of the converted color</returns>
public static (double cyan, double magenta, double yellow, double blackKey) ConvertToCMYKColor(Color color) public static (double Cyan, double Magenta, double Yellow, double BlackKey) ConvertToCMYKColor(Color color)
{ {
// special case for black (avoid division by zero) // special case for black (avoid division by zero)
if (color.R == 0 && color.G == 0 && color.B == 0) if (color.R == 0 && color.G == 0 && color.B == 0)
@@ -48,7 +48,7 @@ namespace ManagedCommon
/// </summary> /// </summary>
/// <param name="color">The <see cref="Color"/> to convert</param> /// <param name="color">The <see cref="Color"/> to convert</param>
/// <returns>The hue [0°..360°], saturation [0..1] and brightness [0..1] of the converted color</returns> /// <returns>The hue [0°..360°], saturation [0..1] and brightness [0..1] of the converted color</returns>
public static (double hue, double saturation, double brightness) ConvertToHSBColor(Color color) public static (double Hue, double Saturation, double Brightness) ConvertToHSBColor(Color color)
{ {
// HSB and HSV represents the same color space // HSB and HSV represents the same color space
return ConvertToHSVColor(color); return ConvertToHSVColor(color);
@@ -59,7 +59,7 @@ namespace ManagedCommon
/// </summary> /// </summary>
/// <param name="color">The <see cref="Color"/> to convert</param> /// <param name="color">The <see cref="Color"/> to convert</param>
/// <returns>The hue [0°..360°], saturation [0..1] and value [0..1] of the converted color</returns> /// <returns>The hue [0°..360°], saturation [0..1] and value [0..1] of the converted color</returns>
public static (double hue, double saturation, double value) ConvertToHSVColor(Color color) public static (double Hue, double Saturation, double Value) ConvertToHSVColor(Color color)
{ {
var min = Math.Min(Math.Min(color.R, color.G), color.B) / 255d; var min = Math.Min(Math.Min(color.R, color.G), color.B) / 255d;
var max = Math.Max(Math.Max(color.R, color.G), color.B) / 255d; var max = Math.Max(Math.Max(color.R, color.G), color.B) / 255d;
@@ -72,7 +72,7 @@ namespace ManagedCommon
/// </summary> /// </summary>
/// <param name="color">The <see cref="Color"/> to convert</param> /// <param name="color">The <see cref="Color"/> to convert</param>
/// <returns>The hue [0°..360°], saturation [0..1] and intensity [0..1] of the converted color</returns> /// <returns>The hue [0°..360°], saturation [0..1] and intensity [0..1] of the converted color</returns>
public static (double hue, double saturation, double intensity) ConvertToHSIColor(Color color) public static (double Hue, double Saturation, double Intensity) ConvertToHSIColor(Color color)
{ {
// special case for black // special case for black
if (color.R == 0 && color.G == 0 && color.B == 0) if (color.R == 0 && color.G == 0 && color.B == 0)
@@ -96,7 +96,7 @@ namespace ManagedCommon
/// </summary> /// </summary>
/// <param name="color">The <see cref="Color"/> to convert</param> /// <param name="color">The <see cref="Color"/> to convert</param>
/// <returns>The hue [0°..360°], saturation [0..1] and lightness [0..1] values of the converted color</returns> /// <returns>The hue [0°..360°], saturation [0..1] and lightness [0..1] values of the converted color</returns>
public static (double hue, double saturation, double lightness) ConvertToHSLColor(Color color) public static (double Hue, double Saturation, double Lightness) ConvertToHSLColor(Color color)
{ {
var min = Math.Min(Math.Min(color.R, color.G), color.B) / 255d; var min = Math.Min(Math.Min(color.R, color.G), color.B) / 255d;
var max = Math.Max(Math.Max(color.R, color.G), color.B) / 255d; var max = Math.Max(Math.Max(color.R, color.G), color.B) / 255d;
@@ -120,7 +120,7 @@ namespace ManagedCommon
/// </summary> /// </summary>
/// <param name="color">The <see cref="Color"/> to convert</param> /// <param name="color">The <see cref="Color"/> to convert</param>
/// <returns>The hue [0°..360°], whiteness [0..1] and blackness [0..1] of the converted color</returns> /// <returns>The hue [0°..360°], whiteness [0..1] and blackness [0..1] of the converted color</returns>
public static (double hue, double whiteness, double blackness) ConvertToHWBColor(Color color) public static (double Hue, double Whiteness, double Blackness) ConvertToHWBColor(Color color)
{ {
var min = Math.Min(Math.Min(color.R, color.G), color.B) / 255d; var min = Math.Min(Math.Min(color.R, color.G), color.B) / 255d;
var max = Math.Max(Math.Max(color.R, color.G), color.B) / 255d; var max = Math.Max(Math.Max(color.R, color.G), color.B) / 255d;
@@ -133,10 +133,10 @@ namespace ManagedCommon
/// </summary> /// </summary>
/// <param name="color">The <see cref="Color"/> to convert</param> /// <param name="color">The <see cref="Color"/> to convert</param>
/// <returns>The lightness [0..100] and two chromaticities [-128..127]</returns> /// <returns>The lightness [0..100] and two chromaticities [-128..127]</returns>
public static (double lightness, double chromaticityA, double chromaticityB) ConvertToCIELABColor(Color color) public static (double Lightness, double ChromaticityA, double ChromaticityB) ConvertToCIELABColor(Color color)
{ {
var xyz = ConvertToCIEXYZColor(color); var xyz = ConvertToCIEXYZColor(color);
var lab = GetCIELABColorFromCIEXYZ(xyz.x, xyz.y, xyz.z); var lab = GetCIELABColorFromCIEXYZ(xyz.X, xyz.Y, xyz.Z);
return lab; return lab;
} }
@@ -150,7 +150,7 @@ namespace ManagedCommon
/// </summary> /// </summary>
/// <param name="color">The <see cref="Color"/> to convert</param> /// <param name="color">The <see cref="Color"/> to convert</param>
/// <returns>The X [0..1], Y [0..1] and Z [0..1]</returns> /// <returns>The X [0..1], Y [0..1] and Z [0..1]</returns>
public static (double x, double y, double z) ConvertToCIEXYZColor(Color color) public static (double X, double Y, double Z) ConvertToCIEXYZColor(Color color)
{ {
double r = color.R / 255d; double r = color.R / 255d;
double g = color.G / 255d; double g = color.G / 255d;
@@ -177,7 +177,7 @@ namespace ManagedCommon
/// <param name="y">The <see cref="y"/> represents the luminance</param> /// <param name="y">The <see cref="y"/> represents the luminance</param>
/// <param name="z">The <see cref="z"/> is quasi-equal to blue (of CIE RGB)</param> /// <param name="z">The <see cref="z"/> is quasi-equal to blue (of CIE RGB)</param>
/// <returns>The lightness [0..100] and two chromaticities [-128..127]</returns> /// <returns>The lightness [0..100] and two chromaticities [-128..127]</returns>
private static (double lightness, double chromaticityA, double chromaticityB) private static (double Lightness, double ChromaticityA, double ChromaticityB)
GetCIELABColorFromCIEXYZ(double x, double y, double z) GetCIELABColorFromCIEXYZ(double x, double y, double z)
{ {
// sRGB reference white (x=0.3127, y=0.3290, Y=1.0), actually CIE Standard Illuminant D65 truncated to 4 decimal places, // sRGB reference white (x=0.3127, y=0.3290, Y=1.0), actually CIE Standard Illuminant D65 truncated to 4 decimal places,
@@ -215,7 +215,7 @@ namespace ManagedCommon
/// </summary> /// </summary>
/// <param name="color">The <see cref="Color"/> to convert</param> /// <param name="color">The <see cref="Color"/> to convert</param>
/// <returns>The hue, whiteness [0..1] and blackness [0..1] of the converted color</returns> /// <returns>The hue, whiteness [0..1] and blackness [0..1] of the converted color</returns>
public static (string hue, double whiteness, double blackness) ConvertToNaturalColor(Color color) public static (string Hue, double Whiteness, double Blackness) ConvertToNaturalColor(Color color)
{ {
var min = Math.Min(Math.Min(color.R, color.G), color.B) / 255d; var min = Math.Min(Math.Min(color.R, color.G), color.B) / 255d;
var max = Math.Max(Math.Max(color.R, color.G), color.B) / 255d; var max = Math.Max(Math.Max(color.R, color.G), color.B) / 255d;

View File

@@ -2,12 +2,12 @@
// The Microsoft Corporation licenses this file to you under the MIT license. // The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information. // See the LICENSE file in the project root for more information.
namespace PowerToys.FileLocksmithUI.Converters
{
using System; using System;
using FileLocksmith.Interop; using FileLocksmith.Interop;
using Microsoft.UI.Xaml.Data; using Microsoft.UI.Xaml.Data;
namespace PowerToys.FileLocksmithUI.Converters
{
public sealed class FileCountConverter : IValueConverter public sealed class FileCountConverter : IValueConverter
{ {
public object Convert(object value, Type targetType, object parameter, string language) public object Convert(object value, Type targetType, object parameter, string language)

View File

@@ -2,13 +2,13 @@
// The Microsoft Corporation licenses this file to you under the MIT license. // The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information. // See the LICENSE file in the project root for more information.
namespace PowerToys.FileLocksmithUI.Converters
{
using System; using System;
using System.IO; using System.IO;
using FileLocksmith.Interop; using FileLocksmith.Interop;
using Microsoft.UI.Xaml.Data; using Microsoft.UI.Xaml.Data;
namespace PowerToys.FileLocksmithUI.Converters
{
public sealed class FileListToDescriptionConverter : IValueConverter public sealed class FileListToDescriptionConverter : IValueConverter
{ {
public object Convert(object value, Type targetType, object parameter, string language) public object Convert(object value, Type targetType, object parameter, string language)

View File

@@ -2,8 +2,6 @@
// The Microsoft Corporation licenses this file to you under the MIT license. // The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information. // See the LICENSE file in the project root for more information.
namespace PowerToys.FileLocksmithUI.Converters
{
using System; using System;
using System.Drawing; using System.Drawing;
using System.IO; using System.IO;
@@ -12,6 +10,8 @@ namespace PowerToys.FileLocksmithUI.Converters
using Microsoft.UI.Xaml.Media.Imaging; using Microsoft.UI.Xaml.Media.Imaging;
using Windows.Storage; using Windows.Storage;
namespace PowerToys.FileLocksmithUI.Converters
{
public sealed class PidToIconConverter : IValueConverter public sealed class PidToIconConverter : IValueConverter
{ {
public object Convert(object value, Type targetType, object parameter, string language) public object Convert(object value, Type targetType, object parameter, string language)

View File

@@ -2,14 +2,14 @@
// The Microsoft Corporation licenses this file to you under the MIT license. // The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information. // See the LICENSE file in the project root for more information.
namespace PowerToys.FileLocksmithUI.Converters
{
using System; using System;
using System.Globalization; using System.Globalization;
using FileLocksmith.Interop; using FileLocksmith.Interop;
using Microsoft.UI.Xaml; using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Data; using Microsoft.UI.Xaml.Data;
namespace PowerToys.FileLocksmithUI.Converters
{
public sealed class UserToSystemWarningVisibilityConverter : IValueConverter public sealed class UserToSystemWarningVisibilityConverter : IValueConverter
{ {
public object Convert(object value, Type targetType, object parameter, string language) public object Convert(object value, Type targetType, object parameter, string language)

View File

@@ -2,8 +2,6 @@
// The Microsoft Corporation licenses this file to you under the MIT license. // The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information. // See the LICENSE file in the project root for more information.
namespace PowerToys.FileLocksmithUI.ViewModels
{
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
@@ -14,11 +12,10 @@ namespace PowerToys.FileLocksmithUI.ViewModels
using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input; using CommunityToolkit.Mvvm.Input;
using FileLocksmith.Interop; using FileLocksmith.Interop;
using global::FileLocksmithUI;
using global::FileLocksmithUI.Helpers; using global::FileLocksmithUI.Helpers;
using Microsoft.UI.Dispatching;
using Microsoft.UI.Xaml.Controls;
namespace PowerToys.FileLocksmithUI.ViewModels
{
#pragma warning disable CA1708 // Identifiers should differ by more than case #pragma warning disable CA1708 // Identifiers should differ by more than case
public partial class MainViewModel : ObservableObject, IDisposable public partial class MainViewModel : ObservableObject, IDisposable
#pragma warning restore CA1708 // Identifiers should differ by more than case #pragma warning restore CA1708 // Identifiers should differ by more than case

View File

@@ -2,12 +2,12 @@
// The Microsoft Corporation licenses this file to you under the MIT license. // The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information. // See the LICENSE file in the project root for more information.
namespace PowerToys.FileLocksmithUI.Views
{
using System; using System;
using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Controls;
using PowerToys.FileLocksmithUI.ViewModels; using PowerToys.FileLocksmithUI.ViewModels;
namespace PowerToys.FileLocksmithUI.Views
{
public sealed partial class MainPage : Page public sealed partial class MainPage : Page
{ {
public MainViewModel ViewModel { get; private set; } public MainViewModel ViewModel { get; private set; }

View File

@@ -2,11 +2,11 @@
// The Microsoft Corporation licenses this file to you under the MIT license. // The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information. // See the LICENSE file in the project root for more information.
namespace Hosts.Helpers
{
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
namespace Hosts.Helpers
{
internal class NativeMethods internal class NativeMethods
{ {
[DllImport("user32.dll", SetLastError = true)] [DllImport("user32.dll", SetLastError = true)]

View File

@@ -13,11 +13,10 @@ using Microsoft.UI.Xaml.Controls.Primitives;
using Microsoft.UI.Xaml.Input; using Microsoft.UI.Xaml.Input;
using Windows.Graphics; using Windows.Graphics;
using WinUIEx; using WinUIEx;
using static NativeMethods;
namespace MeasureToolUI namespace MeasureToolUI
{ {
using static NativeMethods;
/// <summary> /// <summary>
/// An empty window that can be used on its own or navigated to within a Frame. /// An empty window that can be used on its own or navigated to within a Frame.
/// </summary> /// </summary>

View File

@@ -57,7 +57,8 @@ namespace Awake.Core
_log.Error($"An error occurred initializing the tray. {ex.Message}"); _log.Error($"An error occurred initializing the tray. {ex.Message}");
_log.Error($"{ex.StackTrace}"); _log.Error($"{ex.StackTrace}");
} }
}, TrayIcon); },
TrayIcon);
} }
/// <summary> /// <summary>

View File

@@ -49,8 +49,10 @@ namespace ColorPicker.Behaviors
DragDrop.DoDragDrop(sender as DependencyObject, data, DragDropEffects.Move); DragDrop.DoDragDrop(sender as DependencyObject, data, DragDropEffects.Move);
e.Handled = true; e.Handled = true;
} }
}), null); }),
}), CancellationToken.None); null);
}),
CancellationToken.None);
} }
} }

View File

@@ -103,28 +103,28 @@ namespace ColorPicker.Controls
HueGradientSlider.Background = gradientBrush; HueGradientSlider.Background = gradientBrush;
} }
private static void SetColorVariationsForCurrentColor(DependencyObject d, (double hue, double saturation, double value) hsv) private static void SetColorVariationsForCurrentColor(DependencyObject d, (double Hue, double Saturation, double Value) hsv)
{ {
var hueCoefficient = 0; var hueCoefficient = 0;
var hueCoefficient2 = 0; var hueCoefficient2 = 0;
if (1 - hsv.value < 0.15) if (1 - hsv.Value < 0.15)
{ {
hueCoefficient = 1; hueCoefficient = 1;
} }
if (hsv.value - 0.3 < 0) if (hsv.Value - 0.3 < 0)
{ {
hueCoefficient2 = 1; hueCoefficient2 = 1;
} }
var s = hsv.saturation; var s = hsv.Saturation;
var control = (ColorPickerControl)d; var control = (ColorPickerControl)d;
control.colorVariation1Button.Background = new SolidColorBrush(HSVColor.RGBFromHSV(Math.Min(hsv.hue + (hueCoefficient * 8), 360), s, Math.Min(hsv.value + 0.3, 1))); control.colorVariation1Button.Background = new SolidColorBrush(HSVColor.RGBFromHSV(Math.Min(hsv.Hue + (hueCoefficient * 8), 360), s, Math.Min(hsv.Value + 0.3, 1)));
control.colorVariation2Button.Background = new SolidColorBrush(HSVColor.RGBFromHSV(Math.Min(hsv.hue + (hueCoefficient * 4), 360), s, Math.Min(hsv.value + 0.15, 1))); control.colorVariation2Button.Background = new SolidColorBrush(HSVColor.RGBFromHSV(Math.Min(hsv.Hue + (hueCoefficient * 4), 360), s, Math.Min(hsv.Value + 0.15, 1)));
control.colorVariation3Button.Background = new SolidColorBrush(HSVColor.RGBFromHSV(Math.Max(hsv.hue - (hueCoefficient2 * 4), 0), s, Math.Max(hsv.value - 0.2, 0))); control.colorVariation3Button.Background = new SolidColorBrush(HSVColor.RGBFromHSV(Math.Max(hsv.Hue - (hueCoefficient2 * 4), 0), s, Math.Max(hsv.Value - 0.2, 0)));
control.colorVariation4Button.Background = new SolidColorBrush(HSVColor.RGBFromHSV(Math.Max(hsv.hue - (hueCoefficient2 * 8), 0), s, Math.Max(hsv.value - 0.3, 0))); control.colorVariation4Button.Background = new SolidColorBrush(HSVColor.RGBFromHSV(Math.Max(hsv.Hue - (hueCoefficient2 * 8), 0), s, Math.Max(hsv.Value - 0.3, 0)));
} }
private void UpdateValueColorGradient(double posX) private void UpdateValueColorGradient(double posX)
@@ -312,9 +312,9 @@ namespace ColorPicker.Controls
{ {
var hsv = ColorFormatHelper.ConvertToHSVColor(color); var hsv = ColorFormatHelper.ConvertToHSVColor(color);
var huePosition = (hsv.hue / 360) * HueGradientSlider.Maximum; var huePosition = (hsv.Hue / 360) * HueGradientSlider.Maximum;
var saturationPosition = hsv.saturation * SaturationGradientSlider.Maximum; var saturationPosition = hsv.Saturation * SaturationGradientSlider.Maximum;
var valuePosition = hsv.value * ValueGradientSlider.Maximum; var valuePosition = hsv.Value * ValueGradientSlider.Maximum;
UpdateHueColorGradient(huePosition); UpdateHueColorGradient(huePosition);
UpdateSaturationColorGradient(saturationPosition); UpdateSaturationColorGradient(saturationPosition);
UpdateValueColorGradient(valuePosition); UpdateValueColorGradient(valuePosition);

View File

@@ -2,7 +2,6 @@
// The Microsoft Corporation licenses this file to you under the MIT license. // The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information. // See the LICENSE file in the project root for more information.
using System;
using System.Drawing; using System.Drawing;
namespace ColorPicker.Helpers namespace ColorPicker.Helpers
@@ -17,7 +16,7 @@ namespace ColorPicker.Helpers
/// </summary> /// </summary>
/// <param name="color">The <see cref="Color"/> to convert</param> /// <param name="color">The <see cref="Color"/> to convert</param>
/// <returns>The int / 255d for each value to get value between 0 and 1</returns> /// <returns>The int / 255d for each value to get value between 0 and 1</returns>
internal static (double red, double green, double blue) ConvertToDouble(Color color) internal static (double Red, double Green, double Blue) ConvertToDouble(Color color)
=> (color.R / 255d, color.G / 255d, color.B / 255d); => (color.R / 255d, color.G / 255d, color.B / 255d);
} }
} }

View File

@@ -189,7 +189,7 @@ namespace ColorPicker.ViewModels
{ {
".TXT" => colors.ToTxt(';'), ".TXT" => colors.ToTxt(';'),
".JSON" => colors.ToJson(), ".JSON" => colors.ToJson(),
_ => string.Empty _ => string.Empty,
}; };
File.WriteAllText(dialog.FileName, contentToWrite); File.WriteAllText(dialog.FileName, contentToWrite);

View File

@@ -5,7 +5,6 @@
using System; using System;
using System.Drawing; using System.Drawing;
using System.Globalization; using System.Globalization;
using ColorPicker.Helpers;
using ManagedCommon; using ManagedCommon;
using Microsoft.VisualStudio.TestTools.UnitTesting; using Microsoft.VisualStudio.TestTools.UnitTesting;
@@ -57,13 +56,13 @@ namespace Microsoft.ColorPicker.UnitTests
var result = ColorFormatHelper.ConvertToHSLColor(color); var result = ColorFormatHelper.ConvertToHSLColor(color);
// hue[0°..360°] // hue[0°..360°]
Assert.AreEqual(result.hue, hue, 0.2d); Assert.AreEqual(result.Hue, hue, 0.2d);
// saturation[0..1] // saturation[0..1]
Assert.AreEqual(result.saturation * 100d, saturation, 0.2d); Assert.AreEqual(result.Saturation * 100d, saturation, 0.2d);
// lightness[0..1] // lightness[0..1]
Assert.AreEqual(result.lightness * 100d, lightness, 0.2d); Assert.AreEqual(result.Lightness * 100d, lightness, 0.2d);
} }
// test values taken from https://de.wikipedia.org/wiki/HSV-Farbraum // test values taken from https://de.wikipedia.org/wiki/HSV-Farbraum
@@ -106,13 +105,13 @@ namespace Microsoft.ColorPicker.UnitTests
var result = ColorFormatHelper.ConvertToHSVColor(color); var result = ColorFormatHelper.ConvertToHSVColor(color);
// hue [0°..360°] // hue [0°..360°]
Assert.AreEqual(result.hue, hue, 0.2d); Assert.AreEqual(result.Hue, hue, 0.2d);
// saturation[0..1] // saturation[0..1]
Assert.AreEqual(result.saturation * 100d, saturation, 0.2d); Assert.AreEqual(result.Saturation * 100d, saturation, 0.2d);
// value[0..1] // value[0..1]
Assert.AreEqual(result.value * 100d, value, 0.2d); Assert.AreEqual(result.Value * 100d, value, 0.2d);
} }
// test values taken from https://de.wikipedia.org/wiki/HSV-Farbraum // test values taken from https://de.wikipedia.org/wiki/HSV-Farbraum
@@ -155,13 +154,13 @@ namespace Microsoft.ColorPicker.UnitTests
var result = ColorFormatHelper.ConvertToHSBColor(color); var result = ColorFormatHelper.ConvertToHSBColor(color);
// hue [0°..360°] // hue [0°..360°]
Assert.AreEqual(result.hue, hue, 0.2d); Assert.AreEqual(result.Hue, hue, 0.2d);
// saturation[0..1] // saturation[0..1]
Assert.AreEqual(result.saturation * 100d, saturation, 0.2d); Assert.AreEqual(result.Saturation * 100d, saturation, 0.2d);
// value[0..1] // value[0..1]
Assert.AreEqual(result.brightness * 100d, value, 0.2d); Assert.AreEqual(result.Brightness * 100d, value, 0.2d);
} }
[TestMethod] [TestMethod]
@@ -199,16 +198,16 @@ namespace Microsoft.ColorPicker.UnitTests
var result = ColorFormatHelper.ConvertToCMYKColor(color); var result = ColorFormatHelper.ConvertToCMYKColor(color);
// cyan[0..1] // cyan[0..1]
Assert.AreEqual(result.cyan * 100d, cyan, 0.5d); Assert.AreEqual(result.Cyan * 100d, cyan, 0.5d);
// magenta[0..1] // magenta[0..1]
Assert.AreEqual(result.magenta * 100d, magenta, 0.5d); Assert.AreEqual(result.Magenta * 100d, magenta, 0.5d);
// yellow[0..1] // yellow[0..1]
Assert.AreEqual(result.yellow * 100d, yellow, 0.5d); Assert.AreEqual(result.Yellow * 100d, yellow, 0.5d);
// black[0..1] // black[0..1]
Assert.AreEqual(result.blackKey * 100d, blackKey, 0.5d); Assert.AreEqual(result.BlackKey * 100d, blackKey, 0.5d);
} }
// values taken from https://en.wikipedia.org/wiki/HSL_and_HSV#Examples // values taken from https://en.wikipedia.org/wiki/HSL_and_HSV#Examples
@@ -249,13 +248,13 @@ namespace Microsoft.ColorPicker.UnitTests
var result = ColorFormatHelper.ConvertToHSIColor(color); var result = ColorFormatHelper.ConvertToHSIColor(color);
// hue[0°..360°] // hue[0°..360°]
Assert.AreEqual(result.hue, hue, 0.5d); Assert.AreEqual(result.Hue, hue, 0.5d);
// saturation[0..1] // saturation[0..1]
Assert.AreEqual(result.saturation * 100d, saturation, 0.5d); Assert.AreEqual(result.Saturation * 100d, saturation, 0.5d);
// intensity[0..1] // intensity[0..1]
Assert.AreEqual(result.intensity * 100d, intensity, 0.5d); Assert.AreEqual(result.Intensity * 100d, intensity, 0.5d);
} }
// values taken from https://en.wikipedia.org/wiki/HSL_and_HSV#Examples // values taken from https://en.wikipedia.org/wiki/HSL_and_HSV#Examples
@@ -297,13 +296,13 @@ namespace Microsoft.ColorPicker.UnitTests
var result = ColorFormatHelper.ConvertToHWBColor(color); var result = ColorFormatHelper.ConvertToHWBColor(color);
// hue[0°..360°] // hue[0°..360°]
Assert.AreEqual(result.hue, hue, 0.5d); Assert.AreEqual(result.Hue, hue, 0.5d);
// whiteness[0..1] // whiteness[0..1]
Assert.AreEqual(result.whiteness * 100d, whiteness, 0.5d); Assert.AreEqual(result.Whiteness * 100d, whiteness, 0.5d);
// blackness[0..1] // blackness[0..1]
Assert.AreEqual(result.blackness * 100d, blackness, 0.5d); Assert.AreEqual(result.Blackness * 100d, blackness, 0.5d);
} }
// values taken from https://en.wikipedia.org/wiki/HSL_and_HSV#Examples // values taken from https://en.wikipedia.org/wiki/HSL_and_HSV#Examples
@@ -345,13 +344,13 @@ namespace Microsoft.ColorPicker.UnitTests
var result = ColorFormatHelper.ConvertToNaturalColor(color); var result = ColorFormatHelper.ConvertToNaturalColor(color);
// hue // hue
Assert.AreEqual(result.hue, hue); Assert.AreEqual(result.Hue, hue);
// whiteness[0..1] // whiteness[0..1]
Assert.AreEqual(result.whiteness * 100d, whiteness, 0.5d); Assert.AreEqual(result.Whiteness * 100d, whiteness, 0.5d);
// blackness[0..1] // blackness[0..1]
Assert.AreEqual(result.blackness * 100d, blackness, 0.5d); Assert.AreEqual(result.Blackness * 100d, blackness, 0.5d);
} }
[TestMethod] [TestMethod]
@@ -401,13 +400,13 @@ namespace Microsoft.ColorPicker.UnitTests
var result = ColorFormatHelper.ConvertToCIELABColor(color); var result = ColorFormatHelper.ConvertToCIELABColor(color);
// lightness[0..100] // lightness[0..100]
Assert.AreEqual(Math.Round(result.lightness, 2), lightness); Assert.AreEqual(Math.Round(result.Lightness, 2), lightness);
// chromaticityA[-128..127] // chromaticityA[-128..127]
Assert.AreEqual(Math.Round(result.chromaticityA, 2), chromaticityA); Assert.AreEqual(Math.Round(result.ChromaticityA, 2), chromaticityA);
// chromaticityB[-128..127] // chromaticityB[-128..127]
Assert.AreEqual(Math.Round(result.chromaticityB, 2), chromaticityB); Assert.AreEqual(Math.Round(result.ChromaticityB, 2), chromaticityB);
} }
// The following results are computed using LittleCMS2, an open-source color management engine, // The following results are computed using LittleCMS2, an open-source color management engine,
@@ -465,13 +464,13 @@ namespace Microsoft.ColorPicker.UnitTests
var result = ColorFormatHelper.ConvertToCIEXYZColor(color); var result = ColorFormatHelper.ConvertToCIEXYZColor(color);
// x[0..0.95047] // x[0..0.95047]
Assert.AreEqual(Math.Round(result.x * 100, 4), x); Assert.AreEqual(Math.Round(result.X * 100, 4), x);
// y[0..1] // y[0..1]
Assert.AreEqual(Math.Round(result.y * 100, 4), y); Assert.AreEqual(Math.Round(result.Y * 100, 4), y);
// z[0..1.08883] // z[0..1.08883]
Assert.AreEqual(Math.Round(result.z * 100, 4), z); Assert.AreEqual(Math.Round(result.Z * 100, 4), z);
} }
[TestMethod] [TestMethod]

View File

@@ -2,11 +2,11 @@
// The Microsoft Corporation licenses this file to you under the MIT license. // The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information. // See the LICENSE file in the project root for more information.
namespace FancyZonesEditor.Controls
{
using System.Windows.Automation.Peers; using System.Windows.Automation.Peers;
using System.Windows.Controls; using System.Windows.Controls;
namespace FancyZonesEditor.Controls
{
/// <summary> /// <summary>
/// Interaction logic for CustomSlider.xaml /// Interaction logic for CustomSlider.xaml
/// </summary> /// </summary>

View File

@@ -2,12 +2,12 @@
// The Microsoft Corporation licenses this file to you under the MIT license. // The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information. // See the LICENSE file in the project root for more information.
namespace FancyZonesEditor.Controls
{
using System.Globalization; using System.Globalization;
using System.Windows.Automation.Peers; using System.Windows.Automation.Peers;
using System.Windows.Controls; using System.Windows.Controls;
namespace FancyZonesEditor.Controls
{
internal class CustomSliderAutomationPeer : SliderAutomationPeer internal class CustomSliderAutomationPeer : SliderAutomationPeer
{ {
private string name = string.Empty; private string name = string.Empty;

View File

@@ -86,7 +86,7 @@ namespace ImageResizer.Models
var batch = CreateBatch(_ => { }); var batch = CreateBatch(_ => { });
batch.Files.Add("Image1.jpg"); batch.Files.Add("Image1.jpg");
batch.Files.Add("Image2.jpg"); batch.Files.Add("Image2.jpg");
var calls = new ConcurrentBag<(int i, double count)>(); var calls = new ConcurrentBag<(int I, double Count)>();
batch.Process( batch.Process(
(i, count) => calls.Add((i, count)), (i, count) => calls.Add((i, count)),

View File

@@ -111,9 +111,9 @@ namespace ImageResizer.Extensions
/// <returns> /// <returns>
/// metadata path and metadata value of all successfully read data items. /// metadata path and metadata value of all successfully read data items.
/// </returns> /// </returns>
public static List<(string metadataPath, object value)> GetListOfMetadata(this BitmapMetadata metadata) public static List<(string MetadataPath, object Value)> GetListOfMetadata(this BitmapMetadata metadata)
{ {
var listOfAllMetadata = new List<(string metadataPath, object value)>(); var listOfAllMetadata = new List<(string MetadataPath, object Value)>();
try try
{ {
@@ -196,7 +196,7 @@ namespace ImageResizer.Extensions
foreach (var metadataItem in listOfMetadata) foreach (var metadataItem in listOfMetadata)
{ {
// Debug.WriteLine($"modifiableMetadata.RemoveQuerySafe(\"{metadataItem.metadataPath}\");"); // Debug.WriteLine($"modifiableMetadata.RemoveQuerySafe(\"{metadataItem.metadataPath}\");");
Debug.WriteLine($"{metadataItem.metadataPath} | {metadataItem.value}"); Debug.WriteLine($"{metadataItem.MetadataPath} | {metadataItem.Value}");
} }
} }
@@ -207,9 +207,9 @@ namespace ImageResizer.Extensions
/// <remarks> /// <remarks>
/// Intented for debug only!!! /// Intented for debug only!!!
/// </remarks> /// </remarks>
public static List<(string metadataPath, object value)> GetListOfMetadataForDebug(this BitmapMetadata metadata) public static List<(string MetadataPath, object Value)> GetListOfMetadataForDebug(this BitmapMetadata metadata)
{ {
var listOfAllMetadata = new List<(string metadataPath, object value)>(); var listOfAllMetadata = new List<(string MetadataPath, object Value)>();
try try
{ {

View File

@@ -2,10 +2,10 @@
// The Microsoft Corporation licenses this file to you under the MIT license. // The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information. // See the LICENSE file in the project root for more information.
namespace Microsoft.Plugin.Folder
{
using Wox.Plugin.Interfaces; using Wox.Plugin.Interfaces;
namespace Microsoft.Plugin.Folder
{
public class SearchResult : IFileDropResult public class SearchResult : IFileDropResult
{ {
public string Path { get; set; } public string Path { get; set; }

View File

@@ -44,7 +44,7 @@ namespace Microsoft.Plugin.Folder.Sources
return query.Any(c => c.Equals('>')); return query.Any(c => c.Equals('>'));
} }
private (string search, string incompleteName) Process(string search) private (string Search, string IncompleteName) Process(string search)
{ {
string incompleteName = string.Empty; string incompleteName = string.Empty;
if (HasSpecialChars(search) || !_directory.Exists($@"{search}\")) if (HasSpecialChars(search) || !_directory.Exists($@"{search}\"))

View File

@@ -2,10 +2,10 @@
// The Microsoft Corporation licenses this file to you under the MIT license. // The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information. // See the LICENSE file in the project root for more information.
namespace Microsoft.Plugin.Indexer.SearchHelper
{
using Wox.Plugin.Interfaces; using Wox.Plugin.Interfaces;
namespace Microsoft.Plugin.Indexer.SearchHelper
{
public class SearchResult : IFileDropResult public class SearchResult : IFileDropResult
{ {
// Contains the Path of the file or folder // Contains the Path of the file or folder

View File

@@ -53,7 +53,7 @@ namespace Microsoft.PowerToys.Run.Plugin.Calculator
return !trailTest.Any(); return !trailTest.Any();
} }
private static (TrailDirection direction, TrailType type) BracketTrail(char @char) private static (TrailDirection Direction, TrailType Type) BracketTrail(char @char)
{ {
switch (@char) switch (@char)
{ {

View File

@@ -19,7 +19,8 @@ namespace Microsoft.PowerToys.Run.Plugin.Calculator
@"pi|" + @"pi|" +
@"==|~=|&&|\|\||" + @"==|~=|&&|\|\||" +
@"e|[0-9]|0x[0-9a-fA-F]+|0b[01]+|[\+\-\*\/\^\., ""]|[\(\)\|\!\[\]]" + @"e|[0-9]|0x[0-9a-fA-F]+|0b[01]+|[\+\-\*\/\^\., ""]|[\(\)\|\!\[\]]" +
@")+$", RegexOptions.Compiled); @")+$",
RegexOptions.Compiled);
public static bool InputValid(string input) public static bool InputValid(string input)
{ {

View File

@@ -42,7 +42,7 @@ namespace Microsoft.PowerToys.Run.Plugin.Registry.Helper
/// </summary> /// </summary>
/// <param name="query">The query to search</param> /// <param name="query">The query to search</param>
/// <returns>A combination of a list of base <see cref="RegistryKey"/> and the sub keys</returns> /// <returns>A combination of a list of base <see cref="RegistryKey"/> and the sub keys</returns>
internal static (IEnumerable<RegistryKey>? baseKey, string subKey) GetRegistryBaseKey(in string query) internal static (IEnumerable<RegistryKey>? BaseKey, string SubKey) GetRegistryBaseKey(in string query)
{ {
if (string.IsNullOrWhiteSpace(query)) if (string.IsNullOrWhiteSpace(query))
{ {

View File

@@ -2,8 +2,6 @@
// The Microsoft Corporation licenses this file to you under the MIT license. // The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information. // See the LICENSE file in the project root for more information.
namespace PowerLauncher.Helper
{
using System; using System;
using System.Drawing; using System.Drawing;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
@@ -11,6 +9,8 @@ namespace PowerLauncher.Helper
using DrawingImaging = System.Drawing.Imaging; using DrawingImaging = System.Drawing.Imaging;
using MediaImaging = System.Windows.Media.Imaging; using MediaImaging = System.Windows.Media.Imaging;
namespace PowerLauncher.Helper
{
// based on: https://stackoverflow.com/questions/61041282/showing-image-thumbnail-with-mouse-cursor-while-dragging/61148788#61148788 // based on: https://stackoverflow.com/questions/61041282/showing-image-thumbnail-with-mouse-cursor-while-dragging/61148788#61148788
public static class DragDataObject public static class DragDataObject
{ {

View File

@@ -156,7 +156,8 @@ namespace PowerLauncher.ViewModel
{ {
PluginManager.UpdatePluginMetadata(e.Results, pair.Metadata, e.Query); PluginManager.UpdatePluginMetadata(e.Results, pair.Metadata, e.Query);
UpdateResultView(e.Results, e.Query.RawQuery, _updateToken); UpdateResultView(e.Results, e.Query.RawQuery, _updateToken);
}, _updateToken); },
_updateToken);
}; };
} }
} }
@@ -698,7 +699,8 @@ namespace PowerLauncher.ViewModel
QueryLength = queryText.Length, QueryLength = queryText.Length,
}; };
PowerToysTelemetry.Log.WriteEvent(queryEvent); PowerToysTelemetry.Log.WriteEvent(queryEvent);
}, currentCancellationToken); },
currentCancellationToken);
if (doFinalSort) if (doFinalSort)
{ {

View File

@@ -2,12 +2,12 @@
// The Microsoft Corporation licenses this file to you under the MIT license. // The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information. // See the LICENSE file in the project root for more information.
namespace PowerAccent.Core
{
using System; using System;
using PowerToys.PowerAccentKeyboardService; using PowerToys.PowerAccentKeyboardService;
using Windows.Globalization; using Windows.Globalization;
namespace PowerAccent.Core
{
public enum Language public enum Language
{ {
ALL, ALL,

View File

@@ -100,7 +100,8 @@ public class PowerAccent : IDisposable
{ {
OnChangeDisplay?.Invoke(true, _characters); OnChangeDisplay?.Invoke(true, _characters);
} }
}, TaskScheduler.FromCurrentSynchronizationContext()); },
TaskScheduler.FromCurrentSynchronizationContext());
} }
private string GetCharacterDescription(string character) private string GetCharacterDescription(string character)

View File

@@ -2,16 +2,14 @@
// The Microsoft Corporation licenses this file to you under the MIT license. // The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information. // See the LICENSE file in the project root for more information.
namespace PowerAccent.Core.Services; using System.IO.Abstractions;
using System.Text.Json;
using Microsoft.PowerToys.Settings.UI.Library; using Microsoft.PowerToys.Settings.UI.Library;
using Microsoft.PowerToys.Settings.UI.Library.Enumerations; using Microsoft.PowerToys.Settings.UI.Library.Enumerations;
using Microsoft.PowerToys.Settings.UI.Library.Utilities; using Microsoft.PowerToys.Settings.UI.Library.Utilities;
using PowerToys.PowerAccentKeyboardService; using PowerToys.PowerAccentKeyboardService;
using System.IO.Abstractions;
using System.Text.Json;
using static Vanara.PInvoke.LANGID;
namespace PowerAccent.Core.Services;
public class SettingsService public class SettingsService
{ {
private const string PowerAccentModuleName = "QuickAccent"; private const string PowerAccentModuleName = "QuickAccent";

View File

@@ -41,7 +41,7 @@ internal static class WindowsFunctions
public static Point GetCaretPosition() public static Point GetCaretPosition()
{ {
User32.GUITHREADINFO guiInfo = new (); User32.GUITHREADINFO guiInfo = default;
guiInfo.cbSize = (uint)Marshal.SizeOf(guiInfo); guiInfo.cbSize = (uint)Marshal.SizeOf(guiInfo);
User32.GetGUIThreadInfo(0, ref guiInfo); User32.GetGUIThreadInfo(0, ref guiInfo);
POINT caretPosition = new POINT(guiInfo.rcCaret.left, guiInfo.rcCaret.top); POINT caretPosition = new POINT(guiInfo.rcCaret.left, guiInfo.rcCaret.top);
@@ -59,12 +59,12 @@ internal static class WindowsFunctions
public static (Point Location, Size Size, double Dpi) GetActiveDisplay() public static (Point Location, Size Size, double Dpi) GetActiveDisplay()
{ {
User32.GUITHREADINFO guiInfo = new (); User32.GUITHREADINFO guiInfo = default;
guiInfo.cbSize = (uint)Marshal.SizeOf(guiInfo); guiInfo.cbSize = (uint)Marshal.SizeOf(guiInfo);
User32.GetGUIThreadInfo(0, ref guiInfo); User32.GetGUIThreadInfo(0, ref guiInfo);
var res = User32.MonitorFromWindow(guiInfo.hwndActive, User32.MonitorFlags.MONITOR_DEFAULTTONEAREST); var res = User32.MonitorFromWindow(guiInfo.hwndActive, User32.MonitorFlags.MONITOR_DEFAULTTONEAREST);
User32.MONITORINFO monitorInfo = new (); User32.MONITORINFO monitorInfo = default;
monitorInfo.cbSize = (uint)Marshal.SizeOf(monitorInfo); monitorInfo.cbSize = (uint)Marshal.SizeOf(monitorInfo);
User32.GetMonitorInfo(res, ref monitorInfo); User32.GetMonitorInfo(res, ref monitorInfo);

View File

@@ -47,7 +47,8 @@ internal static class Program
{ {
Terminate(); Terminate();
} }
}, _tokenSource.Token); },
_tokenSource.Token);
} }
private static void Arguments(string[] args) private static void Arguments(string[] args)

View File

@@ -97,7 +97,7 @@ public partial class Selector : Window, IDisposable, INotifyPropertyChanged
Position.Left or Position.TopLeft or Position.BottomLeft => HorizontalAlignment.Left, Position.Left or Position.TopLeft or Position.BottomLeft => HorizontalAlignment.Left,
Position.Right or Position.TopRight or Position.BottomRight => HorizontalAlignment.Right, Position.Right or Position.TopRight or Position.BottomRight => HorizontalAlignment.Right,
Position.Center or Position.Top or Position.Bottom => HorizontalAlignment.Center, Position.Center or Position.Top or Position.Bottom => HorizontalAlignment.Center,
_ => HorizontalAlignment.Center _ => HorizontalAlignment.Center,
}; };
} }

View File

@@ -2,13 +2,13 @@
// The Microsoft Corporation licenses this file to you under the MIT license. // The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information. // See the LICENSE file in the project root for more information.
namespace Microsoft.PowerToys.PreviewHandler.Gcode
{
using System.Globalization; using System.Globalization;
using System.Windows.Threading; using System.Windows.Threading;
using Common.UI; using Common.UI;
using interop; using interop;
namespace Microsoft.PowerToys.PreviewHandler.Gcode
{
internal static class Program internal static class Program
{ {
private static CancellationTokenSource _tokenSource = new CancellationTokenSource(); private static CancellationTokenSource _tokenSource = new CancellationTokenSource();

View File

@@ -2,10 +2,10 @@
// The Microsoft Corporation licenses this file to you under the MIT license. // The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information. // See the LICENSE file in the project root for more information.
namespace Microsoft.PowerToys.ThumbnailHandler.Gcode
{
using System.Globalization; using System.Globalization;
namespace Microsoft.PowerToys.ThumbnailHandler.Gcode
{
internal static class Program internal static class Program
{ {
private static GcodeThumbnailProvider _thumbnailProvider; private static GcodeThumbnailProvider _thumbnailProvider;

View File

@@ -2,13 +2,13 @@
// The Microsoft Corporation licenses this file to you under the MIT license. // The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information. // See the LICENSE file in the project root for more information.
namespace Microsoft.PowerToys.PreviewHandler.Markdown
{
using System.Globalization; using System.Globalization;
using System.Windows.Threading; using System.Windows.Threading;
using Common.UI; using Common.UI;
using interop; using interop;
namespace Microsoft.PowerToys.PreviewHandler.Markdown
{
internal static class Program internal static class Program
{ {
private static CancellationTokenSource _tokenSource = new CancellationTokenSource(); private static CancellationTokenSource _tokenSource = new CancellationTokenSource();

View File

@@ -2,10 +2,10 @@
// The Microsoft Corporation licenses this file to you under the MIT license. // The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information. // See the LICENSE file in the project root for more information.
namespace Microsoft.PowerToys.PreviewHandler.Monaco.Formatters
{
using System.Text.Json; using System.Text.Json;
namespace Microsoft.PowerToys.PreviewHandler.Monaco.Formatters
{
public class JsonFormatter : IFormatter public class JsonFormatter : IFormatter
{ {
/// <inheritdoc/> /// <inheritdoc/>

View File

@@ -2,11 +2,11 @@
// The Microsoft Corporation licenses this file to you under the MIT license. // The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information. // See the LICENSE file in the project root for more information.
namespace Microsoft.PowerToys.PreviewHandler.Monaco.Formatters
{
using System.Text; using System.Text;
using System.Xml; using System.Xml;
namespace Microsoft.PowerToys.PreviewHandler.Monaco.Formatters
{
public class XmlFormatter : IFormatter public class XmlFormatter : IFormatter
{ {
/// <inheritdoc/> /// <inheritdoc/>

View File

@@ -2,13 +2,13 @@
// The Microsoft Corporation licenses this file to you under the MIT license. // The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information. // See the LICENSE file in the project root for more information.
namespace Microsoft.PowerToys.PreviewHandler.Monaco
{
using System.Globalization; using System.Globalization;
using System.Windows.Threading; using System.Windows.Threading;
using Common.UI; using Common.UI;
using interop; using interop;
namespace Microsoft.PowerToys.PreviewHandler.Monaco
{
internal static class Program internal static class Program
{ {
private static CancellationTokenSource _tokenSource = new CancellationTokenSource(); private static CancellationTokenSource _tokenSource = new CancellationTokenSource();

View File

@@ -1,14 +1,13 @@
// Copyright (c) Microsoft Corporation // Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license. // The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information. // See the LICENSE file in the project root for more information.
namespace Microsoft.PowerToys.PreviewHandler.Pdf
{
using System.Globalization; using System.Globalization;
using System.Windows.Threading; using System.Windows.Threading;
using Common.UI; using Common.UI;
using interop; using interop;
namespace Microsoft.PowerToys.PreviewHandler.Pdf
{
internal static class Program internal static class Program
{ {
private static CancellationTokenSource _tokenSource = new CancellationTokenSource(); private static CancellationTokenSource _tokenSource = new CancellationTokenSource();

View File

@@ -2,10 +2,10 @@
// The Microsoft Corporation licenses this file to you under the MIT license. // The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information. // See the LICENSE file in the project root for more information.
namespace Microsoft.PowerToys.ThumbnailHandler.Pdf
{
using System.Globalization; using System.Globalization;
namespace Microsoft.PowerToys.ThumbnailHandler.Pdf
{
internal static class Program internal static class Program
{ {
private static PdfThumbnailProvider _thumbnailProvider; private static PdfThumbnailProvider _thumbnailProvider;

View File

@@ -1,11 +1,10 @@
// Copyright (c) Microsoft Corporation // Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license. // The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information. // See the LICENSE file in the project root for more information.
using System.Globalization;
namespace Microsoft.PowerToys.ThumbnailHandler.Stl namespace Microsoft.PowerToys.ThumbnailHandler.Stl
{ {
using System.Globalization;
internal static class Program internal static class Program
{ {
private static StlThumbnailProvider _thumbnailProvider; private static StlThumbnailProvider _thumbnailProvider;

View File

@@ -2,13 +2,13 @@
// The Microsoft Corporation licenses this file to you under the MIT license. // The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information. // See the LICENSE file in the project root for more information.
namespace Microsoft.PowerToys.PreviewHandler.Svg
{
using System.Globalization; using System.Globalization;
using System.Windows.Threading; using System.Windows.Threading;
using Common.UI; using Common.UI;
using interop; using interop;
namespace Microsoft.PowerToys.PreviewHandler.Svg
{
internal static class Program internal static class Program
{ {
private static CancellationTokenSource _tokenSource = new CancellationTokenSource(); private static CancellationTokenSource _tokenSource = new CancellationTokenSource();

View File

@@ -2,10 +2,10 @@
// The Microsoft Corporation licenses this file to you under the MIT license. // The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information. // See the LICENSE file in the project root for more information.
namespace Microsoft.PowerToys.ThumbnailHandler.Svg
{
using System.Globalization; using System.Globalization;
namespace Microsoft.PowerToys.ThumbnailHandler.Svg
{
internal static class Program internal static class Program
{ {
private static SvgThumbnailProvider _thumbnailProvider; private static SvgThumbnailProvider _thumbnailProvider;

View File

@@ -22,7 +22,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library
public class SettingsBackupAndRestoreUtils public class SettingsBackupAndRestoreUtils
{ {
private static SettingsBackupAndRestoreUtils instance; private static SettingsBackupAndRestoreUtils instance;
private (bool success, string severity, bool lastBackupExists, DateTime? lastRan) lastBackupSettingsResults; private (bool Success, string Severity, bool LastBackupExists, DateTime? LastRan) lastBackupSettingsResults;
private static object backupSettingsInternalLock = new object(); private static object backupSettingsInternalLock = new object();
private static object removeOldBackupsLock = new object(); private static object removeOldBackupsLock = new object();
@@ -262,7 +262,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library
/// A tuple that indicates if the backup was done or not, and a message. /// A tuple that indicates if the backup was done or not, and a message.
/// The message usually is a localized reference key. /// The message usually is a localized reference key.
/// </returns> /// </returns>
public (bool success, string message, string severity) RestoreSettings(string appBasePath, string settingsBackupAndRestoreDir) public (bool Success, string Message, string Severity) RestoreSettings(string appBasePath, string settingsBackupAndRestoreDir)
{ {
try try
{ {
@@ -554,26 +554,26 @@ namespace Microsoft.PowerToys.Settings.UI.Library
/// <remarks> /// <remarks>
/// This is a wrapper for BackupSettingsInternal, so we can check the time to run. /// This is a wrapper for BackupSettingsInternal, so we can check the time to run.
/// </remarks> /// </remarks>
public (bool success, string message, string severity, bool lastBackupExists) BackupSettings(string appBasePath, string settingsBackupAndRestoreDir, bool dryRun) public (bool Success, string Message, string Severity, bool LastBackupExists) BackupSettings(string appBasePath, string settingsBackupAndRestoreDir, bool dryRun)
{ {
var sw = Stopwatch.StartNew(); var sw = Stopwatch.StartNew();
var results = BackupSettingsInternal(appBasePath, settingsBackupAndRestoreDir, dryRun); var results = BackupSettingsInternal(appBasePath, settingsBackupAndRestoreDir, dryRun);
sw.Stop(); sw.Stop();
Logger.LogInfo($"BackupSettings took {sw.ElapsedMilliseconds}"); Logger.LogInfo($"BackupSettings took {sw.ElapsedMilliseconds}");
lastBackupSettingsResults = (results.success, results.severity, results.lastBackupExists, DateTime.UtcNow); lastBackupSettingsResults = (results.Success, results.Severity, results.LastBackupExists, DateTime.UtcNow);
return results; return results;
} }
/// <summary> /// <summary>
/// Method <c>DryRunBackup</c> wrapper function to do a dry-run backup /// Method <c>DryRunBackup</c> wrapper function to do a dry-run backup
/// </summary> /// </summary>
public (bool success, string message, string severity, bool lastBackupExists) DryRunBackup() public (bool Success, string Message, string Severity, bool LastBackupExists) DryRunBackup()
{ {
var settingsUtils = new SettingsUtils(); var settingsUtils = new SettingsUtils();
var appBasePath = Path.GetDirectoryName(settingsUtils.GetSettingsFilePath()); var appBasePath = Path.GetDirectoryName(settingsUtils.GetSettingsFilePath());
string settingsBackupAndRestoreDir = GetSettingsBackupAndRestoreDir(); string settingsBackupAndRestoreDir = GetSettingsBackupAndRestoreDir();
var results = BackupSettings(appBasePath, settingsBackupAndRestoreDir, true); var results = BackupSettings(appBasePath, settingsBackupAndRestoreDir, true);
lastBackupSettingsResults = (results.success, results.severity, results.lastBackupExists, DateTime.UtcNow); lastBackupSettingsResults = (results.Success, results.Severity, results.LastBackupExists, DateTime.UtcNow);
return results; return results;
} }
@@ -583,9 +583,9 @@ namespace Microsoft.PowerToys.Settings.UI.Library
/// <returns> /// <returns>
/// A tuple that indicates if the backup was done or not, and other information /// A tuple that indicates if the backup was done or not, and other information
/// </returns> /// </returns>
public (bool success, bool hadError, bool lastBackupExists, DateTime? lastRan) GetLastBackupSettingsResults() public (bool Success, bool HadError, bool LastBackupExists, DateTime? LastRan) GetLastBackupSettingsResults()
{ {
return (lastBackupSettingsResults.success, lastBackupSettingsResults.severity == "Error", lastBackupSettingsResults.lastBackupExists, lastBackupSettingsResults.lastRan); return (lastBackupSettingsResults.Success, lastBackupSettingsResults.Severity == "Error", lastBackupSettingsResults.LastBackupExists, lastBackupSettingsResults.LastRan);
} }
/// <summary> /// <summary>
@@ -595,7 +595,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library
/// A tuple that indicates if the backup was done or not, and a message. /// A tuple that indicates if the backup was done or not, and a message.
/// The message usually is a localized reference key. /// The message usually is a localized reference key.
/// </returns> /// </returns>
private (bool success, string message, string severity, bool lastBackupExists) BackupSettingsInternal(string appBasePath, string settingsBackupAndRestoreDir, bool dryRun) private (bool Success, string Message, string Severity, bool LastBackupExists) BackupSettingsInternal(string appBasePath, string settingsBackupAndRestoreDir, bool dryRun)
{ {
var lastBackupExists = false; var lastBackupExists = false;
@@ -650,7 +650,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library
} }
var anyFileBackedUp = false; var anyFileBackedUp = false;
var skippedSettingsFiles = new Dictionary<string, (string path, string settings)>(); var skippedSettingsFiles = new Dictionary<string, (string Path, string Settings)>();
var updatedSettingsFiles = new Dictionary<string, string>(); var updatedSettingsFiles = new Dictionary<string, string>();
foreach (var currentFile in currentSettingsFiles) foreach (var currentFile in currentSettingsFiles)
@@ -717,7 +717,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library
{ {
// if we did do a backup, we need to copy in all the settings files we skipped so the backup is complete. // if we did do a backup, we need to copy in all the settings files we skipped so the backup is complete.
// this is needed since we might use the backup on another machine/ // this is needed since we might use the backup on another machine/
var relativePath = currentFile.Value.path.Substring(appBasePath.Length + 1); var relativePath = currentFile.Value.Path.Substring(appBasePath.Length + 1);
var backupFullPath = Path.Combine(fullBackupDir, relativePath); var backupFullPath = Path.Combine(fullBackupDir, relativePath);
Logger.LogInfo($"BackupSettings writing, {backupFullPath}, dryRun:{dryRun}"); Logger.LogInfo($"BackupSettings writing, {backupFullPath}, dryRun:{dryRun}");
@@ -726,7 +726,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library
TryCreateDirectory(fullBackupDir); TryCreateDirectory(fullBackupDir);
TryCreateDirectory(Path.GetDirectoryName(backupFullPath)); TryCreateDirectory(Path.GetDirectoryName(backupFullPath));
File.WriteAllText(backupFullPath, currentFile.Value.settings); File.WriteAllText(backupFullPath, currentFile.Value.Settings);
} }
} }

View File

@@ -189,7 +189,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library
/// <summary> /// <summary>
/// Method <c>BackupSettings</c> Mostly a wrapper for SettingsBackupAndRestoreUtils.BackupSettings /// Method <c>BackupSettings</c> Mostly a wrapper for SettingsBackupAndRestoreUtils.BackupSettings
/// </summary> /// </summary>
public static (bool success, string message, string severity, bool lastBackupExists) BackupSettings() public static (bool Success, string Message, string Severity, bool LastBackupExists) BackupSettings()
{ {
var settingsBackupAndRestoreUtilsX = SettingsBackupAndRestoreUtils.Instance; var settingsBackupAndRestoreUtilsX = SettingsBackupAndRestoreUtils.Instance;
var settingsUtils = new SettingsUtils(); var settingsUtils = new SettingsUtils();
@@ -202,7 +202,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library
/// <summary> /// <summary>
/// Method <c>RestoreSettings</c> Mostly a wrapper for SettingsBackupAndRestoreUtils.RestoreSettings /// Method <c>RestoreSettings</c> Mostly a wrapper for SettingsBackupAndRestoreUtils.RestoreSettings
/// </summary> /// </summary>
public static (bool success, string message, string severity) RestoreSettings() public static (bool Success, string Message, string Severity) RestoreSettings()
{ {
var settingsBackupAndRestoreUtilsX = SettingsBackupAndRestoreUtils.Instance; var settingsBackupAndRestoreUtilsX = SettingsBackupAndRestoreUtils.Instance;
var settingsUtils = new SettingsUtils(); var settingsUtils = new SettingsUtils();

View File

@@ -1,30 +0,0 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
// This file is used by Code Analysis to maintain SuppressMessage
// attributes that are applied to this project.
// Project-level suppressions either have no target or are given
// a specific target and scoped to a namespace, type, member, etc.
using System.Diagnostics.CodeAnalysis;
[assembly: SuppressMessage("StyleCop.CSharp.SpacingRules", "SA1009:ClosingParenthesisMustBeSpacedCorrectly", Justification = "All current violations are due to Tuple shorthand and so valid.")]
[assembly: SuppressMessage("StyleCop.CSharp.ReadabilityRules", "SA1101:PrefixLocalCallsWithThis", Justification = "We follow the C# Core Coding Style which avoids using `this` unless absolutely necessary.")]
[assembly: SuppressMessage("StyleCop.CSharp.OrderingRules", "SA1200:UsingDirectivesMustBePlacedWithinNamespace", Justification = "We follow the C# Core Coding Style which puts using statements outside the namespace.")]
[assembly: SuppressMessage("StyleCop.CSharp.OrderingRules", "SA1201:ElementsMustAppearInTheCorrectOrder", Justification = "It is not a priority and have hight impact in code changes.")]
[assembly: SuppressMessage("StyleCop.CSharp.OrderingRules", "SA1202:ElementsMustBeOrderedByAccess", Justification = "It is not a priority and have hight impact in code changes.")]
[assembly: SuppressMessage("StyleCop.CSharp.OrderingRules", "SA1203:ConstantsMustAppearBeforeFields", Justification = "It is not a priority and have hight impact in code changes.")]
[assembly: SuppressMessage("StyleCop.CSharp.OrderingRules", "SA1204:StaticElementsMustAppearBeforeInstanceElements", Justification = "It is not a priority and have hight impact in code changes.")]
[assembly: SuppressMessage("StyleCop.CSharp.NamingRules", "SA1309:FieldNamesMustNotBeginWithUnderscore", Justification = "We follow the C# Core Coding Style which uses underscores as prefixes rather than using `this.`.")]
[assembly: SuppressMessage("StyleCop.CSharp.SpecialRules", "SA0001:XmlCommentAnalysisDisabled", Justification = "Not enabled as we don't want or need XML documentation.")]
[assembly: SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1629:DocumentationTextMustEndWithAPeriod", Justification = "Not enabled as we don't want or need XML documentation.")]
// Non general suppressions
[assembly: SuppressMessage("Naming", "CA1707:Identifiers should not contain underscores", Justification = "Used in a lot of places for meaningful method names")]
[assembly: SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "Static methods may improve performance but decrease maintainability")]
[assembly: SuppressMessage("Naming", "CA1711:Identifiers should not have incorrect suffix", Justification = "Renaming everything would be a lot of work. It does not do any harm if an EventHandler delegate ends with the suffix EventHandler. Besides this, the Rule causes some false positives.")]
[assembly: SuppressMessage("Performance", "CA1838:Avoid 'StringBuilder' parameters for P/Invokes", Justification = "We are not concerned about the performance impact of marshaling a StringBuilder")]

View File

@@ -418,16 +418,16 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
var resultText = string.Empty; var resultText = string.Empty;
if (!results.lastRan.HasValue) if (!results.LastRan.HasValue)
{ {
// not ran since started. // not ran since started.
return GetResourceString("General_SettingsBackupAndRestore_CurrentSettingsNoChecked"); // "Current Settings Unknown"; return GetResourceString("General_SettingsBackupAndRestore_CurrentSettingsNoChecked"); // "Current Settings Unknown";
} }
else else
{ {
if (results.success) if (results.Success)
{ {
if (results.lastBackupExists) if (results.LastBackupExists)
{ {
// if true, it means a backup would have been made // if true, it means a backup would have been made
resultText = GetResourceString("General_SettingsBackupAndRestore_CurrentSettingsDiffer"); // "Current Settings Differ"; resultText = GetResourceString("General_SettingsBackupAndRestore_CurrentSettingsDiffer"); // "Current Settings Differ";
@@ -440,7 +440,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
} }
else else
{ {
if (results.hadError) if (results.HadError)
{ {
// if false and error we don't really know // if false and error we don't really know
resultText = GetResourceString("General_SettingsBackupAndRestore_CurrentSettingsUnknown"); // "Current Settings Unknown"; resultText = GetResourceString("General_SettingsBackupAndRestore_CurrentSettingsUnknown"); // "Current Settings Unknown";
@@ -452,7 +452,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
} }
} }
return $"{resultText} {GetResourceString("General_SettingsBackupAndRestore_CurrentSettingsStatusAt")} {results.lastRan.Value.ToLocalTime().ToString("G", CultureInfo.CurrentCulture)}"; return $"{resultText} {GetResourceString("General_SettingsBackupAndRestore_CurrentSettingsStatusAt")} {results.LastRan.Value.ToLocalTime().ToString("G", CultureInfo.CurrentCulture)}";
} }
} }
catch (Exception e) catch (Exception e)
@@ -683,13 +683,13 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
} }
var results = SettingsUtils.RestoreSettings(); var results = SettingsUtils.RestoreSettings();
_backupRestoreMessageSeverity = results.severity; _backupRestoreMessageSeverity = results.Severity;
if (!results.success) if (!results.Success)
{ {
_settingsBackupRestoreMessageVisible = true; _settingsBackupRestoreMessageVisible = true;
_settingsBackupMessage = GetResourceString(results.message); _settingsBackupMessage = GetResourceString(results.Message);
NotifyAllBackupAndRestoreProperties(); NotifyAllBackupAndRestoreProperties();
@@ -720,8 +720,8 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
var results = SettingsUtils.BackupSettings(); var results = SettingsUtils.BackupSettings();
_settingsBackupRestoreMessageVisible = true; _settingsBackupRestoreMessageVisible = true;
_backupRestoreMessageSeverity = results.severity; _backupRestoreMessageSeverity = results.Severity;
_settingsBackupMessage = GetResourceString(results.message); _settingsBackupMessage = GetResourceString(results.Message);
// now we do a dry run to get the results for "setting match" // now we do a dry run to get the results for "setting match"
var settingsUtils = new SettingsUtils(); var settingsUtils = new SettingsUtils();