Stuffs
This commit is contained in:
parent
13953fe9b8
commit
b292b8f679
@ -4,17 +4,19 @@ using System.Diagnostics;
|
|||||||
using System.Management;
|
using System.Management;
|
||||||
using CommandLine.Utility;
|
using CommandLine.Utility;
|
||||||
using WinPart.Properties;
|
using WinPart.Properties;
|
||||||
|
using System.Collections;
|
||||||
#pragma warning disable IDE1006
|
#pragma warning disable IDE1006
|
||||||
namespace WinPart {
|
namespace WinPart {
|
||||||
class Program {
|
class Program {
|
||||||
List<Device> drives;
|
List<Device> drives;
|
||||||
bool longInputSupport;
|
bool longInputSupport, debug;
|
||||||
static void Main(string[] args) => new Program().main(new Arguments(args));
|
static void Main(string[] args) => new Program().main(new Arguments(args));
|
||||||
void main(Arguments args) {
|
void main(Arguments args) {
|
||||||
longInputSupport = args["li"] != null;
|
longInputSupport = args["li"] != null;
|
||||||
|
debug = args["debug"] != null;
|
||||||
bool run = true;
|
bool run = true;
|
||||||
if (args["help"] != null) {
|
if ((args["help"] != null) || (args["?"] != null)) {
|
||||||
Console.WriteLine("WinPart is a tool for manipulating storage.\r\n\r\nWinPart [-li] [-help]\r\n\r\nli Enables large inputs (over 1 char)\r\nhelp Shows this message");
|
Console.WriteLine("WinPart is a tool for manipulating storage.\r\n\r\nWinPart [-li] [-help] [-debug]\r\n\r\nli Enables large inputs (over 1 char)\r\nhelp Shows this message\r\ndebug Troubleshooting");
|
||||||
run = false;
|
run = false;
|
||||||
}
|
}
|
||||||
if (run)
|
if (run)
|
||||||
@ -22,7 +24,6 @@ namespace WinPart {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void mainWindow() {
|
void mainWindow() {
|
||||||
Console.Clear();
|
|
||||||
Console.WriteLine("Use \"WinPart -help\" for CMD Args");
|
Console.WriteLine("Use \"WinPart -help\" for CMD Args");
|
||||||
Console.WriteLine("Welcome to WinPart. Choose one of the disks by their number to continue.");
|
Console.WriteLine("Welcome to WinPart. Choose one of the disks by their number to continue.");
|
||||||
try {
|
try {
|
||||||
@ -30,13 +31,12 @@ namespace WinPart {
|
|||||||
int i = 0;
|
int i = 0;
|
||||||
foreach (ManagementObject mo in new ManagementObjectSearcher("select * from Win32_DiskDrive").Get()) {
|
foreach (ManagementObject mo in new ManagementObjectSearcher("select * from Win32_DiskDrive").Get()) {
|
||||||
i++;
|
i++;
|
||||||
drives.Add(new Device().getFromMO(mo));
|
drives.Add(new Device().getFromMO(mo, this));
|
||||||
Console.WriteLine(i.ToString() + ": " + drives[drives.Count - 1].name);
|
Console.WriteLine(i.ToString() + ": " + drives[drives.Count - 1].name);
|
||||||
}
|
}
|
||||||
Device drive = drives[int.Parse(getInput()) - 1];
|
Device drive = drives[int.Parse(getInput()) - 1];
|
||||||
Console.WriteLine("Choose one of the operations by their number to continue.\r\n1: Info\r\n2: Open");
|
Console.WriteLine("Choose one of the operations by their number to continue.\r\n1: Info\r\n2: Open");
|
||||||
switch (int.Parse(getInput()))
|
switch (int.Parse(getInput())) {
|
||||||
{
|
|
||||||
case 1:
|
case 1:
|
||||||
drive.getInfo();
|
drive.getInfo();
|
||||||
break;
|
break;
|
||||||
@ -46,8 +46,7 @@ namespace WinPart {
|
|||||||
Console.WriteLine((i + 1).ToString() + ": " + drive.partitions[i].name);
|
Console.WriteLine((i + 1).ToString() + ": " + drive.partitions[i].name);
|
||||||
Partition partition = drive.partitions[int.Parse(getInput()) - 1];
|
Partition partition = drive.partitions[int.Parse(getInput()) - 1];
|
||||||
Console.WriteLine("Choose one of the operations by their number to continue.\r\n1: Info\r\n2: Open");
|
Console.WriteLine("Choose one of the operations by their number to continue.\r\n1: Info\r\n2: Open");
|
||||||
switch (int.Parse(getInput()))
|
switch (int.Parse(getInput())) {
|
||||||
{
|
|
||||||
case 1:
|
case 1:
|
||||||
partition.getInfo();
|
partition.getInfo();
|
||||||
break;
|
break;
|
||||||
@ -57,8 +56,7 @@ namespace WinPart {
|
|||||||
Console.WriteLine((i + 1).ToString() + ": " + partition.logicalDrives[i].name);
|
Console.WriteLine((i + 1).ToString() + ": " + partition.logicalDrives[i].name);
|
||||||
LogicalDrive logicalDrive = partition.logicalDrives[int.Parse(getInput()) - 1];
|
LogicalDrive logicalDrive = partition.logicalDrives[int.Parse(getInput()) - 1];
|
||||||
Console.WriteLine("Choose one of the operations by their number to continue.\r\n1: Info\r\n2: Explorer");
|
Console.WriteLine("Choose one of the operations by their number to continue.\r\n1: Info\r\n2: Explorer");
|
||||||
switch (int.Parse(getInput()))
|
switch (int.Parse(getInput())) {
|
||||||
{
|
|
||||||
case 1:
|
case 1:
|
||||||
logicalDrive.getInfo();
|
logicalDrive.getInfo();
|
||||||
break;
|
break;
|
||||||
@ -79,6 +77,7 @@ namespace WinPart {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} catch (Exception e) { Console.WriteLine(e.ToString()); }
|
} catch (Exception e) { Console.WriteLine(e.ToString()); }
|
||||||
|
if (debug) Console.ReadKey();
|
||||||
}
|
}
|
||||||
|
|
||||||
string getInput() {
|
string getInput() {
|
||||||
@ -91,78 +90,86 @@ namespace WinPart {
|
|||||||
Console.Write("\r\n\r\n");
|
Console.Write("\r\n\r\n");
|
||||||
return out_;
|
return out_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void printInfo(ManagementObject mo, string s) {
|
||||||
|
string[] tmp1 = { };
|
||||||
|
PropertyData tmp2;
|
||||||
|
try {
|
||||||
|
tmp1 = s.Split(" ".ToCharArray());
|
||||||
|
if (tmp1[tmp1.Length - 1].EndsWith("[]")) {
|
||||||
|
tmp2 = mo.Properties[tmp1[tmp1.Length - 1].Replace("[]", "")];
|
||||||
|
string tmp3 = "[ ";
|
||||||
|
object[] list = (object[])tmp2.Value;
|
||||||
|
for (int i = 0; i < list.Length; i++) {
|
||||||
|
tmp3 += list[i].ToString();
|
||||||
|
if (i + 1 < list.Length) tmp3 += " | ";
|
||||||
|
}
|
||||||
|
tmp3 += " ]";
|
||||||
|
Console.WriteLine(tmp2.Name + ": " + tmp3);
|
||||||
|
} else {
|
||||||
|
tmp2 = mo.Properties[tmp1[tmp1.Length - 1]];
|
||||||
|
Console.WriteLine(tmp2.Name + ": " + tmp2.Value);
|
||||||
|
}
|
||||||
|
} catch (Exception e) { Console.Write("Could not read: " + tmp1[tmp1.Length - 1]); if (debug) Console.Write(" due to: " + e.ToString()); Console.Write("\r\n"); }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Device {
|
class Device {
|
||||||
|
public Program program;
|
||||||
public List<Partition> partitions;
|
public List<Partition> partitions;
|
||||||
public string name;
|
public string name;
|
||||||
public ManagementObject mo;
|
public ManagementObject mo;
|
||||||
public Device getFromMO(ManagementObject MO) {
|
public Device getFromMO(ManagementObject MO, Program program_) {
|
||||||
|
mo = MO;
|
||||||
|
program = program_;
|
||||||
partitions = new List<Partition>() { };
|
partitions = new List<Partition>() { };
|
||||||
foreach (ManagementObject m in new ManagementObjectSearcher(string.Format("associators of {{{0}}} where AssocClass = Win32_DiskDriveToDiskPartition", MO.Path.RelativePath)).Get())
|
foreach (ManagementObject m in new ManagementObjectSearcher(string.Format("associators of {{{0}}} where AssocClass = Win32_DiskDriveToDiskPartition", MO.Path.RelativePath)).Get())
|
||||||
partitions.Add(new Partition().getFromMO(m));
|
partitions.Add(new Partition().getFromMO(m, program));
|
||||||
name = (string)MO.Properties["DeviceId"].Value;
|
name = (string)MO.Properties["Model"].Value;
|
||||||
mo = MO;
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void getInfo() {
|
public void getInfo() {
|
||||||
Console.WriteLine("PhysicalName: " + Convert.ToString(mo.Properties["Name"].Value));
|
foreach (string s in Resources.Device.Split(new[] { "\r\n" }, StringSplitOptions.None))
|
||||||
Console.WriteLine("DiskName: " + Convert.ToString(mo.Properties["Caption"].Value));
|
program.printInfo(mo, s);
|
||||||
Console.WriteLine("DiskModel: " + Convert.ToString(mo.Properties["Model"].Value));
|
|
||||||
Console.WriteLine("DiskInterface: " + Convert.ToString(mo.Properties["InterfaceType"].Value));
|
|
||||||
Console.WriteLine("Capabilities: " + (ushort[])mo.Properties["Capabilities"].Value);
|
|
||||||
Console.WriteLine("MediaLoaded: " + Convert.ToBoolean(mo.Properties["MediaLoaded"].Value));
|
|
||||||
Console.WriteLine("MediaType: " + Convert.ToString(mo.Properties["MediaType"].Value));
|
|
||||||
Console.WriteLine("MediaSignature: " + Convert.ToUInt32(mo.Properties["Signature"].Value));
|
|
||||||
Console.WriteLine("MediaStatus: " + Convert.ToString(mo.Properties["Status"].Value));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Partition {
|
class Partition {
|
||||||
|
public Program program;
|
||||||
public List<LogicalDrive> logicalDrives;
|
public List<LogicalDrive> logicalDrives;
|
||||||
public string name;
|
public string name;
|
||||||
public ManagementObject mo;
|
public ManagementObject mo;
|
||||||
public Partition getFromMO(ManagementObject MO) {
|
public Partition getFromMO(ManagementObject MO, Program program_) {
|
||||||
|
mo = MO;
|
||||||
|
program = program_;
|
||||||
logicalDrives = new List<LogicalDrive>() { };
|
logicalDrives = new List<LogicalDrive>() { };
|
||||||
foreach (ManagementObject m in new ManagementObjectSearcher(string.Format("associators of {{{0}}} where AssocClass = Win32_LogicalDiskToPartition", MO.Path.RelativePath)).Get())
|
foreach (ManagementObject m in new ManagementObjectSearcher(string.Format("associators of {{{0}}} where AssocClass = Win32_LogicalDiskToPartition", MO.Path.RelativePath)).Get())
|
||||||
logicalDrives.Add(new LogicalDrive().getFromMO(m));
|
logicalDrives.Add(new LogicalDrive().getFromMO(m, program));
|
||||||
name = MO.ToString();
|
name = MO.ToString();
|
||||||
mo = MO;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void getInfo()
|
|
||||||
{
|
|
||||||
foreach (string s in Resources.Partition.Split("\r\n".ToCharArray()))
|
|
||||||
{
|
|
||||||
var tmp1 = s.Split(" ".ToCharArray());
|
|
||||||
var tmp2 = mo.Properties[tmp1[tmp1.Length]];
|
|
||||||
Console.WriteLine(tmp2.Name + tmp2.Value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class LogicalDrive {
|
|
||||||
public string name;
|
|
||||||
public ManagementObject mo;
|
|
||||||
public LogicalDrive getFromMO(ManagementObject MO) {
|
|
||||||
name = (string)MO.Properties["Name"].Value;
|
|
||||||
mo = MO;
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void getInfo() {
|
public void getInfo() {
|
||||||
Console.WriteLine("DriveName: " + mo.Properties["Name"].Value);
|
foreach (string s in Resources.Partition.Split(new[] { "\r\n" }, StringSplitOptions.None))
|
||||||
Console.WriteLine("DriveId: " + mo.Properties["DeviceId"].Value);
|
program.printInfo(mo, s);
|
||||||
Console.WriteLine("DriveCompressed: " + mo.Properties["Compressed"].Value);
|
}
|
||||||
Console.WriteLine("DriveType: " + mo.Properties["DriveType"].Value);
|
}
|
||||||
Console.WriteLine("FileSystem: " + mo.Properties["FileSystem"].Value);
|
|
||||||
Console.WriteLine("FreeSpace: " + mo.Properties["FreeSpace"].Value);
|
class LogicalDrive {
|
||||||
Console.WriteLine("TotalSpace: " + mo.Properties["Size"].Value);
|
public Program program;
|
||||||
Console.WriteLine("DriveMediaType: " + mo.Properties["MediaType"].Value);
|
public string name;
|
||||||
Console.WriteLine("VolumeName: " + mo.Properties["VolumeName"].Value);
|
public ManagementObject mo;
|
||||||
Console.WriteLine("VolumeSerial: " + mo.Properties["VolumeSerialNumber"].Value);
|
public LogicalDrive getFromMO(ManagementObject MO, Program program_) {
|
||||||
|
name = (string)MO.Properties["Name"].Value;
|
||||||
|
mo = MO;
|
||||||
|
program = program_;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void getInfo() {
|
||||||
|
foreach (string s in Resources.Logical.Split(new[] { "\r\n" }, StringSplitOptions.None))
|
||||||
|
program.printInfo(mo, s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user