Files
winutil/functions/public/Invoke-WPFImpex.ps1
T

63 lines
1.7 KiB
PowerShell
Raw Normal View History

+3
2023-03-07 12:28:00 -08:00
function Invoke-WPFImpex {
<#
2023-10-19 17:12:55 -05:00
.SYNOPSIS
Handles importing and exporting of the checkboxes checked for the tweaks section
+3
2023-03-07 12:28:00 -08:00
2023-10-19 17:12:55 -05:00
.PARAMETER type
Indicates whether to 'import' or 'export'
.PARAMETER checkbox
The checkbox to export to a file or apply the imported file to
.EXAMPLE
+3
2023-03-07 12:28:00 -08:00
Invoke-WPFImpex -type "export"
2023-10-19 17:12:55 -05:00
+3
2023-03-07 12:28:00 -08:00
#>
+2
2023-05-09 13:14:27 -05:00
param(
$type,
2024-01-15 11:32:19 -06:00
$Config = $null
+2
2023-05-09 13:14:27 -05:00
)
+3
2023-03-07 12:28:00 -08:00
if ($type -eq "export") {
+3
2023-03-07 12:28:00 -08:00
$FileBrowser = New-Object System.Windows.Forms.SaveFileDialog
}
if ($type -eq "import") {
2023-10-19 17:12:55 -05:00
$FileBrowser = New-Object System.Windows.Forms.OpenFileDialog
+3
2023-03-07 12:28:00 -08:00
}
if (-not $Config) {
2024-01-15 11:32:19 -06:00
$FileBrowser.InitialDirectory = [Environment]::GetFolderPath('Desktop')
$FileBrowser.Filter = "JSON Files (*.json)|*.json"
$FileBrowser.ShowDialog() | Out-Null
if($FileBrowser.FileName -eq "") {
2024-01-15 11:32:19 -06:00
return
} else {
2024-01-15 11:32:19 -06:00
$Config = $FileBrowser.FileName
}
+3
2023-03-07 12:28:00 -08:00
}
if ($type -eq "export") {
2024-01-15 11:32:19 -06:00
$jsonFile = Get-WinUtilCheckBoxes -unCheck $false
+3
2023-03-07 12:28:00 -08:00
$jsonFile | ConvertTo-Json | Out-File $FileBrowser.FileName -Force
2024-08-30 16:29:23 +02:00
$runscript = "iex ""& { `$(irm christitus.com/win) } -Config '$($FileBrowser.FileName)'"""
$runscript | Set-Clipboard
+3
2023-03-07 12:28:00 -08:00
}
if ($type -eq "import") {
2024-01-15 11:32:19 -06:00
$jsonFile = Get-Content $Config | ConvertFrom-Json
$flattenedJson = @()
$jsonFile.PSObject.Properties | ForEach-Object {
$category = $_.Name
foreach ($checkboxName in $_.Value) {
if ($category -ne "Install") {
$flattenedJson += $checkboxName
}
}
}
2024-09-23 12:55:43 -05:00
2024-01-15 11:32:19 -06:00
Invoke-WPFPresets -preset $flattenedJson -imported $true
+3
2023-03-07 12:28:00 -08:00
}
}