Cool stuffs

This commit is contained in:
CreepyCrafter24 2020-03-16 20:05:44 +01:00
parent a44b6ccbd4
commit 731a2dff4b
11 changed files with 157 additions and 288 deletions

View File

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/>
</startup>
</configuration>

View File

@ -2,28 +2,30 @@
using System.Collections.Generic;
using System.Management;
using WinPart.Properties;
#pragma warning disable IDE1006
namespace WinPart
namespace WinPart.Data_structure
{
class Device
internal class Device
{
public List<Partition> partitions;
public string name;
public ManagementObject mo;
public Device getFromMO(ManagementObject MO)
private ManagementBaseObject _mo;
public string Name;
public List<Partition> Partitions;
public Device GetFromMo(ManagementObject mo)
{
mo = MO;
partitions = new List<Partition>() { };
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));
name = (string)MO.Properties["Model"].Value;
_mo = mo;
Partitions = new List<Partition>();
foreach (ManagementObject m in new ManagementObjectSearcher(
$"associators of {{{mo.Path.RelativePath}}} where AssocClass = Win32_DiskDriveToDiskPartition").Get())
Partitions.Add(new Partition().GetFromMo(m));
Name = (string) mo.Properties["Model"].Value;
return this;
}
public void getInfo()
public void GetInfo()
{
foreach (string s in Resources.Device.Split(new[] { "\r\n" }, StringSplitOptions.None))
Program.printInfo(mo, s);
foreach (string s in Resources.Device.Split(new[] {"\r\n"}, StringSplitOptions.None))
Program.PrintInfo(_mo, s);
}
}
}
}

View File

@ -1,24 +1,25 @@
using System;
using System.Management;
using WinPart.Properties;
#pragma warning disable IDE1006
namespace WinPart
namespace WinPart.Data_structure
{
class LogicalDrive
internal class LogicalDrive
{
public string name;
public ManagementObject mo;
public LogicalDrive getFromMO(ManagementObject MO)
private ManagementBaseObject _mo;
public string Name;
public LogicalDrive GetFromMo(ManagementBaseObject mo)
{
name = (string)MO.Properties["Name"].Value;
mo = MO;
Name = (string) mo.Properties["Name"].Value;
_mo = mo;
return this;
}
public void getInfo()
public void GetInfo()
{
foreach (string s in Resources.LogicalDrive.Split(new[] { "\r\n" }, StringSplitOptions.None))
Program.printInfo(mo, s);
foreach (string s in Resources.LogicalDrive.Split(new[] {"\r\n"}, StringSplitOptions.None))
Program.PrintInfo(_mo, s);
}
}
}
}

View File

@ -2,28 +2,30 @@
using System.Collections.Generic;
using System.Management;
using WinPart.Properties;
#pragma warning disable IDE1006
namespace WinPart
namespace WinPart.Data_structure
{
class Partition
internal class Partition
{
public List<LogicalDrive> logicalDrives;
public string name;
public ManagementObject mo;
public Partition getFromMO(ManagementObject MO)
private ManagementBaseObject _mo;
public List<LogicalDrive> LogicalDrives;
public string Name;
public Partition GetFromMo(ManagementObject mo)
{
mo = MO;
logicalDrives = new List<LogicalDrive>() { };
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));
name = (string)MO.Properties["Type"].Value;
_mo = mo;
LogicalDrives = new List<LogicalDrive>();
foreach (ManagementBaseObject m in new ManagementObjectSearcher(
$"associators of {{{mo.Path.RelativePath}}} where AssocClass = Win32_LogicalDiskToPartition").Get())
LogicalDrives.Add(new LogicalDrive().GetFromMo(m));
Name = (string) mo.Properties["Type"].Value;
return this;
}
public void getInfo()
public void GetInfo()
{
foreach (string s in Resources.Partition.Split(new[] { "\r\n" }, StringSplitOptions.None))
Program.printInfo(mo, s);
foreach (string s in Resources.Partition.Split(new[] {"\r\n"}, StringSplitOptions.None))
Program.PrintInfo(_mo, s);
}
}
}
}

View File

