mirror of
https://github.com/ChrisTitusTech/winutil.git
synced 2024-11-24 11:55:31 +00:00
[IMPEX] add link support (#2815)
* rework impex - rework impex - add link logic * add error handling
This commit is contained in:
parent
806cbd021a
commit
e165388117
@ -19,44 +19,59 @@ function Invoke-WPFImpex {
|
||||
$Config = $null
|
||||
)
|
||||
|
||||
if ($type -eq "export") {
|
||||
$FileBrowser = New-Object System.Windows.Forms.SaveFileDialog
|
||||
function ConfigDialog {
|
||||
if (!$Config) {
|
||||
switch ($type) {
|
||||
"export" { $FileBrowser = New-Object System.Windows.Forms.SaveFileDialog }
|
||||
"import" { $FileBrowser = New-Object System.Windows.Forms.OpenFileDialog }
|
||||
}
|
||||
if ($type -eq "import") {
|
||||
$FileBrowser = New-Object System.Windows.Forms.OpenFileDialog
|
||||
}
|
||||
|
||||
if (-not $Config) {
|
||||
$FileBrowser.InitialDirectory = [Environment]::GetFolderPath('Desktop')
|
||||
$FileBrowser.Filter = "JSON Files (*.json)|*.json"
|
||||
$FileBrowser.ShowDialog() | Out-Null
|
||||
|
||||
if ($FileBrowser.FileName -eq "") {
|
||||
return
|
||||
return $null
|
||||
} else {
|
||||
$Config = $FileBrowser.FileName
|
||||
return $FileBrowser.FileName
|
||||
}
|
||||
} else {
|
||||
return $Config
|
||||
}
|
||||
}
|
||||
|
||||
if ($type -eq "export") {
|
||||
$jsonFile = Get-WinUtilCheckBoxes -unCheck $false
|
||||
$jsonFile | ConvertTo-Json | Out-File $FileBrowser.FileName -Force
|
||||
$runscript = "iex ""& { `$(irm christitus.com/win) } -Config '$($FileBrowser.FileName)'"""
|
||||
$runscript | Set-Clipboard
|
||||
switch ($type) {
|
||||
"export" {
|
||||
try {
|
||||
$Config = ConfigDialog
|
||||
if ($Config) {
|
||||
$jsonFile = Get-WinUtilCheckBoxes -unCheck $false | ConvertTo-Json
|
||||
$jsonFile | Out-File $Config -Force
|
||||
"iex ""& { `$(irm christitus.com/win) } -Config '$Config'""" | Set-Clipboard
|
||||
}
|
||||
if ($type -eq "import") {
|
||||
} catch {
|
||||
Write-Error "An error occurred while exporting: $_"
|
||||
}
|
||||
}
|
||||
"import" {
|
||||
try {
|
||||
$Config = ConfigDialog
|
||||
if ($Config) {
|
||||
try {
|
||||
if ($Config -match '^https?://') {
|
||||
$jsonFile = (Invoke-WebRequest "$Config").Content | ConvertFrom-Json
|
||||
} else {
|
||||
$jsonFile = Get-Content $Config | ConvertFrom-Json
|
||||
|
||||
$flattenedJson = @()
|
||||
$jsonFile.PSObject.Properties | ForEach-Object {
|
||||
$category = $_.Name
|
||||
foreach ($checkboxName in $_.Value) {
|
||||
if ($category -ne "Install") {
|
||||
$flattenedJson += $checkboxName
|
||||
}
|
||||
} catch {
|
||||
Write-Error "Failed to load the JSON file from the specified path or URL: $_"
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
$flattenedJson = $jsonFile.PSObject.Properties.Where({ $_.Name -ne "Install" }).ForEach({ $_.Value })
|
||||
Invoke-WPFPresets -preset $flattenedJson -imported $true
|
||||
}
|
||||
} catch {
|
||||
Write-Error "An error occurred while importing: $_"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user