From 73047376c9d6409e5c5c51cc585b09d7561593d2 Mon Sep 17 00:00:00 2001 From: Smurf-IV Date: Mon, 1 Oct 2018 18:18:12 +0100 Subject: [PATCH] Catch-up and fix issues #21 #17 #19 #20 --- Elucidate/Elucidate.sln | 22 ++- Elucidate/Elucidate/ConfigFileHelper.cs | 20 ++- .../Controls/LiveRunLogControl.Designer.cs | 4 +- .../Elucidate/Controls/LogsViewerControl.cs | 5 +- .../Elucidate/HelperClasses/StorageUtil.cs | 127 ++++++++++-------- .../Elucidate/Properties/AssemblyInfo.cs | 4 +- 6 files changed, 112 insertions(+), 70 deletions(-) diff --git a/Elucidate/Elucidate.sln b/Elucidate/Elucidate.sln index c4553cd..a224a6a 100644 --- a/Elucidate/Elucidate.sln +++ b/Elucidate/Elucidate.sln @@ -10,23 +10,41 @@ EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 Release|Any CPU = Release|Any CPU + Release|x64 = Release|x64 + Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {C45A0899-34D4-4CB0-B5FF-9DFADBC5E70E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {C45A0899-34D4-4CB0-B5FF-9DFADBC5E70E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C45A0899-34D4-4CB0-B5FF-9DFADBC5E70E}.Debug|x64.ActiveCfg = Debug|x64 + {C45A0899-34D4-4CB0-B5FF-9DFADBC5E70E}.Debug|x64.Build.0 = Debug|x64 + {C45A0899-34D4-4CB0-B5FF-9DFADBC5E70E}.Debug|x86.ActiveCfg = Debug|x86 + {C45A0899-34D4-4CB0-B5FF-9DFADBC5E70E}.Debug|x86.Build.0 = Debug|x86 {C45A0899-34D4-4CB0-B5FF-9DFADBC5E70E}.Release|Any CPU.ActiveCfg = Release|Any CPU {C45A0899-34D4-4CB0-B5FF-9DFADBC5E70E}.Release|Any CPU.Build.0 = Release|Any CPU + {C45A0899-34D4-4CB0-B5FF-9DFADBC5E70E}.Release|x64.ActiveCfg = Release|x64 + {C45A0899-34D4-4CB0-B5FF-9DFADBC5E70E}.Release|x64.Build.0 = Release|x64 + {C45A0899-34D4-4CB0-B5FF-9DFADBC5E70E}.Release|x86.ActiveCfg = Release|x86 + {C45A0899-34D4-4CB0-B5FF-9DFADBC5E70E}.Release|x86.Build.0 = Release|x86 {EA76FDE5-C6AE-46B7-ADA4-F3DC9DCCC9FB}.Debug|Any CPU.ActiveCfg = Debug|x64 + {EA76FDE5-C6AE-46B7-ADA4-F3DC9DCCC9FB}.Debug|x64.ActiveCfg = Debug|x64 + {EA76FDE5-C6AE-46B7-ADA4-F3DC9DCCC9FB}.Debug|x64.Build.0 = Debug|x64 + {EA76FDE5-C6AE-46B7-ADA4-F3DC9DCCC9FB}.Debug|x86.ActiveCfg = Debug|x64 {EA76FDE5-C6AE-46B7-ADA4-F3DC9DCCC9FB}.Release|Any CPU.ActiveCfg = Release|x64 {EA76FDE5-C6AE-46B7-ADA4-F3DC9DCCC9FB}.Release|Any CPU.Build.0 = Release|x64 + {EA76FDE5-C6AE-46B7-ADA4-F3DC9DCCC9FB}.Release|x64.ActiveCfg = Release|x64 + {EA76FDE5-C6AE-46B7-ADA4-F3DC9DCCC9FB}.Release|x64.Build.0 = Release|x64 + {EA76FDE5-C6AE-46B7-ADA4-F3DC9DCCC9FB}.Release|x86.ActiveCfg = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution - BuildVersion_UseGlobalSettings = False - BuildVersion_StartDate = 2000/1/1 SolutionGuid = {39E6A612-AC12-4D63-BE2A-60EA16940A8A} + BuildVersion_StartDate = 2000/1/1 + BuildVersion_UseGlobalSettings = False EndGlobalSection EndGlobal diff --git a/Elucidate/Elucidate/ConfigFileHelper.cs b/Elucidate/Elucidate/ConfigFileHelper.cs index 432dd95..6c151d2 100644 --- a/Elucidate/Elucidate/ConfigFileHelper.cs +++ b/Elucidate/Elucidate/ConfigFileHelper.cs @@ -33,16 +33,18 @@ using System.IO; using System.Linq; using System.Text; + using Elucidate.HelperClasses; using Elucidate.Logging; using Elucidate.Objects; + using MoreLinq.Extensions; namespace Elucidate { public class ConfigFileHelper { - public bool IsValid => !ConfigErrors.Any(); + public bool IsValid => (ConfigFileExists && !ConfigErrors.Any()); public bool IsErrors => ConfigErrors.Any(); @@ -319,14 +321,20 @@ private static bool IsRulePassDevicesMustNotRepeat(List paths) internal static bool IsRulePassDevicesMustNotRepeat(List paths, string current) { - if (paths == null || string.IsNullOrEmpty(current)) + try { - return true; - } + if (paths == null || string.IsNullOrEmpty(current)) return true; - int count = paths.Where(s => !string.IsNullOrEmpty(s)).Count(temp => StorageUtil.GetPathRoot(temp).Equals(StorageUtil.GetPathRoot(current))); + var count = paths.Where(s => !string.IsNullOrEmpty(s)).Count(temp => StorageUtil.GetPathRoot(temp).Equals(StorageUtil.GetPathRoot(current))); - return count <= 1; + return count <= 1; + } + catch + { + // ignored + } + + return true; } public static bool IsRulePassPreviousCannotBeEmpty(string previous, string current) diff --git a/Elucidate/Elucidate/Controls/LiveRunLogControl.Designer.cs b/Elucidate/Elucidate/Controls/LiveRunLogControl.Designer.cs index bb3511e..5544b30 100644 --- a/Elucidate/Elucidate/Controls/LiveRunLogControl.Designer.cs +++ b/Elucidate/Elucidate/Controls/LiveRunLogControl.Designer.cs @@ -164,8 +164,8 @@ private void InitializeComponent() // // txtAddCommands // + this.txtAddCommands.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right))); this.txtAddCommands.BorderStyle = System.Windows.Forms.BorderStyle.None; - this.txtAddCommands.Dock = System.Windows.Forms.DockStyle.Fill; this.txtAddCommands.Location = new System.Drawing.Point(347, 3); this.txtAddCommands.Margin = new System.Windows.Forms.Padding(2); this.txtAddCommands.MaxLength = 128; @@ -178,7 +178,7 @@ private void InitializeComponent() // this.tableLayoutPanelAdditionalCommands.AutoSize = true; this.tableLayoutPanelAdditionalCommands.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; - this.tableLayoutPanelAdditionalCommands.BackColor = System.Drawing.SystemColors.Control; + this.tableLayoutPanelAdditionalCommands.BackColor = System.Drawing.SystemColors.Window; this.tableLayoutPanelAdditionalCommands.CellBorderStyle = System.Windows.Forms.TableLayoutPanelCellBorderStyle.Single; this.tableLayoutPanelAdditionalCommands.ColumnCount = 2; this.tableLayoutPanelAdditionalCommands.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle()); diff --git a/Elucidate/Elucidate/Controls/LogsViewerControl.cs b/Elucidate/Elucidate/Controls/LogsViewerControl.cs index 5000b28..4f2e9ba 100644 --- a/Elucidate/Elucidate/Controls/LogsViewerControl.cs +++ b/Elucidate/Elucidate/Controls/LogsViewerControl.cs @@ -52,7 +52,6 @@ public LogsViewerControl() private void LogFileWatcher_OnChanged(object sender, FileSystemEventArgs e) { // let's keep the file selected by the user as selected after the refresh - //UpdateLogFileList(); listBoxViewLogFiles.BeginInvoke((MethodInvoker)delegate { UpdateLogFileList(); }); } @@ -104,6 +103,7 @@ private void UpdateLogFileList(string selectedDirectoryTitle = null) warningSearchTerm = _snapraidWarningSearchTerm; LexerToUse = LexerNameEnum.ScanRaid; _logSourcePath = $@"{Path.GetDirectoryName(Properties.Settings.Default.ConfigFileLocation)}\{Properties.Settings.Default.LogFileDirectory}\"; + if (!Directory.Exists(_logSourcePath)) return; _logFileWatcher.Path = $@"{Path.GetDirectoryName(Properties.Settings.Default.ConfigFileLocation)}\{Properties.Settings.Default.LogFileDirectory}\"; _logFileWatcher.Filter = "*.log"; _logFileWatcher.EnableRaisingEvents = true; @@ -114,6 +114,7 @@ private void UpdateLogFileList(string selectedDirectoryTitle = null) warningSearchTerm = _elucidateWarningSearchTerm; LexerToUse = LexerNameEnum.NLog; _logSourcePath = LogFileLocation.GetActiveLogFileLocation(); + if (!Directory.Exists(_logSourcePath)) return; _logFileWatcher.Path = LogFileLocation.GetActiveLogFileLocation(); _logFileWatcher.Filter = "*.log"; _logFileWatcher.EnableRaisingEvents = true; @@ -163,7 +164,7 @@ where fileText.Contains(warningSearchTerm) listBoxViewLogFiles.Items.Add(log.Name); } - // restore user selection, if it stil lexists + // restore user selection, if it still exists if (selectedIndex >= 0 && !string.IsNullOrEmpty(selectedIndexValue)) { int indexFound = -1; diff --git a/Elucidate/Elucidate/HelperClasses/StorageUtil.cs b/Elucidate/Elucidate/HelperClasses/StorageUtil.cs index b2ffa15..8430933 100644 --- a/Elucidate/Elucidate/HelperClasses/StorageUtil.cs +++ b/Elucidate/Elucidate/HelperClasses/StorageUtil.cs @@ -123,67 +123,82 @@ public static List GetStorageDevices(bool isIncludeNonMountedStor { List storageDevices = new List(); - ManagementObjectSearcher mgmtObjSearcher = new ManagementObjectSearcher("SELECT * FROM Win32_Volume"); - - ManagementObjectCollection colDisks = mgmtObjSearcher.Get(); - - foreach (ManagementBaseObject colDisk in colDisks) + using (ManagementObjectSearcher mgmtObjSearcher = new ManagementObjectSearcher("SELECT * FROM Win32_Volume")) { - ManagementObject objDisk = (ManagementObject)colDisk; - - try + using (var managementQuery = mgmtObjSearcher.Get()) { - // ReSharper disable once UnusedVariable - bool success = GetDiskFreeSpaceEx( - (string)objDisk["DeviceID"], - out ulong freeBytesAvailable, - out ulong totalNumberOfBytes, - out ulong totalNumberOfFreeBytes); - - StorageDevice device = new StorageDevice - { - Caption = (string)objDisk["Caption"], - Name = (string)objDisk["Name"], - DeviceID = (string)objDisk["DeviceID"], - DriveLetter = (string)objDisk["DriveLetter"], - FileSystem = (string)objDisk["FileSystem"], - Capacity = (uint)totalNumberOfBytes, - FreeSpace = (uint)freeBytesAvailable - }; - - switch ((uint)objDisk["DriveType"]) - { - case (uint)DriveType.Removable: - device.DriveType = DriveType.Removable; - break; - - case (uint)DriveType.Fixed: - device.DriveType = DriveType.Fixed; - break; - - case (uint)DriveType.Network: - device.DriveType = DriveType.Network; - break; - - case (uint)DriveType.CDRom: - device.DriveType = DriveType.CDRom; - break; - - default: - device.DriveType = DriveType.Unknown; - break; - } - - if (!string.IsNullOrEmpty(device.Caption) && (!device.Caption.StartsWith(@"\\?\") || isIncludeNonMountedStorage)) + // convert to LINQ to Objects query + var query = + from ManagementObject mo in managementQuery + orderby Convert.ToString(mo["DriveLetter"]) + select new + { + Caption = Convert.ToString(mo["Caption"]), + Name = Convert.ToString(mo["Name"]), + DeviceID = Convert.ToString(mo["DeviceID"]), + DriveType = Convert.ToUInt32(mo["DriveType"]), + DriveLetter = Convert.ToString(mo["DriveLetter"]), + FileSystem = Convert.ToString(mo["FileSystem"]) + }; + + // grab the fields + foreach (var item in query) { - storageDevices.Add(device); + try + { + // ReSharper disable once UnusedVariable + bool success = GetDiskFreeSpaceEx( + item.DeviceID, + out var freeBytesAvailable, + out var totalNumberOfBytes, + out var totalNumberOfFreeBytes); + + StorageDevice device = new StorageDevice + { + Caption = item.Caption, + Name = item.Name, + DeviceID = item.DeviceID, + DriveLetter = item.DriveLetter, + FileSystem = item.FileSystem, + Capacity = (uint)totalNumberOfBytes, + FreeSpace = (uint)freeBytesAvailable + }; + + switch (item.DriveType) + { + case (uint)DriveType.Removable: + device.DriveType = DriveType.Removable; + break; + + case (uint)DriveType.Fixed: + device.DriveType = DriveType.Fixed; + break; + + case (uint)DriveType.Network: + device.DriveType = DriveType.Network; + break; + + case (uint)DriveType.CDRom: + device.DriveType = DriveType.CDRom; + break; + + default: + device.DriveType = DriveType.Unknown; + break; + } + + if (!string.IsNullOrEmpty(device.Caption) && (!device.Caption.StartsWith(@"\\?\") || isIncludeNonMountedStorage)) + { + storageDevices.Add(device); + } + } + catch (Exception ex) + { + Log.Instance.Warn("A storage device failed to enumerate."); + Log.Instance.Warn(ex); + } } } - catch (Exception ex) - { - Log.Instance.Warn("A storage device failed to enumerate."); - Log.Instance.Warn(ex); - } } return storageDevices; diff --git a/Elucidate/Elucidate/Properties/AssemblyInfo.cs b/Elucidate/Elucidate/Properties/AssemblyInfo.cs index d21d5f3..3e9544f 100644 --- a/Elucidate/Elucidate/Properties/AssemblyInfo.cs +++ b/Elucidate/Elucidate/Properties/AssemblyInfo.cs @@ -56,5 +56,5 @@ // Build Number - Increment // Revision - Day // -[assembly: AssemblyVersion("2018.9.607.30")] -[assembly: AssemblyFileVersion("18.9.607.30")] +[assembly: AssemblyVersion("2018.10.608.1")] +[assembly: AssemblyFileVersion("18.10.608.1")]