Powershell GUI fronted (WPF) to run categorized console scripts

โŒˆโŒ‹ โŽ‡ branch:  ClickyColoury


Artifact [c7bc8a4648]

Artifact c7bc8a4648fdbc00ba304435c86dd34bbc1db5ec:

  • File modules/starter.ps1 — part of check-in [168d091f87] at 2018-05-19 22:49:43 on branch trunk — New menu/plugin which adds dummy entries for unclassified scripts. (user: mario size: 3863)

# api: ps
# type: main
# title: ClickyColoury + TextyTypey - GUI+CLI tool frontend
# description: Convenience invocation of various Powershell and CMD scripts
# url: http://fossil.include-once.org/clickycoloury/
# version: 0.9.2
# depends: menu, wpf, clipboard
# category: misc
# config:
#   { name: cfg.gridview, type: select, value: Format-Table, select: Format-Table|Out-GridView, description: default table display mode }
#   { name: cfg.cli, type: bool, value: 0, description: Start console (CLI) version per default? }
#   { name: cfg.cached, type: bool, value: 0, description: Use CLIXML script cache on startup }
# author: mario
# license: MITL
# priority: core
# status: stable
#
# Note that this is the WindowsPresentationForm version, but also renders a
# classic -CLI menu otherwise. Utilizes:
#
#   ยท guimenu.psm1 = graphical toolkit features
#   ยท menu.psm1 = mostly CLI features
#   ยท clipboard.psm1 = for the HTML output
#
# Whereas scripts (and plugins) reside in tools*/*.ps1
#
# Starting up with `-cli` parameter should yield the text version.
#
# Requires powershell.exe -STA -File ... startup (for GUI mode).
#


#-- params
[CmdletBinding()]
Param(
    [switch]$CLI = $false,
    $Filter = "", $NotFilter = "admin"   # to cut down $menu list ("ClickyInfo")
)

#-- config
$global:cfg = @{
    domain = "WORKWORKWORKWORKWORK"  # (Get-ADDomain).Netbiosname
    threading = 1
    autoclear = 300
    exchange = @{
        ConfigurationName = "Microsoft.Exchange"
        ConnectionUri = "http://YOUREXCHANGESRV/psremote/"
    }
    main = @{} 
    theme = "dark"
    curr_script_fn = $MyInvocation.MyCommand.Path
    multitool_base = (Split-Path -Parent (Split-Path -Parent $MyInvocation.MyCommand.Path))
    user_config_fn  = "$env:APPDATA\multitool\config.ps1"
    user_plugins_d  = "$env:APPDATA\multitool"
    tools_cache_fn = "./data/tools.cache.clixml"
    tool_dirs = @("./tools/*/*.ps1")  # add custom dirs here!
}
$global:plugins = @{
    "init" = @()
    "before" = @()
    "after" = @()
    "menu" = @()
}


#-- add user config
cd ($cfg.multitool_base)
if (Test-Path ($cfg.user_config_fn)) {
    . ($cfg.user_config_fn)
}
if (Test-Path ($cfg.user_plugins_d)) {
    $cfg.tool_dirs += @($cfg.user_plugins_d+"/*.ps1")
}
if ($Debug) { $cfg|FL }


#-- modules
$ENV:PSModulePath += ";$($cfg.multitool_base)\modules"
$global:GUI = [hashtable]::Synchronized(@{Host=$Host})
Import-Module -DisableNameChecking "$($cfg.multitool_base)\modules\guimenu.psm1"
Write-Splash "Loading Modules.." 30
Import-Module -DisableNameChecking "$($cfg.multitool_base)\modules\menu.psm1"
Import-Module -DisableNameChecking "$($cfg.multitool_base)\modules\clipboard.psm1"
if (!(Get-Module -Name ActiveDirectory)) { Import-Module ActiveDirectory }


#-- scan tools/plugins
Write-Splash "Scanning Plugins.." 120
$cfg.main = (Extract-PluginMeta $cfg.curr_script_fn)

#-- collect entries
$menu = @()
$menu += @(Get-Item ($cfg.tool_dirs) | % { Extract-PluginMeta $_ } | ? { Is-PluginCompatible $_ })

#-- run `type:init` plugins here
Write-Splash "Init Plugins.." 55
$menu | ? { $_.type -eq "init" -and $_.fn } | % { 
    try {
        . $_.fn
    }
    catch {
        Write-Host -f Red "Failure init plugin: $($_.fn)"
        $PSItem | FL | Out-String | Write-Host -f Gray
    }
}


#-- CLI mode
if ($CLI) {
    Write-Splash "Done" 1000
    cls ; Init-Screen
    $menu = $menu + @{key="m|menu"; category="extras"; title="print menu"; func='Print-Menu $menu'}
    Print-Menu $menu
    Process-Menu -Menu $menu -Prompt "Typey"
}
#-- WPF multi-tool
else {
    Write-Splash "Starting GUI version.." 50
    $cfg.main.title = "Clicky"
    $shell = Start-Win (Sort-Menu $menu)
}

#-- cleanup
if ($Debug) {
    Remove-Module wpf
    $Error
}