mirror of
https://github.com/ChrisTitusTech/winutil.git
synced 2024-11-14 14:45:52 -06:00
c741e006eb
* try1: apps panel * refractor - removed Get-TabXaml.ps1 - removed compilation part from compile.ps1 - removed existing changes from main.ps1 - added Invoke-WinUtilUIElements.ps1 - refractor existing changes into new function - modified inputXML to call function * removed unused replacementlogics * fix toggle style * move naming from winutil to wpf * hotfixes - reworked function calling - working on correct theming support * hotfix * hotfix fix missing elements fix var naming * some fixes * hotfixes * add image logic * fix ? issue in search * filter out unneeded categories * cleanup * fix border styling * fixes * preprocessing * fix typo * last fixes & add notes * Update functions/public/Invoke-WPFUIElements.ps1 Co-authored-by: Mr.k <mineshtine28546271@gmail.com> * fix margin * fix tabcontent margin * fix some other margin issues * move fixed values outside of iterations * little fix * add Dispatcher.Invoke * add error handling for styles * Update functions/public/Invoke-WPFUIElements.ps1 Co-authored-by: Mr.k <mineshtine28546271@gmail.com> * remove dispatcher * fix search * move run & undo tweaks to be fixed * add error handling * fix throw exception * fixed accidental removal of findname grid call * add padding & margin to make search look good * remove grid to make it look correctly on small window * fix rectangle * Compiler Improvements for PR #2465 (#7) * Remove the Special Character Escaping for Json Files as there's no need for it anymore * Simplify 'application.json' Json Prefix Addition in 'Compile.ps1' Script Thanks to @fam007e for improving this section in his PR #2587 changes Co-authored-by: fam007e <faisalmoshiur@gmail.com> --------- Co-authored-by: fam007e <faisalmoshiur@gmail.com> * fix margin of search clear * fix cursor on clear search button * undo fixed run & undo * refractor themes.json * undo themes.json --------- Co-authored-by: Mr.k <mineshtine28546271@gmail.com> Co-authored-by: fam007e <faisalmoshiur@gmail.com> Co-authored-by: Chris Titus <contact@christitus.com>
128 lines
5.2 KiB
PowerShell
128 lines
5.2 KiB
PowerShell
param (
|
|
[switch]$Debug,
|
|
[switch]$Run,
|
|
[switch]$SkipPreprocessing
|
|
)
|
|
$OFS = "`r`n"
|
|
$scriptname = "winutil.ps1"
|
|
$workingdir = $PSScriptRoot
|
|
|
|
# Variable to sync between runspaces
|
|
$sync = [Hashtable]::Synchronized(@{})
|
|
$sync.PSScriptRoot = $workingdir
|
|
$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 = @"
|
|
################################################################################################################
|
|
### ###
|
|
### WARNING: This file is automatically generated DO NOT modify this file directly as it will be overwritten ###
|
|
### ###
|
|
################################################################################################################
|
|
"@
|
|
|
|
if (-NOT $SkipPreprocessing) {
|
|
Update-Progress "Pre-req: Running Preprocessor..." 0
|
|
|
|
# Dot source the 'Invoke-Preprocessing' Function from 'tools/Invoke-Preprocessing.ps1' Script
|
|
$preprocessingFilePath = ".\tools\Invoke-Preprocessing.ps1"
|
|
. "$(($workingdir -replace ('\\$', '')) + '\' + ($preprocessingFilePath -replace ('\.\\', '')))"
|
|
|
|
$excludedFiles = @('.\.git\', '.\.gitignore', '.\.gitattributes', '.\.github\CODEOWNERS', '.\LICENSE', "$preprocessingFilePath", '*.png', '*.exe')
|
|
$msg = "Pre-req: Code Formatting"
|
|
Invoke-Preprocessing -WorkingDir "$workingdir" -ExcludedFiles $excludedFiles -ProgressStatusMessage $msg
|
|
}
|
|
|
|
# Create the script in memory.
|
|
Update-Progress "Pre-req: Allocating Memory" 0
|
|
$script_content = [System.Collections.Generic.List[string]]::new()
|
|
|
|
Update-Progress "Adding: Header" 5
|
|
$script_content.Add($header)
|
|
|
|
Update-Progress "Adding: Version" 10
|
|
$script_content.Add($(Get-Content "$workingdir\scripts\start.ps1").replace('#{replaceme}',"$(Get-Date -Format yy.MM.dd)"))
|
|
|
|
Update-Progress "Adding: Functions" 20
|
|
Get-ChildItem "$workingdir\functions" -Recurse -File | ForEach-Object {
|
|
$script_content.Add($(Get-Content $psitem.FullName))
|
|
}
|
|
Update-Progress "Adding: Config *.json" 40
|
|
Get-ChildItem "$workingdir\config" | Where-Object {$psitem.extension -eq ".json"} | ForEach-Object {
|
|
$json = (Get-Content $psitem.FullName).replace("'","''")
|
|
$jsonAsObject = $json | convertfrom-json
|
|
|
|
# Add 'WPFInstall' as a prefix to every entry-name in 'applications.json' file
|
|
if ($psitem.Name -eq "applications.json") {
|
|
foreach ($appEntryName in $jsonAsObject.PSObject.Properties.Name) {
|
|
$appEntryContent = $jsonAsObject.$appEntryName
|
|
$jsonAsObject.PSObject.Properties.Remove($appEntryName)
|
|
$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")
|
|
|
|
$sync.configs.$($psitem.BaseName) = $json | convertfrom-json
|
|
$script_content.Add($(Write-output "`$sync.configs.$($psitem.BaseName) = '$json' `| convertfrom-json" ))
|
|
}
|
|
|
|
$xaml = (Get-Content "$workingdir\xaml\inputXML.xaml").replace("'","''")
|
|
|
|
Update-Progress "Adding: Xaml " 90
|
|
|
|
$script_content.Add($(Write-output "`$inputXML = '$xaml'"))
|
|
|
|
$script_content.Add($(Get-Content "$workingdir\scripts\main.ps1"))
|
|
|
|
if ($Debug) {
|
|
Update-Progress "Writing debug files" 95
|
|
$appXamlContent | Out-File -FilePath "$workingdir\xaml\inputApp.xaml" -Encoding ascii
|
|
$tweaksXamlContent | Out-File -FilePath "$workingdir\xaml\inputTweaks.xaml" -Encoding ascii
|
|
$featuresXamlContent | Out-File -FilePath "$workingdir\xaml\inputFeatures.xaml" -Encoding ascii
|
|
} else {
|
|
Update-Progress "Removing temporary files" 99
|
|
Remove-Item "$workingdir\xaml\inputApp.xaml" -ErrorAction SilentlyContinue
|
|
Remove-Item "$workingdir\xaml\inputTweaks.xaml" -ErrorAction SilentlyContinue
|
|
Remove-Item "$workingdir\xaml\inputFeatures.xaml" -ErrorAction SilentlyContinue
|
|
}
|
|
|
|
Set-Content -Path "$workingdir\$scriptname" -Value ($script_content -join "`r`n") -Encoding ascii
|
|
Write-Progress -Activity "Compiling" -Completed
|
|
|
|
Update-Progress -Activity "Validating" -StatusMessage "Checking winutil.ps1 Syntax" -Percent 0
|
|
try {
|
|
$null = Get-Command -Syntax .\winutil.ps1
|
|
}
|
|
catch {
|
|
Write-Warning "Syntax Validation for 'winutil.ps1' has failed"
|
|
Write-Host "$($Error[0])" -ForegroundColor Red
|
|
}
|
|
Write-Progress -Activity "Validating" -Completed
|
|
|
|
if ($run) {
|
|
try {
|
|
Start-Process -FilePath "pwsh" -ArgumentList "$workingdir\$scriptname"
|
|
} catch {
|
|
Start-Process -FilePath "powershell" -ArgumentList "$workingdir\$scriptname"
|
|
}
|
|
|
|
}
|