Skip to content

Commit

Permalink
Microwin ISO downloader (#2581)
Browse files Browse the repository at this point in the history
* try1

* little fix

* change back to using Fido

* little update

* fix some stuff

* fix (maybe?)

* remove architecture selection

* add somewhat of a lang support (needs improvement)

* WIP: refractor of existing logic & addition of language selection

* WIP: correct lang display (not working rn)

* improve, fix and more

- call ed with default windows edition (Home/Pro/Edu)
- fix language combobox logic
- add @CodingWonders 's "Get-FidoLangFromCulture"
- hide comboboxes if manual ISO selection is toggled

* little output fix

- added | Out-Null to combobox item additions to prevent unneeded console output

* improve coloring

- using ToggleButtonOnColor for Radiobuttons
- add theme color ToggleButtonOffColor and use where needed

* fix lang

* fix "en-" lang

remove (United States) bc it is wrong and not accepted by fido/ms

* always add "English"

* fix theming

- add ToggleButtonOffColor to all themes

* fix merge issue

* update instructions

* update ui

- manual download is primary option
- radiobuttons renamed to refrect what they are
- fix styling of instruction
- add margin to radiobuttons

* fix  by adding line break to instructions

* fix merge issues
  • Loading branch information
MyDrift-user authored Sep 21, 2024
1 parent 1f683d3 commit ba45c33
Show file tree
Hide file tree
Showing 5 changed files with 162 additions and 16 deletions.
4 changes: 3 additions & 1 deletion config/themes.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
"ButtonBackgroundSelectedColor": "#F0F0F0",
"ButtonForegroundColor": "#232629",
"ToggleButtonOnColor": "#2e77ff",
"ToggleButtonOffColor": "#707070",
"BorderColor": "#232629",
"BorderOpacity": "0.2"

Expand Down Expand Up @@ -100,7 +101,8 @@
"ButtonBackgroundMouseoverColor": "#3B4252",
"ButtonBackgroundSelectedColor": "#5E81AC",
"ButtonForegroundColor": "#F7F7F7",
"ToggleButtonOnColor": "#2e77ff",
"ToggleButtonOnColor": "#2e77ff",
"ToggleButtonOffColor": "#707070",
"BorderColor": "#2F373D",
"BorderOpacity": "0.2"
}
Expand Down
50 changes: 50 additions & 0 deletions functions/private/Invoke-WinUtilMicroWin-Helper.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,56 @@ function Test-CompatibleImage() {
}
}

function Get-FidoLangFromCulture {

param (
[Parameter(Mandatory, Position = 0)] [string] $langName
)

switch -Wildcard ($langName)
{
"ar*" { return "Arabic" }
"pt-BR" { return "Brazilian Portuguese" }
"bg*" { return "Bulgarian" }
{($_ -eq "zh-CH") -or ($_ -like "zh-Hans*") -or ($_ -eq "zh-SG") -or ($_ -eq "zh-CHS")} { return "Chinese (Simplified)" }
{($_ -eq "zh") -or ($_ -eq "zh-Hant") -or ($_ -eq "zh-HK") -or ($_ -eq "zh-MO") -or ($_ -eq "zh-TW") -or ($_ -eq "zh-CHT")} { return "Chinese (Traditional)" }
"hr*" { return "Croatian" }
"cs*" { return "Czech" }
"da*" { return "Danish" }
"nl*" { return "Dutch" }
"en-US" { return "English" }
{($_ -like "en*") -and ($_ -ne "en-US")} { return "English International" }
"et*" { return "Estonian" }
"fi*" { return "Finnish" }
{($_ -like "fr*") -and ($_ -ne "fr-CA")} { return "French" }
"fr-CA" { return "French Canadian" }
"de*" { return "German" }
"el*" { return "Greek" }
"he*" { return "Hebrew" }
"hu*" { return "Hungarian" }
"it*" { return "Italian" }
"ja*" { return "Japanese" }
"ko*" { return "Korean" }
"lv*" { return "Latvian" }
"lt*" { return "Lituanian" }
"nb*" { return "Norwegian" }
"pl*" { return "Polish" }
{($_ -like "pt*") -and ($_ -ne "pt-BR")} { return "Portuguese" }
"ro*" { return "Romanian" }
"ru*" { return "Russian" }
"sr-Latn*" { return "Serbian Latin" }
"sk*" { return "Slovak" }
"sl*" { return "Slovenian" }
{($_ -like "es*") -and ($_ -ne "es-MX")} { return "Spanish" }
"es-MX" { return "Spanish (Mexico)" }
"sv*" { return "Swedish" }
"th*" { return "Thai" }
"tr*" { return "Turkish" }
"uk*" { return "Ukrainian" }
default { return "English" }
}
}

