From 0669fbcc27e2e0480a7e8663e8ab311bf3d93ba1 Mon Sep 17 00:00:00 2001 From: Clint Rutkas Date: Wed, 18 Nov 2020 11:38:45 -0800 Subject: [PATCH 1/6] Renaming nativemethods --- .../editor/FancyZonesEditor/FancyZonesEditor.csproj | 7 ++++++- .../FancyZonesEditor/{Native.cs => NativeMethods.cs} | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) rename src/modules/fancyzones/editor/FancyZonesEditor/{Native.cs => NativeMethods.cs} (94%) diff --git a/src/modules/fancyzones/editor/FancyZonesEditor/FancyZonesEditor.csproj b/src/modules/fancyzones/editor/FancyZonesEditor/FancyZonesEditor.csproj index 211435d465..f6d99f1cd4 100644 --- a/src/modules/fancyzones/editor/FancyZonesEditor/FancyZonesEditor.csproj +++ b/src/modules/fancyzones/editor/FancyZonesEditor/FancyZonesEditor.csproj @@ -152,7 +152,7 @@ - + GridEditorWindow.xaml @@ -267,6 +267,11 @@ 2.3.2 + + 3.3.1 + runtime; build; native; contentfiles; analyzers; buildtransitive + all + 12.2.5 diff --git a/src/modules/fancyzones/editor/FancyZonesEditor/Native.cs b/src/modules/fancyzones/editor/FancyZonesEditor/NativeMethods.cs similarity index 94% rename from src/modules/fancyzones/editor/FancyZonesEditor/Native.cs rename to src/modules/fancyzones/editor/FancyZonesEditor/NativeMethods.cs index 64da24667f..7982cd09b0 100644 --- a/src/modules/fancyzones/editor/FancyZonesEditor/Native.cs +++ b/src/modules/fancyzones/editor/FancyZonesEditor/NativeMethods.cs @@ -8,7 +8,7 @@ using System.Runtime.InteropServices; namespace FancyZonesEditor { // PInvokes to handshake with fancyzones backend - internal static class Native + internal static class NativeMethods { [DllImport("kernel32", SetLastError = true, CharSet = CharSet.Ansi)] public static extern IntPtr LoadLibrary([MarshalAs(UnmanagedType.LPStr)] string lpFileName); From f113aadb68843b5c3a3f8baef3a300500cd8b2df Mon Sep 17 00:00:00 2001 From: Clint Rutkas Date: Wed, 18 Nov 2020 11:40:59 -0800 Subject: [PATCH 2/6] removing default values --- src/modules/fancyzones/editor/FancyZonesEditor/App.xaml.cs | 2 +- .../fancyzones/editor/FancyZonesEditor/CanvasZone.xaml.cs | 2 +- .../fancyzones/editor/FancyZonesEditor/GridEditor.xaml.cs | 2 +- .../fancyzones/editor/FancyZonesEditor/GridZone.xaml.cs | 4 ++-- .../fancyzones/editor/FancyZonesEditor/Models/LayoutModel.cs | 2 +- src/modules/fancyzones/editor/FancyZonesEditor/Overlay.cs | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/modules/fancyzones/editor/FancyZonesEditor/App.xaml.cs b/src/modules/fancyzones/editor/FancyZonesEditor/App.xaml.cs index e7486c401a..efcf1f6be5 100644 --- a/src/modules/fancyzones/editor/FancyZonesEditor/App.xaml.cs +++ b/src/modules/fancyzones/editor/FancyZonesEditor/App.xaml.cs @@ -60,7 +60,7 @@ namespace FancyZonesEditor } } - private static bool _debugMode = false; + private static bool _debugMode; [Conditional("DEBUG")] private void DebugModeCheck() diff --git a/src/modules/fancyzones/editor/FancyZonesEditor/CanvasZone.xaml.cs b/src/modules/fancyzones/editor/FancyZonesEditor/CanvasZone.xaml.cs index 2678ccd077..a3e0ade075 100644 --- a/src/modules/fancyzones/editor/FancyZonesEditor/CanvasZone.xaml.cs +++ b/src/modules/fancyzones/editor/FancyZonesEditor/CanvasZone.xaml.cs @@ -271,7 +271,7 @@ namespace FancyZonesEditor Model.Zones[ZoneIndex] = rect; } - private static int zIndex = 0; + private static int zIndex; private const int MinZoneWidth = 64; private const int MinZoneHeight = 72; diff --git a/src/modules/fancyzones/editor/FancyZonesEditor/GridEditor.xaml.cs b/src/modules/fancyzones/editor/FancyZonesEditor/GridEditor.xaml.cs index 1171ad7aaf..eb931ad114 100644 --- a/src/modules/fancyzones/editor/FancyZonesEditor/GridEditor.xaml.cs +++ b/src/modules/fancyzones/editor/FancyZonesEditor/GridEditor.xaml.cs @@ -24,7 +24,7 @@ namespace FancyZonesEditor public static readonly DependencyProperty ModelProperty = DependencyProperty.Register(ObjectDependencyID, typeof(GridLayoutModel), typeof(GridEditor), new PropertyMetadata(null, OnGridDimensionsChanged)); - private static int gridEditorUniqueIdCounter = 0; + private static int gridEditorUniqueIdCounter; private int gridEditorUniqueId; diff --git a/src/modules/fancyzones/editor/FancyZonesEditor/GridZone.xaml.cs b/src/modules/fancyzones/editor/FancyZonesEditor/GridZone.xaml.cs index 837a6f2ab0..210120cdf3 100644 --- a/src/modules/fancyzones/editor/FancyZonesEditor/GridZone.xaml.cs +++ b/src/modules/fancyzones/editor/FancyZonesEditor/GridZone.xaml.cs @@ -37,10 +37,10 @@ namespace FancyZonesEditor public double[] HorizontalSnapPoints { get; set; } private readonly Rectangle _splitter; - private bool _switchOrientation = false; + private bool _switchOrientation; private Point _lastPos = new Point(-1, -1); private Point _mouseDownPos = new Point(-1, -1); - private bool _inMergeDrag = false; + private bool _inMergeDrag; private Orientation _splitOrientation; private static void OnSelectionChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) diff --git a/src/modules/fancyzones/editor/FancyZonesEditor/Models/LayoutModel.cs b/src/modules/fancyzones/editor/FancyZonesEditor/Models/LayoutModel.cs index f921afb5d2..9c900623b8 100644 --- a/src/modules/fancyzones/editor/FancyZonesEditor/Models/LayoutModel.cs +++ b/src/modules/fancyzones/editor/FancyZonesEditor/Models/LayoutModel.cs @@ -185,7 +185,7 @@ namespace FancyZonesEditor.Models return _customModels; } - private static ObservableCollection _customModels = null; + private static ObservableCollection _customModels; private static List _deletedCustomModels = new List(); private static List _createdCustomLayouts = new List(); diff --git a/src/modules/fancyzones/editor/FancyZonesEditor/Overlay.cs b/src/modules/fancyzones/editor/FancyZonesEditor/Overlay.cs index d61bf85499..be527fa5e8 100644 --- a/src/modules/fancyzones/editor/FancyZonesEditor/Overlay.cs +++ b/src/modules/fancyzones/editor/FancyZonesEditor/Overlay.cs @@ -115,7 +115,7 @@ namespace FancyZonesEditor } } - private int _currentDesktop = 0; + private int _currentDesktop; public bool SpanZonesAcrossMonitors { From 4c853a8f45e274af009d54493a8ff9149216a1a5 Mon Sep 17 00:00:00 2001 From: Clint Rutkas Date: Wed, 18 Nov 2020 11:44:00 -0800 Subject: [PATCH 3/6] more tweaks --- src/modules/fancyzones/editor/FancyZonesEditor/App.xaml.cs | 3 --- .../FancyZonesEditor/Models/MainWindowSettingsModel.cs | 5 ----- .../fancyzones/editor/FancyZonesEditor/Utils/RelayCommand.cs | 2 +- .../editor/FancyZonesEditor/Utils/RelayCommand`1.cs | 2 +- 4 files changed, 2 insertions(+), 10 deletions(-) diff --git a/src/modules/fancyzones/editor/FancyZonesEditor/App.xaml.cs b/src/modules/fancyzones/editor/FancyZonesEditor/App.xaml.cs index efcf1f6be5..6ee98f3b18 100644 --- a/src/modules/fancyzones/editor/FancyZonesEditor/App.xaml.cs +++ b/src/modules/fancyzones/editor/FancyZonesEditor/App.xaml.cs @@ -7,7 +7,6 @@ using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; -using System.IO.Abstractions; using System.Linq; using System.Text; using System.Windows; @@ -42,8 +41,6 @@ namespace FancyZonesEditor private const string CrashReportDynamicAssemblyTag = "dynamic assembly doesn't have location"; private const string CrashReportLocationNullTag = "location is null or empty"; - private readonly IFileSystem _fileSystem = new FileSystem(); - public MainWindowSettingsModel MainWindowSettings { get; } public static FancyZonesEditorIO FancyZonesEditorIO { get; private set; } diff --git a/src/modules/fancyzones/editor/FancyZonesEditor/Models/MainWindowSettingsModel.cs b/src/modules/fancyzones/editor/FancyZonesEditor/Models/MainWindowSettingsModel.cs index 85334d286a..7eb01a7e67 100644 --- a/src/modules/fancyzones/editor/FancyZonesEditor/Models/MainWindowSettingsModel.cs +++ b/src/modules/fancyzones/editor/FancyZonesEditor/Models/MainWindowSettingsModel.cs @@ -40,15 +40,10 @@ namespace FancyZonesEditor public const ushort _blankCustomModelId = 0xFFFA; public const ushort _lastDefinedId = _blankCustomModelId; - private const int MaxNegativeSpacing = -10; - // Non-localizable strings public static readonly string RegistryPath = "SOFTWARE\\SuperFancyZones"; public static readonly string FullRegistryPath = "HKEY_CURRENT_USER\\" + RegistryPath; - private const string LayoutTypeBlankStr = "blank"; - private const string NullUuidStr = "null"; - // hard coded data for all the "Priority Grid" configurations that are unique to "Grid" private static readonly byte[][] _priorityData = new byte[][] { diff --git a/src/modules/fancyzones/editor/FancyZonesEditor/Utils/RelayCommand.cs b/src/modules/fancyzones/editor/FancyZonesEditor/Utils/RelayCommand.cs index 8086689b5e..ecb0d0f285 100644 --- a/src/modules/fancyzones/editor/FancyZonesEditor/Utils/RelayCommand.cs +++ b/src/modules/fancyzones/editor/FancyZonesEditor/Utils/RelayCommand.cs @@ -22,7 +22,7 @@ namespace FancyZonesEditor.Utils { if (execute == null) { - throw new ArgumentNullException("execute"); + throw new ArgumentNullException(nameof(execute)); } _execute = execute; diff --git a/src/modules/fancyzones/editor/FancyZonesEditor/Utils/RelayCommand`1.cs b/src/modules/fancyzones/editor/FancyZonesEditor/Utils/RelayCommand`1.cs index 21c9ed7d17..3575f3546b 100644 --- a/src/modules/fancyzones/editor/FancyZonesEditor/Utils/RelayCommand`1.cs +++ b/src/modules/fancyzones/editor/FancyZonesEditor/Utils/RelayCommand`1.cs @@ -22,7 +22,7 @@ namespace FancyZonesEditor.Utils { if (execute == null) { - throw new ArgumentNullException("execute"); + throw new ArgumentNullException(nameof(execute)); } _execute = execute; From 98a8129f939797d33ac6b4d6298da25cd59a656a Mon Sep 17 00:00:00 2001 From: Clint Rutkas Date: Wed, 18 Nov 2020 11:47:24 -0800 Subject: [PATCH 4/6] null checks --- .../fancyzones/editor/FancyZonesEditor/GridData.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/modules/fancyzones/editor/FancyZonesEditor/GridData.cs b/src/modules/fancyzones/editor/FancyZonesEditor/GridData.cs index 9610b50b68..8aecf12015 100644 --- a/src/modules/fancyzones/editor/FancyZonesEditor/GridData.cs +++ b/src/modules/fancyzones/editor/FancyZonesEditor/GridData.cs @@ -48,6 +48,16 @@ namespace FancyZonesEditor public void CalcAdjacentZones(int index, int size, List info, Func indexCmpr) { + if (info == null) + { + throw new ArgumentNullException(nameof(info)); + } + + if (indexCmpr == null) + { + throw new ArgumentNullException(nameof(indexCmpr)); + } + int ind = index; while (ind > 0 && indexCmpr(ind)) { From d056c136dd1c6ff3d1d16eb4883894dea775d45a Mon Sep 17 00:00:00 2001 From: Clint Rutkas Date: Wed, 18 Nov 2020 12:04:24 -0800 Subject: [PATCH 5/6] invariants --- .../editor/FancyZonesEditor/Models/Device.cs | 26 ++++++++----------- .../FancyZonesEditor/Models/LayoutModel.cs | 2 +- .../Models/MainWindowSettingsModel.cs | 2 +- .../Utils/FancyZonesEditorIO.cs | 8 +++--- 4 files changed, 17 insertions(+), 21 deletions(-) diff --git a/src/modules/fancyzones/editor/FancyZonesEditor/Models/Device.cs b/src/modules/fancyzones/editor/FancyZonesEditor/Models/Device.cs index 00031f170f..ed8a7d04cd 100644 --- a/src/modules/fancyzones/editor/FancyZonesEditor/Models/Device.cs +++ b/src/modules/fancyzones/editor/FancyZonesEditor/Models/Device.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. using System; +using System.Globalization; using System.Text; using System.Windows; @@ -50,6 +51,7 @@ namespace FancyZonesEditor.Utils { float dpi = Dpi != 0 ? Dpi : 96f; double scaleFactor = 96f / dpi; + return Math.Round(coordinate * scaleFactor); } @@ -57,23 +59,17 @@ namespace FancyZonesEditor.Utils { var sb = new StringBuilder(); - sb.Append("ID: "); - sb.AppendLine(Id); - sb.Append("DPI: "); - sb.AppendLine(Dpi.ToString()); - sb.Append("Is primary: "); - sb.AppendLine(Primary.ToString()); + sb.AppendFormat(CultureInfo.InvariantCulture, "ID: {0}{1}", Id, Environment.NewLine); + sb.AppendFormat(CultureInfo.InvariantCulture, "DPI: {0}{1}", Dpi, Environment.NewLine); + sb.AppendFormat(CultureInfo.InvariantCulture, "Is primary: {0}{1}", Primary, Environment.NewLine); - string workArea = string.Format("({0}, {1}, {2}, {3})", WorkAreaRect.X, WorkAreaRect.Y, WorkAreaRect.Width, WorkAreaRect.Height); - string bounds = string.Format("({0}, {1}, {2}, {3})", UnscaledBounds.X, UnscaledBounds.Y, UnscaledBounds.Width, UnscaledBounds.Height); - string scaledBounds = string.Format("({0}, {1}, {2}, {3})", ScaledBounds.X, ScaledBounds.Y, ScaledBounds.Width, ScaledBounds.Height); + string workArea = string.Format(CultureInfo.InvariantCulture, "({0}, {1}, {2}, {3})", WorkAreaRect.X, WorkAreaRect.Y, WorkAreaRect.Width, WorkAreaRect.Height); + string bounds = string.Format(CultureInfo.InvariantCulture, "({0}, {1}, {2}, {3})", UnscaledBounds.X, UnscaledBounds.Y, UnscaledBounds.Width, UnscaledBounds.Height); + string scaledBounds = string.Format(CultureInfo.InvariantCulture, "({0}, {1}, {2}, {3})", ScaledBounds.X, ScaledBounds.Y, ScaledBounds.Width, ScaledBounds.Height); - sb.Append("Work area: "); - sb.AppendLine(workArea); - sb.Append("Unscaled bounds: "); - sb.AppendLine(bounds); - sb.Append("Scaled bounds: "); - sb.AppendLine(scaledBounds); + sb.AppendFormat(CultureInfo.InvariantCulture, "Work area: {0}{1}", workArea, Environment.NewLine); + sb.AppendFormat(CultureInfo.InvariantCulture, "Unscaled bounds: {0}{1}", bounds, Environment.NewLine); + sb.AppendFormat(CultureInfo.InvariantCulture, "Scaled bounds: {0}{1}", scaledBounds, Environment.NewLine); return sb.ToString(); } diff --git a/src/modules/fancyzones/editor/FancyZonesEditor/Models/LayoutModel.cs b/src/modules/fancyzones/editor/FancyZonesEditor/Models/LayoutModel.cs index 9c900623b8..61d3ac76bd 100644 --- a/src/modules/fancyzones/editor/FancyZonesEditor/Models/LayoutModel.cs +++ b/src/modules/fancyzones/editor/FancyZonesEditor/Models/LayoutModel.cs @@ -78,7 +78,7 @@ namespace FancyZonesEditor.Models { get { - return "{" + Guid.ToString().ToUpper() + "}"; + return "{" + Guid.ToString().ToUpperInvariant() + "}"; } } diff --git a/src/modules/fancyzones/editor/FancyZonesEditor/Models/MainWindowSettingsModel.cs b/src/modules/fancyzones/editor/FancyZonesEditor/Models/MainWindowSettingsModel.cs index 7eb01a7e67..c969ee3f5f 100644 --- a/src/modules/fancyzones/editor/FancyZonesEditor/Models/MainWindowSettingsModel.cs +++ b/src/modules/fancyzones/editor/FancyZonesEditor/Models/MainWindowSettingsModel.cs @@ -378,7 +378,7 @@ namespace FancyZonesEditor { foreach (LayoutModel model in MainWindowSettingsModel.CustomModels) { - if ("{" + model.Guid.ToString().ToUpper() + "}" == currentApplied.ZonesetUuid.ToUpper()) + if ("{" + model.Guid.ToString().ToUpperInvariant() + "}" == currentApplied.ZonesetUuid.ToUpperInvariant()) { // found match foundModel = model; diff --git a/src/modules/fancyzones/editor/FancyZonesEditor/Utils/FancyZonesEditorIO.cs b/src/modules/fancyzones/editor/FancyZonesEditor/Utils/FancyZonesEditorIO.cs index a34886565a..54e9ecd492 100644 --- a/src/modules/fancyzones/editor/FancyZonesEditor/Utils/FancyZonesEditorIO.cs +++ b/src/modules/fancyzones/editor/FancyZonesEditor/Utils/FancyZonesEditorIO.cs @@ -377,7 +377,7 @@ namespace FancyZonesEditor.Utils string uuid = current.GetProperty(UuidJsonTag).GetString(); var info = current.GetProperty(InfoJsonTag); - if (type.Equals(GridJsonTag)) + if (type.Equals(GridJsonTag, StringComparison.OrdinalIgnoreCase)) { bool error = false; @@ -449,13 +449,13 @@ namespace FancyZonesEditor.Utils if (error) { App.ShowExceptionMessageBox(string.Format(Properties.Resources.Error_Layout_Malformed_Data, name)); - deleted.Add(Guid.Parse(uuid).ToString().ToUpper()); + deleted.Add(Guid.Parse(uuid).ToString().ToUpperInvariant()); continue; } custom.Add(new GridLayoutModel(uuid, name, LayoutType.Custom, rows, columns, rowsPercentage, columnsPercentage, cellChildMap)); } - else if (type.Equals(CanvasJsonTag)) + else if (type.Equals(CanvasJsonTag, StringComparison.OrdinalIgnoreCase)) { int workAreaWidth = info.GetProperty(RefWidthJsonTag).GetInt32(); int workAreaHeight = info.GetProperty(RefHeightJsonTag).GetInt32(); @@ -489,7 +489,7 @@ namespace FancyZonesEditor.Utils if (error) { App.ShowExceptionMessageBox(string.Format(Properties.Resources.Error_Layout_Malformed_Data, name)); - deleted.Add(Guid.Parse(uuid).ToString().ToUpper()); + deleted.Add(Guid.Parse(uuid).ToString().ToUpperInvariant()); continue; } From 567e4a39d527ccf0467350399645768d324c624e Mon Sep 17 00:00:00 2001 From: Clint Rutkas Date: Wed, 18 Nov 2020 12:07:59 -0800 Subject: [PATCH 6/6] removing fxcop --- .../editor/FancyZonesEditor/FancyZonesEditor.csproj | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/modules/fancyzones/editor/FancyZonesEditor/FancyZonesEditor.csproj b/src/modules/fancyzones/editor/FancyZonesEditor/FancyZonesEditor.csproj index f6d99f1cd4..94931136e9 100644 --- a/src/modules/fancyzones/editor/FancyZonesEditor/FancyZonesEditor.csproj +++ b/src/modules/fancyzones/editor/FancyZonesEditor/FancyZonesEditor.csproj @@ -267,11 +267,6 @@ 2.3.2 - - 3.3.1 - runtime; build; native; contentfiles; analyzers; buildtransitive - all - 12.2.5