mirror of
https://github.com/Hofknecht/SystemTrayMenu.git
synced 2024-07-04 14:00:25 +12:00
[Feature] CodeBuity&Refactor #49 - fix warnings
This commit is contained in:
parent
254d888baf
commit
01b8fbe4dc
|
@ -6,9 +6,9 @@ using SystemTrayMenu.Helper;
|
||||||
|
|
||||||
namespace SystemTrayMenu
|
namespace SystemTrayMenu
|
||||||
{
|
{
|
||||||
public class Config
|
public static class Config
|
||||||
{
|
{
|
||||||
public static string Language = "en";
|
public const string Language = "en";
|
||||||
|
|
||||||
public static string Path
|
public static string Path
|
||||||
{
|
{
|
||||||
|
|
|
@ -90,7 +90,7 @@ namespace SystemTrayMenu.Controls
|
||||||
}
|
}
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (value == "")
|
if (string.IsNullOrEmpty(value))
|
||||||
{
|
{
|
||||||
AppDescriptionLabel.Visible = false;
|
AppDescriptionLabel.Visible = false;
|
||||||
}
|
}
|
||||||
|
@ -117,7 +117,7 @@ namespace SystemTrayMenu.Controls
|
||||||
}
|
}
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (value == "")
|
if (string.IsNullOrEmpty(value))
|
||||||
{
|
{
|
||||||
AppVersionLabel.Visible = false;
|
AppVersionLabel.Visible = false;
|
||||||
}
|
}
|
||||||
|
@ -145,7 +145,7 @@ namespace SystemTrayMenu.Controls
|
||||||
}
|
}
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (value == "")
|
if (string.IsNullOrEmpty(value))
|
||||||
{
|
{
|
||||||
AppCopyrightLabel.Visible = false;
|
AppCopyrightLabel.Visible = false;
|
||||||
}
|
}
|
||||||
|
@ -192,7 +192,7 @@ namespace SystemTrayMenu.Controls
|
||||||
}
|
}
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (value == null || value == "")
|
if (string.IsNullOrEmpty(value))
|
||||||
{
|
{
|
||||||
MoreRichTextBox.Visible = false;
|
MoreRichTextBox.Visible = false;
|
||||||
}
|
}
|
||||||
|
@ -223,18 +223,19 @@ namespace SystemTrayMenu.Controls
|
||||||
// exception-safe retrieval of LastWriteTime for this assembly.
|
// exception-safe retrieval of LastWriteTime for this assembly.
|
||||||
// </summary>
|
// </summary>
|
||||||
// <returns>File.GetLastWriteTime, or DateTime.MaxValue if exception was encountered.</returns>
|
// <returns>File.GetLastWriteTime, or DateTime.MaxValue if exception was encountered.</returns>
|
||||||
private DateTime AssemblyLastWriteTime(Assembly a)
|
private static DateTime AssemblyLastWriteTime(Assembly a)
|
||||||
|
{
|
||||||
|
DateTime assemblyLastWriteTime = DateTime.MaxValue;
|
||||||
|
if (!string.IsNullOrEmpty(a.Location))
|
||||||
{
|
{
|
||||||
if (a.Location == null || a.Location == "")
|
|
||||||
return DateTime.MaxValue;
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return File.GetLastWriteTime(a.Location);
|
assemblyLastWriteTime = File.GetLastWriteTime(a.Location);
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception) { }
|
||||||
{
|
|
||||||
return DateTime.MaxValue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return assemblyLastWriteTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
// <summary>
|
// <summary>
|
||||||
|
@ -244,7 +245,7 @@ namespace SystemTrayMenu.Controls
|
||||||
// <param name="a">Assembly to get build date for</param>
|
// <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>
|
// <param name="ForceFileDate">Don't attempt to use the build number to calculate the date</param>
|
||||||
// <returns>DateTime this assembly was last built</returns>
|
// <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;
|
Version AssemblyVersion = a.GetName().Version;
|
||||||
DateTime dt;
|
DateTime dt;
|
||||||
|
@ -436,12 +437,12 @@ namespace SystemTrayMenu.Controls
|
||||||
string strSysInfoPath = "";
|
string strSysInfoPath = "";
|
||||||
|
|
||||||
strSysInfoPath = RegistryHklmValue(@"SOFTWARE\Microsoft\Shared Tools Location", "MSINFO");
|
strSysInfoPath = RegistryHklmValue(@"SOFTWARE\Microsoft\Shared Tools Location", "MSINFO");
|
||||||
if (strSysInfoPath == "")
|
if (string.IsNullOrEmpty(strSysInfoPath))
|
||||||
{
|
{
|
||||||
strSysInfoPath = RegistryHklmValue(@"SOFTWARE\Microsoft\Shared Tools\MSINFO", "PATH");
|
strSysInfoPath = RegistryHklmValue(@"SOFTWARE\Microsoft\Shared Tools\MSINFO", "PATH");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strSysInfoPath == "")
|
if (string.IsNullOrEmpty(strSysInfoPath))
|
||||||
{
|
{
|
||||||
MessageBox.Show("System Information is unavailable at this time." +
|
MessageBox.Show("System Information is unavailable at this time." +
|
||||||
Environment.NewLine +
|
Environment.NewLine +
|
||||||
|
@ -471,13 +472,14 @@ namespace SystemTrayMenu.Controls
|
||||||
// </summary>
|
// </summary>
|
||||||
private void Populate(ListView lvw, string Key, string Value)
|
private void Populate(ListView lvw, string Key, string Value)
|
||||||
{
|
{
|
||||||
if (Value == "")
|
if (!string.IsNullOrEmpty(Value))
|
||||||
return;
|
{
|
||||||
ListViewItem lvi = new ListViewItem();
|
ListViewItem lvi = new ListViewItem();
|
||||||
lvi.Text = Key;
|
lvi.Text = Key;
|
||||||
lvi.SubItems.Add(Value);
|
lvi.SubItems.Add(Value);
|
||||||
lvw.Items.Add(lvi);
|
lvw.Items.Add(lvi);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// <summary>
|
// <summary>
|
||||||
// populates the Application Information listview
|
// populates the Application Information listview
|
||||||
|
|
|
@ -50,7 +50,7 @@ namespace SystemTrayMenu.Controls
|
||||||
|
|
||||||
public void SetText(string text)
|
public void SetText(string text)
|
||||||
{
|
{
|
||||||
if (text.Length > MenuDefines.LengthMax)
|
if (text != null && text.Length > MenuDefines.LengthMax)
|
||||||
{
|
{
|
||||||
text = $"{text.Substring(0, MenuDefines.LengthMax)}...";
|
text = $"{text.Substring(0, MenuDefines.LengthMax)}...";
|
||||||
}
|
}
|
||||||
|
@ -122,7 +122,8 @@ namespace SystemTrayMenu.Controls
|
||||||
string browserPath = FileUrl.GetDefaultBrowserPath();
|
string browserPath = FileUrl.GetDefaultBrowserPath();
|
||||||
if (string.IsNullOrEmpty(browserPath))
|
if (string.IsNullOrEmpty(browserPath))
|
||||||
{
|
{
|
||||||
Log.Info($"No default browser found!");
|
Log.Info($"Resolve *.URL '{TargetFilePath}'" +
|
||||||
|
$"No default browser found!");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -159,7 +160,7 @@ namespace SystemTrayMenu.Controls
|
||||||
var executable = new StringBuilder(1024);
|
var executable = new StringBuilder(1024);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
FindExecutable(TargetFilePath, string.Empty, executable);
|
_ = FindExecutable(TargetFilePath, string.Empty, executable);
|
||||||
// icon = IconReader.GetFileIcon(executable, false);
|
// icon = IconReader.GetFileIcon(executable, false);
|
||||||
// e.g. VS 2019 icon, need another icom in imagelist
|
// e.g. VS 2019 icon, need another icom in imagelist
|
||||||
List<Icon> extractedIcons = IconHelper.ExtractAllIcons(
|
List<Icon> extractedIcons = IconHelper.ExtractAllIcons(
|
||||||
|
|
|
@ -54,7 +54,7 @@ namespace SystemTrayMenu
|
||||||
menuNotifyIcon.HandleClick += SwitchOpenClose;
|
menuNotifyIcon.HandleClick += SwitchOpenClose;
|
||||||
void SwitchOpenClose()
|
void SwitchOpenClose()
|
||||||
{
|
{
|
||||||
if (Config.Path == string.Empty)
|
if (string.IsNullOrEmpty(Config.Path))
|
||||||
{
|
{
|
||||||
//Case when Folder Dialog open
|
//Case when Folder Dialog open
|
||||||
}
|
}
|
||||||
|
@ -333,7 +333,7 @@ namespace SystemTrayMenu
|
||||||
return isAnyMenuActive;
|
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 menuData = new MenuData();
|
||||||
menuData.RowDatas = new List<RowData>();
|
menuData.RowDatas = new List<RowData>();
|
||||||
|
@ -341,7 +341,7 @@ namespace SystemTrayMenu
|
||||||
menuData.Level = level;
|
menuData.Level = level;
|
||||||
if (!worker.CancellationPending)
|
if (!worker.CancellationPending)
|
||||||
{
|
{
|
||||||
string[] directories = new string[] { };
|
string[] directories = Array.Empty<string>();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -381,7 +381,7 @@ namespace SystemTrayMenu
|
||||||
|
|
||||||
if (!worker.CancellationPending)
|
if (!worker.CancellationPending)
|
||||||
{
|
{
|
||||||
string[] files = new string[] { };
|
string[] files = Array.Empty<string>();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -436,7 +436,7 @@ namespace SystemTrayMenu
|
||||||
return menuData;
|
return menuData;
|
||||||
}
|
}
|
||||||
|
|
||||||
RowData ReadMenuButtonData(string fileName,
|
private static RowData ReadMenuButtonData(string fileName,
|
||||||
bool isResolvedLnk, RowData menuButtonData = null)
|
bool isResolvedLnk, RowData menuButtonData = null)
|
||||||
{
|
{
|
||||||
if (menuButtonData == null)
|
if (menuButtonData == null)
|
||||||
|
@ -645,7 +645,7 @@ namespace SystemTrayMenu
|
||||||
Menu menu = new Menu();
|
Menu menu = new Menu();
|
||||||
if (title != null)
|
if (title != null)
|
||||||
{
|
{
|
||||||
if (title == string.Empty)
|
if (string.IsNullOrEmpty(title))
|
||||||
{
|
{
|
||||||
title = Path.GetPathRoot(Config.Path);
|
title = Path.GetPathRoot(Config.Path);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue