Skip to content

Commit

Permalink
Add USB media generation
Browse files Browse the repository at this point in the history
  • Loading branch information
mtniehaus committed Aug 29, 2024
1 parent c75ebd5 commit bdf16a9
Show file tree
Hide file tree
Showing 8 changed files with 195 additions and 59 deletions.
17 changes: 12 additions & 5 deletions MediaToolApp/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,18 @@

<Label Content="Settings" HorizontalAlignment="Left" Margin="400,42,0,0" VerticalAlignment="Top" FontFamily="Segoe UI Semibold" FontSize="16" Foreground="Blue"/>
<Border Margin="400,71,78,711" Background="Blue"/>
<Label Content="Destination Folder" HorizontalAlignment="Left" Margin="400,90,0,0" VerticalAlignment="Top" Width="322"/>
<TextBox x:Name="folderPath" HorizontalAlignment="Left" Margin="400,118,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="322" Height="20" IsEnabled="False" Background="#FFECECEC"/>
<Button x:Name="browseButton" Content="Browse..." HorizontalAlignment="Left" Margin="672,143,0,0" VerticalAlignment="Top" Click="browseButton_Click"/>
<CheckBox x:Name="noPrompt" Content="Do not require pressing a key to boot from ISO" HorizontalAlignment="Left" Margin="400,180,0,0" VerticalAlignment="Top" />
<CheckBox x:Name="recompress" Content="Re-compress the OS image using standard compression" HorizontalAlignment="Left" Margin="400,200,0,0" VerticalAlignment="Top" />

<RadioButton x:Name="createISO" GroupName="MediaChoice" Content="Create a bootable ISO" HorizontalAlignment="Left" Margin="400,90,0,0" VerticalAlignment="Top" IsEnabled="False" IsChecked="True" />
<Label Content="Destination Folder:" HorizontalAlignment="Left" Margin="430,110,0,0" VerticalAlignment="Top" Width="322"/>
<TextBox x:Name="folderPath" HorizontalAlignment="Left" Margin="430,135,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="322" Height="20" IsEnabled="False" Background="#FFECECEC"/>
<Button x:Name="browseButton" Content="Browse..." HorizontalAlignment="Left" Margin="702,160,0,0" VerticalAlignment="Top" Click="browseButton_Click"/>
<CheckBox x:Name="noPrompt" Content="Do not require pressing a key to boot from ISO" HorizontalAlignment="Left" Margin="430,185,0,0" VerticalAlignment="Top" IsEnabled="False" />

<RadioButton x:Name="createUSB" GroupName="MediaChoice" Content="Create Media" HorizontalAlignment="Left" Margin="400,220,0,0" VerticalAlignment="Top" IsEnabled="False" />
<Label Content="Destination Drive:" HorizontalAlignment="Left" Margin="430,240,0,0" VerticalAlignment="Top" Width="322"/>
<ComboBox x:Name="destDrive" HorizontalAlignment="Left" Margin="430,265,0,0" VerticalAlignment="Top" Width="322" IsEnabled="False" />

<CheckBox x:Name="recompress" Content="Re-compress the OS image using standard compression" HorizontalAlignment="Left" Margin="400,315,0,0" VerticalAlignment="Top" />

<Button x:Name="generateButton" Content="Generate" HorizontalAlignment="Left" Margin="328,398,0,0" VerticalAlignment="Top" FontSize="20" Background="Blue" Foreground="White" Width="100" Height="40" IsEnabled="False" Click="generateButton_Click"/>

Expand Down
62 changes: 50 additions & 12 deletions MediaToolApp/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,46 @@ private async Task Init()
wrapper = new ModuleWrapper(this.progress);
await wrapper.Initialize();

// Get the USB media list
Collection<PSObject> usbDrives = await wrapper.GetUSBList();

// Populate the USB media list
destDrive.Dispatcher.Invoke(() =>
{
destDrive.Items.Clear();
foreach (PSObject l in usbDrives.OrderBy(p => p.Properties["DriveLetter"].Value))
{
destDrive.Items.Add(l.Properties["DriveLetter"].Value + ":");
}
destDrive.SelectedIndex = 0;
destDrive.IsEnabled = true;

// While we're here, populate the default ISO path
folderPath.Text = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
});

// Get the product list
Collection<PSObject> list = await wrapper.GetList(null, null, null, null);

// Populate the list
// Populate the media list
osList.Dispatcher.Invoke(() =>
{
osList.Items.Clear();
foreach (PSObject l in list.OrderBy(p => p.Properties["Version"].Value))
{
this.osList.Items.Add(l.Properties["Version"].Value);
osList.Items.Add(l.Properties["Version"].Value);
}
osList.SelectedIndex = 0;
osList.IsEnabled = true;

folderPath.Text = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
});

// Enable the needed UI elements, select ISO by default
createISO.Dispatcher.Invoke(() =>
{
createISO.IsEnabled = true;
createUSB.IsEnabled = true;
noPrompt.IsEnabled = true;
});
}

