More warning fixes

This commit is contained in:
2019-05-27 07:34:45 +02:00
parent c5b76ee077
commit 1f1cbfd1e5
12 changed files with 58 additions and 93 deletions

View File

@@ -4,7 +4,13 @@
{ {
public string Name { get { return "Dummy"; } } 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) public bool ExecuteCmd(string cmdString, IOutputHandler outputHandler)
{ {

View File

@@ -6,7 +6,7 @@ namespace VAR.Toolbox.Code.ProxyCmdExecutors
{ {
public string Name { get { return "WMIC"; } } public string Name { get { return "WMIC"; } }
private string _configWMIC; private readonly string _configWMIC;
public ProxyCmdExecutorWMIC(string configWMIC) public ProxyCmdExecutorWMIC(string configWMIC)
{ {

View File

@@ -52,8 +52,8 @@ namespace VAR.Toolbox.Code
User32.GetWindowRect(handle, ref windowRect); User32.GetWindowRect(handle, ref windowRect);
int left = windowRect.left; int left = windowRect.left;
int top = windowRect.top; int top = windowRect.top;
int width = windowRect.right - windowRect.left; int width = windowRect.right - left;
int height = windowRect.bottom - windowRect.top; int height = windowRect.bottom - top;
// create a device context we can copy to // create a device context we can copy to
IntPtr hdcDest = GDI32.CreateCompatibleDC(hdcSrc); IntPtr hdcDest = GDI32.CreateCompatibleDC(hdcSrc);
// create a bitmap we can copy it to, // create a bitmap we can copy it to,

View File

@@ -1,4 +1,5 @@
#pragma warning disable IDE0018 #pragma warning disable IDE0018
#pragma warning disable IDE0059
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@@ -15,17 +16,17 @@ namespace VAR.Toolbox.Code
{ {
#region Declarations #region Declarations
private IFilterGraph2 graph; private readonly IFilterGraph2 graph;
private ICaptureGraphBuilder2 capture; private readonly ICaptureGraphBuilder2 capture;
private IMediaControl control; private readonly IMediaControl control;
private IBaseFilter sourceFilter; private readonly IBaseFilter sourceFilter;
private IBaseFilter samplegrabberfilter; private readonly IBaseFilter samplegrabberfilter;
private IBaseFilter nullrenderer; private readonly IBaseFilter nullrenderer;
private readonly Grabber grabber; private readonly Grabber grabber;
private int width = 0; private readonly int width = 0;
private int height = 0; private readonly int height = 0;
private readonly int bpp = 0; private readonly int bpp = 0;
private bool active = false; private bool active = false;
@@ -264,7 +265,7 @@ namespace VAR.Toolbox.Code
private class Grabber : ISampleGrabberCB private class Grabber : ISampleGrabberCB
{ {
private Webcam _parent; private readonly Webcam _parent;
private readonly Bitmap[] _frames = null; private readonly Bitmap[] _frames = null;
private readonly int _numFrames = 10; private readonly int _numFrames = 10;

View File

@@ -10,12 +10,6 @@ namespace VAR.Toolbox.Controls
private Image _imageShow = null; 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 #endregion
#region Properties #region Properties
@@ -28,7 +22,7 @@ namespace VAR.Toolbox.Controls
lock (this) lock (this)
{ {
_imageShow = value; _imageShow = value;
this.Invalidate(); Invalidate();
} }
} }
} }
@@ -81,41 +75,37 @@ namespace VAR.Toolbox.Controls
if (relation > 0) if (relation > 0)
{ {
// Imagen mas ancha que alta // Imagen mas ancha que alta
imgDrawHeight = (int)(this.Width / relation); imgDrawHeight = (int)(Width / relation);
if (imgDrawHeight > this.Height) if (imgDrawHeight > Height)
{ {
imgDrawHeight = this.Height; imgDrawHeight = Height;
imgDrawWidth = (int)(this.Height * relation); imgDrawWidth = (int)(Height * relation);
imgDrawX = ((this.Width - imgDrawWidth) / 2.0f); imgDrawX = ((Width - imgDrawWidth) / 2.0f);
} }
else else
{ {
imgDrawWidth = this.Width; imgDrawWidth = Width;
imgDrawY = ((this.Height - imgDrawHeight) / 2.0f); imgDrawY = ((Height - imgDrawHeight) / 2.0f);
} }
} }
else else
{ {
// Imagen mas alta que ancha // Imagen mas alta que ancha
imgDrawWidth = (int)(this.Width * relation); imgDrawWidth = (int)(Width * relation);
if (imgDrawWidth > this.Width) if (imgDrawWidth > Width)
{ {
imgDrawWidth = this.Width; imgDrawWidth = Width;
imgDrawHeight = (int)(this.Height / relation); imgDrawHeight = (int)(Height / relation);
imgDrawY = ((this.Height - imgDrawHeight) / 2.0f); imgDrawY = ((Height - imgDrawHeight) / 2.0f);
} }
else else
{ {
imgDrawHeight = this.Height; imgDrawHeight = Height;
imgDrawX = ((this.Width - imgDrawWidth) / 2.0f); imgDrawX = ((Width - imgDrawWidth) / 2.0f);
} }
} }
graph.DrawImage(_imageShow, imgDrawX, imgDrawY, imgDrawWidth, imgDrawHeight); graph.DrawImage(_imageShow, imgDrawX, imgDrawY, imgDrawWidth, imgDrawHeight);
offsetX = imgDrawX;
offsetY = imgDrawY;
scaleX = (double)imgDrawWidth / (double)_imageShow.Width;
scaleY = (double)imgDrawHeight / (double)_imageShow.Height;
} }
} }

View File

@@ -41,8 +41,8 @@ namespace VAR.Toolbox.Controls
ForeColor = Color.Gray, ForeColor = Color.Gray,
SelectionMode = SelectionMode.MultiExtended, SelectionMode = SelectionMode.MultiExtended,
}; };
_listBox.MouseDoubleClick += _listBox_MouseDoubleClick; _listBox.MouseDoubleClick += ListBox_MouseDoubleClick;
_listBox.KeyDown += _listBox_KeyDown; _listBox.KeyDown += ListBox_KeyDown;
Controls.Add(_listBox); Controls.Add(_listBox);
_timer = new Timer _timer = new Timer
@@ -50,7 +50,7 @@ namespace VAR.Toolbox.Controls
Interval = 100, Interval = 100,
Enabled = true Enabled = true
}; };
_timer.Tick += _timer_Tick; _timer.Tick += Timer_Tick;
Disposed += CtrOutput_Disposed; Disposed += CtrOutput_Disposed;
} }
@@ -71,7 +71,7 @@ namespace VAR.Toolbox.Controls
return base.ProcessCmdKey(ref msg, keyData); 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) 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); DoubleClick?.Invoke(sender, e);
} }
private void _timer_Tick(object sender, EventArgs e) private void Timer_Tick(object sender, EventArgs e)
{ {
if (_updated) if (_updated)
{ {
@@ -106,7 +106,7 @@ namespace VAR.Toolbox.Controls
} }
private bool _updated = false; private bool _updated = false;
private List<OutputItem> _pendingOutput = new List<OutputItem>(); private readonly List<OutputItem> _pendingOutput = new List<OutputItem>();
private void UpdatePosition() private void UpdatePosition()
{ {

View File

@@ -33,10 +33,6 @@ namespace VAR.Toolbox.UI
_currentInstance = this; _currentInstance = this;
} }
private void InitializeCustomControls()
{
}
private void FrmToolbox_Load(object sender, EventArgs e) private void FrmToolbox_Load(object sender, EventArgs e)
{ {
Icon ico = Icon.ExtractAssociatedIcon(Application.ExecutablePath); Icon ico = Icon.ExtractAssociatedIcon(Application.ExecutablePath);

View File

@@ -10,8 +10,8 @@ namespace VAR.Toolbox.UI
{ {
#region Declarations #region Declarations
private Random rnd = new Random(); private readonly Random _rnd = new Random();
private Timer _timer = new Timer(); private readonly Timer _timer = new Timer();
private readonly uint _mouseX = 0; private readonly uint _mouseX = 0;
private readonly uint _mouseY = 0; private readonly uint _mouseY = 0;
@@ -85,8 +85,8 @@ namespace VAR.Toolbox.UI
try try
{ {
Mouse.Move( Mouse.Move(
(rnd.Next() % 11) - 5, (_rnd.Next() % 11) - 5,
(rnd.Next() % 11) - 5); (_rnd.Next() % 11) - 5);
} }
catch (Exception) { } // ignore exceptions moving mouse catch (Exception) { } // ignore exceptions moving mouse
_timer.Stop(); _timer.Stop();

View File

@@ -135,7 +135,7 @@ namespace VAR.Toolbox.UI
public static string[] GetConfigurationLines() public static string[] GetConfigurationLines()
{ {
string configFile = GetConfigFileName(); string configFile = GetConfigFileName();
string[] config = null; string[] config;
if (File.Exists(configFile) == false) if (File.Exists(configFile) == false)
{ {
config = new string[] { "Dummy|Dummy:" }; config = new string[] { "Dummy|Dummy:" };

View File

@@ -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<string, string> prms, string content) public static string CallApi(string urlService, string urlApiMethod, Dictionary<string, string> prms, string content)
{ {

View File

@@ -15,22 +15,16 @@ namespace VAR.Toolbox.UI
{ {
if (DesignMode) { return; } if (DesignMode) { return; }
timTicker.Stop(); timTicker.Stop();
bool userInactive = false;
uint inactiveTime = Win32.GetLastInputTime(); uint inactiveTime = Win32.GetLastInputTime();
lblInactive.Text = string.Format("Inactive by {0} seconds", inactiveTime); lblInactive.Text = string.Format("Inactive by {0} seconds", inactiveTime);
if (chkAutoCover.Checked) if (chkAutoCover.Checked)
{ {
if (!userInactive && inactiveTime > numInactive.Value) if (inactiveTime > numInactive.Value)
{ {
userInactive = true;
CoverScreen(); CoverScreen();
} }
if (inactiveTime < 1)
{
userInactive = false;
}
} }
timTicker.Start(); timTicker.Start();
} }

View File

@@ -6,7 +6,7 @@ namespace VAR.Toolbox.UI
{ {
public partial class PnlSuspension : UserControl, IToolPanel public partial class PnlSuspension : UserControl, IToolPanel
{ {
private Random rnd = new Random(); private readonly Random _rnd = new Random();
public PnlSuspension() public PnlSuspension()
{ {
@@ -48,31 +48,13 @@ namespace VAR.Toolbox.UI
0) 0)
.AddSeconds(Convert.ToInt32(numOffset.Value)); .AddSeconds(Convert.ToInt32(numOffset.Value));
if (DateTime.Compare(now, dtSuspendAtCustom) > 0) CheckTime(chkSuspendAtCustom, dtSuspendAtCustom, now);
{
if (chkSuspendAtCustom.Checked)
{
chkSuspendAtCustom.Checked = false;
RandomizeOffset();
SuspendSystem();
}
else
{
chkSuspendAtCustom.Enabled = false;
}
}
else
{
SetCountdown(dtSuspendAtCustom, now);
chkSuspendAtCustom.Enabled = true;
}
} }
timTicker.Stop(); timTicker.Stop();
timTicker.Start(); timTicker.Start();
} }
private void DdlCustomHour_Load() private void DdlCustomHour_Load()
{ {
for (int i = 0; i < 24; i++) for (int i = 0; i < 24; i++)
@@ -98,7 +80,7 @@ namespace VAR.Toolbox.UI
private void RandomizeOffset() private void RandomizeOffset()
{ {
numOffset.Value = (rnd.Next() % 599) + 1; numOffset.Value = (_rnd.Next() % 599) + 1;
} }
private void ResetCountdown() 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); 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; chkSuspendAtCustom.Checked = false;
RandomizeOffset(); RandomizeOffset();
@@ -124,16 +106,13 @@ namespace VAR.Toolbox.UI
} }
else else
{ {
checkBox.Enabled = false; chkSuspendAtCustom.Enabled = false;
} }
} }
else else
{ {
checkBox.Enabled = true; SetCountdown(dtSuspendAtCustom, now);
} chkSuspendAtCustom.Enabled = true;
if (dtSuspension > now)
{
SetCountdown(dtSuspension, now);
} }
} }
@@ -141,6 +120,5 @@ namespace VAR.Toolbox.UI
{ {
Win32.SetSuspendState(false, true, false); Win32.SetSuspendState(false, true, false);
} }
} }
} }