mirror of
https://github.com/ChrisTitusTech/winutil.git
synced 2024-12-22 05:51:30 -06:00
Compiler simple improvements and remove app prefix from app list (#2117)
* Re-formate Comments to be a bit Clear-er * Add New Helper Function to be an Interface for writing Progress Bar when Compiling * Remove the Need to add 'WPFInstall' for every App Entry Name in 'applications.json' File * Add 'ValidateRange' to 'Percent' Parameter for 'Update-Progress' Helper Function This will insure that the passed value is neither below zero nor higher than 100 Co-authored-by: Martin Wiethan <47688561+Marterich@users.noreply.github.com> * Remove the 'WPFInstall' prefix for several newly added apps --------- Co-authored-by: Martin Wiethan <47688561+Marterich@users.noreply.github.com>
This commit is contained in:
parent
45818fd80c
commit
0c32d016b4
62
Compile.ps1
62
Compile.ps1
@ -10,6 +10,22 @@ $sync = [Hashtable]::Synchronized(@{})
|
||||
$sync.PSScriptRoot = $PSScriptRoot
|
||||
$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 = @"
|
||||
################################################################################################################
|
||||
### ###
|
||||
@ -18,36 +34,39 @@ $header = @"
|
||||
################################################################################################################
|
||||
"@
|
||||
|
||||
|
||||
# Create the script in memory.
|
||||
Update-Progress "Pre-req: Allocating Memory" 0
|
||||
$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)
|
||||
|
||||
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)"))
|
||||
|
||||
Write-Progress -Activity "Compiling" -Status "Adding: Functions" -PercentComplete 20
|
||||
Update-Progress "Adding: Functions" 20
|
||||
Get-ChildItem .\functions -Recurse -File | ForEach-Object {
|
||||
$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 {
|
||||
|
||||
$json = (Get-Content $psitem.FullName).replace("'","''")
|
||||
|
||||
# Replace every XML Special Character so it'll render correctly in final build
|
||||
# Only do so if json files has content to be displayed (for example the applications, tweaks, features json files)
|
||||
# Some Type Convertion using Casting and Cleaning Up of the convertion result using 'Replace' Method
|
||||
# Some Type Convertion using Casting and Cleaning Up of the convertion result using 'Replace' Method
|
||||
$jsonAsObject = $json | convertfrom-json
|
||||
$firstLevelJsonList = ([System.String]$jsonAsObject).split('=;') | ForEach-Object {
|
||||
$_.Replace('=}','').Replace('@{','').Replace(' ','')
|
||||
}
|
||||
|
||||
for ($i = 0; $i -lt $firstLevelJsonList.Count; $i += 1) {
|
||||
# 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) {
|
||||
$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) {
|
||||
$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
|
||||
@ -57,9 +76,22 @@ 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
|
||||
}
|
||||
}
|
||||
# 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
|
||||
$json = ($jsonAsObject | convertto-json -Depth 3).replace('\r\n',"`r`n")
|
||||
|
||||
# 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")
|
||||
|
||||
$sync.configs.$($psitem.BaseName) = $json | convertfrom-json
|
||||
$script_content.Add($(Write-output "`$sync.configs.$($psitem.BaseName) = '$json' `| convertfrom-json" ))
|
||||
@ -70,13 +102,13 @@ $xaml = (Get-Content .\xaml\inputXML.xaml).replace("'","''")
|
||||
# Dot-source the Get-TabXaml function
|
||||
. .\functions\private\Get-TabXaml.ps1
|
||||
|
||||
Write-Progress -Activity "Compiling" -Status "Building: Xaml " -PercentComplete 75
|
||||
Update-Progress "Building: Xaml " 75
|
||||
$appXamlContent = Get-TabXaml "applications" 5
|
||||
$tweaksXamlContent = Get-TabXaml "tweaks"
|
||||
$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
|
||||
$xaml = $xaml -replace "{{InstallPanel_applications}}", $appXamlContent
|
||||
$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))
|
||||
|
||||
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
|
||||
$tweaksXamlContent | Out-File -FilePath ".\xaml\inputTweaks.xaml" -Encoding ascii
|
||||
$featuresXamlContent | Out-File -FilePath ".\xaml\inputFeatures.xaml" -Encoding ascii
|
||||
}
|
||||
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\inputTweaks.xaml" -ErrorAction SilentlyContinue
|
||||
Remove-Item ".\xaml\inputFeatures.xaml" -ErrorAction SilentlyContinue
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user