Skip to content

Commit d9951cc

Browse files
committed
Merge branch 'main' into feature/oss-tags
2 parents 7a8c64d + 70a94ab commit d9951cc

18 files changed

+280
-255
lines changed

config/feature.json

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -181,15 +181,6 @@
181181
"ButtonWidth": "300",
182182
"link": "https://winutil.christitus.com/dev/features/fixes/winget"
183183
},
184-
"WPFRunAdobeCCCleanerTool": {
185-
"Content": "Remove Adobe Creative Cloud",
186-
"category": "Fixes",
187-
"panel": "1",
188-
"Order": "a045_",
189-
"Type": "Button",
190-
"ButtonWidth": "300",
191-
"link": "https://winutil.christitus.com/dev/features/fixes/runadobecccleanertool"
192-
},
193184
"WPFPanelControl": {
194185
"Content": "Control Panel",
195186
"category": "Legacy Windows Panels",

config/tweaks.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1987,9 +1987,9 @@
19871987
"InvokeScript": [
19881988
"
19891989
$hostsUrl = \"https://github.com/Ruddernation-Designs/Adobe-URL-Block-List/raw/refs/heads/master/hosts\"
1990-
$hosts = \"$env:SystemRoot\\System32\\drivers\\etc\\hosts\"
1990+
$hosts = \"$Env:SystemRoot\\System32\\drivers\\etc\\hosts\"
19911991

1992-
Copy-Item $hosts \"$env:SystemRoot\\System32\\drivers\\etc\\hosts\\$hosts.bak\"
1992+
Move-Item $hosts \"$hosts.bak\"
19931993
Invoke-WebRequest $hostsUrl -OutFile $hosts
19941994
ipconfig /flushdns
19951995

@@ -1998,10 +1998,10 @@
19981998
],
19991999
"UndoScript": [
20002000
"
2001-
$hosts = \"$env:SystemRoot\\System32\\drivers\\etc\\hosts\"
2002-
$backup = \"$env:SystemRoot\\System32\\drivers\\etc\\hosts\\$hosts.bak\"
2001+
$hosts = \"$Env:SystemRoot\\System32\\drivers\\etc\\hosts\"
20032002

20042003
Remove-Item $hosts
2004+
Move-Item \"$hosts.bak\" $hosts
20052005
ipconfig /flushdns
20062006

20072007
Write-Host \"Removed Adobe url block list from host file\"

functions/private/Get-WinUtilCheckBoxes.ps1

Lines changed: 0 additions & 92 deletions
This file was deleted.

functions/private/Initialize-InstallAppEntry.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@ function Initialize-InstallAppEntry {
4747
$checkBox.Tag = $appKey
4848
$checkbox.Style = $sync.Form.Resources.AppEntryCheckboxStyle
4949
$checkbox.Add_Checked({
50-
Invoke-WPFSelectedAppsUpdate -type "Add" -checkbox $this
50+
Invoke-WPFSelectedCheckboxesUpdate -type "Add" -checkboxName $this.Parent.Tag
5151
$borderElement = $this.Parent
5252
$borderElement.SetResourceReference([Windows.Controls.Control]::BackgroundProperty, "AppInstallSelectedColor")
5353
})
5454

5555
$checkbox.Add_Unchecked({
56-
Invoke-WPFSelectedAppsUpdate -type "Remove" -checkbox $this
56+
Invoke-WPFSelectedCheckboxesUpdate -type "Remove" -checkboxName $this.Parent.Tag
5757
$borderElement = $this.Parent
5858
$borderElement.SetResourceReference([Windows.Controls.Control]::BackgroundProperty, "AppInstallUnselectedColor")
5959
})

functions/private/Invoke-WinUtilCurrentSystem.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Function Invoke-WinUtilCurrentSystem {
66
Checks to see what tweaks have already been applied and what programs are installed, and checks the according boxes
77
88
.EXAMPLE
9-
Get-WinUtilCheckBoxes "WPFInstall"
9+
InvokeWinUtilCurrentSystem -Checkbox "winget"
1010
1111
#>
1212

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
function Reset-WPFCheckBoxes {
2+
<#
3+
4+
.SYNOPSIS
5+
Set winutil checkboxs to match $sync.selected values.
6+
Should only need to be run if $sync.selected updated outside of UI (i.e. presets or import)
7+
8+
.PARAMETER doToggles
9+
Whether or not to set UI toggles. WARNING: they will trigger if altered
10+
11+
.PARAMETER checkboxfilterpattern
12+
The Pattern to use when filtering through CheckBoxes, defaults to "**"
13+
Used to make reset blazingly fast.
14+
#>
15+
16+
param (
17+
[Parameter(position=0)]
18+
[bool]$doToggles = $false,
19+
20+
[Parameter(position=1)]
21+
[string]$checkboxfilterpattern = "**"
22+
)
23+
24+
$CheckBoxesToCheck = $sync.selectedApps + $sync.selectedTweaks + $sync.selectedFeatures
25+
$CheckBoxes = ($sync.GetEnumerator()).where{ $_.Value -is [System.Windows.Controls.CheckBox] -and $_.Name -notlike "WPFToggle*" -and $_.Name -like "$checkboxfilterpattern"}
26+
Write-Debug "Getting checkboxes to set, number of checkboxes: $($CheckBoxes.Count)"
27+
28+
if ($CheckBoxesToCheck -ne "") {
29+
$debugMsg = "CheckBoxes to Check are: "
30+
$CheckBoxesToCheck | ForEach-Object { $debugMsg += "$_, " }
31+
$debugMsg = $debugMsg -replace (',\s*$', '')
32+
Write-Debug "$debugMsg"
33+
}
34+
35+
foreach ($CheckBox in $CheckBoxes) {
36+
$checkboxName = $CheckBox.Key
37+
if (-not $CheckBoxesToCheck) {
38+
$sync.$checkBoxName.IsChecked = $false
39+
continue
40+
}
41+
42+
# Check if the checkbox name exists in the flattened JSON hashtable
43+
if ($CheckBoxesToCheck -contains $checkboxName) {
44+
# If it exists, set IsChecked to true
45+
$sync.$checkboxName.IsChecked = $true
46+
Write-Debug "$checkboxName is checked"
47+
} else {
48+
# If it doesn't exist, set IsChecked to false
49+
$sync.$checkboxName.IsChecked = $false
50+
Write-Debug "$checkboxName is not checked"
51+
}
52+
}
53+
54+
# Update Installs tab UI values
55+
$count = $sync.SelectedApps.Count
56+
$sync.WPFselectedAppsButton.Content = "Selected Apps: $count"
57+
# On every change, remove all entries inside the Popup Menu. This is done, so we can keep the alphabetical order even if elements are selected in a random way
58+
$sync.selectedAppsstackPanel.Children.Clear()
59+
$sync.selectedApps | Foreach-Object { Add-SelectedAppsMenuItem -name $($sync.configs.applicationsHashtable.$_.Content) -key $_ }
60+
61+
if($doToggles) {
62+
# Restore toggle switch states
63+
$importedToggles = $sync.selectedToggles
64+
$allToggles = $sync.GetEnumerator() | Where-Object { $_.Key -like "WPFToggle*" -and $_.Value -is [System.Windows.Controls.CheckBox] }
65+
foreach ($toggle in $allToggles) {
66+
if ($importedToggles -contains $toggle.Key) {
67+
$sync[$toggle.Key].IsChecked = $true
68+
Write-Debug "Restoring toggle: $($toggle.Key) = checked"
69+
} else {
70+
$sync[$toggle.Key].IsChecked = $false
71+
Write-Debug "Restoring toggle: $($toggle.Key) = unchecked"
72+
}
73+
}
74+
}
75+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
function Update-WinUtilSelections {
2+
<#
3+
4+
.SYNOPSIS
5+
Updates the $sync.selected variables with a given preset.
6+
7+
.PARAMETER flatJson
8+
The flattened json list of $sync values to select.
9+
#>
10+
11+
param (
12+
$flatJson
13+
)
14+
15+
Write-Debug "JSON to import: $($flatJson)"
16+
17+
foreach ($cbkey in $flatJson) {
18+
$group = if ($cbkey.StartsWith("WPFInstall")) { "Install" }
19+
elseif ($cbkey.StartsWith("WPFTweaks")) { "Tweaks" }
20+
elseif ($cbkey.StartsWith("WPFToggle")) { "Toggle" }
21+
elseif ($cbkey.StartsWith("WPFFeature")) { "Feature" }
22+
else { "na" }
23+
24+
switch ($group) {
25+
"Install" {
26+
if (!$sync.selectedApps.Contains($cbkey)) {
27+
$sync.selectedApps.Add($cbkey)
28+
# The List type needs to be specified again, because otherwise Sort-Object will convert the list to a string if there is only a single entry
29+
[System.Collections.Generic.List[pscustomobject]]$sync.selectedApps = $sync.SelectedApps | Sort-Object
30+
}
31+
}
32+
"Tweaks" {
33+
if (!$sync.selectedTweaks.Contains($cbkey)) {
34+
$sync.selectedTweaks.Add($cbkey)
35+
}
36+
}
37+
"Toggle" {
38+
if (!$sync.selectedToggles.Contains($cbkey)) {
39+
$sync.selectedToggles.Add($cbkey)
40+
}
41+
}
42+
"Feature" {
43+
if (!$sync.selectedFeatures.Contains($cbkey)) {
44+
$sync.selectedFeatures.Add($cbkey)
45+
}
46+
}
47+
default {
48+
Write-Host "Unknown group for checkbox: $($cbkey)"
49+
}
50+
}
51+
}
52+
53+
Write-Debug "-------------------------------------"
54+
Write-Debug "Selected Apps: $($sync.selectedApps)"
55+
Write-Debug "Selected Tweaks: $($sync.selectedTweaks)"
56+
Write-Debug "Selected Toggles: $($sync.selectedToggles)"
57+
Write-Debug "Selected Features: $($sync.selectedFeatures)"
58+
Write-Debug "--------------------------------------"
59+
}

functions/public/Invoke-AutoConfigDialog.ps1

Lines changed: 0 additions & 20 deletions
This file was deleted.

functions/public/Invoke-WPFFeatureInstall.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function Invoke-WPFFeatureInstall {
1212
return
1313
}
1414

15-
$Features = (Get-WinUtilCheckBoxes)["WPFFeature"]
15+
$Features = $sync.selectedFeatures
1616

1717
Invoke-WPFRunspace -ArgumentList $Features -DebugPreference $DebugPreference -ScriptBlock {
1818
param($Features, $DebugPreference)

functions/public/Invoke-WPFImpex.ps1

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ function Invoke-WPFImpex {
4444
try {
4545
$Config = ConfigDialog
4646
if ($Config) {
47-
$jsonFile = Get-WinUtilCheckBoxes -unCheck $false | ConvertTo-Json
47+
$allConfs = $sync.selectedApps + $sync.selectedTweaks + $sync.selectedToggles + $sync.selectedFeatures
48+
$jsonFile = $allConfs | ConvertTo-Json
4849
$jsonFile | Out-File $Config -Force
4950
"iex ""& { `$(irm https://christitus.com/win) } -Config '$Config'""" | Set-Clipboard
5051
}
@@ -66,21 +67,12 @@ function Invoke-WPFImpex {
6667
Write-Error "Failed to load the JSON file from the specified path or URL: $_"
6768
return
6869
}
69-
$flattenedJson = $jsonFile.PSObject.Properties.Where({ $_.Name -ne "Install" -and $_.Name -ne "WPFToggle" }).ForEach({ $_.Value })
70-
Invoke-WPFPresets -preset $flattenedJson -imported $true
71-
72-
# Restore toggle switch states
73-
$importedToggles = if ($jsonFile.WPFToggle) { $jsonFile.WPFToggle } else { @() }
74-
$allToggles = $sync.GetEnumerator() | Where-Object { $_.Key -like "WPFToggle*" -and $_.Value -is [System.Windows.Controls.CheckBox] }
75-
foreach ($toggle in $allToggles) {
76-
if ($importedToggles -contains $toggle.Key) {
77-
$sync[$toggle.Key].IsChecked = $true
78-
Write-Debug "Restoring toggle: $($toggle.Key) = checked"
79-
} else {
80-
$sync[$toggle.Key].IsChecked = $false
81-
Write-Debug "Restoring toggle: $($toggle.Key) = unchecked"
82-
}
83-
}
70+
# TODO how to handle old style? detected json type then flatten it in a func?
71+
# $flattenedJson = $jsonFile.PSObject.Properties.Where({ $_.Name -ne "Install" }).ForEach({ $_.Value })
72+
$flattenedJson = $jsonFile
73+
Update-WinUtilSelections -flatJson $flattenedJson
74+
# TODO test with toggles
75+
Reset-WPFCheckBoxes -doToggles $true
8476
}
8577
} catch {
8678
Write-Error "An error occurred while importing: $_"

0 commit comments

Comments
 (0)