mirror of
https://github.com/ChrisTitusTech/winutil.git
synced 2025-01-16 09:50:36 -06:00
Merge branch 'main' into remove-trailing-whitespace-characters
This commit is contained in:
commit
0da09c04c0
56
Compile.ps1
56
Compile.ps1
@ -10,6 +10,22 @@ $sync = [Hashtable]::Synchronized(@{})
|
|||||||
$sync.PSScriptRoot = $PSScriptRoot
|
$sync.PSScriptRoot = $PSScriptRoot
|
||||||
$sync.configs = @{}
|
$sync.configs = @{}
|
||||||
|
|
||||||
|
function Update-Progress {
|
||||||
|
param (
|
||||||
|
[Parameter(Mandatory, position=0)]
|
||||||
|
[string]$StatusMessage,
|
||||||
|
|
||||||
|
[Parameter(Mandatory, position=1)]
|
||||||
|
[ValidateRange(0,100)]
|
||||||
|
[int]$Percent,
|
||||||
|
|
||||||
|
[Parameter(position=2)]
|
||||||
|
[string]$Activity = "Compiling"
|
||||||
|
)
|
||||||
|
|
||||||
|
Write-Progress -Activity $Activity -Status $StatusMessage -PercentComplete $Percent
|
||||||
|
}
|
||||||
|
|
||||||
$header = @"
|
$header = @"
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
### ###
|
### ###
|
||||||
@ -18,20 +34,22 @@ $header = @"
|
|||||||
################################################################################################################
|
################################################################################################################
|
||||||
"@
|
"@
|
||||||
|
|
||||||
|
|
||||||
# Create the script in memory.
|
# Create the script in memory.
|
||||||
|
Update-Progress "Pre-req: Allocating Memory" 0
|
||||||
$script_content = [System.Collections.Generic.List[string]]::new()
|
$script_content = [System.Collections.Generic.List[string]]::new()
|
||||||
|
|
||||||
Write-Progress -Activity "Compiling" -Status "Adding: Header" -PercentComplete 5
|
Update-Progress "Adding: Header" 5
|
||||||
$script_content.Add($header)
|
$script_content.Add($header)
|
||||||
|
|
||||||
Write-Progress -Activity "Compiling" -Status "Adding: Version" -PercentComplete 10
|
Update-Progress "Adding: Version" 10
|
||||||
$script_content.Add($(Get-Content .\scripts\start.ps1).replace('#{replaceme}',"$(Get-Date -Format yy.MM.dd)"))
|
$script_content.Add($(Get-Content .\scripts\start.ps1).replace('#{replaceme}',"$(Get-Date -Format yy.MM.dd)"))
|
||||||
|
|
||||||
Write-Progress -Activity "Compiling" -Status "Adding: Functions" -PercentComplete 20
|
Update-Progress "Adding: Functions" 20
|
||||||
Get-ChildItem .\functions -Recurse -File | ForEach-Object {
|
Get-ChildItem .\functions -Recurse -File | ForEach-Object {
|
||||||
$script_content.Add($(Get-Content $psitem.FullName))
|
$script_content.Add($(Get-Content $psitem.FullName))
|
||||||
}
|
}
|
||||||
Write-Progress -Activity "Compiling" -Status "Adding: Config *.json" -PercentComplete 40
|
Update-Progress "Adding: Config *.json" 40
|
||||||
Get-ChildItem .\config | Where-Object {$psitem.extension -eq ".json"} | ForEach-Object {
|
Get-ChildItem .\config | Where-Object {$psitem.extension -eq ".json"} | ForEach-Object {
|
||||||
|
|
||||||
$json = (Get-Content $psitem.FullName).replace("'","''")
|
$json = (Get-Content $psitem.FullName).replace("'","''")
|
||||||
@ -44,10 +62,11 @@ Get-ChildItem .\config | Where-Object {$psitem.extension -eq ".json"} | ForEach-
|
|||||||
$_.Replace('=}','').Replace('@{','').Replace(' ','')
|
$_.Replace('=}','').Replace('@{','').Replace(' ','')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Note:
|
||||||
|
# Avoid using HTML Entity Codes, for example '”' (stands for "Right Double Quotation Mark"),
|
||||||
|
# Use **HTML decimal/hex codes instead**, as using HTML Entity Codes will result in XML parse Error when running the compiled script.
|
||||||
for ($i = 0; $i -lt $firstLevelJsonList.Count; $i += 1) {
|
for ($i = 0; $i -lt $firstLevelJsonList.Count; $i += 1) {
|
||||||
$firstLevelName = $firstLevelJsonList[$i]
|
$firstLevelName = $firstLevelJsonList[$i]
|
||||||
# Note: Avoid using HTML Entity Codes (for example '”' (stands for "Right Double Quotation Mark")), and use HTML decimal/hex codes instead.
|
|
||||||
# as using HTML Entity Codes will result in XML parse Error when running the compiled script.
|
|
||||||
if ($jsonAsObject.$firstLevelName.content -ne $null) {
|
if ($jsonAsObject.$firstLevelName.content -ne $null) {
|
||||||
$jsonAsObject.$firstLevelName.content = $jsonAsObject.$firstLevelName.content.replace('&','&').replace('“','“').replace('”','”').replace("'",''').replace('<','<').replace('>','>').replace('—','—')
|
$jsonAsObject.$firstLevelName.content = $jsonAsObject.$firstLevelName.content.replace('&','&').replace('“','“').replace('”','”').replace("'",''').replace('<','<').replace('>','>').replace('—','—')
|
||||||
$jsonAsObject.$firstLevelName.content = $jsonAsObject.$firstLevelName.content.replace('''',"'") # resolves the Double Apostrophe caused by the first replace function in the main loop
|
$jsonAsObject.$firstLevelName.content = $jsonAsObject.$firstLevelName.content.replace('''',"'") # resolves the Double Apostrophe caused by the first replace function in the main loop
|
||||||
@ -57,8 +76,21 @@ Get-ChildItem .\config | Where-Object {$psitem.extension -eq ".json"} | ForEach-
|
|||||||
$jsonAsObject.$firstLevelName.description = $jsonAsObject.$firstLevelName.description.replace('''',"'") # resolves the Double Apostrophe caused by the first replace function in the main loop
|
$jsonAsObject.$firstLevelName.description = $jsonAsObject.$firstLevelName.description.replace('''',"'") # resolves the Double Apostrophe caused by the first replace function in the main loop
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
# The replace at the end is required, as without it the output of converto-json will be somewhat weird for Multiline String
|
|
||||||
# Most Notably is the scripts in json files, making it harder for users who want to review these scripts that are found in the final compiled script
|
# Add 'WPFInstall' as a prefix to every entry-name in 'applications.json' file
|
||||||
|
if ($psitem.Name -eq "applications.json") {
|
||||||
|
for ($i = 0; $i -lt $firstLevelJsonList.Count; $i += 1) {
|
||||||
|
$appEntryName = $firstLevelJsonList[$i]
|
||||||
|
$appEntryContent = $jsonAsObject.$appEntryName
|
||||||
|
# Remove the entire app entry, so we could add it later with a different name
|
||||||
|
$jsonAsObject.PSObject.Properties.Remove($appEntryName)
|
||||||
|
# Add the app entry, but with a different name (WPFInstall + The App Entry Name)
|
||||||
|
$jsonAsObject | Add-Member -MemberType NoteProperty -Name "WPFInstall$appEntryName" -Value $appEntryContent
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# The replace at the end is required, as without it the output of 'converto-json' will be somewhat weird for Multiline Strings
|
||||||
|
# Most Notably is the scripts in some json files, making it harder for users who want to review these scripts, which're found in the compiled script
|
||||||
$json = ($jsonAsObject | convertto-json -Depth 3).replace('\r\n',"`r`n")
|
$json = ($jsonAsObject | convertto-json -Depth 3).replace('\r\n',"`r`n")
|
||||||
|
|
||||||
$sync.configs.$($psitem.BaseName) = $json | convertfrom-json
|
$sync.configs.$($psitem.BaseName) = $json | convertfrom-json
|
||||||
@ -70,13 +102,13 @@ $xaml = (Get-Content .\xaml\inputXML.xaml).replace("'","''")
|
|||||||
# Dot-source the Get-TabXaml function
|
# Dot-source the Get-TabXaml function
|
||||||
. .\functions\private\Get-TabXaml.ps1
|
. .\functions\private\Get-TabXaml.ps1
|
||||||
|
|
||||||
Write-Progress -Activity "Compiling" -Status "Building: Xaml " -PercentComplete 75
|
Update-Progress "Building: Xaml " 75
|
||||||
$appXamlContent = Get-TabXaml "applications" 5
|
$appXamlContent = Get-TabXaml "applications" 5
|
||||||
$tweaksXamlContent = Get-TabXaml "tweaks"
|
$tweaksXamlContent = Get-TabXaml "tweaks"
|
||||||
$featuresXamlContent = Get-TabXaml "feature"
|
$featuresXamlContent = Get-TabXaml "feature"
|
||||||
|
|
||||||
|
|
||||||
Write-Progress -Activity "Compiling" -Status "Adding: Xaml " -PercentComplete 90
|
Update-Progress "Adding: Xaml " 90
|
||||||
# Replace the placeholder in $inputXML with the content of inputApp.xaml
|
# Replace the placeholder in $inputXML with the content of inputApp.xaml
|
||||||
$xaml = $xaml -replace "{{InstallPanel_applications}}", $appXamlContent
|
$xaml = $xaml -replace "{{InstallPanel_applications}}", $appXamlContent
|
||||||
$xaml = $xaml -replace "{{InstallPanel_tweaks}}", $tweaksXamlContent
|
$xaml = $xaml -replace "{{InstallPanel_tweaks}}", $tweaksXamlContent
|
||||||
@ -87,13 +119,13 @@ $script_content.Add($(Write-output "`$inputXML = '$xaml'"))
|
|||||||
$script_content.Add($(Get-Content .\scripts\main.ps1))
|
$script_content.Add($(Get-Content .\scripts\main.ps1))
|
||||||
|
|
||||||
if ($Debug){
|
if ($Debug){
|
||||||
Write-Progress -Activity "Compiling" -Status "Writing debug files" -PercentComplete 95
|
Update-Progress "Writing debug files" 95
|
||||||
$appXamlContent | Out-File -FilePath ".\xaml\inputApp.xaml" -Encoding ascii
|
$appXamlContent | Out-File -FilePath ".\xaml\inputApp.xaml" -Encoding ascii
|
||||||
$tweaksXamlContent | Out-File -FilePath ".\xaml\inputTweaks.xaml" -Encoding ascii
|
$tweaksXamlContent | Out-File -FilePath ".\xaml\inputTweaks.xaml" -Encoding ascii
|
||||||
$featuresXamlContent | Out-File -FilePath ".\xaml\inputFeatures.xaml" -Encoding ascii
|
$featuresXamlContent | Out-File -FilePath ".\xaml\inputFeatures.xaml" -Encoding ascii
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Write-Progress -Activity "Compiling" -Status "Removing temporary files" -PercentComplete 99
|
Update-Progress "Removing temporary files" 99
|
||||||
Remove-Item ".\xaml\inputApp.xaml" -ErrorAction SilentlyContinue
|
Remove-Item ".\xaml\inputApp.xaml" -ErrorAction SilentlyContinue
|
||||||
Remove-Item ".\xaml\inputTweaks.xaml" -ErrorAction SilentlyContinue
|
Remove-Item ".\xaml\inputTweaks.xaml" -ErrorAction SilentlyContinue
|
||||||
Remove-Item ".\xaml\inputFeatures.xaml" -ErrorAction SilentlyContinue
|
Remove-Item ".\xaml\inputFeatures.xaml" -ErrorAction SilentlyContinue
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -11,9 +11,7 @@ function Get-WinUtilVariables {
|
|||||||
[Parameter()]
|
[Parameter()]
|
||||||
[string[]]$Type
|
[string[]]$Type
|
||||||
)
|
)
|
||||||
|
$keys = ($sync.keys).where{ $_ -like "WPF*" }
|
||||||
$keys = $sync.keys | Where-Object { $_ -like "WPF*" }
|
|
||||||
|
|
||||||
if ($Type) {
|
if ($Type) {
|
||||||
$output = $keys | ForEach-Object {
|
$output = $keys | ForEach-Object {
|
||||||
Try {
|
Try {
|
||||||
|
@ -10,7 +10,7 @@ $InitialSessionState = [System.Management.Automation.Runspaces.InitialSessionSta
|
|||||||
$InitialSessionState.Variables.Add($hashVars)
|
$InitialSessionState.Variables.Add($hashVars)
|
||||||
|
|
||||||
# Get every private function and add them to the session state
|
# Get every private function and add them to the session state
|
||||||
$functions = Get-ChildItem function:\ | Where-Object {$_.name -like "*winutil*" -or $_.name -like "*WPF*"}
|
$functions = (Get-ChildItem function:\).where{$_.name -like "*winutil*" -or $_.name -like "*WPF*"}
|
||||||
foreach ($function in $functions){
|
foreach ($function in $functions){
|
||||||
$functionDefinition = Get-Content function:\$($function.name)
|
$functionDefinition = Get-Content function:\$($function.name)
|
||||||
$functionEntry = New-Object System.Management.Automation.Runspaces.SessionStateFunctionEntry -ArgumentList $($function.name), $functionDefinition
|
$functionEntry = New-Object System.Management.Automation.Runspaces.SessionStateFunctionEntry -ArgumentList $($function.name), $functionDefinition
|
||||||
@ -276,7 +276,7 @@ Add-Type @"
|
|||||||
"@
|
"@
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($proc in (Get-Process | Where-Object { $_.MainWindowTitle -and $_.MainWindowTitle -like "*titus*" })) {
|
foreach ($proc in (Get-Process).where{ $_.MainWindowTitle -and $_.MainWindowTitle -like "*titus*" }) {
|
||||||
# Check if the process's MainWindowHandle is valid
|
# Check if the process's MainWindowHandle is valid
|
||||||
if ($proc.MainWindowHandle -ne [System.IntPtr]::Zero) {
|
if ($proc.MainWindowHandle -ne [System.IntPtr]::Zero) {
|
||||||
Write-Debug "MainWindowHandle: $($proc.Id) $($proc.MainWindowTitle) $($proc.MainWindowHandle)"
|
Write-Debug "MainWindowHandle: $($proc.Id) $($proc.MainWindowTitle) $($proc.MainWindowHandle)"
|
||||||
@ -392,11 +392,11 @@ Add-Type @"
|
|||||||
|
|
||||||
# Load Checkboxes and Labels outside of the Filter fuction only once on startup for performance reasons
|
# Load Checkboxes and Labels outside of the Filter fuction only once on startup for performance reasons
|
||||||
$filter = Get-WinUtilVariables -Type CheckBox
|
$filter = Get-WinUtilVariables -Type CheckBox
|
||||||
$CheckBoxes = $sync.GetEnumerator() | Where-Object { $psitem.Key -in $filter }
|
$CheckBoxes = ($sync.GetEnumerator()).where{ $psitem.Key -in $filter }
|
||||||
|
|
||||||
$filter = Get-WinUtilVariables -Type Label
|
$filter = Get-WinUtilVariables -Type Label
|
||||||
$labels = @{}
|
$labels = @{}
|
||||||
$sync.GetEnumerator() | Where-Object {$PSItem.Key -in $filter} | ForEach-Object {$labels[$_.Key] = $_.Value}
|
($sync.GetEnumerator()).where{$PSItem.Key -in $filter} | ForEach-Object {$labels[$_.Key] = $_.Value}
|
||||||
|
|
||||||
$allCategories = $checkBoxes.Name | ForEach-Object {$sync.configs.applications.$_} | Select-Object -Unique -ExpandProperty category
|
$allCategories = $checkBoxes.Name | ForEach-Object {$sync.configs.applications.$_} | Select-Object -Unique -ExpandProperty category
|
||||||
|
|
||||||
@ -499,6 +499,5 @@ Version : <a href="https://github.com/ChrisTitusTech/winutil/releases/tag/$($sy
|
|||||||
"@
|
"@
|
||||||
Show-CustomDialog -Message $authorInfo -Width 400
|
Show-CustomDialog -Message $authorInfo -Width 400
|
||||||
})
|
})
|
||||||
|
|
||||||
$sync["Form"].ShowDialog() | out-null
|
$sync["Form"].ShowDialog() | out-null
|
||||||
Stop-Transcript
|
Stop-Transcript
|
||||||
|
13
winutil.ps1
13
winutil.ps1
@ -585,9 +585,7 @@ function Get-WinUtilVariables {
|
|||||||
[Parameter()]
|
[Parameter()]
|
||||||
[string[]]$Type
|
[string[]]$Type
|
||||||
)
|
)
|
||||||
|
$keys = ($sync.keys).where{ $_ -like "WPF*" }
|
||||||
$keys = $sync.keys | Where-Object { $_ -like "WPF*" }
|
|
||||||
|
|
||||||
if ($Type) {
|
if ($Type) {
|
||||||
$output = $keys | ForEach-Object {
|
$output = $keys | ForEach-Object {
|
||||||
Try {
|
Try {
|
||||||
@ -14121,7 +14119,7 @@ $InitialSessionState = [System.Management.Automation.Runspaces.InitialSessionSta
|
|||||||
$InitialSessionState.Variables.Add($hashVars)
|
$InitialSessionState.Variables.Add($hashVars)
|
||||||
|
|
||||||
# Get every private function and add them to the session state
|
# Get every private function and add them to the session state
|
||||||
$functions = Get-ChildItem function:\ | Where-Object {$_.name -like "*winutil*" -or $_.name -like "*WPF*"}
|
$functions = (Get-ChildItem function:\).where{$_.name -like "*winutil*" -or $_.name -like "*WPF*"}
|
||||||
foreach ($function in $functions){
|
foreach ($function in $functions){
|
||||||
$functionDefinition = Get-Content function:\$($function.name)
|
$functionDefinition = Get-Content function:\$($function.name)
|
||||||
$functionEntry = New-Object System.Management.Automation.Runspaces.SessionStateFunctionEntry -ArgumentList $($function.name), $functionDefinition
|
$functionEntry = New-Object System.Management.Automation.Runspaces.SessionStateFunctionEntry -ArgumentList $($function.name), $functionDefinition
|
||||||
@ -14387,7 +14385,7 @@ Add-Type @"
|
|||||||
"@
|
"@
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($proc in (Get-Process | Where-Object { $_.MainWindowTitle -and $_.MainWindowTitle -like "*titus*" })) {
|
foreach ($proc in (Get-Process).where{ $_.MainWindowTitle -and $_.MainWindowTitle -like "*titus*" }) {
|
||||||
# Check if the process's MainWindowHandle is valid
|
# Check if the process's MainWindowHandle is valid
|
||||||
if ($proc.MainWindowHandle -ne [System.IntPtr]::Zero) {
|
if ($proc.MainWindowHandle -ne [System.IntPtr]::Zero) {
|
||||||
Write-Debug "MainWindowHandle: $($proc.Id) $($proc.MainWindowTitle) $($proc.MainWindowHandle)"
|
Write-Debug "MainWindowHandle: $($proc.Id) $($proc.MainWindowTitle) $($proc.MainWindowHandle)"
|
||||||
@ -14503,11 +14501,11 @@ Add-Type @"
|
|||||||
|
|
||||||
# Load Checkboxes and Labels outside of the Filter fuction only once on startup for performance reasons
|
# Load Checkboxes and Labels outside of the Filter fuction only once on startup for performance reasons
|
||||||
$filter = Get-WinUtilVariables -Type CheckBox
|
$filter = Get-WinUtilVariables -Type CheckBox
|
||||||
$CheckBoxes = $sync.GetEnumerator() | Where-Object { $psitem.Key -in $filter }
|
$CheckBoxes = ($sync.GetEnumerator()).where{ $psitem.Key -in $filter }
|
||||||
|
|
||||||
$filter = Get-WinUtilVariables -Type Label
|
$filter = Get-WinUtilVariables -Type Label
|
||||||
$labels = @{}
|
$labels = @{}
|
||||||
$sync.GetEnumerator() | Where-Object {$PSItem.Key -in $filter} | ForEach-Object {$labels[$_.Key] = $_.Value}
|
($sync.GetEnumerator()).where{$PSItem.Key -in $filter} | ForEach-Object {$labels[$_.Key] = $_.Value}
|
||||||
|
|
||||||
$allCategories = $checkBoxes.Name | ForEach-Object {$sync.configs.applications.$_} | Select-Object -Unique -ExpandProperty category
|
$allCategories = $checkBoxes.Name | ForEach-Object {$sync.configs.applications.$_} | Select-Object -Unique -ExpandProperty category
|
||||||
|
|
||||||
@ -14610,6 +14608,5 @@ Version : <a href="https://github.com/ChrisTitusTech/winutil/releases/tag/$($sy
|
|||||||
"@
|
"@
|
||||||
Show-CustomDialog -Message $authorInfo -Width 400
|
Show-CustomDialog -Message $authorInfo -Width 400
|
||||||
})
|
})
|
||||||
|
|
||||||
$sync["Form"].ShowDialog() | out-null
|
$sync["Form"].ShowDialog() | out-null
|
||||||
Stop-Transcript
|
Stop-Transcript
|
||||||
|
Loading…
Reference in New Issue
Block a user