@@ -6,48 +6,88 @@ param (
66
77Add-Type - AssemblyName System.Windows.Forms
88Add-Type - AssemblyName System.Drawing
9+ Add-Type - AssemblyName PresentationFramework
10+ Add-Type - AssemblyName WindowsFormsIntegration
911
1012[Windows.Forms.Application ]::EnableVisualStyles()
1113
1214$form = New-Object Windows.Forms.Form
1315$form.Text = $Name
14- $form.Size = New-Object Drawing.Size(400 , 120 )
16+ $form.Size = New-Object Drawing.Size(400 , 100 )
1517$form.StartPosition = " CenterScreen"
1618$form.FormBorderStyle = " FixedDialog"
1719$form.MaximizeBox = $false
1820$form.MinimizeBox = $false
1921$form.ControlBox = $false
2022$form.TopMost = $true
2123
24+ $Icon = Join-Path $PSScriptRoot " ..\..\..\..\jssc.ico"
25+ $Icon = [System.IO.Path ]::GetFullPath($Icon )
26+ Add-Type - Path " $PSScriptRoot \process.cs"
27+ if (Test-Path $Icon ) {
28+ [Taskbar ]::SetCurrentProcessExplicitAppUserModelID(" JSSC.Compress" ) | Out-Null
29+ $form.Icon = New-Object System.Drawing.Icon($Icon )
30+ }
31+
2232$label = New-Object Windows.Forms.Label
2333$label.Text = " $Text ($Progress %)"
24- $label.Location = New-Object Drawing.Point(20 , 15 )
34+ $label.Location = New-Object Drawing.Point(20 , 5 )
2535$label.AutoSize = $true
2636$label.Font = New-Object System.Drawing.Font(' Microsoft JhengHei' , 10 )
2737
28- $progressBar = New-Object Windows.Forms.ProgressBar
29- $progressBar.Location = New-Object Drawing.Point(20 , 50 )
30- $progressBar.Size = New-Object Drawing.Size(340 , 20 )
31- $progressBar.Minimum = 0
32- $progressBar.Maximum = 100
33- $progressBar.Value = $Progress
38+ $wpfProgress = New-Object System.Windows.Controls.ProgressBar
39+ $wpfProgress.Minimum = 0
40+ $wpfProgress.Maximum = 100
41+ $wpfProgress.Value = $Progress
42+ $wpfProgress.Height = 20
43+ $wpfProgress.Width = 340
44+ $wpfProgress.Margin = ' 0'
45+ $wpfProgress.Resources [" ProgressBarCornerRadius" ] = 10
46+ $wpfProgress.IsIndeterminate = $true
47+ $wpfProgress.Foreground = [System.Windows.Media.SolidColorBrush ]::new(
48+ [System.Windows.Media.Color ]::FromArgb(150 , 81 , 90 , 218 )
49+ )
50+ $wpfProgress.Background = [System.Windows.Media.SolidColorBrush ]::new(
51+ [System.Windows.Media.Color ]::FromArgb(150 , 239 , 213 , 255 )
52+ )
3453
3554$form.Controls.Add ($label )
36- $form.Controls.Add ($progressBar )
55+
56+ $elhost = New-Object System.Windows.Forms.Integration.ElementHost
57+ $elhost.Location = New-Object Drawing.Point(20 , 30 )
58+ $elhost.Size = New-Object Drawing.Size(340 , 20 )
59+ $elhost.Child = $wpfProgress
60+ $elhost.BackColor = [System.Drawing.Color ]::Transparent
61+
62+ $form.Controls.Add ($elhost )
3763
3864$timer = New-Object Windows.Forms.Timer
3965$timer.Interval = 100
4066
41- $timer.Add_Tick ({
42- while ([Console ]::In .Peek() -ne -1 ) {
43- $line = [Console ]::In .ReadLine()
44- if ($line -ne $null ) {
45- $value = [int ]$line
46- if ($value -ge 0 -and $value -le 100 ) {
47- $progressBar.Value = $value
48- $label.Text = " $Text ($value %)"
49- }
67+ $idleTicks = 0
68+ function Idle {
69+ $idleTicks ++
70+ $timeout = New-Object Windows.Forms.Timer
71+ $timeout.Interval = 3000
72+ $timeout.Add_Tick ({
73+ if ($idleTicks -ge 0 ) {
74+ $wpfProgress.IsIndeterminate = $true
75+ } else {
76+ $timeout.Stop ()
5077 }
78+ })
79+ $timeout.Start ()
80+ }
81+
82+ $timer.Add_Tick ({
83+ Idle
84+ $line = [Console ]::In .ReadLine()
85+ $newValue = [int ]$line
86+ if ($newValue -ne $wpfProgress.Value ) {
87+ $idleTicks = 0
88+ $wpfProgress.Value = $newValue
89+ $wpfProgress.IsIndeterminate = $false
90+ $label.Text = " $Text ($newValue %)"
5191 }
5292})
5393
0 commit comments