@ -1,82 +1,92 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Management;
using System.Collections;
using System.Linq;
#pragma warning disable IDE1006
using System.Management;
using WinPart.Data_structure;
using static System.Environment;
namespace WinPart
{
class Program
internal static class Program
{
static List<Device> drives;
static bool longInputSupport, debug;
static void Main(string[] args)
private static List<Device> _drives;
private static bool _longInputSupport, _debug;
private static void Main(string[] args)
{
List<string> li = new List<string>(args.Select(s => {
List<string> li = new List<string>(args.Select(s =>
{
if (s.StartsWith("-") || s.StartsWith("/"))
s = s.Remove(0, 1);
return s;
}));
longInputSupport = li.Contains("li");
debug = li.Contains("debug");
_longInputSupport = li.Contains("li");
_debug = li.Contains("debug");
bool run = true;
if (li.Contains("help") || li.Contains("?"))
{
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");
Console.WriteLine(@"WinPart is a tool for manipulating storage.
WinPart [-li] [-help] [-debug]
li Enables large inputs (over 1 char)
help Shows this message
debug Troubleshooting");
run = false;
}
if (run)
mainWindow();
}
static void mainWindow()
{
if (!run) return;
Console.WriteLine("Use \"WinPart -help\" for CMD Args");
Console.WriteLine("Welcome to WinPart. Choose one of the disks by their number to continue.");
try
{
drives = new List<Device>() { };
_drives = new List<Device>();
int i = 0;
foreach (ManagementObject mo in new ManagementObjectSearcher("select * from Win32_DiskDrive").Get())
{
i++;
drives.Add(new Device().getFromMO(mo));
Console.WriteLine(i.ToString() + ": " + drives[drives.Count - 1].name);
_drives.Add(new Device().GetFromMo(mo));
Console.WriteLine($"{i}: {_drives[^1].Name}");
}
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");
switch (int.Parse(getInput()))
Device drive = _drives[int.Parse(GetInput()) - 1];
Console.WriteLine(@"Choose one of the operations by their number to continue.
1: Info
2: Open");
switch (int.Parse(GetInput()))
{
case 1:
drive.getInfo();
drive.GetInfo();
break;
case 2:
Console.WriteLine("Processing...\r\nChoose one of the partitions by their number to continue.");
for (i = 0; i < drive.partitions.Count; i++)
Console.WriteLine((i + 1).ToString() + ": " + drive.partitions[i].name);
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");
switch (int.Parse(getInput()))
Console.WriteLine(@"Processing...
Choose one of the partitions by their number to continue.");
for (i = 0; i < drive.Partitions.Count; i++)
Console.WriteLine($"{i + 1}: {drive.Partitions[i].Name}");
Partition partition = drive.Partitions[int.Parse(GetInput()) - 1];
Console.WriteLine(@"Choose one of the operations by their number to continue.
1: Info
2: Open");
switch (int.Parse(GetInput()))
{
case 1:
partition.getInfo();
partition.GetInfo();
break;
case 2:
Console.WriteLine("Processing...\r\nChoose one of the logical drives by their number to continue.");
for (i = 0; i < partition.logicalDrives.Count; i++)
Console.WriteLine((i + 1).ToString() + ": " + partition.logicalDrives[i].name);
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");
switch (int.Parse(getInput()))
Console.WriteLine(@"Processing...
Choose one of the logical drives by their number to continue.");
for (i = 0; i < partition.LogicalDrives.Count; i++)
Console.WriteLine($"{i + 1}: {partition.LogicalDrives[i].Name}");
LogicalDrive logicalDrive = partition.LogicalDrives[int.Parse(GetInput()) - 1];
Console.WriteLine(@"Choose one of the operations by their number to continue.
1: Info
2: Explorer");
switch (int.Parse(GetInput()))
{
case 1:
logicalDrive.getInfo();
logicalDrive.GetInfo();
break;
case 2:
Process.Start(logicalDrive.name);
break;
default:
Process.Start(logicalDrive.Name);
break;
}
break;
@ -90,49 +100,53 @@ namespace WinPart
break;
}
}
catch (Exception e) { Console.WriteLine(e.ToString()); }
if (debug) Console.ReadKey();
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
if (_debug) Console.ReadKey();
}
static string getInput()
private static string GetInput()
{
Console.Write("\r\n==> ");
var out_ = "";
if (longInputSupport)
out_ = Console.ReadLine();
else
out_ = Console.ReadKey().KeyChar.ToString();
string output = _longInputSupport ? Console.ReadLine() : Console.ReadKey().KeyChar.ToString();
Console.Write("\r\n\r\n");
return out_;
return output;
}
public static void printInfo(ManagementObject mo, string s)
public static void PrintInfo(ManagementBaseObject mo, string s)
{
string[] tmp1 = { };
PropertyData tmp2;
try
{
tmp1 = s.Split(" ".ToCharArray());
if (tmp1[tmp1.Length - 1].EndsWith("[]"))
PropertyData tmp2;
if (tmp1[^1].EndsWith("[]"))
{
tmp2 = mo.Properties[tmp1[tmp1.Length - 1].Replace("[]", "")];
tmp2 = mo.Properties[tmp1[^1].Replace("[]", "")];
string tmp3 = "[ ";
IList list = (Array)tmp2.Value;
IList list = (Array) tmp2.Value;
for (int i = 0; i < list.Count; i++)
{
tmp3 += list[i].ToString();
if (i + 1 < list.Count) tmp3 += " | ";
}
tmp3 += " ]";
Console.WriteLine(tmp2.Name + ": " + tmp3);
Console.WriteLine($"{tmp2.Name}: {tmp3}");
}
else
{
tmp2 = mo.Properties[tmp1[tmp1.Length - 1]];
Console.WriteLine(tmp2.Name + ": " + tmp2.Value);
tmp2 = mo.Properties[tmp1[^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"); }
catch (Exception e)
{
Console.Write($"Could not read: {tmp1[^1]}");
if (_debug) Console.Write($" due to: {e}");
Console.Write(NewLine);
}
}
}
}
}

View File

@ -1,5 +1,4 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
@ -32,5 +31,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("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@ -8,10 +8,15 @@
// </auto-generated>
//------------------------------------------------------------------------------
using System.CodeDom.Compiler;
using System.ComponentModel;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Resources;
using System.Runtime.CompilerServices;
namespace WinPart.Properties {
using System;
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
@ -19,27 +24,27 @@ namespace WinPart.Properties {
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[GeneratedCode("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")]
[DebuggerNonUserCode()]
[CompilerGenerated()]
internal class Resources {
private static global::System.Resources.ResourceManager resourceMan;
private static ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
private static CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources() {
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
[EditorBrowsable(EditorBrowsableState.Advanced)]
internal static ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("WinPart.Properties.Resources", typeof(Resources).Assembly);
if (ReferenceEquals(resourceMan, null)) {
ResourceManager temp = new ResourceManager("WinPart.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
@ -50,8 +55,8 @@ namespace WinPart.Properties {
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
[EditorBrowsable(EditorBrowsableState.Advanced)]
internal static CultureInfo Culture {
get {
return resourceCulture;
}

View File

@ -1,26 +0,0 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace WinPart.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.3.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
public static Settings Default {
get {
return defaultInstance;
}
}
}
}

View File

@ -1,6 +0,0 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)">
<Profiles>
<Profile Name="(Default)" />
</Profiles>
</SettingsFile>

View File

@ -1,122 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{2EF21D5A-1476-4C07-8D1F-5440231547AE}</ProjectGuid>
<TargetFramework>netcoreapp3.1</TargetFramework>
<OutputType>Exe</OutputType>
<RootNamespace>WinPart</RootNamespace>
<AssemblyName>WinPart</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
<TargetFrameworkProfile />
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<LangVersion>8</LangVersion>
<Nullable>enable</Nullable>
<Deterministic>false</Deterministic>
</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>
<PropertyGroup />
<PropertyGroup />
<PropertyGroup>
<StartupObject>WinPart.Program</StartupObject>
</PropertyGroup>
<PropertyGroup />
<PropertyGroup>
<ApplicationManifest>app.manifest</ApplicationManifest>
<PostBuildEvent>if exist "$(SolutionDir)Data\pkgtool.exe" ($(SolutionDir)Data\pkgtool.exe build --noLogo --binDir .) else if exist "%appdata%\UpTool2\Apps\0e35d154-d0d3-45e0-b080-62f521263a44\app\pkgtool.exe" ("%appdata%\UpTool2\Apps\0e35d154-d0d3-45e0-b080-62f521263a44\app\pkgtool.exe" build --noLogo --binDir .) else echo Cound not find Package build tools, skipping</PostBuildEvent>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Management" />
<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="Data structure\Device.cs" />
<Compile Include="Data structure\LogicalDrive.cs" />
<Compile Include="Data structure\Partition.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Properties\Resources.Designer.cs">
<Compile Update="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="Properties\Settings.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
<DependentUpon>Settings.settings</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="app.manifest">
<SubType>Designer</SubType>
</None>
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Properties\Resources.resx">
<EmbeddedResource Update="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.7.2">
<Visible>False</Visible>
<ProductName>Microsoft .NET Framework 4.7.2 %28x86 and x64%29</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>false</Install>
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<Content Include="Data structure\Device.txt" />
<Content Include="Data structure\LogicalDrive.txt" />
<Content Include="Data structure\Partition.txt" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<ItemGroup>
<PackageReference Include="System.Management" Version="4.7.0" />
</ItemGroup>
</Project>

View File

@ -1,28 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<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="highestAvailable" uiAccess="false" />
</requestedPrivileges>
</security>
</trustInfo>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />
</application>
</compatibility>
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="*"
publicKeyToken="6595b64144ccf1df"
language="*"
/>
</dependentAssembly>
</dependency>
</assembly>