# 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{}
# ...