mirror of
https://github.com/ChrisTitusTech/winutil.git
synced 2024-11-14 14:45:52 -06:00
4be4805e7c
* Compile Winutil * fix enable toggle visual shape (#1179) * Compile Winutil * Update README.md (#1142) * Update README.md * Update README.md Update the README.md to be more precise & clear. Fix up grammatical mistakes, allow users to figure out their issues easier. Fix crediting of IRM execution script. * Update README.md * Compile Winutil * replacing the hard-coded paths for windows dir (#1126) * Changed version of python for winget to 3.12 (#1137) * Compile Winutil * Added Programs to the Install List (#1143) * Added the checkboxes of what I want to add * Added duplicati * Added KDE Connect * Added OpenVPN Connect * Added Oracle Virtual Box * Added Paint.net * Fixed an error spotted in the KDE Connect package names * Added the checkboxes into inputXML.xaml * Added the package details to config\applications.json * Reverted changes from winutil --------- Co-authored-by: Chris Titus <contact@christitus.com> * Compile Winutil * New Section: Customize Preferences (inside tweaks section) (#1163) * convert numlock on startup checkboxs into toggle button * convert verboselogon checkbox into toggle button * gui changes : added new section, new style for toggle buttons * convert showfileextentions checkbox into toggle button * convert mouse acceleration checkboxs into togglebutton * manor changes : cleanup, adding tooltips * fix style of toggle tweaks added new style 'labelfortweaks' that fix sytle and give mouse hover effect like previous tweaks that are using checkbox style but here for toggle tweaks we are using label and to make other tweaks style 'labelfortweaks' sytle is used. it mimic the style of checkbox style --------- Co-authored-by: Chris Titus <contact@christitus.com> * Compile Winutil * add Thunderbird (#1165) * Compile Winutil * Update the screenshot in README w/ dark mode (#1173) * took a pr on main and pulling it to test (#1175) * Add Session messenger to the applications list. (#1166) * Update applications.json * Update inputXML.xaml * Compile Winutil --------- Co-authored-by: charlescgs <135472912+charlescgs@users.noreply.github.com> Co-authored-by: ChrisTitusTech <ChrisTitusTech@users.noreply.github.com> * Compile Winutil * fix enable toggle visual shape --------- Co-authored-by: ChrisTitusTech <ChrisTitusTech@users.noreply.github.com> Co-authored-by: aim <aimansadiqrahman@gmail.com> Co-authored-by: edelvarden <42596339+edelvarden@users.noreply.github.com> Co-authored-by: dass2608 <139251779+dass2608@users.noreply.github.com> Co-authored-by: Inventhrice <45127310+Inventhrice@users.noreply.github.com> Co-authored-by: Chris Titus <contact@christitus.com> Co-authored-by: Antun Nitraj <antnitraj@gmail.com> Co-authored-by: Meen Beese <meenbeese@tutanota.com> Co-authored-by: charlescgs <135472912+charlescgs@users.noreply.github.com> Co-authored-by: padsalatushal <padsalatushal@users.noreply.github.com> * Add 2 Applications (#1180) This adds KDE Dolphin File Manager and Sublime Merge. * Compile Winutil * Microwin and fixes (#1184) * Microwin and fixes * comment out product key --------- Co-authored-by: KonTy <KonTy@github.com> Co-authored-by: Chris Titus <contact@christitus.com> * Compile Winutil * Microwin Fixes * Set owner fix for issue (#1184) (#1185) * Microwin and fixes * Fix for #1184, takeown doesn't work on non English Windows --------- Co-authored-by: KonTy <KonTy@github.com> * Compile Winutil * Microwin Fix on Bare Metal Fixes the "The computer restarted unexpectedly" error on a fresh install * Compile Winutil * MicroWin: fixing German and Spanish bugs (#1194) * Fixing German and other languages local issue, also doing some house keeping * Fixed several Microwin bugs * Fixing local bug and adding copy to USB feature * Adding driver injection capabilities and fixing bugs in Microwin --------- Co-authored-by: KonTy <KonTy@github.com> * Compile Winutil * error check before removing mountDir * MicroWin Finalized - fix typo - changed oscdimg from using & to Start-Process * Compile Winutil * winget reinstall addition * Adding Floorp Browser (#1204) * Update applications.json * Khalylexe patch 1 (#2) * Update inputXML.xaml * Update applications.json (#1) * Update applications.json * Update applications.json * Update inputXML.xaml * Compile Winutil * Mercury Browser from Alex313031 (#1206) * Compile Winutil * Add Git Extensions git client (#1201) * Compile Winutil * Add PDFsam Basic (#1198) * Compile Winutil * Add new applications (#1197) * Compile Winutil * fixed typo in a few places. (#1192) * Compile Winutil * Added new tools! (#1190) * Update applications.json Added: - Anki - Clipgrab - clink - copyq - Devtoys - ohmyposh - masscode - portmaster - starship * Update inputXML.xaml added the software to the form --------- Co-authored-by: Chris Titus <contact@christitus.com> * Compile Winutil * Update applications.json (#1187) Added to choco : nilesoft-shell prismlauncher bluestacks flameshot * Compile Winutil * fix unit test * Update functions.Tests.ps1 FIXED * fix trailing comma * Compile Winutil * Update winutil.ps1 --------- Co-authored-by: ChrisTitusTech <ChrisTitusTech@users.noreply.github.com> Co-authored-by: Padsala Tushal <57517785+padsalatushal@users.noreply.github.com> Co-authored-by: aim <aimansadiqrahman@gmail.com> Co-authored-by: edelvarden <42596339+edelvarden@users.noreply.github.com> Co-authored-by: dass2608 <139251779+dass2608@users.noreply.github.com> Co-authored-by: Inventhrice <45127310+Inventhrice@users.noreply.github.com> Co-authored-by: Antun Nitraj <antnitraj@gmail.com> Co-authored-by: Meen Beese <meenbeese@tutanota.com> Co-authored-by: charlescgs <135472912+charlescgs@users.noreply.github.com> Co-authored-by: padsalatushal <padsalatushal@users.noreply.github.com> Co-authored-by: AshlynOrSomethin <31773733+AshlynOrSomethin@users.noreply.github.com> Co-authored-by: KonTy <9524513+KonTy@users.noreply.github.com> Co-authored-by: KonTy <KonTy@github.com> Co-authored-by: Khalyl <119526243+Khalylexe@users.noreply.github.com> Co-authored-by: Rodhri Erebo <109485128+erebus05@users.noreply.github.com> Co-authored-by: Julius Vitkauskas <jvitkauskas@users.noreply.github.com> Co-authored-by: Finn Krestel <83225836+FinnKrestel@users.noreply.github.com> Co-authored-by: BladeWDR <ssbarning@gmail.com> Co-authored-by: Albert <87888006+MustCodeAl@users.noreply.github.com> Co-authored-by: Straight <107145976+DaEpicR@users.noreply.github.com>
333 lines
11 KiB
PowerShell
333 lines
11 KiB
PowerShell
# SPDX-License-Identifier: MIT
|
|
|
|
# Set the maximum number of threads for the RunspacePool to the number of threads on the machine
|
|
$maxthreads = [int]$env:NUMBER_OF_PROCESSORS
|
|
|
|
# Create a new session state for parsing variables into our runspace
|
|
$hashVars = New-object System.Management.Automation.Runspaces.SessionStateVariableEntry -ArgumentList 'sync',$sync,$Null
|
|
$InitialSessionState = [System.Management.Automation.Runspaces.InitialSessionState]::CreateDefault()
|
|
|
|
# Add the variable to the session state
|
|
$InitialSessionState.Variables.Add($hashVars)
|
|
|
|
# Get every private function and add them to the session state
|
|
$functions = Get-ChildItem function:\ | Where-Object {$_.name -like "*winutil*" -or $_.name -like "*WPF*"}
|
|
foreach ($function in $functions){
|
|
$functionDefinition = Get-Content function:\$($function.name)
|
|
$functionEntry = New-Object System.Management.Automation.Runspaces.SessionStateFunctionEntry -ArgumentList $($function.name), $functionDefinition
|
|
|
|
$initialSessionState.Commands.Add($functionEntry)
|
|
}
|
|
|
|
# Create the runspace pool
|
|
$sync.runspace = [runspacefactory]::CreateRunspacePool(
|
|
1, # Minimum thread count
|
|
$maxthreads, # Maximum thread count
|
|
$InitialSessionState, # Initial session state
|
|
$Host # Machine to create runspaces on
|
|
)
|
|
|
|
# Open the RunspacePool instance
|
|
$sync.runspace.Open()
|
|
|
|
# Create classes for different exceptions
|
|
|
|
class WingetFailedInstall : Exception {
|
|
[string] $additionalData
|
|
|
|
WingetFailedInstall($Message) : base($Message) {}
|
|
}
|
|
|
|
class ChocoFailedInstall : Exception {
|
|
[string] $additionalData
|
|
|
|
ChocoFailedInstall($Message) : base($Message) {}
|
|
}
|
|
|
|
class GenericException : Exception {
|
|
[string] $additionalData
|
|
|
|
GenericException($Message) : base($Message) {}
|
|
}
|
|
|
|
|
|
$inputXML = $inputXML -replace 'mc:Ignorable="d"', '' -replace "x:N", 'N' -replace '^<Win.*', '<Window'
|
|
|
|
if ((Get-WinUtilToggleStatus WPFToggleDarkMode) -eq $True){
|
|
$ctttheme = 'Matrix'
|
|
}
|
|
Else{
|
|
$ctttheme = 'Classic'
|
|
}
|
|
|
|
$inputXML = Set-WinUtilUITheme -inputXML $inputXML -themeName $ctttheme
|
|
|
|
[void][System.Reflection.Assembly]::LoadWithPartialName('presentationframework')
|
|
[xml]$XAML = $inputXML
|
|
|
|
# Read the XAML file
|
|
$reader = (New-Object System.Xml.XmlNodeReader $xaml)
|
|
try { $sync["Form"] = [Windows.Markup.XamlReader]::Load( $reader ) }
|
|
catch [System.Management.Automation.MethodInvocationException] {
|
|
Write-Warning "We ran into a problem with the XAML code. Check the syntax for this control..."
|
|
Write-Host $error[0].Exception.Message -ForegroundColor Red
|
|
If ($error[0].Exception.Message -like "*button*") {
|
|
write-warning "Ensure your <button in the `$inputXML does NOT have a Click=ButtonClick property. PS can't handle this`n`n`n`n"
|
|
}
|
|
}
|
|
catch {
|
|
Write-Host "Unable to load Windows.Markup.XamlReader. Double-check syntax and ensure .net is installed."
|
|
}
|
|
|
|
#===========================================================================
|
|
# Store Form Objects In PowerShell
|
|
#===========================================================================
|
|
|
|
$xaml.SelectNodes("//*[@Name]") | ForEach-Object {$sync["$("$($psitem.Name)")"] = $sync["Form"].FindName($psitem.Name)}
|
|
|
|
$sync.keys | ForEach-Object {
|
|
if($sync.$psitem){
|
|
if($($sync["$psitem"].GetType() | Select-Object -ExpandProperty Name) -eq "Button"){
|
|
$sync["$psitem"].Add_Click({
|
|
[System.Object]$Sender = $args[0]
|
|
Invoke-WPFButton $Sender.name
|
|
})
|
|
}
|
|
}
|
|
}
|
|
|
|
$sync.keys | ForEach-Object {
|
|
if($sync.$psitem){
|
|
if($($sync["$psitem"].GetType() | Select-Object -ExpandProperty Name) -eq "ToggleButton"){
|
|
$sync["$psitem"].Add_Click({
|
|
[System.Object]$Sender = $args[0]
|
|
Invoke-WPFButton $Sender.name
|
|
})
|
|
}
|
|
}
|
|
}
|
|
|
|
$sync.keys | ForEach-Object {
|
|
if($sync.$psitem){
|
|
if(
|
|
$($sync["$psitem"].GetType() | Select-Object -ExpandProperty Name) -eq "CheckBox" `
|
|
-and $sync["$psitem"].Name -like "WPFToggle*"
|
|
){
|
|
$sync["$psitem"].IsChecked = Get-WinUtilToggleStatus $sync["$psitem"].Name
|
|
|
|
$sync["$psitem"].Add_Click({
|
|
[System.Object]$Sender = $args[0]
|
|
Invoke-WPFToggle $Sender.name
|
|
})
|
|
}
|
|
}
|
|
}
|
|
|
|
#===========================================================================
|
|
# Setup background config
|
|
#===========================================================================
|
|
|
|
# Load computer information in the background
|
|
Invoke-WPFRunspace -ScriptBlock {
|
|
$sync.ConfigLoaded = $False
|
|
$sync.ComputerInfo = Get-ComputerInfo
|
|
$sync.ConfigLoaded = $True
|
|
} | Out-Null
|
|
|
|
#===========================================================================
|
|
# Setup and Show the Form
|
|
#===========================================================================
|
|
|
|
# Print the logo
|
|
Invoke-WPFFormVariables
|
|
|
|
# Check if Chocolatey is installed
|
|
Install-WinUtilChoco
|
|
|
|
# Set the titlebar
|
|
$sync["Form"].title = $sync["Form"].title + " " + $sync.version
|
|
# Set the commands that will run when the form is closed
|
|
$sync["Form"].Add_Closing({
|
|
$sync.runspace.Dispose()
|
|
$sync.runspace.Close()
|
|
[System.GC]::Collect()
|
|
})
|
|
|
|
# add some shortcuts for people that don't like clicking
|
|
$commonKeyEvents = {
|
|
if ($sync.ProcessRunning -eq $true) {
|
|
return
|
|
}
|
|
|
|
# Escape removes focus from the searchbox that way all shortcuts will start workinf again
|
|
if ($_.Key -eq "Escape") {
|
|
if ($sync.CheckboxFilter.IsFocused)
|
|
{
|
|
$sync.CheckboxFilter.SelectAll()
|
|
$sync.CheckboxFilter.Text = ""
|
|
$sync.CheckboxFilter.Focus()
|
|
return
|
|
}
|
|
}
|
|
|
|
# don't ask, I know what I'm doing, just go...
|
|
if (($_.Key -eq "Q" -and $_.KeyboardDevice.Modifiers -eq "Ctrl"))
|
|
{
|
|
$this.Close()
|
|
}
|
|
|
|
# $ret = [System.Windows.Forms.MessageBox]::Show("Are you sure you want to Exit?", "Winutil", [System.Windows.Forms.MessageBoxButtons]::YesNo,
|
|
# [System.Windows.Forms.MessageBoxIcon]::Question, [System.Windows.Forms.MessageBoxDefaultButton]::Button2)
|
|
|
|
# switch ($ret) {
|
|
# "Yes" {
|
|
# $this.Close()
|
|
# }
|
|
# "No" {
|
|
# return
|
|
# }
|
|
# }
|
|
|
|
|
|
if ($_.KeyboardDevice.Modifiers -eq "Alt") {
|
|
# this is an example how to handle shortcuts per tab
|
|
# Alt-I on the MicroWin tab (4) would press GetIso Button
|
|
# NOTE: All per tab shortcuts have to be handled *before* regular tab keys
|
|
# if ($_.SystemKey -eq "I") {
|
|
# $TabNav = Get-WinUtilVariables | Where-Object {$psitem -like "WPFTabNav"}
|
|
# if ($sync.$TabNav.Items[4].IsSelected -eq $true) {
|
|
# Invoke-WPFButton "WPFGetIso"
|
|
# break
|
|
# }
|
|
# }
|
|
if ($_.SystemKey -eq "I") {
|
|
Invoke-WPFButton "WPFTab1BT"
|
|
}
|
|
if ($_.SystemKey -eq "T") {
|
|
Invoke-WPFButton "WPFTab2BT"
|
|
}
|
|
if ($_.SystemKey -eq "C") {
|
|
Invoke-WPFButton "WPFTab3BT"
|
|
}
|
|
if ($_.SystemKey -eq "U") {
|
|
Invoke-WPFButton "WPFTab4BT"
|
|
}
|
|
if ($_.SystemKey -eq "M") {
|
|
Invoke-WPFButton "WPFTab5BT"
|
|
}
|
|
}
|
|
# shortcut for the filter box
|
|
if ($_.Key -eq "F" -and $_.KeyboardDevice.Modifiers -eq "Ctrl") {
|
|
if ($sync.CheckboxFilter.Text -eq "Ctrl-F to filter") {
|
|
$sync.CheckboxFilter.SelectAll()
|
|
$sync.CheckboxFilter.Text = ""
|
|
}
|
|
$sync.CheckboxFilter.Focus()
|
|
}
|
|
}
|
|
$sync["Form"].Add_PreViewKeyDown($commonKeyEvents)
|
|
|
|
# adding some left mouse window move on drag capability
|
|
$sync["Form"].Add_MouseLeftButtonDown({
|
|
$sync["Form"].DragMove()
|
|
})
|
|
|
|
# setting window icon to make it look more professional
|
|
$sync["Form"].Add_Loaded({
|
|
|
|
$downloadUrl = "https://christitus.com/images/logo-full.png"
|
|
$destinationPath = Join-Path $env:TEMP "cttlogo.png"
|
|
|
|
# Check if the file already exists
|
|
if (-not (Test-Path $destinationPath)) {
|
|
# File does not exist, download it
|
|
$wc = New-Object System.Net.WebClient
|
|
$wc.DownloadFile($downloadUrl, $destinationPath)
|
|
Write-Output "File downloaded to: $destinationPath"
|
|
} else {
|
|
Write-Output "File already exists at: $destinationPath"
|
|
}
|
|
$sync["Form"].Icon = $destinationPath
|
|
|
|
Try {
|
|
[Void][Window]
|
|
} Catch {
|
|
Add-Type @"
|
|
using System;
|
|
using System.Runtime.InteropServices;
|
|
public class Window {
|
|
[DllImport("user32.dll")]
|
|
[return: MarshalAs(UnmanagedType.Bool)]
|
|
public static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect);
|
|
[DllImport("user32.dll")]
|
|
[return: MarshalAs(UnmanagedType.Bool)]
|
|
public static extern bool MoveWindow(IntPtr handle, int x, int y, int width, int height, bool redraw);
|
|
[DllImport("user32.dll")]
|
|
[return: MarshalAs(UnmanagedType.Bool)]
|
|
public static extern bool ShowWindow(IntPtr handle, int state);
|
|
}
|
|
public struct RECT {
|
|
public int Left; // x position of upper-left corner
|
|
public int Top; // y position of upper-left corner
|
|
public int Right; // x position of lower-right corner
|
|
public int Bottom; // y position of lower-right corner
|
|
}
|
|
"@
|
|
}
|
|
|
|
$processId = [System.Diagnostics.Process]::GetCurrentProcess().Id
|
|
$windowHandle = (Get-Process -Id $processId).MainWindowHandle
|
|
$rect = New-Object RECT
|
|
[Void][Window]::GetWindowRect($windowHandle,[ref]$rect)
|
|
|
|
# only snap upper edge don't move left to right, in case people have multimon setup
|
|
$x = $rect.Left
|
|
$y = 0
|
|
$width = $rect.Right - $rect.Left
|
|
$height = $rect.Bottom - $rect.Top
|
|
|
|
# Move the window to that position...
|
|
[Void][Window]::MoveWindow($windowHandle, $x, $y, $width, $height, $True)
|
|
Invoke-WPFTab "WPFTab1BT"
|
|
$sync["Form"].Focus()
|
|
})
|
|
|
|
$sync["CheckboxFilter"].Add_TextChanged({
|
|
#Write-host $sync.CheckboxFilter.Text
|
|
|
|
$filter = Get-WinUtilVariables -Type Checkbox
|
|
$CheckBoxes = $sync.GetEnumerator() | Where-Object {$psitem.Key -in $filter}
|
|
$textToSearch = $sync.CheckboxFilter.Text
|
|
Foreach ($CheckBox in $CheckBoxes) {
|
|
#Write-Host "$($sync.CheckboxFilter.Text)"
|
|
if ($CheckBox -eq $null -or $CheckBox.Value -eq $null -or $CheckBox.Value.Content -eq $null) {
|
|
continue
|
|
}
|
|
if ($CheckBox.Value.Content.ToLower().Contains($textToSearch)) {
|
|
$CheckBox.Value.Visibility = "Visible"
|
|
}
|
|
else {
|
|
$CheckBox.Value.Visibility = "Collapsed"
|
|
}
|
|
}
|
|
})
|
|
|
|
|
|
$downloadUrl = "https://christitus.com/images/logo-full.png"
|
|
$destinationPath = Join-Path $env:TEMP "cttlogo.png"
|
|
|
|
# Check if the file already exists
|
|
if (-not (Test-Path $destinationPath)) {
|
|
# File does not exist, download it
|
|
$wc = New-Object System.Net.WebClient
|
|
$wc.DownloadFile($downloadUrl, $destinationPath)
|
|
Write-Output "File downloaded to: $destinationPath"
|
|
} else {
|
|
Write-Output "File already exists at: $destinationPath"
|
|
}
|
|
|
|
# show current windowsd Product ID
|
|
#Write-Host "Your Windows Product Key: $((Get-WmiObject -query 'select * from SoftwareLicensingService').OA3xOriginalProductKey)"
|
|
|
|
$sync["Form"].ShowDialog() | out-null
|
|
Stop-Transcript |