Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes, improvements + Auto Window handling #2648

Merged
merged 11 commits into from
Aug 30, 2024
15 changes: 9 additions & 6 deletions Compile.ps1
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
param (
[switch]$Debug,
[switch]$Run,
[switch]$SkipPreprocessing
[switch]$SkipPreprocessing,
[string]$arg
MyDrift-user marked this conversation as resolved.
Show resolved Hide resolved
)
$OFS = "`r`n"
$scriptname = "winutil.ps1"
Expand Down Expand Up @@ -118,10 +119,12 @@ catch {
Write-Progress -Activity "Validating" -Completed

if ($run) {
try {
Start-Process -FilePath "pwsh" -ArgumentList "$workingdir\$scriptname"
} catch {
Start-Process -FilePath "powershell" -ArgumentList "$workingdir\$scriptname"
}
$script = "& '$workingdir\$scriptname' $arg"

$powershellcmd = if (Get-Command pwsh -ErrorAction SilentlyContinue) { "pwsh" } else { "powershell" }
$processCmd = if (Get-Command wt.exe -ErrorAction SilentlyContinue) { "wt.exe" } else { $powershellcmd }

Start-Process $processCmd -ArgumentList "$powershellcmd -NoProfile -Command $script"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... so if you don't have wt.exe installed, it'll launch powershell (or pwsh).. and then that powershell will launch another powershell, which'll run the script?
This's way too nested, and I do agree that most devs working on this project work in Windows 11 (not 10), but I think there's room for improvements.

Copy link
Contributor Author

@MyDrift-user MyDrift-user Aug 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I totally agree there, Chris liked using wt.exe if possible so I implemented it. Sure needs some work bc wt.exe and powershell work diffrently. I think that may be a task for another PR tho..


break
}
3 changes: 2 additions & 1 deletion config/themes.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"CustomDialogWidth": "400",
"CustomDialogHeight": "200",

"FontSize": "14",
"FontSize": "12",
"FontFamily": "Arial",
"FontSizeHeading": "16",
"HeaderFontFamily": "Consolas, Monaco",
Expand All @@ -26,6 +26,7 @@
"CloseIconFontSize": "18",

"MicroWinLogoSize": "10",
"MicrowinCheckBoxMargin": "-10,5,0,0",
MyDrift-user marked this conversation as resolved.
Show resolved Hide resolved

"ProgressBarForegroundColor": "#FFAC1C",
"ProgressBarBackgroundColor": "Transparent",
Expand Down
6 changes: 6 additions & 0 deletions scripts/main.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,12 @@ $sync["SearchBar"].Add_TextChanged({
}
})

$sync["Form"].Add_Loaded({
param($e)
$sync["Form"].MaxWidth = [Double]::PositiveInfinity
$sync["Form"].MaxHeight = [Double]::PositiveInfinity
})

# Initialize the hashtable
$winutildir = @{}

Expand Down
29 changes: 22 additions & 7 deletions scripts/start.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
GitHub : https://github.com/ChrisTitusTech
Version : #{replaceme}
#>

