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

Code Formatting of Repo - Add Preprocessing to Compilation Process - Introduction of Dev/Build Tools to WinUtil (Although very simple at the moment) #2383

Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
99d88a0
Replace Tabs with Spaces to follow the conventions
og-mrk Jul 25, 2024
3a30f9d
Add Preprocessing in Compiler
og-mrk Jul 25, 2024
03e3227
Compile from Anywhere you want - Running 'Compile.ps1' Works in any d…
og-mrk Jul 26, 2024
1d6d0d6
Code Formatting Changes
og-mrk Jul 26, 2024
b5dffd6
Result of Preprocessing Step in 'Compile.ps1' Script - Remove Trailin…
og-mrk Jul 26, 2024
1ed15a4
Make Preprocessing more advanced
og-mrk Jul 26, 2024
a57c6a8
Move Preprocessing to a separate script file
og-mrk Jul 26, 2024
5f88508
Make Self Modification impossible for 'tools/Do-PreProcessing.ps1' Sc…
og-mrk Jul 26, 2024
1026ada
Merge branch 'main' into compiler-improvement/remove-trailing-whitespace
og-mrk Jul 26, 2024
2732b27
Revert commit b5dffd671ff4f870026e4d384f393c0491692ab7
og-mrk Jul 26, 2024
177bbc7
Patched a Bug of some Excluded Files not actually get excluded in 'Ge…
og-mrk Jul 26, 2024
1803337
Update Replace Regex for Code Formatting in 'Do-PreProcessing' Script…
og-mrk Jul 26, 2024
24d33fc
Rename 'Do-PreProcessing' to 'Invoke-Preprocessing' - Update some Com…
og-mrk Jul 26, 2024
64b115e
Make 'Invoke-Preprocessing' Modular - Update RegEx to handle more cas…
og-mrk Jul 26, 2024
dbf3aa2
Replace Tabs with Spaces to follow the conventions - 'applications.js…
og-mrk Jul 26, 2024
b7b6417
Code Formatting Changes - 'Copy-Files' Private Function
og-mrk Jul 26, 2024
0fb067a
Update Replace Regex for Code Formatting in 'Invoke-Preprocessing' Sc…
og-mrk Jul 27, 2024
d67415f
Replace Tabs with Spaces to follow the conventions - Make 'ExcludedFi…
og-mrk Jul 29, 2024
b94dfc7
Result of 'Invoke-Preprocessing' Script
og-mrk Jul 29, 2024
1adbe2c
Merge to 'main' branch compiler-improvement/remove-trailing-whitespace
og-mrk Jul 31, 2024
6527756
Merge branch 'main' into compiler-improvement/remove-trailing-whitespace
og-mrk Aug 1, 2024
3b7bbc1
Update Replace Regex for Code Formatting in 'Invoke-Preprocessing' Sc…
og-mrk Aug 1, 2024
1b0271f
Merge to 'main' branch compiler-improvement/remove-trailing-whitespace
og-mrk Aug 6, 2024
0b88c23
Merge to 'main' branch compiler-improvement/remove-trailing-whitespace
og-mrk Aug 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 36 additions & 28 deletions Compile.ps1
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
param (
[switch]$Debug,
[switch]$Run
[switch]$Run,
[switch]$SkipPreprocessing
)
$OFS = "`r`n"
$scriptname = "winutil.ps1"
$workingdir = $PSScriptRoot

# Variable to sync between runspaces
$sync = [Hashtable]::Synchronized(@{})
$sync.PSScriptRoot = $PSScriptRoot
$sync.PSScriptRoot = $workingdir
$sync.configs = @{}

function Update-Progress {
param (
[Parameter(Mandatory, position=0)]
[string]$StatusMessage,

[Parameter(Mandatory, position=1)]
[ValidateRange(0,100)]
[Parameter(Mandatory, position=1)]
[ValidateRange(0,100)]
[int]$Percent,

[Parameter(position=2)]
[string]$Activity = "Compiling"
[Parameter(position=2)]
[string]$Activity = "Compiling"
)

Write-Progress -Activity $Activity -Status $StatusMessage -PercentComplete $Percent
Expand All @@ -34,6 +36,13 @@ $header = @"
################################################################################################################
"@

if (-NOT $SkipPreprocessing) {
# Dot source the 'Do-PreProcessing' Function from 'tools/Do-PreProcessing.ps1' Function
. "$workingdir\tools\Do-PreProcessing.ps1"
$msg = "Pre-req: Code Formatting"
Update-Progress "Pre-req: Allocating Memory" 0
Do-PreProcessing $msg
}

# Create the script in memory.
Update-Progress "Pre-req: Allocating Memory" 0
Expand All @@ -43,14 +52,14 @@ Update-Progress "Adding: Header" 5
$script_content.Add($header)

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 "$workingdir\scripts\start.ps1").replace('#{replaceme}',"$(Get-Date -Format yy.MM.dd)"))

Update-Progress "Adding: Functions" 20
Get-ChildItem .\functions -Recurse -File | ForEach-Object {
Get-ChildItem "$workingdir\functions" -Recurse -File | ForEach-Object {
$script_content.Add($(Get-Content $psitem.FullName))
}
Update-Progress "Adding: Config *.json" 40
Get-ChildItem .\config | Where-Object {$psitem.extension -eq ".json"} | ForEach-Object {
Get-ChildItem "$workingdir\config" | Where-Object {$psitem.extension -eq ".json"} | ForEach-Object {

$json = (Get-Content $psitem.FullName).replace("'","''")

Expand All @@ -65,15 +74,15 @@ Get-ChildItem .\config | Where-Object {$psitem.extension -eq ".json"} | ForEach-
# 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]
if ($jsonAsObject.$firstLevelName.content -ne $null) {
if ($jsonAsObject.$firstLevelName.content -ne $null) {
$jsonAsObject.$firstLevelName.content = $jsonAsObject.$firstLevelName.content.replace('&','&#38;').replace('“','&#8220;').replace('”','&#8221;').replace("'",'&#39;').replace('<','&#60;').replace('>','&#62;').replace('—','&#8212;')
$jsonAsObject.$firstLevelName.content = $jsonAsObject.$firstLevelName.content.replace('&#39;&#39;',"&#39;") # resolves the Double Apostrophe caused by the first replace function in the main loop
}
if ($jsonAsObject.$firstLevelName.description -ne $null) {
$jsonAsObject.$firstLevelName.description = $jsonAsObject.$firstLevelName.description.replace('&','&#38;').replace('“','&#8220;').replace('”','&#8221;').replace("'",'&#39;').replace('<','&#60;').replace('>','&#62;').replace('—','&#8212;')
$jsonAsObject.$firstLevelName.description = $jsonAsObject.$firstLevelName.description.replace('&#39;&#39;',"&#39;") # resolves the Double Apostrophe caused by the first replace function in the main loop
}
}
}
}

# Add 'WPFInstall' as a prefix to every entry-name in 'applications.json' file
if ($psitem.Name -eq "applications.json") {
Expand All @@ -95,10 +104,10 @@ Get-ChildItem .\config | Where-Object {$psitem.extension -eq ".json"} | ForEach-
$script_content.Add($(Write-output "`$sync.configs.$($psitem.BaseName) = '$json' `| convertfrom-json" ))
}

$xaml = (Get-Content .\xaml\inputXML.xaml).replace("'","''")
$xaml = (Get-Content "$workingdir\xaml\inputXML.xaml").replace("'","''")

# Dot-source the Get-TabXaml function
. .\functions\private\Get-TabXaml.ps1
. "$workingdir\functions\private\Get-TabXaml.ps1"

Update-Progress "Building: Xaml " 75
$appXamlContent = Get-TabXaml "applications" 5
Expand All @@ -114,30 +123,29 @@ $xaml = $xaml -replace "{{InstallPanel_features}}", $featuresXamlContent

$script_content.Add($(Write-output "`$inputXML = '$xaml'"))

$script_content.Add($(Get-Content .\scripts\main.ps1))
$script_content.Add($(Get-Content "$workingdir\scripts\main.ps1"))

if ($Debug){
if ($Debug) {
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
$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 ".\xaml\inputApp.xaml" -ErrorAction SilentlyContinue
Remove-Item ".\xaml\inputTweaks.xaml" -ErrorAction SilentlyContinue
Remove-Item ".\xaml\inputFeatures.xaml" -ErrorAction SilentlyContinue
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 $scriptname -Value ($script_content -join "`r`n") -Encoding ascii
Set-Content -Path "$workingdir\$scriptname" -Value ($script_content -join "`r`n") -Encoding ascii
Write-Progress -Activity "Compiling" -Completed

if ($run){
if ($run) {
try {
Start-Process -FilePath "pwsh" -ArgumentList ".\$scriptname"
}
catch {
Start-Process -FilePath "powershell" -ArgumentList ".\$scriptname"
Start-Process -FilePath "pwsh" -ArgumentList "$workingdir\$scriptname"
} catch {
Start-Process -FilePath "powershell" -ArgumentList "$workingdir\$scriptname"
}

}
4 changes: 2 additions & 2 deletions functions/private/ConvertTo-Icon.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ function ConvertTo-Icon {

#>
param(
[Parameter(Mandatory=$true, position=0)]
[Parameter(Mandatory, position=0)]
[string]$bitmapPath,
[Parameter(Mandatory=$true, position=1)]
[Parameter(Mandatory, position=1)]
[string]$iconPath,
[Parameter(position=2)]
[bool]$overrideIconFile = $true
Expand Down
6 changes: 4 additions & 2 deletions functions/private/Get-Oscdimg.ps1
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
function Get-Oscdimg {
<#

.DESCRIPTION
This function will download oscdimg file from github Release folders and put it into env:temp folder

.EXAMPLE
Get-Oscdimg
#>
param( [Parameter(Mandatory=$true)]

param(
[Parameter(Mandatory, position=0)]
[string]$oscdimgPath
)

$oscdimgPath = "$env:TEMP\oscdimg.exe"
$downloadUrl = "https://github.com/ChrisTitusTech/winutil/raw/main/releases/oscdimg.exe"
Invoke-RestMethod -Uri $downloadUrl -OutFile $oscdimgPath
Expand Down
34 changes: 19 additions & 15 deletions functions/private/Get-TabXaml.ps1
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
function Get-TabXaml {
<#
.SYNOPSIS
Generates XAML for a tab in the WinUtil GUI
This function is used to generate the XAML for the applications tab in the WinUtil GUI
It takes the tabname and the number of columns to display the applications in as input and returns the XAML for the tab as output
.PARAMETER tabname
The name of the tab to generate XAML for
Note: the 'tabname' parameter must equal one of the json files found in $sync.configs variable
Otherwise, it'll throw an exception
.PARAMETER columncount
The number of columns to display the applications in, default is 0
.OUTPUTS
The XAML for the tab
.EXAMPLE
Get-TabXaml "applications" 3
.SYNOPSIS
Generates XAML for a tab in the WinUtil GUI
This function is used to generate the XAML for the applications tab in the WinUtil GUI
It takes the tabname and the number of columns to display the applications in as input and returns the XAML for the tab as output

.PARAMETER tabname
The name of the tab to generate XAML for
Note: the 'tabname' parameter must equal one of the json files found in $sync.configs variable
Otherwise, it'll throw an exception

.PARAMETER columncount
The number of columns to display the applications in, default is 0

.OUTPUTS
The XAML for the tab

.EXAMPLE
Get-TabXaml "applications" 3
#>


Expand Down Expand Up @@ -115,7 +119,7 @@ function Get-TabXaml {
}

# Dot-source the Get-WPFObjectName function
. .\functions\private\Get-WPFObjectName
. "$($sync.PSScriptRoot)\functions\private\Get-WPFObjectName.ps1"

$categorycontent = $($category -replace '^.__', '')
$categoryname = Get-WPFObjectName -type "Label" -name $categorycontent
Expand Down
46 changes: 25 additions & 21 deletions functions/private/Get-WPFObjectName.ps1
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
function Get-WPFObjectName {
<#
.SYNOPSIS
This is a helper function that generates an objectname with the prefix WPF that can be used as a Powershell Variable after compilation.
To achieve this, all characters that are not a-z, A-Z or 0-9 are simply removed from the name.
.PARAMETER type
The type of object for which the name should be generated. (e.g. Label, Button, CheckBox...)
.PARAMETER name
The name or description to be used for the object. (invalid characters are removed)
.OUTPUTS
A string that can be used as a object/variable name in powershell.
For example: WPFLabelMicrosoftTools
<#
.SYNOPSIS
This is a helper function that generates an objectname with the prefix WPF that can be used as a Powershell Variable after compilation.
To achieve this, all characters that are not a-z, A-Z or 0-9 are simply removed from the name.

.EXAMPLE
Get-WPFObjectName -type Label -name "Microsoft Tools"
#>
.PARAMETER type
The type of object for which the name should be generated. (e.g. Label, Button, CheckBox...)

.PARAMETER name
The name or description to be used for the object. (invalid characters are removed)

param( [Parameter(Mandatory=$true)]
$type,
$name
)
.OUTPUTS
A string that can be used as a object/variable name in powershell.
For example: WPFLabelMicrosoftTools

.EXAMPLE
Get-WPFObjectName -type Label -name "Microsoft Tools"
#>

$Output = $("WPF"+$type+$name) -replace '[^a-zA-Z0-9]', ''
param(
[Parameter(Mandatory, position=0)]
[string]$type,

return $Output
[Parameter(position=1)]
[string]$name
)

}
$Output = $("WPF"+$type+$name) -replace '[^a-zA-Z0-9]', ''
return $Output
}
Loading