Powershell GUI fronted (WPF) to run categorized console scripts

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


Check-in [85c87f27b5]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:New plugin manager to install contrib/ scripts.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:85c87f27b5fc90d85c444257bd26aefc70f04603
User & Date: mario 2018-05-16 18:07:37
Context
2018-05-16
18:08
Swirly arrow indicator for Window title - when scripts are running. check-in: e076d85d3d user: mario tags: trunk
18:07
New plugin manager to install contrib/ scripts. check-in: 85c87f27b5 user: mario tags: trunk
18:07
All-in-one CIM query plugin (lengthy class list), with support for Out-DisplayDispatch check-in: 94b744668d user: mario tags: trunk
Changes

Added tools/plugins/plugin_manager.ps1.







































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# api: multitool
# version: 0.2
# title: Plugin Manager
# description: Install/delete user plugins in %APPDATA%
# type: inline
# depends: menu
# category: config
# hidden: 1
# key: plugins?
# config:
#    { name: plugin_online_repo, type: str, value: "http://fossil.include-once.org/repo.json/clickycoloury/contrib/*.ps1", description: online repository of additional plugins }
# img: tools
#
#
# Scan contrib/*.ps1 and allow copying files to %APPDATA%/multitool
# Not overly pretty. Just lists some file details with [Install] or [Delete] button.
#


Param(
    $repodir = ".\contrib\",
    $userdir = "$env:APPDATA\multitool\"
)

# scan plugins
Write-Host "ā Scanning available plugins.."
$p_filter = { $_.title -and $_.api -match "ps|powershell|clicky|multitool" -and $_.id -ne "config" }
$p_users = dir $userdir\*.ps1 | % { Extract-PluginMeta $_ } | ? $p_filter
$p_avail = dir $repodir\*.ps1 | % { Extract-PluginMeta $_ } | ? $p_filter | ? { @($p_users) -notcontains @($_) }



#-- Decorative entry for plugin
function Out-PluginDesc($e) {
    $e.Values = $e.Values | % { [Security.SecurityElement]::Escape($_) }
    $xaml = @"
<TextBlock xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' Padding="5,2" TextWrapping="Wrap">
<TextBlock.ToolTip>
 <ToolTip Background="#eeeeeeee" Width="400"><TextBlock Width="380" TextWrapping="Wrap">
   <Run Background="Black" Foreground="White">$($e.doc)</Run>
   <LineBreak/>
   <Italic>api</Italic>: <Run Foreground="Red">$($e.api)</Run> <LineBreak/>
   <Italic>state</Italic>: <Bold Foreground="Orange">$($e.state)</Bold> <LineBreak/>
   <Italic>version</Italic>: <Bold Foreground="#ff997711">$($e.version)</Bold> <LineBreak/>
   <Italic>category</Italic>: <Run Foreground="DarkBlue">$($e.category)</Run> <LineBreak/>
   <Italic>icon</Italic>: <Run>$($e.icon)</Run> <LineBreak/>
   <Italic>vars</Italic>: <Run Foreground="Green">$($e.vars | % { $_.name })</Run>
 </TextBlock></ToolTip>
</TextBlock.ToolTip>
 <Bold FontSize="14">$($e.title)</Bold>
 - <Bold Background="#ffffddaa">$($e.version)</Bold>
 - <Italic Foreground="#ff777777">$($e.type)</Italic>
 - <Bold Foreground="#ff222277">$($e.category)</Bold>
 <LineBreak/>
 <Run Foreground="#ff111155" Background="#fff0f3ff">$($e.description)</Run>
</TextBlock>
"@
#    Write-Host $xaml
    [Windows.Markup.XamlReader]::Load((New-Object System.Xml.XmlNodeReader ([xml]$xaml)))
}

#-- calbacks
function Install-Plugin($fn) {
    copy $fn $userdir
    $this.Content = "āœ”"
    #$this.visibility = "Hidden"
}
function Uninstall-Plugin($fn) {
    rm $fn
    $this.Content = 'āœ˜';
}


#-- Plugin window
function Run-PluginManager {
    Param(
       $p_avail, $p_users
    )
    $is_inst = $p_users | % { $_.id }
    

    #-- create action widgets
    $installable = @($p_avail | ? {$_} | % {
        $label = "Install"; if ($is_inst -contains $_.id) { $label = "Reinstall" }
        W Separator
        W StackPanel @{Width=500; Background="White"; Orientation="Horizontal"; Add=@(
            (W Button @{Content="$label"; Width=65; Height=35; Add_Click = [scriptblock]::create("Install-Plugin '{0}'" -f $_.fn)}),
            (Out-PluginDesc $_)
        )}
        W Separator
    })
    $removable = @($p_users |  ? {$_} | % {
        W Separator
        W StackPanel @{Width=500; Background="White"; Orientation="Horizontal"; Add=@(
            (W Button @{Content="Delete"; Width=65; Height=35; Add_Click = [scriptblock]::create("Uninstall-Plugin '{0}'" -f $_.fn)}),
            (Out-PluginDesc $_)
        )}
        W Separator
    })

    #-- window
    $w = (W (New-Object System.Windows.Window) @{
      Title="Plugin installation/removal";
      Width=520; Height=450; Top=350; Left=600; TopMost=$true;
      Background="#eef7f7ff";
      Content=(
        W ScrollViewer @{
           Padding="10,5"; HorizontalAlignment="Left";
          Content=(
            W StackPanel @{
              Add=@(
                 @(W Label @{Content="āœŽ Tooltips contain additional script/plugin details.`r`nā˜› Close window when done."}) +
                 @(W Label @{Content="Install new plugins/tools"; FontSize=20}) +
                 $installable +
                 @(W Label @{Content="Remove from %APPDATA% dir"; FontSize=20}) +
                 $removable
                 @(W Label @{Content="Manually manage"; FontSize=20}) +
                 @(W Button @{Content="open %APPDATA%\multitool config dir"; Add_Click={II $userdir}; Width=250; HorizontalAlignment="Left"})
              )
            }
          )
        }
      )
    })#=window
    [void]$w.ShowDialog()
}

Write-Host "ā Show plugin manager.."
Run-PluginManager $p_avail $p_users

Write-Host "ā˜› Restart for changes to take effect."