mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 11:48:06 +01:00
fx cop for Fz Editor part2 (#11293)
* disposable not being disposed * CA1305 fixes Co-authored-by: crutkas <crutkas@microsoft.com>
This commit is contained in:
@@ -21,7 +21,7 @@ namespace FancyZonesEditor
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Interaction logic for App.xaml
|
/// Interaction logic for App.xaml
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public partial class App : Application
|
public partial class App : Application, IDisposable
|
||||||
{
|
{
|
||||||
// Non-localizable strings
|
// Non-localizable strings
|
||||||
private const string CrashReportLogFile = "FZEditorCrashLog.txt";
|
private const string CrashReportLogFile = "FZEditorCrashLog.txt";
|
||||||
@@ -66,6 +66,7 @@ namespace FancyZonesEditor
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static bool _debugMode;
|
private static bool _debugMode;
|
||||||
|
private bool _isDisposed;
|
||||||
|
|
||||||
[Conditional("DEBUG")]
|
[Conditional("DEBUG")]
|
||||||
private void DebugModeCheck()
|
private void DebugModeCheck()
|
||||||
@@ -290,5 +291,27 @@ namespace FancyZonesEditor
|
|||||||
|
|
||||||
return sb.ToString();
|
return sb.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected virtual void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (!_isDisposed)
|
||||||
|
{
|
||||||
|
if (disposing)
|
||||||
|
{
|
||||||
|
_themeManager?.Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: free unmanaged resources (unmanaged objects) and override finalizer
|
||||||
|
// TODO: set large fields to null
|
||||||
|
_isDisposed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
|
||||||
|
Dispose(disposing: true);
|
||||||
|
GC.SuppressFinalize(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Globalization;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
@@ -29,8 +30,9 @@ namespace FancyZonesEditor
|
|||||||
|
|
||||||
private void CanvasZone_SizeChanged(object sender, SizeChangedEventArgs e)
|
private void CanvasZone_SizeChanged(object sender, SizeChangedEventArgs e)
|
||||||
{
|
{
|
||||||
WidthLabel.Text = Width.ToString();
|
// using current culture as this is end user facing
|
||||||
HeightLabel.Text = Height.ToString();
|
WidthLabel.Text = Width.ToString(CultureInfo.CurrentCulture);
|
||||||
|
HeightLabel.Text = Height.ToString(CultureInfo.CurrentCulture);
|
||||||
}
|
}
|
||||||
|
|
||||||
private CanvasLayoutModel model;
|
private CanvasLayoutModel model;
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
// 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;
|
||||||
|
using System.Globalization;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
@@ -82,8 +83,9 @@ namespace FancyZonesEditor
|
|||||||
|
|
||||||
private void GridZone_SizeChanged(object sender, SizeChangedEventArgs e)
|
private void GridZone_SizeChanged(object sender, SizeChangedEventArgs e)
|
||||||
{
|
{
|
||||||
WidthLabel.Text = Math.Round(ActualWidth).ToString();
|
// using current culture as this is end user facing
|
||||||
HeightLabel.Text = Math.Round(ActualHeight).ToString();
|
WidthLabel.Text = Math.Round(ActualWidth).ToString(CultureInfo.CurrentCulture);
|
||||||
|
HeightLabel.Text = Math.Round(ActualHeight).ToString(CultureInfo.CurrentCulture);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateShiftState(bool shiftState)
|
public void UpdateShiftState(bool shiftState)
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Globalization;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.IO.Abstractions;
|
using System.IO.Abstractions;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
@@ -74,15 +75,16 @@ namespace FancyZonesEditor.Utils
|
|||||||
{
|
{
|
||||||
var sb = new StringBuilder();
|
var sb = new StringBuilder();
|
||||||
|
|
||||||
|
// using CultureInfo.InvariantCulture since this is internal data
|
||||||
sb.Append("ID: ");
|
sb.Append("ID: ");
|
||||||
sb.AppendLine(MonitorId);
|
sb.AppendLine(MonitorId);
|
||||||
sb.Append("DPI: ");
|
sb.Append("DPI: ");
|
||||||
sb.AppendLine(Dpi.ToString());
|
sb.AppendLine(Dpi.ToString(CultureInfo.InvariantCulture));
|
||||||
|
|
||||||
sb.Append("X: ");
|
sb.Append("X: ");
|
||||||
sb.AppendLine(LeftCoordinate.ToString());
|
sb.AppendLine(LeftCoordinate.ToString(CultureInfo.InvariantCulture));
|
||||||
sb.Append("Y: ");
|
sb.Append("Y: ");
|
||||||
sb.AppendLine(TopCoordinate.ToString());
|
sb.AppendLine(TopCoordinate.ToString(CultureInfo.InvariantCulture));
|
||||||
|
|
||||||
return sb.ToString();
|
return sb.ToString();
|
||||||
}
|
}
|
||||||
@@ -259,14 +261,15 @@ namespace FancyZonesEditor.Utils
|
|||||||
* (7) monitor left
|
* (7) monitor left
|
||||||
* (8) monitor top
|
* (8) monitor top
|
||||||
* ...
|
* ...
|
||||||
|
* Using CultureInfo.InvariantCulture since this is us parsing our own data
|
||||||
*/
|
*/
|
||||||
var argsParts = args[1].Split('/');
|
var argsParts = args[1].Split('/');
|
||||||
|
|
||||||
// Process ID
|
// Process ID
|
||||||
App.PowerToysPID = int.Parse(argsParts[(int)CmdArgs.PowerToysPID]);
|
App.PowerToysPID = int.Parse(argsParts[(int)CmdArgs.PowerToysPID], CultureInfo.InvariantCulture);
|
||||||
|
|
||||||
// Span zones across monitors
|
// Span zones across monitors
|
||||||
App.Overlay.SpanZonesAcrossMonitors = int.Parse(argsParts[(int)CmdArgs.SpanZones]) == 1;
|
App.Overlay.SpanZonesAcrossMonitors = int.Parse(argsParts[(int)CmdArgs.SpanZones], CultureInfo.InvariantCulture) == 1;
|
||||||
|
|
||||||
// Target monitor id
|
// Target monitor id
|
||||||
string targetMonitorName = argsParts[(int)CmdArgs.TargetMonitorId];
|
string targetMonitorName = argsParts[(int)CmdArgs.TargetMonitorId];
|
||||||
@@ -281,7 +284,7 @@ namespace FancyZonesEditor.Utils
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Monitors count
|
// Monitors count
|
||||||
int count = int.Parse(argsParts[(int)CmdArgs.MonitorsCount]);
|
int count = int.Parse(argsParts[(int)CmdArgs.MonitorsCount], CultureInfo.InvariantCulture);
|
||||||
if (count != App.Overlay.DesktopsCount && !isCustomMonitorConfigurationMode)
|
if (count != App.Overlay.DesktopsCount && !isCustomMonitorConfigurationMode)
|
||||||
{
|
{
|
||||||
MessageBox.Show(Properties.Resources.Error_Invalid_Arguments, Properties.Resources.Error_Message_Box_Title);
|
MessageBox.Show(Properties.Resources.Error_Invalid_Arguments, Properties.Resources.Error_Message_Box_Title);
|
||||||
@@ -298,9 +301,9 @@ namespace FancyZonesEditor.Utils
|
|||||||
{
|
{
|
||||||
var nativeData = default(NativeMonitorData);
|
var nativeData = default(NativeMonitorData);
|
||||||
nativeData.MonitorId = argsParts[(int)CmdArgs.MonitorId + (i * monitorArgsCount)];
|
nativeData.MonitorId = argsParts[(int)CmdArgs.MonitorId + (i * monitorArgsCount)];
|
||||||
nativeData.Dpi = int.Parse(argsParts[(int)CmdArgs.DPI + (i * monitorArgsCount)]);
|
nativeData.Dpi = int.Parse(argsParts[(int)CmdArgs.DPI + (i * monitorArgsCount)], CultureInfo.InvariantCulture);
|
||||||
nativeData.LeftCoordinate = int.Parse(argsParts[(int)CmdArgs.MonitorLeft + (i * monitorArgsCount)]);
|
nativeData.LeftCoordinate = int.Parse(argsParts[(int)CmdArgs.MonitorLeft + (i * monitorArgsCount)], CultureInfo.InvariantCulture);
|
||||||
nativeData.TopCoordinate = int.Parse(argsParts[(int)CmdArgs.MonitorTop + (i * monitorArgsCount)]);
|
nativeData.TopCoordinate = int.Parse(argsParts[(int)CmdArgs.MonitorTop + (i * monitorArgsCount)], CultureInfo.InvariantCulture);
|
||||||
|
|
||||||
nativeMonitorData.Add(nativeData);
|
nativeMonitorData.Add(nativeData);
|
||||||
|
|
||||||
@@ -325,8 +328,8 @@ namespace FancyZonesEditor.Utils
|
|||||||
foreach (NativeMonitorData nativeData in nativeMonitorData)
|
foreach (NativeMonitorData nativeData in nativeMonitorData)
|
||||||
{
|
{
|
||||||
var splittedId = nativeData.MonitorId.Split('_');
|
var splittedId = nativeData.MonitorId.Split('_');
|
||||||
int width = int.Parse(splittedId[1]);
|
int width = int.Parse(splittedId[1], CultureInfo.InvariantCulture);
|
||||||
int height = int.Parse(splittedId[2]);
|
int height = int.Parse(splittedId[2], CultureInfo.InvariantCulture);
|
||||||
|
|
||||||
Rect bounds = new Rect(nativeData.LeftCoordinate, nativeData.TopCoordinate, width, height);
|
Rect bounds = new Rect(nativeData.LeftCoordinate, nativeData.TopCoordinate, width, height);
|
||||||
bool isPrimary = nativeData.LeftCoordinate == 0 && nativeData.TopCoordinate == 0;
|
bool isPrimary = nativeData.LeftCoordinate == 0 && nativeData.TopCoordinate == 0;
|
||||||
@@ -1020,8 +1023,10 @@ namespace FancyZonesEditor.Utils
|
|||||||
|
|
||||||
sb.Append("Span zones across monitors: ");
|
sb.Append("Span zones across monitors: ");
|
||||||
sb.AppendLine(App.Overlay.SpanZonesAcrossMonitors.ToString());
|
sb.AppendLine(App.Overlay.SpanZonesAcrossMonitors.ToString());
|
||||||
|
|
||||||
|
// using CultureInfo.InvariantCulture since this is for PowerToys team
|
||||||
sb.Append("Monitors count: ");
|
sb.Append("Monitors count: ");
|
||||||
sb.AppendLine(count.ToString());
|
sb.AppendLine(count.ToString(CultureInfo.InvariantCulture));
|
||||||
sb.Append("Target monitor: ");
|
sb.Append("Target monitor: ");
|
||||||
sb.AppendLine(targetMonitorName);
|
sb.AppendLine(targetMonitorName);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user