[Feature] CodeBuity&Refactor #49 - fix warnings

This commit is contained in:
Markus Hofknecht 2020-03-23 12:22:26 +01:00
parent 254d888baf
commit 01b8fbe4dc
4 changed files with 36 additions and 33 deletions

View file

@ -6,9 +6,9 @@ using SystemTrayMenu.Helper;
namespace SystemTrayMenu
{
public class Config
public static class Config
{
public static string Language = "en";
public const string Language = "en";
public static string Path
{

View file

@ -90,7 +90,7 @@ namespace SystemTrayMenu.Controls
}
set
{
if (value == "")
if (string.IsNullOrEmpty(value))
{
AppDescriptionLabel.Visible = false;
}
@ -117,7 +117,7 @@ namespace SystemTrayMenu.Controls
}
set
{
if (value == "")
if (string.IsNullOrEmpty(value))
{
AppVersionLabel.Visible = false;
}
@ -145,7 +145,7 @@ namespace SystemTrayMenu.Controls
}
set
{
if (value == "")
if (string.IsNullOrEmpty(value))
{
AppCopyrightLabel.Visible = false;
}
@ -192,7 +192,7 @@ namespace SystemTrayMenu.Controls
}
set
{
if (value == null || value == "")
if (string.IsNullOrEmpty(value))
{
MoreRichTextBox.Visible = false;
}
@ -223,18 +223,19 @@ namespace SystemTrayMenu.Controls
// exception-safe retrieval of LastWriteTime for this assembly.
// </summary>
// <returns>File.GetLastWriteTime, or DateTime.MaxValue if exception was encountered.</returns>
private DateTime AssemblyLastWriteTime(Assembly a)
private static DateTime AssemblyLastWriteTime(Assembly a)
{
if (a.Location == null || a.Location == "")
return DateTime.MaxValue;
try
DateTime assemblyLastWriteTime = DateTime.MaxValue;
if (!string.IsNullOrEmpty(a.Location))
{
return File.GetLastWriteTime(a.Location);
}
catch (Exception)
{
return DateTime.MaxValue;
try
{
assemblyLastWriteTime = File.GetLastWriteTime(a.Location);
}
catch (Exception) { }
}
return assemblyLastWriteTime;
}
// <summary>
@ -244,7 +245,7 @@ namespace SystemTrayMenu.Controls
// <param name="a">Assembly to get build date for</param>
// <param name="ForceFileDate">Don't attempt to use the build number to calculate the date</param>
// <returns>DateTime this assembly was last built</returns>
private DateTime AssemblyBuildDate(Assembly a, bool ForceFileDate)
private static DateTime AssemblyBuildDate(Assembly a, bool ForceFileDate)
{
Version AssemblyVersion = a.GetName().Version;
DateTime dt;
@ -436,12 +437,12 @@ namespace SystemTrayMenu.Controls
string strSysInfoPath = "";
strSysInfoPath = RegistryHklmValue(@"SOFTWARE\Microsoft\Shared Tools Location", "MSINFO");
if (strSysInfoPath == "")
if (string.IsNullOrEmpty(strSysInfoPath))
{
strSysInfoPath = RegistryHklmValue(@"SOFTWARE\Microsoft\Shared Tools\MSINFO", "PATH");
}
if (strSysInfoPath == "")
if (string.IsNullOrEmpty(strSysInfoPath))
{
MessageBox.Show("System Information is unavailable at this time." +
Environment.NewLine +
@ -471,12 +472,13 @@ namespace SystemTrayMenu.Controls
// </summary>
private void Populate(ListView lvw, string Key, string Value)
{
if (Value == "")
return;
ListViewItem lvi = new ListViewItem();
lvi.Text = Key;
lvi.SubItems.Add(Value);
lvw.Items.Add(lvi);
if (!string.IsNullOrEmpty(Value))
{
ListViewItem lvi = new ListViewItem();
lvi.Text = Key;
lvi.SubItems.Add(Value);
lvw.Items.Add(lvi);
}
}
// <summary>

View file

@ -50,7 +50,7 @@ namespace SystemTrayMenu.Controls
public void SetText(string text)
{
if (text.Length > MenuDefines.LengthMax)
if (text != null && text.Length > MenuDefines.LengthMax)
{
text = $"{text.Substring(0, MenuDefines.LengthMax)}...";
}
@ -122,7 +122,8 @@ namespace SystemTrayMenu.Controls
string browserPath = FileUrl.GetDefaultBrowserPath();
if (string.IsNullOrEmpty(browserPath))
{
Log.Info($"No default browser found!");
Log.Info($"Resolve *.URL '{TargetFilePath}'" +
$"No default browser found!");
}
else
{
@ -159,7 +160,7 @@ namespace SystemTrayMenu.Controls
var executable = new StringBuilder(1024);
try
{
FindExecutable(TargetFilePath, string.Empty, executable);
_ = FindExecutable(TargetFilePath, string.Empty, executable);
// icon = IconReader.GetFileIcon(executable, false);
// e.g. VS 2019 icon, need another icom in imagelist
List<Icon> extractedIcons = IconHelper.ExtractAllIcons(

View file

@ -54,7 +54,7 @@ namespace SystemTrayMenu
menuNotifyIcon.HandleClick += SwitchOpenClose;
void SwitchOpenClose()
{
if (Config.Path == string.Empty)
if (string.IsNullOrEmpty(Config.Path))
{
//Case when Folder Dialog open
}
@ -333,7 +333,7 @@ namespace SystemTrayMenu
return isAnyMenuActive;
}
MenuData ReadMenu(BackgroundWorker worker, string path, int level)
private static MenuData ReadMenu(BackgroundWorker worker, string path, int level)
{
MenuData menuData = new MenuData();
menuData.RowDatas = new List<RowData>();
@ -341,7 +341,7 @@ namespace SystemTrayMenu
menuData.Level = level;
if (!worker.CancellationPending)
{
string[] directories = new string[] { };
string[] directories = Array.Empty<string>();
try
{
@ -381,7 +381,7 @@ namespace SystemTrayMenu
if (!worker.CancellationPending)
{
string[] files = new string[] { };
string[] files = Array.Empty<string>();
try
{
@ -436,7 +436,7 @@ namespace SystemTrayMenu
return menuData;
}
RowData ReadMenuButtonData(string fileName,
private static RowData ReadMenuButtonData(string fileName,
bool isResolvedLnk, RowData menuButtonData = null)
{
if (menuButtonData == null)
@ -645,7 +645,7 @@ namespace SystemTrayMenu
Menu menu = new Menu();
if (title != null)
{
if (title == string.Empty)
if (string.IsNullOrEmpty(title))
{
title = Path.GetPathRoot(Config.Path);
}