Expand Down Expand Up @@ -91,7 +116,7 @@ private async Task InitArch(string osVersion)
archList.Items.Clear();
foreach (PSObject l in list.OrderBy(p => p.Properties["Architecture"].Value))
{
this.archList.Items.Add(l.Properties["Architecture"].Value);
archList.Items.Add(l.Properties["Architecture"].Value);
}
archList.SelectedIndex = 0;
archList.IsEnabled = true;
Expand Down Expand Up @@ -119,7 +144,7 @@ private async Task InitLang(string osVersion, string architecture)
langList.Items.Clear();
foreach (PSObject l in list.OrderBy(p => p.Properties["Language"].Value))
{
this.langList.Items.Add(l.Properties["Language"].Value);
langList.Items.Add(l.Properties["Language"].Value);
}
langList.SelectedIndex = 0;
langList.IsEnabled = true;
Expand Down Expand Up @@ -148,7 +173,7 @@ private async Task InitMedia(string osVersion, string architecture, string langu
mediaList.Items.Clear();
foreach (PSObject l in list.OrderBy(p => p.Properties["Media"].Value))
{
this.mediaList.Items.Add(l.Properties["Media"].Value);
mediaList.Items.Add(l.Properties["Media"].Value);
}
mediaList.SelectedIndex = 0;
mediaList.IsEnabled = true;
Expand Down Expand Up @@ -176,10 +201,10 @@ private async Task InitEdition(string osVersion, string architecture, string lan
editionList.Dispatcher.Invoke(() =>
{
editionList.Items.Clear();
this.editionList.Items.Add("(All)");
editionList.Items.Add("(All)");
foreach (PSObject l in list.OrderBy(p => p.Properties["Edition"].Value))
{
this.editionList.Items.Add(l.Properties["Edition"].Value);
editionList.Items.Add(l.Properties["Edition"].Value);
}
editionList.SelectedIndex = 0;
editionList.IsEnabled = true;
Expand All @@ -199,6 +224,7 @@ private async void generateButton_Click(object sender, RoutedEventArgs e)
edition = "";
}
string dest = folderPath.Text;
string drive = (string) destDrive.SelectedValue;
bool noP = noPrompt.IsChecked.GetValueOrDefault(false);
bool recomp = recompress.IsChecked.GetValueOrDefault(false);
// Disable everything
Expand All @@ -212,8 +238,17 @@ private async void generateButton_Click(object sender, RoutedEventArgs e)
browseButton.IsEnabled = false;
noPrompt.IsEnabled = false;
recompress.IsEnabled = false;
// Call the async routine to initialize
await Task.Run(async () => await this.Generate(os, arch, lang, media, edition, dest, noP, recomp));
createISO.IsEnabled = false;
createUSB.IsEnabled = false;
mediaList.IsEnabled = false;
// Call the async routine to create media
if ((bool)createISO.IsChecked)
{
await Task.Run(async () => await this.Generate(os, arch, lang, media, edition, dest, noP, recomp));
} else
{
await Task.Run(async () => await this.Generate(os, arch, lang, media, edition, drive, noP, recomp));
}
// Re-enable everything
generating = false;
osList.IsEnabled = true;
Expand All @@ -225,6 +260,9 @@ private async void generateButton_Click(object sender, RoutedEventArgs e)
browseButton.IsEnabled = true;
noPrompt.IsEnabled = true;
recompress.IsEnabled = true;
createISO.IsEnabled = true;
createUSB.IsEnabled = true;
mediaList.IsEnabled = true;
progress.Value = 0;
}

Expand Down Expand Up @@ -252,9 +290,9 @@ public class MyTraceListener : TraceListener

public MyTraceListener(System.Windows.Controls.RichTextBox output, ScrollViewer scroll)
{
this.Name = "Trace";
Name = "Trace";
this.output = output;
this.viewer = scroll;
viewer = scroll;
}

public override void Write(string message)
Expand Down
19 changes: 18 additions & 1 deletion MediaToolApp/ModuleWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,29 @@ public async Task<Collection<PSObject>> GetList(string product, string architect
return null;
}

public async Task<Collection<PSObject>> GetUSBList()
{
try
{
PSCommand list = new PSCommand();
list.AddCommand("Get-MediaToolUSB");

Task<Collection<PSObject>> t = RunCommandAsync(list);
return t.Result;
}
catch (Exception ex)
{
Trace.WriteLine("Unhandled exception: " + ex.ToString());
}
return null;
}

public async Task<Collection<PSObject>> Generate(string product, string architecture, string language, string media, string edition, string dest, bool noPrompt, bool recompress)
{
try
{
PSCommand list = new PSCommand();
list.AddCommand("Get-MediaToolISO")
list.AddCommand("New-MediaToolMedia")
.AddParameter("Product", product)
.AddParameter("Architecture", architecture)
.AddParameter("Language", language)
Expand Down
6 changes: 3 additions & 3 deletions MediaToolApp/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Oofhours.com")]
[assembly: AssemblyProduct("Oofhours.com Media Tool")]
[assembly: AssemblyCopyright("Copyright © 2023 by Michael Niehaus")]
[assembly: AssemblyCopyright("Copyright © 2024 by Michael Niehaus")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Expand Down Expand Up @@ -51,5 +51,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.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("3.0.0.0")]
[assembly: AssemblyFileVersion("3.0.0.0")]
2 changes: 1 addition & 1 deletion MediaToolApp/app.manifest
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?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" />
<assemblyIdentity version="3.0.0.0" name="OofhoursMediaTool.app" />
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
Expand Down
Binary file modified Modules/MediaTool/MediaTool.psd1
Binary file not shown.
Loading

0 comments on commit bdf16a9

Please sign in to comment.