Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Another Version
without SMARTCTL and without WMIC (but with WMI haha)
- Loading branch information
Showing
21 changed files
with
364 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 14 | ||
VisualStudioVersion = 14.0.25420.1 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DiskcheckV3", "DiskcheckV3\DiskcheckV3.csproj", "{1E09E93B-5B91-434E-96DC-E5A0211AA91E}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{1E09E93B-5B91-434E-96DC-E5A0211AA91E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{1E09E93B-5B91-434E-96DC-E5A0211AA91E}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{1E09E93B-5B91-434E-96DC-E5A0211AA91E}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{1E09E93B-5B91-434E-96DC-E5A0211AA91E}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<configuration> | ||
<startup> | ||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" /> | ||
</startup> | ||
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProjectGuid>{1E09E93B-5B91-434E-96DC-E5A0211AA91E}</ProjectGuid> | ||
<OutputType>Exe</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>DiskcheckV3</RootNamespace> | ||
<AssemblyName>DiskcheckV3</AssemblyName> | ||
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="System.Xml.Linq" /> | ||
<Reference Include="System.Data.DataSetExtensions" /> | ||
<Reference Include="Microsoft.CSharp" /> | ||
<Reference Include="System.Data" /> | ||
<Reference Include="System.Net.Http" /> | ||
<Reference Include="System.Xml" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="Program.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="App.config" /> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. | ||
Other similar extension points exist, see Microsoft.Common.targets. | ||
<Target Name="BeforeBuild"> | ||
</Target> | ||
<Target Name="AfterBuild"> | ||
</Target> | ||
--> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'"> | ||
<StartArguments>-a</StartArguments> | ||
</PropertyGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,205 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace DiskcheckV3 { | ||
public class Program { | ||
string programPath = ""; | ||
string programName = "smartctl"; | ||
string argumentOne = " --scan -d ata -d sat "; | ||
string argumentTwo = " --identify "; | ||
string argumentThree = " -i "; | ||
|
||
List<List<string>> devices = new List<List<string>>(); | ||
|
||
public static void Main(string[] args) { | ||
Program program = new Program(); | ||
program.Start(args); | ||
} | ||
|
||
private void Start(string[] args) { | ||
foreach (var item in args) { | ||
if (item == "-a") { | ||
argumentOne += "-d usb"; | ||
} | ||
} | ||
|
||
List<string> paths = ValidatePaths(GetAllDevices()); | ||
|
||
for (int i = 0; i < paths.Count; i++) { | ||
devices.Add(new List<string>()); | ||
devices[i].Add(paths[i]); | ||
devices[i] = AddSerialAndModel(devices[i]); | ||
} | ||
} | ||
|
||
private List<string> AddSerialAndModel(List<string> device) { | ||
List<string> content = ExecuteProcess(programPath, programName, argumentTwo + device[0]); | ||
string serial = ""; | ||
string model = ""; | ||
|
||
foreach (var item in content) { | ||
if (item.StartsWith(" 10-13") || item.StartsWith(" 14-17") || item.StartsWith(" 18-19")) { | ||
serial += item; | ||
} else if (item.StartsWith(" 27-30") || item.StartsWith(" 31-34") || item.StartsWith(" 35-38") || item.StartsWith(" 39-42") || item.StartsWith(" 43-46")) { | ||
model += item; | ||
} | ||
} | ||
|
||
List<string> tempSerial = SplitAndRemoveEmpty(serial, ' '); | ||
List<string> tempModel = SplitAndRemoveEmpty(model, ' '); | ||
|
||
tempSerial.RemoveAll(PredicateIsNotHex); | ||
tempModel.RemoveAll(PredicateIsNotHex); | ||
|
||
tempSerial = SplitAndRemoveEmpty(String.Join(":", tempSerial), ':'); | ||
tempModel = SplitAndRemoveEmpty(String.Join(":", tempModel), ':'); | ||
|
||
for (int i = 0; i < tempSerial.Count; i++) { | ||
Console.WriteLine(tempSerial[i]); | ||
|
||
if (tempSerial[i].Contains(":")) { | ||
tempSerial[i] = tempSerial[i].Remove(0, 1); | ||
} else if (tempSerial[i].Contains("0x")) { | ||
tempSerial[i] = tempSerial[i].Remove(0, 2); | ||
} | ||
|
||
Console.WriteLine(tempSerial[i]); | ||
} | ||
|
||
serial = String.Join("", tempSerial); | ||
|
||
for (int i = 0; i < tempModel.Count; i++) { | ||
Console.WriteLine(tempModel[i]); | ||
|
||
if (tempModel[i].Contains(":")) { | ||
tempModel[i] = tempModel[i].Remove(0, 1); | ||
} else if (tempModel[i].Contains("0x")) { | ||
tempModel[i] = tempModel[i].Remove(0, 2); | ||
} | ||
|
||
Console.WriteLine(tempModel[i]); | ||
} | ||
|
||
serial = HexToAscii(String.Join("", tempSerial)); | ||
model= HexToAscii(String.Join("", tempModel)); | ||
|
||
Console.WriteLine(serial + "\n" + model); | ||
|
||
return device; | ||
} | ||
|
||
private string HexToAscii(string input) { | ||
try { | ||
string serial = input; | ||
|
||
char[] tempCharArray; | ||
|
||
StringBuilder sb = new StringBuilder(); | ||
|
||
for (int i = 0; i < serial.Length; i += 2) { | ||
string someString = ""; | ||
someString = serial.Substring(i, 2); | ||
sb.Append(Convert.ToChar(Convert.ToUInt32(someString, 16))); | ||
} | ||
|
||
serial = sb.ToString(); | ||
tempCharArray = serial.Where(c => !Char.IsWhiteSpace(c)).ToArray(); | ||
|
||
return new string(tempCharArray); | ||
} catch (Exception) { | ||
return null; | ||
} | ||
} | ||
|
||
private List<string> GetAllDevices() { | ||
return ExaminePaths((from path in (ExecuteProcess(programPath, programName, argumentOne)) where path.Contains("/dev") select path).ToList()); | ||
} | ||
|
||
private List<string> ExecuteProcess(string path, string name, string argument) { | ||
return ReadStandardOutputFromProcess(CreateProcess(path, name, argument)); | ||
} | ||
|
||
private List<string> ReadStandardOutputFromProcess(Process proc) { | ||
List<string> output = new List<string>(); | ||
|
||
proc.Start(); | ||
|
||
if (proc.StartInfo.RedirectStandardOutput == true) { | ||
while (!proc.StandardOutput.EndOfStream) { | ||
output.Add(proc.StandardOutput.ReadLine()); | ||
} | ||
} else { | ||
// Error | ||
} | ||
|
||
proc.Close(); | ||
|
||
return output; | ||
} | ||
|
||
private Process CreateProcess(string path, string name, string argument) { | ||
return new Process { | ||
StartInfo = new ProcessStartInfo { | ||
FileName = @path + name, | ||
Arguments = argument, | ||
UseShellExecute = false, // Ermöglicht das redirecten der StandardOutput, - Error und -Input Streams | ||
RedirectStandardOutput = true, | ||
RedirectStandardError = true, | ||
CreateNoWindow = true | ||
} | ||
}; | ||
} | ||
|
||
private List<string> ExaminePaths(List<string> inputPaths) { | ||
List<string> paths = new List<string>(); | ||
|
||
foreach (var inputPath in inputPaths) { | ||
paths.Add(SplitAndRemoveEmpty(inputPath, ' ')[0]); | ||
} | ||
|
||
return paths; | ||
} | ||
|
||
private List<string> ValidatePaths(List<string> paths) { | ||
List<string> output = new List<string>(); | ||
string notValid = "Use smartctl -h to get a usage summary"; | ||
|
||
foreach (var path in paths) { | ||
if (!ExecuteProcess(programPath, programName, argumentThree + path).Contains(notValid)) { | ||
output.Add(path); | ||
} | ||
} | ||
|
||
return output; | ||
} | ||
|
||
private List<string> RemoveEmptyStringList(List<string> input) { | ||
input.RemoveAll(PredicateIsEmpty); | ||
return input; | ||
} | ||
|
||
private List<string> SplitAndRemoveEmpty(string input, char seperator) { | ||
return RemoveEmptyStringList(SplitString(input, seperator)); | ||
} | ||
|
||
private List<string> SplitString(string input, char seperator) { | ||
return input.Split(seperator).ToList(); | ||
} | ||
|
||
private bool PredicateIsEmpty(string s) { | ||
return s == ""; | ||
} | ||
|
||
private bool PredicateIsNotHex(string s) { | ||
if (s.StartsWith("0x")) { | ||
return false; | ||
} else { | ||
return true; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
|
||
// Allgemeine Informationen über eine Assembly werden über die folgenden | ||
// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern, | ||
// die einer Assembly zugeordnet sind. | ||
[assembly: AssemblyTitle("DiskcheckV3")] | ||
[assembly: AssemblyDescription("")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("")] | ||
[assembly: AssemblyProduct("DiskcheckV3")] | ||
[assembly: AssemblyCopyright("Copyright © 2017")] | ||
[assembly: AssemblyTrademark("")] | ||
[assembly: AssemblyCulture("")] | ||
|
||
// Durch Festlegen von ComVisible auf "false" werden die Typen in dieser Assembly unsichtbar | ||
// für COM-Komponenten. Wenn Sie auf einen Typ in dieser Assembly von | ||
// COM aus zugreifen müssen, sollten Sie das ComVisible-Attribut für diesen Typ auf "True" festlegen. | ||
[assembly: ComVisible(false)] | ||
|
||
// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird | ||
[assembly: Guid("1e09e93b-5b91-434e-96dc-e5a0211aa91e")] | ||
|
||
// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten: | ||
// | ||
// Hauptversion | ||
// Nebenversion | ||
// Buildnummer | ||
// Revision | ||
// | ||
// Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern | ||
// übernehmen, indem Sie "*" eingeben: | ||
// [assembly: AssemblyVersion("1.0.*")] | ||
[assembly: AssemblyVersion("1.0.0.0")] | ||
[assembly: AssemblyFileVersion("1.0.0.0")] |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<configuration> | ||
<startup> | ||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" /> | ||
</startup> | ||
</configuration> |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<configuration> | ||
<startup> | ||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" /> | ||
</startup> | ||
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> | ||
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"> | ||
<assemblyIdentity version="1.0.0.0" name="MyApplication.app"/> | ||
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2"> | ||
<security> | ||
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3"> | ||
<requestedExecutionLevel level="asInvoker" uiAccess="false"/> | ||
</requestedPrivileges> | ||
</security> | ||
</trustInfo> | ||
</assembly> |
Binary file not shown.
6 changes: 6 additions & 0 deletions
6
DiskcheckV3/obj/Debug/DiskcheckV3.csproj.FileListAbsolute.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
c:\users\danzeglo\documents\visual studio 2015\Projects\DiskcheckV3\DiskcheckV3\bin\Debug\DiskcheckV3.exe.config | ||
c:\users\danzeglo\documents\visual studio 2015\Projects\DiskcheckV3\DiskcheckV3\obj\Debug\DiskcheckV3.csprojResolveAssemblyReference.cache | ||
c:\users\danzeglo\documents\visual studio 2015\Projects\DiskcheckV3\DiskcheckV3\bin\Debug\DiskcheckV3.exe | ||
c:\users\danzeglo\documents\visual studio 2015\Projects\DiskcheckV3\DiskcheckV3\bin\Debug\DiskcheckV3.pdb | ||
c:\users\danzeglo\documents\visual studio 2015\Projects\DiskcheckV3\DiskcheckV3\obj\Debug\DiskcheckV3.exe | ||
c:\users\danzeglo\documents\visual studio 2015\Projects\DiskcheckV3\DiskcheckV3\obj\Debug\DiskcheckV3.pdb |
Binary file added
BIN
+1.88 KB
DiskcheckV3/obj/Debug/DiskcheckV3.csprojResolveAssemblyReference.cache
Binary file not shown.
Binary file not shown.
Binary file not shown.
Empty file.
Empty file.
Empty file.