Skip to content

Commit

Permalink
Added a disk manager holding all devices informations such as SMART
Browse files Browse the repository at this point in the history
Added more information to disks under Hadware > HDDs including SMART, problems will be reported too
Added the program version to the GUI title
Added a search box to every table to be able to filter the results
Added DataTable js script and style
Added floatThead js script
Changed the html tables code to use DataTables that gives much more customization features
Changed the background color to lightgrey of the tables head
Changed the tables head to be fixed and always show on scroll while a table is visible
Changed the tables are now wrapped inside a '<div class="responsive"></div>'
Improved tables sort are now more realible
Fixed the tables big font-size aren't the default from theme
Moved Malware folder into Core
Moved Libraries into Resources
Removed table-responsive class from tables (wrong usage)
  • Loading branch information
sn4k3 committed Apr 18, 2015
1 parent bd42884 commit 331ab8e
Show file tree
Hide file tree
Showing 16 changed files with 753 additions and 154 deletions.
15 changes: 14 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
# Changelog

# Current
## ??/04/2015
## 18/04/2015

* Added a disk manager holding all devices informations such as SMART
* Added more information to disks under Hadware > HDDs including SMART, problems will be reported too
* Added the program version to the GUI title
* Added a search box to every table to be able to filter the results
* Added DataTable js script and style
* Added floatThead js script
* Changed the html tables code to use DataTables that gives much more customization features
* Changed the background color to lightgrey of the tables head
* Changed the tables head to be fixed and always show on scroll while a table is visible
* Changed the tables are now wrapped inside a '<div class="responsive"></div>'
* Improved tables sort are now more realible
* Fixed the tables big font-size aren't the default from theme
* Moved Malware folder into Core
* Moved Libraries into Resources
* Removed table-responsive class from tables (wrong usage)


# 1.4.0.0
## 16/04/2015
Expand Down
337 changes: 322 additions & 15 deletions SystemInfoSnapshot/Core/Disk/DiskItem.cs

Large diffs are not rendered by default.

235 changes: 166 additions & 69 deletions SystemInfoSnapshot/Core/Disk/DiskManager.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Management;
using System.Text;

Expand All @@ -12,7 +13,7 @@ public sealed class DiskManager : IEnumerable<DiskItem>
/// <summary>
/// Gets the avaliable devices list
/// </summary>
public List<DiskItem> Devices { get; private set; }
public Dictionary<uint, DiskItem> Devices { get; private set; }
#endregion

#region Constructor
Expand All @@ -27,116 +28,181 @@ public DiskManager()

#region Static Methods

public static List<DiskItem> GetAll()
public static Dictionary<uint, DiskItem> GetAll()
{
var drives = new List<DiskItem>();
var drives = new Dictionary<uint, DiskItem>();
//var props = typeof (DiskItem).GetProperties();

// Win32_DiskDrive
var wdSearcher = new ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive");

// extract model and interface information
foreach (ManagementObject drive in wdSearcher.Get())
{
var hdd = new DiskItem
var hdd = new DiskItem();

/*foreach (var property in drive.Properties)
{
Model = drive["Model"].ToString().Trim(),
Type = drive["InterfaceType"].ToString().Trim()
};
drives.Add(hdd);
}
Console.Write(property.Name + ": ");
Console.WriteLine(property.Value);
}*/

foreach (var prop in hdd.GetType().GetProperties())
{
try
{
prop.SetValue(hdd, drive[prop.Name]);
}
catch (Exception)
{
//prop.SetValue(drives[iDriveIndex], null);
}

}
hdd.Model = string.IsNullOrEmpty(hdd.Model) ? "None" : hdd.Model.Trim();
hdd.SerialNumber = string.IsNullOrEmpty(hdd.SerialNumber) ? "None" : hdd.SerialNumber.Trim();

drives.Add(hdd.Index, hdd);
}


// Win32_PhysicalMedia
var pmsearcher = new ManagementObjectSearcher("SELECT * FROM Win32_PhysicalMedia");
/*var pmsearcher = new ManagementObjectSearcher("SELECT * FROM Win32_PhysicalMedia");
// retrieve hdd serial number
var iDriveIndex = 0;
//iDriveIndex = 0;
foreach (ManagementObject drive in pmsearcher.Get())
{
// because all physical media will be returned we need to exit
// after the hard drives serial info is extracted
if (iDriveIndex >= drives.Count)
break;
//if (iDriveIndex >= drives.Count)
// break;
drives[iDriveIndex].Serial = drive["SerialNumber"] == null ? "None" : drive["SerialNumber"].ToString().Trim();
iDriveIndex++;
}
foreach (var property in drive.Properties)
{
Console.Write(property.Name + ": ");
Console.WriteLine(property.Value);
}
foreach (var prop in drives[iDriveIndex].GetType().GetProperties())
{
Console.WriteLine(prop.Name);
try
{
prop.SetValue(drives[iDriveIndex], drive[prop.Name]);
}
catch (Exception)
{
//prop.SetValue(drives[iDriveIndex], null);
}
}
//drives[iDriveIndex].SerialNumber = drive["SerialNumber"] == null ? "None" : drive["SerialNumber"].ToString().Trim();
//iDriveIndex++;
}*/
// get wmi access to hdd
var searcher = new ManagementObjectSearcher("Select * from Win32_DiskDrive")
{
Scope = new ManagementScope(@"\root\wmi"),
Query = new ObjectQuery("Select * from MSStorageDriver_FailurePredictStatus")
};
uint iDriveIndex = 0;

// check if SMART reports the drive is failing
iDriveIndex = 0;
foreach (ManagementObject drive in searcher.Get())
try
{
drives[iDriveIndex].IsOK = (bool)drive.Properties["PredictFailure"].Value == false;
iDriveIndex++;
// check if SMART reports the drive is failing

foreach (ManagementObject drive in searcher.Get())
{
drives[iDriveIndex].IsOK = (bool)drive.Properties["PredictFailure"].Value == false;
iDriveIndex++;
}
}
catch (Exception)
{
// ignored
}

// retrive attribute flags, value worste and vendor data information
searcher.Query = new ObjectQuery("Select * from MSStorageDriver_FailurePredictData");
iDriveIndex = 0;
foreach (ManagementObject data in searcher.Get())

try
{
byte[] bytes = (Byte[])data.Properties["VendorSpecific"].Value;
for (int i = 0; i < 30; ++i)
// retrive attribute flags, value worste and vendor data information
searcher.Query = new ObjectQuery("Select * from MSStorageDriver_FailurePredictData");
iDriveIndex = 0;
foreach (ManagementObject data in searcher.Get())
{
try
{
int id = bytes[i * 12 + 2];

int flags = bytes[i * 12 + 4]; // least significant status byte, +3 most significant byte, but not used so ignored.
//bool advisory = (flags & 0x1) == 0x0;
bool failureImminent = (flags & 0x1) == 0x1;
//bool onlineDataCollection = (flags & 0x2) == 0x2;

int value = bytes[i * 12 + 5];
int worst = bytes[i * 12 + 6];
int vendordata = BitConverter.ToInt32(bytes, i * 12 + 7);
if (id == 0) continue;

var attr = drives[iDriveIndex].Attributes[id];
attr.Current = value;
attr.Worst = worst;
attr.Raw = vendordata;
attr.IsOK = failureImminent == false;
}
catch
byte[] bytes = (Byte[]) data.Properties["VendorSpecific"].Value;
for (int i = 0; i < 30; ++i)
{
// given key does not exist in attribute collection (attribute not in the dictionary of attributes)
try
{
int id = bytes[i*12 + 2];

int flags = bytes[i*12 + 4];
// least significant status byte, +3 most significant byte, but not used so ignored.
//bool advisory = (flags & 0x1) == 0x0;
bool failureImminent = (flags & 0x1) == 0x1;
//bool onlineDataCollection = (flags & 0x2) == 0x2;

int value = bytes[i*12 + 5];
int worst = bytes[i*12 + 6];
int vendordata = BitConverter.ToInt32(bytes, i*12 + 7);
if (id == 0) continue;

var attr = drives[iDriveIndex].Attributes[id];
attr.Current = value;
attr.Worst = worst;
attr.Raw = vendordata;
attr.IsOK = failureImminent == false;
}
catch
{
// given key does not exist in attribute collection (attribute not in the dictionary of attributes)
}
}
iDriveIndex++;
}
iDriveIndex++;
}
catch (Exception)
{
// ignored
}

// retreive threshold values foreach attribute
searcher.Query = new ObjectQuery("Select * from MSStorageDriver_FailurePredictThresholds");
iDriveIndex = 0;
foreach (ManagementObject data in searcher.Get())
try
{
Byte[] bytes = (Byte[])data.Properties["VendorSpecific"].Value;
for (int i = 0; i < 30; ++i)
// retreive threshold values foreach attribute
searcher.Query = new ObjectQuery("Select * from MSStorageDriver_FailurePredictThresholds");
iDriveIndex = 0;
foreach (ManagementObject data in searcher.Get())
{
try
Byte[] bytes = (Byte[]) data.Properties["VendorSpecific"].Value;
for (int i = 0; i < 30; ++i)
{
try
{

int id = bytes[i * 12 + 2];
int thresh = bytes[i * 12 + 3];
if (id == 0) continue;
int id = bytes[i*12 + 2];
int thresh = bytes[i*12 + 3];
if (id == 0) continue;

var attr = drives[iDriveIndex].Attributes[id];
attr.Threshold = thresh;
var attr = drives[iDriveIndex].Attributes[id];
attr.Threshold = thresh;
}
catch
{
// given key does not exist in attribute collection (attribute not in the dictionary of attributes)
}
}
catch
{
// given key does not exist in attribute collection (attribute not in the dictionary of attributes)
}
}

iDriveIndex++;
iDriveIndex++;
}
}
catch (Exception)
{
// ignored
}


Expand All @@ -148,7 +214,7 @@ public static List<DiskItem> GetAll()

public IEnumerator<DiskItem> GetEnumerator()
{
return Devices.GetEnumerator();
return Devices.Values.GetEnumerator();
}

/// <summary>
Expand Down Expand Up @@ -181,6 +247,24 @@ IEnumerator IEnumerable.GetEnumerator()
/// <param name="index">index</param>
/// <returns></returns>
public DiskItem this[int index] // Indexer declaration
{
get
{
return Devices[(uint)index];
}

set
{
Devices[(uint)index] = value;
}
}

/// <summary>
/// Indexers
/// </summary>
/// <param name="index">index</param>
/// <returns></returns>
public DiskItem this[uint index] // Indexer declaration
{
get
{
Expand All @@ -193,6 +277,19 @@ public DiskItem this[int index] // Indexer declaration
}
}

public DiskItem this[string name] // Indexer declaration
{
get
{
var result = Devices.FirstOrDefault(item => item.Value.Equals(name));
if (ReferenceEquals(result.Value, null))
{
result = Devices.FirstOrDefault(item => item.Value.Model.Equals(name));
}
return result.Value;
}
}

#endregion
}
}
16 changes: 16 additions & 0 deletions SystemInfoSnapshot/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,21 @@ public static bool Contains(this string source, string toCheck, StringComparison
{
return source.IndexOf(toCheck, comp) >= 0;
}

public static string GetNotNull(this string source, string defaultString = "")
{
if (!string.IsNullOrEmpty(source))
return defaultString;

return source;
}

/*public static bool SetIfNull(this string source, string value)
{
if (!string.IsNullOrEmpty(source))
return false;
source = value;
return true;
}*/
}
}
4 changes: 3 additions & 1 deletion SystemInfoSnapshot/FrmMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@ public FrmMain()
};
tmClock.Tick += (sender, args) =>
{
lbStatus.Text = string.Format("Generating the report. Please wait... {0:0.##}s", Math.Ceiling((DateTime.Now - StartDateTime).TotalSeconds));
lbStatus.Text = string.Format("Generating the report. Please wait... {0:0.##}s", Math.Round((DateTime.Now - StartDateTime).TotalSeconds));
};

Text += string.Format(" v{0}", ApplicationInfo.Version);
}
#endregion

Expand Down
4 changes: 2 additions & 2 deletions SystemInfoSnapshot/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// 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("1.4.0.0")]
[assembly: AssemblyFileVersion("1.4.0.0")]
[assembly: AssemblyVersion("1.5.0.0")]
[assembly: AssemblyFileVersion("1.5.0.0")]
Loading

0 comments on commit 331ab8e

Please sign in to comment.