Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
electro-logic committed Jul 5, 2023
1 parent aa3328b commit 1b8ee84
Show file tree
Hide file tree
Showing 15 changed files with 630 additions and 0 deletions.
14 changes: 14 additions & 0 deletions App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="VBoxManageUI.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" />
</startup>
<appSettings>
<add key="VBoxManagePath" value="C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" />
</appSettings>
</configuration>
9 changes: 9 additions & 0 deletions App.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Application x:Class="VBoxManageUI.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:VBoxManageUI"
StartupUri="MainWindow.xaml">
<Application.Resources>

</Application.Resources>
</Application>
17 changes: 17 additions & 0 deletions App.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;

namespace VBoxManageUI
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
}
}
28 changes: 28 additions & 0 deletions MainWindow.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<Window x:Class="VBoxManageUI.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:VBoxManageUI"
mc:Ignorable="d"
Title="VBoxManageUI - electro-logic.blogspot.com" Height="768" Width="1024" WindowStartupLocation="CenterScreen">
<Grid Margin="10">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="40"/>
</Grid.RowDefinitions>
<DataGrid x:Name="dg" ItemsSource="{Binding HDDs}" SelectionChanged="dg_SelectionChanged" SelectionMode="Single" AutoGenerateColumns="True" />
<Grid Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="20" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="20" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Button x:Name="btnList" Content="List HDDs" Click="btnList_Click"/>
<Button Grid.Column="2" x:Name="btnCompact" IsEnabled="False" Content="Compact" Click="btnCompact_Click"/>
<Button Grid.Column="4" x:Name="btnHelp" Content="Help" Click="btnHelp_Click" />
</Grid>
</Grid>
</Window>
119 changes: 119 additions & 0 deletions MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
using System.Collections.Generic;
using System.Configuration;
using System.Diagnostics;
using System.Windows;

namespace VBoxManageUI
{
public partial class MainWindow : Window
{
public List<VBoxHdd> HDDs { get; set; } = new List<VBoxHdd>();
public MainWindow()
{
DataContext = this;
InitializeComponent();
ListHdd();
}
public void ListHdd()
{
var vbox_exe = ConfigurationManager.AppSettings["VBoxManagePath"];
var vbox_process = Process.Start(new ProcessStartInfo(vbox_exe, "list hdds")
{
UseShellExecute = false,
RedirectStandardOutput = true,
CreateNoWindow = true
});
const string UUID = "UUID";
const string ParentUUID = "Parent UUID";
const string State = "State";
const string Type = "Type";
const string Location = "Location";
const string Format = "Storage format";
const string Capacity = "Capacity";
const string Encryption = "Encryption";
HDDs.Clear();
VBoxHdd hdd = null;
while (!vbox_process.StandardOutput.EndOfStream)
{
string line = vbox_process.StandardOutput.ReadLine();
if (line.StartsWith(UUID))
{
hdd = new VBoxHdd();
hdd.UUID = line.Substring(UUID.Length + 1).Trim();
}
if (line.StartsWith(ParentUUID))
{
hdd.ParentUUID = line.Substring(ParentUUID.Length + 1).Trim();
}
if (line.StartsWith(State))
{
hdd.State = line.Substring(State.Length + 1).Trim();
}
if (line.StartsWith(Type))
{
hdd.Type = line.Substring(Type.Length + 1).Trim();
}
if (line.StartsWith(Location))
{
hdd.Location = line.Substring(Location.Length + 1).Trim();
}
if (line.StartsWith(Format))
{
hdd.Format = line.Substring(Format.Length + 1).Trim();
}
if (line.StartsWith(Capacity))
{
hdd.Capacity = line.Substring(Capacity.Length + 1).Trim();
}
if (line.StartsWith(Encryption))
{
hdd.Encryption = line.Substring(Encryption.Length + 1).Trim();
HDDs.Add(hdd);
}
}
DataContext = null;
DataContext = this;
}
void btnList_Click(object sender, RoutedEventArgs e)
{
ListHdd();
}
void dg_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
{
if (dg.SelectedItem != null)
{
btnCompact.IsEnabled = true;
}
else
{
btnCompact.IsEnabled = false;
}
}
void btnCompact_Click(object sender, RoutedEventArgs e)
{
var hdd = dg.SelectedItem as VBoxHdd;
if (hdd==null)
{
return;
}
if (hdd.Format != "VDI")
{
MessageBox.Show("Compacting is currently only available for VDI images");
return;
}
if (hdd.State.StartsWith("locked"))
{
MessageBox.Show("Hard Drive is currently locked");
return;
}
var vbox_exe = ConfigurationManager.AppSettings["VBoxManagePath"];
var vbox_process = Process.Start(vbox_exe, $"modifyhd {hdd.UUID} --compact");
vbox_process.WaitForExit();
MessageBox.Show($"Done. Exit Code {vbox_process.ExitCode}.");
}
void btnHelp_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show("Please Defragment and Zero (ex. \"sdelete.exe c: -z\") your virtual hard drive before compacting it.");
}
}
}
55 changes: 55 additions & 0 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Windows;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("VBoxManageUI")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("VBoxManageUI")]
[assembly: AssemblyCopyright("Copyright © 2023")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

//In order to begin building localizable applications, set
//<UICulture>CultureYouAreCodingWith</UICulture> in your .csproj file
//inside a <PropertyGroup>. For example, if you are using US english
//in your source files, set the <UICulture> to en-US. Then uncomment
//the NeutralResourceLanguage attribute below. Update the "en-US" in
//the line below to match the UICulture setting in the project file.

//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]


[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]


// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// 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")]
71 changes: 71 additions & 0 deletions Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 1b8ee84

Please sign in to comment.