mirror of
https://github.com/Hofknecht/SystemTrayMenu.git
synced 2024-05-19 20:03:25 +12:00
Code Analyze and Refactor 0.12 (#109), version 0.11.4.5
This commit is contained in:
parent
d38750c0b9
commit
14cc6af244
|
@ -38,6 +38,8 @@ namespace SystemTrayMenu.Business
|
|||
private readonly WaitLeave waitLeave = new WaitLeave(MenuDefines.TimeUntilClose);
|
||||
private DateTime deactivatedTime = DateTime.MinValue;
|
||||
private OpenCloseState openCloseState = OpenCloseState.Default;
|
||||
private RowData loadingRowData = null;
|
||||
private bool showingMessageBox = false;
|
||||
|
||||
public Menus()
|
||||
{
|
||||
|
@ -65,11 +67,40 @@ namespace SystemTrayMenu.Business
|
|||
keyboardInput.ResetSelectedByKey();
|
||||
LoadStopped();
|
||||
MenuData menuData = (MenuData)e.Result;
|
||||
if (menuData.Validity == MenuDataValidity.Valid)
|
||||
switch (menuData.Validity)
|
||||
{
|
||||
DisposeMenu(menus[menuData.Level]);
|
||||
menus[0] = Create(menuData, Path.GetFileName(Config.Path));
|
||||
AsEnumerable.ToList().ForEach(m => { m.ShowWithFade(); });
|
||||
case MenuDataValidity.Valid:
|
||||
DisposeMenu(menus[menuData.Level]);
|
||||
menus[0] = Create(menuData, Path.GetFileName(Config.Path));
|
||||
AsEnumerable.ToList().ForEach(m => { m.ShowWithFade(); });
|
||||
break;
|
||||
case MenuDataValidity.Empty:
|
||||
if (!showingMessageBox)
|
||||
{
|
||||
showingMessageBox = true;
|
||||
MessageBox.Show(Translator.GetText(
|
||||
"MessageRootFolderEmpty"));
|
||||
OpenFolder();
|
||||
showingMessageBox = false;
|
||||
}
|
||||
|
||||
break;
|
||||
case MenuDataValidity.NoAccess:
|
||||
if (!showingMessageBox)
|
||||
{
|
||||
showingMessageBox = true;
|
||||
MessageBox.Show(Translator.GetText(
|
||||
"MessageRootFolderNoAccess"));
|
||||
OpenFolder();
|
||||
showingMessageBox = false;
|
||||
}
|
||||
|
||||
break;
|
||||
case MenuDataValidity.AbortedOrUnknown:
|
||||
Log.Info("MenuDataValidity.AbortedOrUnknown");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -87,9 +118,11 @@ namespace SystemTrayMenu.Business
|
|||
void StartLoadMenu(RowData rowData)
|
||||
{
|
||||
if (menus[0].IsUsable &&
|
||||
loadingRowData != rowData &&
|
||||
(menus[rowData.MenuLevel + 1] == null ||
|
||||
menus[rowData.MenuLevel + 1].Tag as RowData != rowData))
|
||||
{
|
||||
loadingRowData = rowData;
|
||||
LoadStarted();
|
||||
BackgroundWorker workerSubMenu = workersSubMenu.
|
||||
Where(w => !w.IsBusy).FirstOrDefault();
|
||||
|
@ -135,6 +168,8 @@ namespace SystemTrayMenu.Business
|
|||
ShowSubMenu(menu);
|
||||
}
|
||||
}
|
||||
|
||||
loadingRowData = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -229,33 +264,48 @@ namespace SystemTrayMenu.Business
|
|||
directories = GetDirectoriesInNetworkLocation(path);
|
||||
static string[] GetDirectoriesInNetworkLocation(string networkLocationRootPath)
|
||||
{
|
||||
Process cmd = new Process();
|
||||
cmd.StartInfo.FileName = "cmd.exe";
|
||||
cmd.StartInfo.RedirectStandardInput = true;
|
||||
cmd.StartInfo.RedirectStandardOutput = true;
|
||||
cmd.StartInfo.CreateNoWindow = true;
|
||||
cmd.StartInfo.UseShellExecute = false;
|
||||
cmd.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
|
||||
cmd.Start();
|
||||
cmd.StandardInput.WriteLine($"net view {networkLocationRootPath}");
|
||||
cmd.StandardInput.Flush();
|
||||
cmd.StandardInput.Close();
|
||||
List<string> directories = new List<string>();
|
||||
try
|
||||
{
|
||||
Process cmd = new Process();
|
||||
cmd.StartInfo.FileName = "cmd.exe";
|
||||
cmd.StartInfo.RedirectStandardInput = true;
|
||||
cmd.StartInfo.RedirectStandardOutput = true;
|
||||
cmd.StartInfo.CreateNoWindow = true;
|
||||
cmd.StartInfo.UseShellExecute = false;
|
||||
cmd.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
|
||||
cmd.Start();
|
||||
cmd.StandardInput.WriteLine($"net view {networkLocationRootPath}");
|
||||
cmd.StandardInput.Flush();
|
||||
cmd.StandardInput.Close();
|
||||
|
||||
string output = cmd.StandardOutput.ReadToEnd();
|
||||
string output = cmd.StandardOutput.ReadToEnd();
|
||||
|
||||
cmd.WaitForExit();
|
||||
cmd.Close();
|
||||
cmd.WaitForExit();
|
||||
cmd.Close();
|
||||
|
||||
output = output.Substring(output.LastIndexOf('-') + 2);
|
||||
output = output.Substring(0, output.IndexOf("The command completed successfully.", StringComparison.InvariantCulture));
|
||||
output = output.Substring(output.LastIndexOf('-') + 2);
|
||||
output = output.Substring(0, output.IndexOf("The command completed successfully.", StringComparison.InvariantCulture));
|
||||
|
||||
return
|
||||
output
|
||||
.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries)
|
||||
.Select(x => Path.Combine(
|
||||
networkLocationRootPath,
|
||||
x.Substring(0, x.IndexOf(' ', StringComparison.InvariantCulture))))
|
||||
.ToArray();
|
||||
foreach (string line in output
|
||||
.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries))
|
||||
{
|
||||
int indexOfSecondColumnTypeDisk = line.IndexOf("Disk", StringComparison.InvariantCulture);
|
||||
if (indexOfSecondColumnTypeDisk > 0)
|
||||
{
|
||||
string directory = Path.Combine(
|
||||
networkLocationRootPath,
|
||||
line.Substring(0, indexOfSecondColumnTypeDisk));
|
||||
directories.Add(directory);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (ArgumentOutOfRangeException ex)
|
||||
{
|
||||
Log.Warn($"Could not resolve network root folder: {networkLocationRootPath}", ex);
|
||||
}
|
||||
|
||||
return directories.ToArray();
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -515,6 +565,11 @@ namespace SystemTrayMenu.Business
|
|||
Form.ActiveForm is UserInterface.TaskbarForm;
|
||||
}
|
||||
|
||||
private static void OpenFolder()
|
||||
{
|
||||
Log.ProcessStart("explorer.exe", Config.Path);
|
||||
}
|
||||
|
||||
private Menu Create(MenuData menuData, string title = null)
|
||||
{
|
||||
Menu menu = new Menu();
|
||||
|
@ -528,10 +583,6 @@ namespace SystemTrayMenu.Business
|
|||
|
||||
menu.SetTitle(title);
|
||||
menu.UserClickedOpenFolder += OpenFolder;
|
||||
static void OpenFolder()
|
||||
{
|
||||
Log.ProcessStart("explorer.exe", Config.Path);
|
||||
}
|
||||
}
|
||||
|
||||
menu.Level = menuData.Level;
|
||||
|
@ -674,7 +725,7 @@ namespace SystemTrayMenu.Business
|
|||
row.DefaultCellStyle.SelectionBackColor = Color.White;
|
||||
row.Selected = false;
|
||||
}
|
||||
else if (rowData.IsMenuOpen && rowData.IsSelected)
|
||||
else if (rowData.IsContextMenuOpen || (rowData.IsMenuOpen && rowData.IsSelected))
|
||||
{
|
||||
row.Selected = true;
|
||||
}
|
||||
|
@ -709,7 +760,7 @@ namespace SystemTrayMenu.Business
|
|||
int width = dgv.Columns[0].Width + dgv.Columns[1].Width;
|
||||
Rectangle rowBounds = new Rectangle(0, e.RowBounds.Top, width, e.RowBounds.Height);
|
||||
|
||||
if (rowData.IsMenuOpen && rowData.IsSelected)
|
||||
if (rowData.IsContextMenuOpen || (rowData.IsMenuOpen && rowData.IsSelected))
|
||||
{
|
||||
ControlPaint.DrawBorder(e.Graphics, rowBounds, MenuDefines.ColorSelectedItemBorder, ButtonBorderStyle.Solid);
|
||||
row.DefaultCellStyle.SelectionBackColor = MenuDefines.ColorSelectedItem;
|
||||
|
|
|
@ -177,9 +177,6 @@ namespace SystemTrayMenu.DataClasses
|
|||
(DateTime.Now - contextMenuClosed).TotalMilliseconds > 200)
|
||||
{
|
||||
IsContextMenuOpen = true;
|
||||
Color colorbefore = dgv.Rows[RowIndex].DefaultCellStyle.SelectionBackColor;
|
||||
dgv.Rows[RowIndex].DefaultCellStyle.SelectionBackColor =
|
||||
MenuDefines.ColorSelectedItem;
|
||||
|
||||
ShellContextMenu ctxMnu = new ShellContextMenu();
|
||||
Point location = dgv.FindForm().Location;
|
||||
|
@ -199,11 +196,6 @@ namespace SystemTrayMenu.DataClasses
|
|||
ctxMnu.ShowContextMenu(arrFI, point);
|
||||
}
|
||||
|
||||
if (!dgv.IsDisposed)
|
||||
{
|
||||
dgv.Rows[RowIndex].DefaultCellStyle.SelectionBackColor = colorbefore;
|
||||
}
|
||||
|
||||
IsContextMenuOpen = false;
|
||||
contextMenuClosed = DateTime.Now;
|
||||
}
|
||||
|
|
|
@ -39,5 +39,5 @@ using System.Runtime.InteropServices;
|
|||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("0.11.4.4")]
|
||||
[assembly: AssemblyFileVersion("0.11.4.4")]
|
||||
[assembly: AssemblyVersion("0.11.4.5")]
|
||||
[assembly: AssemblyFileVersion("0.11.4.5")]
|
||||
|
|
18
Resources/lang.Designer.cs
generated
18
Resources/lang.Designer.cs
generated
|
@ -222,6 +222,24 @@ namespace SystemTrayMenu.Resources {
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Your root folder for the SystemTrayMenu is empty! Put some files, folders or shortcuts into the folder or change the root folder..
|
||||
/// </summary>
|
||||
internal static string MessageRootFolderEmpty {
|
||||
get {
|
||||
return ResourceManager.GetString("MessageRootFolderEmpty", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to You have no access to the root folder for the SystemTrayMenu. Grant access to the folder or change the root folder..
|
||||
/// </summary>
|
||||
internal static string MessageRootFolderNoAccess {
|
||||
get {
|
||||
return ResourceManager.GetString("MessageRootFolderNoAccess", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Restart.
|
||||
/// </summary>
|
||||
|
|
|
@ -189,4 +189,10 @@
|
|||
<data name="Select Folder" xml:space="preserve">
|
||||
<value>Select Folder</value>
|
||||
</data>
|
||||
<data name="MessageRootFolderEmpty" xml:space="preserve">
|
||||
<value>Dein Hauptordner für die SystemTrayMenu ist leer! Pack ein paar Dateien, Ordner oder Verknüpfungen in den Hauptordner oder ändere den Hauptordner.</value>
|
||||
</data>
|
||||
<data name="MessageRootFolderNoAccess" xml:space="preserve">
|
||||
<value>Du hast keine Rechte für den Hauptordner. Gewähre die Rechte oder ändere den Hauptordner.</value>
|
||||
</data>
|
||||
</root>
|
|
@ -189,4 +189,10 @@
|
|||
<data name="Select Folder" xml:space="preserve">
|
||||
<value>Select Folder</value>
|
||||
</data>
|
||||
<data name="MessageRootFolderEmpty" xml:space="preserve">
|
||||
<value>Your root folder for the SystemTrayMenu is empty! Put some files, folders or shortcuts into the folder or change the root folder.</value>
|
||||
</data>
|
||||
<data name="MessageRootFolderNoAccess" xml:space="preserve">
|
||||
<value>You have no access to the root folder for the SystemTrayMenu. Grant access to the folder or change the root folder.</value>
|
||||
</data>
|
||||
</root>
|
|
@ -197,6 +197,10 @@
|
|||
</BootstrapperPackage>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.9.6">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="StyleCop.Analyzers.Unstable" Version="1.2.0.164">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
|
|
|
@ -24,8 +24,8 @@ namespace SystemTrayMenu.Utilities
|
|||
public static class IconReader
|
||||
{
|
||||
private static readonly ConcurrentDictionary<string, Icon> DictIconCache = new ConcurrentDictionary<string, Icon>();
|
||||
private static readonly object ReadIcon = new object();
|
||||
|
||||
// private static readonly object ReadIcon = new object();
|
||||
public enum IconSize
|
||||
{
|
||||
Large = 0, // 32x32 pixels
|
||||
|
@ -50,22 +50,23 @@ namespace SystemTrayMenu.Utilities
|
|||
{
|
||||
Icon icon = null;
|
||||
string extension = Path.GetExtension(filePath);
|
||||
lock (ReadIcon)
|
||||
|
||||
// lock (ReadIcon)
|
||||
// {
|
||||
if (IsExtensionWitSameIcon(extension))
|
||||
{
|
||||
if (IsExtensionWitSameIcon(extension))
|
||||
icon = DictIconCache.GetOrAdd(extension, GetIcon);
|
||||
Icon GetIcon(string keyExtension)
|
||||
{
|
||||
icon = DictIconCache.GetOrAdd(extension, GetIcon);
|
||||
Icon GetIcon(string keyExtension)
|
||||
{
|
||||
return GetFileIcon(filePath, linkOverlay, size);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
icon = GetFileIcon(filePath, linkOverlay, size);
|
||||
return GetFileIcon(filePath, linkOverlay, size);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
icon = GetFileIcon(filePath, linkOverlay, size);
|
||||
}
|
||||
|
||||
// }
|
||||
return icon;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
// <copyright file="Language.cs" company="PlaceholderCompany">
|
||||
// Copyright (c) PlaceholderCompany. All rights reserved.
|
||||
// </copyright>
|
||||
|
||||
namespace SystemTrayMenu.Utilities
|
||||
{
|
||||
internal class Language
|
||||
{
|
||||
public string Name { get; set; }
|
||||
|
||||
public string Value { get; set; }
|
||||
}
|
||||
}
|
|
@ -65,39 +65,29 @@ namespace SystemTrayMenu.Utilities
|
|||
|
||||
internal static void ProcessStart(string fileName, string arguments = null)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(arguments) &&
|
||||
!Directory.Exists(arguments))
|
||||
try
|
||||
{
|
||||
Exception ex = new DirectoryNotFoundException();
|
||||
Warn($"path:'{arguments}'", ex);
|
||||
MessageBox.Show(ex.Message);
|
||||
using Process p = new Process
|
||||
{
|
||||
StartInfo = new ProcessStartInfo(fileName)
|
||||
{
|
||||
Arguments = arguments,
|
||||
UseShellExecute = true,
|
||||
},
|
||||
};
|
||||
p.Start();
|
||||
}
|
||||
else
|
||||
catch (Exception ex)
|
||||
{
|
||||
try
|
||||
if (ex is FileNotFoundException ||
|
||||
ex is Win32Exception)
|
||||
{
|
||||
using Process p = new Process
|
||||
{
|
||||
StartInfo = new ProcessStartInfo(fileName)
|
||||
{
|
||||
Arguments = arguments,
|
||||
UseShellExecute = true,
|
||||
},
|
||||
};
|
||||
p.Start();
|
||||
Warn($"fileName:'{fileName}' arguments:'{arguments}'", ex);
|
||||
MessageBox.Show(ex.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
else
|
||||
{
|
||||
if (ex is FileNotFoundException ||
|
||||
ex is Win32Exception)
|
||||
{
|
||||
Warn($"fileName:'{fileName}' arguments:'{arguments}'", ex);
|
||||
MessageBox.Show(ex.Message);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw;
|
||||
}
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue