From 1f1cbfd1e576a8e8109ffa921eebc678dc7439a1 Mon Sep 17 00:00:00 2001 From: "Valeriano A.R" Date: Mon, 27 May 2019 07:34:45 +0200 Subject: [PATCH] More warning fixes --- .../ProxyCmdExecutorDummy.cs | 8 +++- .../ProxyCmdExecutors/ProxyCmdExecutorWMIC.cs | 2 +- VAR.Toolbox/Code/Screenshooter.cs | 4 +- VAR.Toolbox/Code/Webcam.cs | 19 ++++----- VAR.Toolbox/Controls/CtrImageViewer.cs | 40 +++++++------------ VAR.Toolbox/Controls/CtrOutput.cs | 14 +++---- VAR.Toolbox/UI/FrmToolbox.cs | 4 -- VAR.Toolbox/UI/Tools/FrmCover.cs | 8 ++-- VAR.Toolbox/UI/Tools/FrmProxyCmdConfig.cs | 2 +- VAR.Toolbox/UI/Tools/FrmTestWebService.cs | 2 +- VAR.Toolbox/UI/Tools/PnlCover.cs | 8 +--- VAR.Toolbox/UI/Tools/PnlSuspension.cs | 40 +++++-------------- 12 files changed, 58 insertions(+), 93 deletions(-) diff --git a/VAR.Toolbox/Code/ProxyCmdExecutors/ProxyCmdExecutorDummy.cs b/VAR.Toolbox/Code/ProxyCmdExecutors/ProxyCmdExecutorDummy.cs index 74b45b3..e21d3cc 100644 --- a/VAR.Toolbox/Code/ProxyCmdExecutors/ProxyCmdExecutorDummy.cs +++ b/VAR.Toolbox/Code/ProxyCmdExecutors/ProxyCmdExecutorDummy.cs @@ -4,7 +4,13 @@ { public string Name { get { return "Dummy"; } } - public ProxyCmdExecutorDummy(string config) { } + public ProxyCmdExecutorDummy(string config) + { + if (config == null) + { + throw new System.ArgumentNullException(nameof(config)); + } + } public bool ExecuteCmd(string cmdString, IOutputHandler outputHandler) { diff --git a/VAR.Toolbox/Code/ProxyCmdExecutors/ProxyCmdExecutorWMIC.cs b/VAR.Toolbox/Code/ProxyCmdExecutors/ProxyCmdExecutorWMIC.cs index afa34d0..eb893c6 100644 --- a/VAR.Toolbox/Code/ProxyCmdExecutors/ProxyCmdExecutorWMIC.cs +++ b/VAR.Toolbox/Code/ProxyCmdExecutors/ProxyCmdExecutorWMIC.cs @@ -6,7 +6,7 @@ namespace VAR.Toolbox.Code.ProxyCmdExecutors { public string Name { get { return "WMIC"; } } - private string _configWMIC; + private readonly string _configWMIC; public ProxyCmdExecutorWMIC(string configWMIC) { diff --git a/VAR.Toolbox/Code/Screenshooter.cs b/VAR.Toolbox/Code/Screenshooter.cs index 2395fa5..82a10c0 100644 --- a/VAR.Toolbox/Code/Screenshooter.cs +++ b/VAR.Toolbox/Code/Screenshooter.cs @@ -52,8 +52,8 @@ namespace VAR.Toolbox.Code User32.GetWindowRect(handle, ref windowRect); int left = windowRect.left; int top = windowRect.top; - int width = windowRect.right - windowRect.left; - int height = windowRect.bottom - windowRect.top; + int width = windowRect.right - left; + int height = windowRect.bottom - top; // create a device context we can copy to IntPtr hdcDest = GDI32.CreateCompatibleDC(hdcSrc); // create a bitmap we can copy it to, diff --git a/VAR.Toolbox/Code/Webcam.cs b/VAR.Toolbox/Code/Webcam.cs index 978f93d..7af0374 100644 --- a/VAR.Toolbox/Code/Webcam.cs +++ b/VAR.Toolbox/Code/Webcam.cs @@ -1,4 +1,5 @@ #pragma warning disable IDE0018 +#pragma warning disable IDE0059 using System; using System.Collections.Generic; @@ -15,17 +16,17 @@ namespace VAR.Toolbox.Code { #region Declarations - private IFilterGraph2 graph; - private ICaptureGraphBuilder2 capture; - private IMediaControl control; - private IBaseFilter sourceFilter; - private IBaseFilter samplegrabberfilter; - private IBaseFilter nullrenderer; + private readonly IFilterGraph2 graph; + private readonly ICaptureGraphBuilder2 capture; + private readonly IMediaControl control; + private readonly IBaseFilter sourceFilter; + private readonly IBaseFilter samplegrabberfilter; + private readonly IBaseFilter nullrenderer; private readonly Grabber grabber; - private int width = 0; - private int height = 0; + private readonly int width = 0; + private readonly int height = 0; private readonly int bpp = 0; private bool active = false; @@ -264,7 +265,7 @@ namespace VAR.Toolbox.Code private class Grabber : ISampleGrabberCB { - private Webcam _parent; + private readonly Webcam _parent; private readonly Bitmap[] _frames = null; private readonly int _numFrames = 10; diff --git a/VAR.Toolbox/Controls/CtrImageViewer.cs b/VAR.Toolbox/Controls/CtrImageViewer.cs index 7da89b0..7f6e88f 100644 --- a/VAR.Toolbox/Controls/CtrImageViewer.cs +++ b/VAR.Toolbox/Controls/CtrImageViewer.cs @@ -10,12 +10,6 @@ namespace VAR.Toolbox.Controls private Image _imageShow = null; - // Image projection - private double offsetX = 0; - private double offsetY = 0; - private double scaleX = 1.0f; - private double scaleY = 1.0f; - #endregion #region Properties @@ -28,7 +22,7 @@ namespace VAR.Toolbox.Controls lock (this) { _imageShow = value; - this.Invalidate(); + Invalidate(); } } } @@ -81,41 +75,37 @@ namespace VAR.Toolbox.Controls if (relation > 0) { // Imagen mas ancha que alta - imgDrawHeight = (int)(this.Width / relation); - if (imgDrawHeight > this.Height) + imgDrawHeight = (int)(Width / relation); + if (imgDrawHeight > Height) { - imgDrawHeight = this.Height; - imgDrawWidth = (int)(this.Height * relation); - imgDrawX = ((this.Width - imgDrawWidth) / 2.0f); + imgDrawHeight = Height; + imgDrawWidth = (int)(Height * relation); + imgDrawX = ((Width - imgDrawWidth) / 2.0f); } else { - imgDrawWidth = this.Width; - imgDrawY = ((this.Height - imgDrawHeight) / 2.0f); + imgDrawWidth = Width; + imgDrawY = ((Height - imgDrawHeight) / 2.0f); } } else { // Imagen mas alta que ancha - imgDrawWidth = (int)(this.Width * relation); - if (imgDrawWidth > this.Width) + imgDrawWidth = (int)(Width * relation); + if (imgDrawWidth > Width) { - imgDrawWidth = this.Width; - imgDrawHeight = (int)(this.Height / relation); - imgDrawY = ((this.Height - imgDrawHeight) / 2.0f); + imgDrawWidth = Width; + imgDrawHeight = (int)(Height / relation); + imgDrawY = ((Height - imgDrawHeight) / 2.0f); } else { - imgDrawHeight = this.Height; - imgDrawX = ((this.Width - imgDrawWidth) / 2.0f); + imgDrawHeight = Height; + imgDrawX = ((Width - imgDrawWidth) / 2.0f); } } graph.DrawImage(_imageShow, imgDrawX, imgDrawY, imgDrawWidth, imgDrawHeight); - offsetX = imgDrawX; - offsetY = imgDrawY; - scaleX = (double)imgDrawWidth / (double)_imageShow.Width; - scaleY = (double)imgDrawHeight / (double)_imageShow.Height; } } diff --git a/VAR.Toolbox/Controls/CtrOutput.cs b/VAR.Toolbox/Controls/CtrOutput.cs index 15e314c..418bff1 100644 --- a/VAR.Toolbox/Controls/CtrOutput.cs +++ b/VAR.Toolbox/Controls/CtrOutput.cs @@ -41,8 +41,8 @@ namespace VAR.Toolbox.Controls ForeColor = Color.Gray, SelectionMode = SelectionMode.MultiExtended, }; - _listBox.MouseDoubleClick += _listBox_MouseDoubleClick; - _listBox.KeyDown += _listBox_KeyDown; + _listBox.MouseDoubleClick += ListBox_MouseDoubleClick; + _listBox.KeyDown += ListBox_KeyDown; Controls.Add(_listBox); _timer = new Timer @@ -50,7 +50,7 @@ namespace VAR.Toolbox.Controls Interval = 100, Enabled = true }; - _timer.Tick += _timer_Tick; + _timer.Tick += Timer_Tick; Disposed += CtrOutput_Disposed; } @@ -71,7 +71,7 @@ namespace VAR.Toolbox.Controls return base.ProcessCmdKey(ref msg, keyData); } - private void _listBox_KeyDown(object sender, KeyEventArgs e) + private void ListBox_KeyDown(object sender, KeyEventArgs e) { if (e.Control && e.KeyCode == Keys.C) { @@ -92,12 +92,12 @@ namespace VAR.Toolbox.Controls } } - private void _listBox_MouseDoubleClick(object sender, MouseEventArgs e) + private void ListBox_MouseDoubleClick(object sender, MouseEventArgs e) { DoubleClick?.Invoke(sender, e); } - private void _timer_Tick(object sender, EventArgs e) + private void Timer_Tick(object sender, EventArgs e) { if (_updated) { @@ -106,7 +106,7 @@ namespace VAR.Toolbox.Controls } private bool _updated = false; - private List _pendingOutput = new List(); + private readonly List _pendingOutput = new List(); private void UpdatePosition() { diff --git a/VAR.Toolbox/UI/FrmToolbox.cs b/VAR.Toolbox/UI/FrmToolbox.cs index 5728a37..5218221 100644 --- a/VAR.Toolbox/UI/FrmToolbox.cs +++ b/VAR.Toolbox/UI/FrmToolbox.cs @@ -33,10 +33,6 @@ namespace VAR.Toolbox.UI _currentInstance = this; } - private void InitializeCustomControls() - { - } - private void FrmToolbox_Load(object sender, EventArgs e) { Icon ico = Icon.ExtractAssociatedIcon(Application.ExecutablePath); diff --git a/VAR.Toolbox/UI/Tools/FrmCover.cs b/VAR.Toolbox/UI/Tools/FrmCover.cs index d9013a5..11fc906 100644 --- a/VAR.Toolbox/UI/Tools/FrmCover.cs +++ b/VAR.Toolbox/UI/Tools/FrmCover.cs @@ -10,8 +10,8 @@ namespace VAR.Toolbox.UI { #region Declarations - private Random rnd = new Random(); - private Timer _timer = new Timer(); + private readonly Random _rnd = new Random(); + private readonly Timer _timer = new Timer(); private readonly uint _mouseX = 0; private readonly uint _mouseY = 0; @@ -85,8 +85,8 @@ namespace VAR.Toolbox.UI try { Mouse.Move( - (rnd.Next() % 11) - 5, - (rnd.Next() % 11) - 5); + (_rnd.Next() % 11) - 5, + (_rnd.Next() % 11) - 5); } catch (Exception) { } // ignore exceptions moving mouse _timer.Stop(); diff --git a/VAR.Toolbox/UI/Tools/FrmProxyCmdConfig.cs b/VAR.Toolbox/UI/Tools/FrmProxyCmdConfig.cs index 6ea0af3..23fa0d8 100644 --- a/VAR.Toolbox/UI/Tools/FrmProxyCmdConfig.cs +++ b/VAR.Toolbox/UI/Tools/FrmProxyCmdConfig.cs @@ -135,7 +135,7 @@ namespace VAR.Toolbox.UI public static string[] GetConfigurationLines() { string configFile = GetConfigFileName(); - string[] config = null; + string[] config; if (File.Exists(configFile) == false) { config = new string[] { "Dummy|Dummy:" }; diff --git a/VAR.Toolbox/UI/Tools/FrmTestWebService.cs b/VAR.Toolbox/UI/Tools/FrmTestWebService.cs index fd84429..532e512 100644 --- a/VAR.Toolbox/UI/Tools/FrmTestWebService.cs +++ b/VAR.Toolbox/UI/Tools/FrmTestWebService.cs @@ -209,7 +209,7 @@ namespace VAR.Toolbox.UI } - private static CookieContainer _cookieJar = new CookieContainer(); + private static readonly CookieContainer _cookieJar = new CookieContainer(); public static string CallApi(string urlService, string urlApiMethod, Dictionary prms, string content) { diff --git a/VAR.Toolbox/UI/Tools/PnlCover.cs b/VAR.Toolbox/UI/Tools/PnlCover.cs index 50d55cd..b24b754 100644 --- a/VAR.Toolbox/UI/Tools/PnlCover.cs +++ b/VAR.Toolbox/UI/Tools/PnlCover.cs @@ -15,22 +15,16 @@ namespace VAR.Toolbox.UI { if (DesignMode) { return; } timTicker.Stop(); - bool userInactive = false; uint inactiveTime = Win32.GetLastInputTime(); lblInactive.Text = string.Format("Inactive by {0} seconds", inactiveTime); if (chkAutoCover.Checked) { - if (!userInactive && inactiveTime > numInactive.Value) + if (inactiveTime > numInactive.Value) { - userInactive = true; CoverScreen(); } - if (inactiveTime < 1) - { - userInactive = false; - } } timTicker.Start(); } diff --git a/VAR.Toolbox/UI/Tools/PnlSuspension.cs b/VAR.Toolbox/UI/Tools/PnlSuspension.cs index 2fd90ec..3d6f23b 100644 --- a/VAR.Toolbox/UI/Tools/PnlSuspension.cs +++ b/VAR.Toolbox/UI/Tools/PnlSuspension.cs @@ -6,7 +6,7 @@ namespace VAR.Toolbox.UI { public partial class PnlSuspension : UserControl, IToolPanel { - private Random rnd = new Random(); + private readonly Random _rnd = new Random(); public PnlSuspension() { @@ -48,31 +48,13 @@ namespace VAR.Toolbox.UI 0) .AddSeconds(Convert.ToInt32(numOffset.Value)); - if (DateTime.Compare(now, dtSuspendAtCustom) > 0) - { - if (chkSuspendAtCustom.Checked) - { - chkSuspendAtCustom.Checked = false; - RandomizeOffset(); - SuspendSystem(); - } - else - { - chkSuspendAtCustom.Enabled = false; - } - } - else - { - SetCountdown(dtSuspendAtCustom, now); - chkSuspendAtCustom.Enabled = true; - } + CheckTime(chkSuspendAtCustom, dtSuspendAtCustom, now); } timTicker.Stop(); timTicker.Start(); } - private void DdlCustomHour_Load() { for (int i = 0; i < 24; i++) @@ -98,7 +80,7 @@ namespace VAR.Toolbox.UI private void RandomizeOffset() { - numOffset.Value = (rnd.Next() % 599) + 1; + numOffset.Value = (_rnd.Next() % 599) + 1; } private void ResetCountdown() @@ -112,11 +94,11 @@ namespace VAR.Toolbox.UI lblCountdown.Text = string.Format("{0:00}:{1:00}:{2:00}:{3:00}", timeSpan.Days, timeSpan.Hours, timeSpan.Minutes, timeSpan.Seconds); } - private void CheckTime(CheckBox checkBox, DateTime dtSuspension, DateTime now) + private void CheckTime(CheckBox chkSuspendAtCustom, DateTime dtSuspendAtCustom, DateTime now) { - if (DateTime.Compare(now, dtSuspension) > 0) + if (DateTime.Compare(now, dtSuspendAtCustom) > 0) { - if (checkBox.Checked) + if (chkSuspendAtCustom.Checked) { chkSuspendAtCustom.Checked = false; RandomizeOffset(); @@ -124,16 +106,13 @@ namespace VAR.Toolbox.UI } else { - checkBox.Enabled = false; + chkSuspendAtCustom.Enabled = false; } } else { - checkBox.Enabled = true; - } - if (dtSuspension > now) - { - SetCountdown(dtSuspension, now); + SetCountdown(dtSuspendAtCustom, now); + chkSuspendAtCustom.Enabled = true; } } @@ -141,6 +120,5 @@ namespace VAR.Toolbox.UI { Win32.SetSuspendState(false, true, false); } - } }