Powershell GUI fronted (WPF) to run categorized console scripts

⌈⌋ ⎇ branch:  ClickyColoury


Artifact [5d1d49dac7]

Artifact 5d1d49dac7a3c8ab6da0f94de4608a1d7dc43451:

  • File tools/plugins/configdialog.ps1 — part of check-in [3e3a726c11] at 2018-04-10 15:29:14 on branch trunk — New config editor (reusing Read-GuiExtraParams dialog) (user: mario size: 1910)

# api: multitool
# version: 0.2
# title: Config Editor
# description: Update config.ps1 settings via dialog
# type: inline
# depends: menu
# category: config
# hidden: 1
# key: conf|confedit
# img: tools
# config: -
#
# Edit config settings and write config.ps1.
# Now utilizes the general input params dialog.
# Config storage is destructive (no custom code / comments retained).


Param(
    $fn="$env:APPDATA\multitool\config.ps1",
    $options=@(),
    $overwrite=0,
    $CRLF="`r`n"
)


#-- fetch options from all plugins and main scripts
$options = @($menu | ? { $_.config -and $_.config.count } | % { $_.config })
$options += dir modules/*.ps*1 | % { @((Extract-PluginMeta $_).config) }
$options = $options | ? { $_.name }
#$options | FL | Out-String | Write-Host -f Yellow

#-- rewrite varnames from $cfg (prefix "cfg.")
$current_cfg = @{}
$cfg.keys | % { $current_cfg["cfg.$_"] = $cfg[$_] }

#-- show editor
$meta = Extract-PluginMeta $e.fn
$meta.vars = $options
$newcfg = Read-GuiExtraParams $meta -height 600 -CURRENT_STORE $current_cfg 
#$newcfg | FL

#-- check results
if (!$newcfg) { return ; }



#-- assemble to script
$src = @"
# x-type: config
# x-api: multitool
# fn: $fn
#
# Clicky global app/tool settings
$CRLF
"@
$options | % {
    $v = $newcfg[$_.name]
    switch ($_.type) {
        bool { $v = @('$False', '$True')[[Int32]$v] }
        int { $v = [String][Int32]$v }
        default { $v = "'$v'" }
    }
    if ($src -notmatch "(?mi)^[$]$($_.name)") {
        $src += '$' + $_.name + " = " + $v + "; # $($_.description)$CRLF"
    }
}
Write-Host -f Green $src;

# create parent dir
if ($overwrite -or !(Test-Path $fn)) {
    $dir = Split-Path $fn -parent
    if ($dir -and !(Test-Path $dir)) { md -Force "$dir" }
}
# (over)write
$src | Out-File $fn -Encoding UTF8



#-- apply to current $cfg{}
# ...