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
|
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
|
2023-03-07 12:28:00 -08:00
|
|
|
Invoke-WPFImpex -type "export"
|
2023-10-19 17:12:55 -05:00
|
|
|
|
2023-03-07 12:28:00 -08:00
|
|
|
#>
|
2023-05-09 13:14:27 -05:00
|
|
|
param(
|
|
|
|
|
$type,
|
2024-01-15 11:32:19 -06:00
|
|
|
$Config = $null
|
2023-05-09 13:14:27 -05:00
|
|
|
)
|
2023-03-07 12:28:00 -08:00
|
|
|
|
2024-08-06 23:35:17 +03:00
|
|
|
if ($type -eq "export") {
|
2023-03-07 12:28:00 -08:00
|
|
|
$FileBrowser = New-Object System.Windows.Forms.SaveFileDialog
|
|
|
|
|
}
|
2024-08-06 23:35:17 +03:00
|
|
|
if ($type -eq "import") {
|
2023-10-19 17:12:55 -05:00
|
|
|
$FileBrowser = New-Object System.Windows.Forms.OpenFileDialog
|
2023-03-07 12:28:00 -08:00
|
|
|
}
|
|
|
|
|
|
2024-08-06 23:35:17 +03: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
|
|
|
|
|
|
2024-08-06 23:35:17 +03:00
|
|
|
if($FileBrowser.FileName -eq "") {
|
2024-01-15 11:32:19 -06:00
|
|
|
return
|
2024-08-06 23:35:17 +03:00
|
|
|
} else {
|
2024-01-15 11:32:19 -06:00
|
|
|
$Config = $FileBrowser.FileName
|
|
|
|
|
}
|
2023-03-07 12:28:00 -08:00
|
|
|
}
|
2024-06-29 01:15:39 +03:00
|
|
|
|
2024-08-06 23:35:17 +03:00
|
|
|
if ($type -eq "export") {
|
2024-01-15 11:32:19 -06:00
|
|
|
$jsonFile = Get-WinUtilCheckBoxes -unCheck $false
|
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
|
2023-03-07 12:28:00 -08:00
|
|
|
}
|
2024-08-06 23:35:17 +03: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
|
2023-03-07 12:28:00 -08:00
|
|
|
}
|
|
|
|
|
}
|