param (
[switch]$Debug,
[string]$Config,
Expand All @@ -27,12 +28,6 @@ if ($Run) {
$PARAM_RUN = $true
}

$dateTime = Get-Date -Format "yyyy-MM-dd_HH-mm-ss"

$logdir = "$env:localappdata\winutil\logs"
[System.IO.Directory]::CreateDirectory("$logdir")
Start-Transcript -Path "$logdir\winutil_$dateTime.log" -Append

# Load DLLs
Add-Type -AssemblyName PresentationFramework
Add-Type -AssemblyName System.Windows.Forms
Expand All @@ -46,8 +41,22 @@ $sync.ProcessRunning = $false

if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
Write-Output "Winutil needs to be run as Administrator. Attempting to relaunch."
$argList = @()

$PSBoundParameters.GetEnumerator() | ForEach-Object {
$argList += if ($_.Value -is [switch] -and $_.Value) {
"-$($_.Key)"
} elseif ($_.Value) {
"-$($_.Key) `"$($_.Value)`""
}
}

$script = if ($MyInvocation.MyCommand.Path) {
"& { & '$($MyInvocation.MyCommand.Path)' $argList }"
} else {
"iex '& { $(irm https://github.com/ChrisTitusTech/winutil/releases/latest/download/winutil.ps1) } $argList'"
}

$script = if ($MyInvocation.MyCommand.Path) { "& '" + $MyInvocation.MyCommand.Path + "'" } else { "irm 'https://github.com/ChrisTitusTech/winutil/releases/latest/download/winutil.ps1' | iex"}
$powershellcmd = if (Get-Command pwsh -ErrorAction SilentlyContinue) { "pwsh" } else { "powershell" }
$processCmd = if (Get-Command wt.exe -ErrorAction SilentlyContinue) { "wt.exe" } else { $powershellcmd }

Expand All @@ -56,6 +65,12 @@ if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]:
break
}

$dateTime = Get-Date -Format "yyyy-MM-dd_HH-mm-ss"

$logdir = "$env:localappdata\winutil\logs"
[System.IO.Directory]::CreateDirectory("$logdir") | Out-Null
Start-Transcript -Path "$logdir\winutil_$dateTime.log" -Append -NoClobber | Out-Null

# Set PowerShell window title
$Host.UI.RawUI.WindowTitle = $myInvocation.MyCommand.Definition + "(Admin)"
clear-host
13 changes: 10 additions & 3 deletions windev.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,15 @@

if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
Write-Output "Winutil needs to be run as Administrator. Attempting to relaunch."
# Capture all the arguments passed to the script
$argList = $args -join ' '

$script = if ($MyInvocation.MyCommand.Path) {
"& { & '$($MyInvocation.MyCommand.Path)' $argList }"
} else {
"iex '& { $(irm https://github.com/ChrisTitusTech/winutil/raw/main/windev.ps1) } $argList'"
}

$script = if ($MyInvocation.MyCommand.Path) { "& '" + $MyInvocation.MyCommand.Path + "'" } else { "irm 'https://github.com/ChrisTitusTech/winutil/raw/main/windev.ps1' | iex"}
$powershellcmd = if (Get-Command pwsh -ErrorAction SilentlyContinue) { "pwsh" } else { "powershell" }
$processCmd = if (Get-Command wt.exe -ErrorAction SilentlyContinue) { "wt.exe" } else { $powershellcmd }

Expand Down Expand Up @@ -46,9 +53,9 @@ function RedirectToLatestPreRelease {
Write-Host "Using latest Full Release"
$url = "https://github.com/ChrisTitusTech/winutil/releases/latest/download/winutil.ps1"
}
Invoke-RestMethod $url | Invoke-Expression

iex "& { $(irm $url) } $argList"
}

# Call the redirect function

RedirectToLatestPreRelease
48 changes: 23 additions & 25 deletions xaml/inputXML.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
WindowStartupLocation="CenterScreen"
UseLayoutRounding="True"
WindowStyle="None"
Title="Chris Titus Tech's Windows Utility" Height="800" Width="1280">
Width="Auto"
Height="Auto"
MaxWidth="1380"
MyDrift-user marked this conversation as resolved.
Show resolved Hide resolved
MaxHeight="800"
Title="Chris Titus Tech's Windows Utility">
<WindowChrome.WindowChrome>
<WindowChrome CaptionHeight="0" CornerRadius="10"/>
</WindowChrome.WindowChrome>
Expand Down Expand Up @@ -689,10 +693,10 @@
</ToggleButton>
<Grid Background="{MainBackgroundColor}" ShowGridLines="False" Width="Auto" Height="Auto" HorizontalAlignment="Stretch">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="50px"/>
<ColumnDefinition Width="50px"/>
<ColumnDefinition Width="*"/> <!-- Main content area -->
<ColumnDefinition Width="Auto"/> <!-- Space for options button -->
<ColumnDefinition Width="Auto"/> <!-- Space for close button -->
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>

<!--
Expand Down Expand Up @@ -722,7 +726,8 @@
VerticalAlignment="Center" HorizontalAlignment="Left"
FontFamily="Segoe MDL2 Assets"
FontSize="{IconFontSize}"
Margin="180,0,0,0">&#xE721;</TextBlock>
Margin="180,0,0,0">&#xE721;
</TextBlock>
<!--
TODO:
Make this ClearButton Positioning react to
Expand All @@ -734,7 +739,8 @@
VerticalAlignment="Center" HorizontalAlignment="Left"
Name="SearchBarClearButton"
Style="{StaticResource SearchBarClearButtonStyle}"
Margin="210,0,0,0" Visibility="Collapsed"/>
Margin="210,0,0,0" Visibility="Collapsed">
</Button>

<ProgressBar
Grid.Column="1"
Expand Down Expand Up @@ -773,7 +779,7 @@
FontSize="{SettingsIconFontSize}"
Width="{IconButtonSize}" Height="{IconButtonSize}"
HorizontalAlignment="Right" VerticalAlignment="Top"
Margin="0,5,5,0"
Margin="5,5,5,0"
FontFamily="Segoe MDL2 Assets"
Content="&#xE713;"/>
<Popup Grid.Column="2" Name="SettingsPopup"
Expand Down Expand Up @@ -870,18 +876,10 @@
</Grid>
</ScrollViewer>
<Border Grid.Row="1" Background="{MainBackgroundColor}" BorderBrush="{BorderColor}" BorderThickness="1" CornerRadius="5" HorizontalAlignment="Stretch" Padding="10">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="1*" />
</Grid.ColumnDefinitions>

<!-- Buttons on the left half -->
<StackPanel Orientation="Horizontal" HorizontalAlignment="Left" VerticalAlignment="Center" Grid.Column="0">
<Button Name="WPFTweaksbutton" Content="Run Tweaks" Margin="5"/>
<Button Name="WPFUndoall" Content="Undo Selected Tweaks" Margin="5"/>
</StackPanel>
</Grid>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Left" VerticalAlignment="Center" Grid.Column="0">
<Button Name="WPFTweaksbutton" Content="Run Tweaks" Margin="5"/>
<Button Name="WPFUndoall" Content="Undo Selected Tweaks" Margin="5"/>
</StackPanel>
</Border>
</Grid>
</TabItem>
Expand Down Expand Up @@ -937,12 +935,12 @@
HorizontalAlignment="Stretch">
<StackPanel Name="MicrowinMain" Background="{MainBackgroundColor}" SnapsToDevicePixels="True" Grid.Column="0" Grid.Row="0">
<StackPanel Background="Transparent" SnapsToDevicePixels="True" Margin="1">
<CheckBox x:Name="WPFMicrowinDownloadFromGitHub" Content="Download oscdimg.exe from CTT Github repo" IsChecked="False" Margin="{CheckBoxMargin}" />
<CheckBox x:Name="WPFMicrowinDownloadFromGitHub" Content="Download oscdimg.exe from CTT Github repo" IsChecked="False" Margin="{MicrowinCheckBoxMargin}" />
<TextBlock Margin="5" Padding="1" TextWrapping="Wrap" Foreground="{ComboBoxForegroundColor}">
Choose a Windows ISO file that you've downloaded <LineBreak/>
Check the status in the console
</TextBlock>
<CheckBox x:Name="WPFMicrowinISOScratchDir" Content="Use ISO directory for ScratchDir " IsChecked="False" Margin="{CheckBoxMargin}"
<CheckBox x:Name="WPFMicrowinISOScratchDir" Content="Use ISO directory for ScratchDir " IsChecked="False" Margin="{MicrowinCheckBoxMargin}"
ToolTip="Use ISO directory for ScratchDir " />
<Grid>
<Grid.ColumnDefinitions>
Expand Down Expand Up @@ -989,7 +987,7 @@
<TextBlock Margin="6" Padding="1" TextWrapping="Wrap">Choose Windows SKU</TextBlock>
<ComboBox x:Name = "MicrowinWindowsFlavors" Margin="1" />
<Rectangle Fill="{MainForegroundColor}" Height="2" HorizontalAlignment="Stretch" Margin="0,10,0,10"/>
<CheckBox Name="MicrowinInjectDrivers" Content="Inject drivers (I KNOW WHAT I'M DOING)" Margin="-10,5,0,0" IsChecked="False" ToolTip="Path to unpacked drivers all sys and inf files for devices that need drivers"/>
<CheckBox Name="MicrowinInjectDrivers" Content="Inject drivers (I KNOW WHAT I'M DOING)" Margin="{MicrowinCheckBoxMargin}" IsChecked="False" ToolTip="Path to unpacked drivers all sys and inf files for devices that need drivers"/>
<TextBox Name="MicrowinDriverLocation" Background="Transparent" BorderThickness="1" BorderBrush="{MainForegroundColor}"
Margin="6"
Text=""
Expand All @@ -998,9 +996,9 @@
Foreground="{LabelboxForegroundColor}"
ToolTip="Path to unpacked drivers all sys and inf files for devices that need drivers"
/>
<CheckBox Name="MicrowinImportDrivers" Content="Import drivers from current system" Margin="{CheckBoxMargin}" IsChecked="False" ToolTip="Export all third-party drivers from your system and inject them to the MicroWin image"/>
<CheckBox Name="MicrowinImportDrivers" Content="Import drivers from current system" Margin="{MicrowinCheckBoxMargin}" IsChecked="False" ToolTip="Export all third-party drivers from your system and inject them to the MicroWin image"/>
<Rectangle Fill="{MainForegroundColor}" Height="2" HorizontalAlignment="Stretch" Margin="0,10,0,10"/>
<CheckBox Name="WPFMicrowinCopyToUsb" Content="Copy to Ventoy" Margin="{CheckBoxMargin}" IsChecked="False" ToolTip="Copy to USB disk with a label Ventoy"/>
<CheckBox Name="WPFMicrowinCopyToUsb" Content="Copy to Ventoy" Margin="{MicrowinCheckBoxMargin}" IsChecked="False" ToolTip="Copy to USB disk with a label Ventoy"/>
<Rectangle Fill="{MainForegroundColor}" Height="2" HorizontalAlignment="Stretch" Margin="0,10,0,10"/>
<TextBlock Margin="6" Padding="1" TextWrapping="Wrap"><Bold>Custom user settings (leave empty for default user)</Bold></TextBlock>
<TextBlock Margin="6" Padding="1" TextWrapping="Wrap">User name (20 characters max.):</TextBlock>
Expand Down