fx cop & FZ editor part 1 of many (#11241)

* fixing first set of host of bugs

* objects are already set to defaults

* shifting to string.is null / empty

* setters

* fixing stylecop oops

* checking in the FxCop dep but commenting it out for easier coming back
This commit is contained in:
Clint Rutkas 2021-05-14 09:54:34 -07:00 committed by GitHub
parent 19952ef634
commit 319adcbd62
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 49 additions and 29 deletions

View file

@ -174,9 +174,12 @@ namespace FancyZonesEditor
public static void ShowExceptionReportMessageBox(string reportData)
{
var fileStream = File.OpenWrite(ErrorReportLogFile);
var sw = new StreamWriter(fileStream);
sw.Write(reportData);
sw.Flush();
using (var sw = new StreamWriter(fileStream))
{
sw.Write(reportData);
sw.Flush();
}
fileStream.Close();
ShowReportMessageBox(fileStream.Name);
@ -185,8 +188,11 @@ namespace FancyZonesEditor
private void OnUnhandledException(object sender, UnhandledExceptionEventArgs args)
{
var fileStream = File.OpenWrite(CrashReportLogFile);
var sw = new StreamWriter(fileStream);
sw.Write(FormatException((Exception)args.ExceptionObject));
using (var sw = new StreamWriter(fileStream))
{
sw.Write(FormatException((Exception)args.ExceptionObject));
}
fileStream.Close();
ShowReportMessageBox(fileStream.Name);

View file

@ -66,6 +66,10 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="ModernWpfUI" Version="0.9.4" />
<!--<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="3.3.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>-->
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

View file

@ -75,18 +75,26 @@ namespace FancyZonesEditor
public struct Zone
{
public int Index;
public int Left;
public int Top;
public int Right;
public int Bottom;
public int Index { get; set; }
public int Left { get; set; }
public int Top { get; set; }
public int Right { get; set; }
public int Bottom { get; set; }
}
public struct Resizer
{
public Orientation Orientation;
public List<int> NegativeSideIndices; // all zones to the left/up, in order
public List<int> PositiveSideIndices; // all zones to the right/down, in order
public Orientation Orientation { get; set; }
// all zones to the left/up, in order
public List<int> NegativeSideIndices { get; set; }
// all zones to the right/down, in order
public List<int> PositiveSideIndices { get; set; }
}
private List<Zone> _zones;

View file

@ -116,7 +116,7 @@ namespace FancyZonesEditor
MagneticSnap snapX = new MagneticSnap(GridData.PrefixSum(Model.ColumnPercents).GetRange(1, Model.ColumnPercents.Count - 1), actualSize.Width);
MagneticSnap snapY = new MagneticSnap(GridData.PrefixSum(Model.RowPercents).GetRange(1, Model.RowPercents.Count - 1), actualSize.Height);
for (int zoneIndex = 0; zoneIndex < _data.Zones.Count(); zoneIndex++)
for (int zoneIndex = 0; zoneIndex < _data.Zones.Count; zoneIndex++)
{
// this is needed for the lambda
int zoneIndexCopy = zoneIndex;
@ -227,8 +227,8 @@ namespace FancyZonesEditor
SetupUI();
}
private double _dragX = 0;
private double _dragY = 0;
private double _dragX;
private double _dragY;
private void Resizer_DragStarted(object sender, System.Windows.Controls.Primitives.DragStartedEventArgs e)
{
@ -379,7 +379,7 @@ namespace FancyZonesEditor
var selectedIndices = new List<int>();
for (int zoneIndex = 0; zoneIndex < _data.Zones.Count(); zoneIndex++)
for (int zoneIndex = 0; zoneIndex < _data.Zones.Count; zoneIndex++)
{
var zoneData = _data.Zones[zoneIndex];
@ -418,7 +418,7 @@ namespace FancyZonesEditor
var selectedIndices = new List<int>();
for (int zoneIndex = 0; zoneIndex < _data.Zones.Count(); zoneIndex++)
for (int zoneIndex = 0; zoneIndex < _data.Zones.Count; zoneIndex++)
{
if ((Preview.Children[zoneIndex] as GridZone).IsSelected)
{

View file

@ -32,7 +32,7 @@ namespace FancyZonesEditor
public event MouseButtonEventHandler MergeComplete;
private readonly Rectangle _splitter;
private bool _switchOrientation = false;
private bool _switchOrientation;
private Point _lastPos = new Point(-1, -1);
private int _snappedPositionX;
private int _snappedPositionY;

View file

@ -23,9 +23,9 @@ namespace FancyZonesEditor
private const int MinimalForDefaultWrapPanelsHeight = 900;
private readonly MainWindowSettingsModel _settings = ((App)Application.Current).MainWindowSettings;
private LayoutModel _backup = null;
private LayoutModel _backup;
private ContentDialog _openedDialog = null;
private ContentDialog _openedDialog;
public int WrapPanelItemSize { get; set; } = DefaultWrapPanelItemSize;

View file

@ -171,7 +171,7 @@ namespace FancyZonesEditor.Models
List<string> result = new List<string>();
foreach (var pair in MainWindowSettingsModel.QuickKeys.SelectedKeys)
{
if (pair.Value == string.Empty || pair.Value == Uuid)
if (string.IsNullOrEmpty(pair.Value) || pair.Value == Uuid)
{
result.Add(pair.Key);
}

View file

@ -161,7 +161,7 @@ namespace FancyZonesEditor
}
}
private LayoutModel _selectedModel = null;
private LayoutModel _selectedModel;
public LayoutModel AppliedModel
{
@ -180,7 +180,7 @@ namespace FancyZonesEditor
}
}
private LayoutModel _appliedModel = null;
private LayoutModel _appliedModel;
public static bool IsPredefinedLayout(LayoutModel model)
{

View file

@ -707,7 +707,7 @@ namespace FancyZonesEditor.Utils
// Serialize quick layout switch keys
foreach (var pair in MainWindowSettingsModel.QuickKeys.SelectedKeys)
{
if (pair.Value != string.Empty)
if (!string.IsNullOrEmpty(pair.Value))
{
try
{
@ -739,10 +739,12 @@ namespace FancyZonesEditor.Utils
private string ReadFile(string fileName)
{
Stream inputStream = _fileSystem.File.Open(fileName, FileMode.Open);
StreamReader reader = new StreamReader(inputStream);
string data = reader.ReadToEnd();
inputStream.Close();
return data;
using (StreamReader reader = new StreamReader(inputStream))
{
string data = reader.ReadToEnd();
inputStream.Close();
return data;
}
}
private bool SetDevices(List<DeviceWrapper> devices)