function Remove-Features() {
<#
.SYNOPSIS
Expand Down
37 changes: 26 additions & 11 deletions functions/public/Invoke-WPFGetIso.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,32 @@ function Invoke-WPFGetIso {
}
}

[System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") | Out-Null
$openFileDialog = New-Object System.Windows.Forms.OpenFileDialog
$openFileDialog.initialDirectory = $initialDirectory
$openFileDialog.filter = "ISO files (*.iso)| *.iso"
$openFileDialog.ShowDialog() | Out-Null
$filePath = $openFileDialog.FileName

if ([string]::IsNullOrEmpty($filePath)) {
Write-Host "No ISO is chosen"
$sync.BusyMessage.Visibility="Hidden"
return
if ($sync["ISOmanual"].IsChecked) {
# Open file dialog to let user choose the ISO file
[System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") | Out-Null
$openFileDialog = New-Object System.Windows.Forms.OpenFileDialog
$openFileDialog.initialDirectory = $initialDirectory
$openFileDialog.filter = "ISO files (*.iso)| *.iso"
$openFileDialog.ShowDialog() | Out-Null
$filePath = $openFileDialog.FileName

if ([string]::IsNullOrEmpty($filePath)) {
Write-Host "No ISO is chosen"
$sync.BusyMessage.Visibility="Hidden"
return
}
} elseif ($sync["ISOdownloader"].IsChecked) {
# Auto download newest ISO
# Credit: https://github.com/pbatard/Fido
$fidopath = "$env:temp\Fido.ps1"
$originalLocation = Get-Location

Invoke-WebRequest "https://github.com/pbatard/Fido/raw/master/Fido.ps1" -OutFile $fidopath

Set-Location -Path $env:temp
& $fidopath -Win 'Windows 11' -Rel $sync["ISORelease"].SelectedItem -Arch "x64" -Lang $sync["ISOLanguage"].SelectedItem -Ed "Windows 11 Home/Pro/Edu"
Set-Location $originalLocation
$filePath = Get-ChildItem -Path "$env:temp" -Filter "Win11*.iso" | Sort-Object LastWriteTime -Descending | Select-Object -First 1
}

Write-Host "File path $($filePath)"
Expand Down
31 changes: 31 additions & 0 deletions scripts/main.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,37 @@ Add-Type @"

})

# Add event handlers for the RadioButtons
$sync["ISOdownloader"].add_Checked({
$sync["ISORelease"].Visibility = [System.Windows.Visibility]::Visible
$sync["ISOLanguage"].Visibility = [System.Windows.Visibility]::Visible
})

$sync["ISOmanual"].add_Checked({
$sync["ISORelease"].Visibility = [System.Windows.Visibility]::Collapsed
$sync["ISOLanguage"].Visibility = [System.Windows.Visibility]::Collapsed
})

$sync["ISORelease"].Items.Add("23H2") | Out-Null
$sync["ISORelease"].Items.Add("22H2") | Out-Null
$sync["ISORelease"].Items.Add("21H2") | Out-Null
$sync["ISORelease"].SelectedItem = "23H2"

$currentCulture = Get-FidoLangFromCulture -langName (Get-Culture).Name

$sync["ISOLanguage"].Items.Add($currentCulture) | Out-Null
if ($currentCulture -ne "English International") {
$sync["ISOLanguage"].Items.Add("English International") | Out-Null
}
if ($currentCulture -ne "English") {
$sync["ISOLanguage"].Items.Add("English") | Out-Null
}
if ($sync["ISOLanguage"].Items.Count -eq 1) {
$sync["ISOLanguage"].IsEnabled = $false
}
$sync["ISOLanguage"].SelectedItem = $currentCulture


# Load Checkboxes and Labels outside of the Filter function only once on startup for performance reasons
$filter = Get-WinUtilVariables -Type CheckBox
$CheckBoxes = ($sync.GetEnumerator()).where{ $psitem.Key -in $filter }
Expand Down
56 changes: 52 additions & 4 deletions xaml/inputXML.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,47 @@
</Setter.Value>
</Setter>
</Style>
<Style TargetType="RadioButton">
<Setter Property="Foreground" Value="{DynamicResource MainForegroundColor}"/>
<Setter Property="Background" Value="{DynamicResource MainBackgroundColor}"/>
<Setter Property="FontSize" Value="{DynamicResource FontSize}" />
<Setter Property="FontFamily" Value="{DynamicResource FontFamily}"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="RadioButton">
<StackPanel Orientation="Horizontal" Margin="{DynamicResource CheckBoxMargin}">
<Grid Width="14" Height="14">
<Ellipse x:Name="OuterCircle"
Stroke="{DynamicResource ToggleButtonOffColor}"
Fill="{DynamicResource ButtonBackgroundColor}"
StrokeThickness="1"
Width="14"
Height="14"
SnapsToDevicePixels="True"/>
<Ellipse x:Name="InnerCircle"
Fill="{DynamicResource ToggleButtonOnColor}"
Width="8"
Height="8"
Visibility="Collapsed"
HorizontalAlignment="Center"
VerticalAlignment="Center"/>
</Grid>
<ContentPresenter Margin="4,0,0,0"
VerticalAlignment="Center"
RecognizesAccessKey="True"/>
</StackPanel>
<ControlTemplate.Triggers>
<Trigger Property="IsChecked" Value="True">
<Setter TargetName="InnerCircle" Property="Visibility" Value="Visible"/>
</Trigger>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="OuterCircle" Property="Stroke" Value="{DynamicResource ToggleButtonOnColor}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="ToggleSwitchStyle" TargetType="CheckBox">
<Setter Property="Template">
<Setter.Value>
Expand Down Expand Up @@ -495,8 +536,8 @@
</Trigger>
<Trigger Property="ToggleButton.IsChecked" Value="False">
<Setter TargetName="Border" Property="Background" Value="{DynamicResource MainBackgroundColor}" />
<Setter TargetName="Border" Property="BorderBrush" Value="#707070" />
<Setter TargetName="Ellipse" Property="Fill" Value="#707070" />
<Setter TargetName="Border" Property="BorderBrush" Value="{DynamicResource ToggleButtonOffColor}" />
<Setter TargetName="Ellipse" Property="Fill" Value="{DynamicResource ToggleButtonOffColor}" />
</Trigger>

<Trigger Property="ToggleButton.IsChecked" Value="True">
Expand Down Expand Up @@ -1038,10 +1079,14 @@
TextWrapping="Wrap"
Foreground="{DynamicResource LabelboxForegroundColor}"
/>
<RadioButton x:Name="ISOmanual" Content="Select your own ISO" GroupName="Options" Margin="0,10,0,0" IsChecked="True"/>
<RadioButton x:Name="ISOdownloader" Content="Get newest ISO automatically" GroupName="Options" Margin="0,5,0,5"/>
<ComboBox x:Name="ISORelease" Visibility="Collapsed"/>
<ComboBox x:Name="ISOLanguage" Visibility="Collapsed"/>
<Button Name="WPFGetIso" Margin="2" Padding="15">
<Button.Content>
<TextBlock Background="Transparent" Foreground="{DynamicResource ButtonForegroundColor}">
Select Windows <Underline>I</Underline>SO
Get Windows <Underline>I</Underline>SO
</TextBlock>
</Button.Content>
</Button>
Expand Down Expand Up @@ -1136,7 +1181,10 @@
<LineBreak/>

<Bold>INSTRUCTIONS</Bold> <LineBreak/>
- <TextBlock Name="Win11DownloadLink" Style="{StaticResource HoverTextBlockStyle}" ToolTip="https://www.microsoft.com/software-download/windows11">Download</TextBlock> the latest Windows 11 image from Microsoft <LineBreak/>
- Download a Windows 11 ISO through the following options: <LineBreak/>
<TextBlock Margin="15,0,0,0" Text="- Select your own ISO: Manually download the latest Windows 11 image from " Foreground="{DynamicResource ComboBoxForegroundColor}"/>
<TextBlock Name="Win11DownloadLink" Style="{StaticResource HoverTextBlockStyle}" ToolTip="https://www.microsoft.com/software-download/windows11">Microsoft</TextBlock>. <LineBreak/>
<TextBlock Margin="15,0,0,0" Text="- Get newest ISO automatically: Choose Windows 11 Edition and preferred language." Foreground="{DynamicResource ComboBoxForegroundColor}"/> <LineBreak/>
May take several minutes to process the ISO depending on your machine and connection <LineBreak/>
- Put it somewhere on the C:\ drive so it is easily accessible <LineBreak/>
- Launch WinUtil and MicroWin <LineBreak/>
Expand Down

0 comments on commit ba45c33

Please sign in to comment.