-
Notifications
You must be signed in to change notification settings - Fork 0
Collapse file tree
Files
Search this repository(forward slash) forward slash/
/
Copy pathLeanSERP-Studio-GUI.ps1
More file actions
More file actions
Latest commit
2220 lines (1953 loc) · 46.6 KB
/
Copy pathLeanSERP-Studio-GUI.ps1
File metadata and controls
2220 lines (1953 loc) · 46.6 KB
You must be signed in to make or propose changes
More edit options
Edit and raw actions
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
[CmdletBinding()]
param()
Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
$scriptPath = $MyInvocation.MyCommand.Path
$scriptDirectory = Split-Path -Parent $scriptPath
$runnerPath = Join-Path $scriptDirectory "Invoke-LeanSERP-Build.ps1"
$builderPath = Join-Path $scriptDirectory "LeanSERP-Studio.ps1"
$defaultOutputDirectory = Join-Path $env:USERPROFILE "Downloads\LeanSERP-Output"
foreach ($requiredPath in @(
$runnerPath,
$builderPath
)) {
if (
-not (
Test-Path `
-LiteralPath $requiredPath `
-PathType Leaf
)
) {
[void][System.Windows.Forms.MessageBox]::Show(
"A required file was not found:`r`n$requiredPath",
"LeanSERP Studio",
[System.Windows.Forms.MessageBoxButtons]::OK,
[System.Windows.Forms.MessageBoxIcon]::Error
)
exit 1
}
}
$selectedFiles =
[System.Collections.Generic.List[string]]::new()
$script:activeProcess = $null
$script:activeLogPath = ""
$script:displayedLogLineCount = 0
$script:buildStartedAt = $null
$script:buildOutputDirectory = ""
$script:stopRequested = $false
$script:activeInputListPath = ""
function New-Button {
param(
[Parameter(Mandatory = $true)]
[string]$Text,
[Parameter(Mandatory = $false)]
[int]$Width = 145
)
$button = [System.Windows.Forms.Button]::new()
$button.Text = $Text
$button.Width = $Width
$button.Height = 34
$button.Margin =
[System.Windows.Forms.Padding]::new(
0,
0,
9,
9
)
return $button
}
function Set-ClipboardText {
param(
[AllowEmptyString()]
[string]$Text,
[Parameter(Mandatory = $true)]
[string]$Description
)
if ([string]::IsNullOrWhiteSpace($Text)) {
[void][System.Windows.Forms.MessageBox]::Show(
"There is no $Description to copy.",
"LeanSERP Studio",
[System.Windows.Forms.MessageBoxButtons]::OK,
[System.Windows.Forms.MessageBoxIcon]::Information
)
return
}
try {
[System.Windows.Forms.Clipboard]::SetText(
$Text
)
}
catch {
[void][System.Windows.Forms.MessageBox]::Show(
"Could not copy the ${Description}:`r`n$($_.Exception.Message)",
"LeanSERP Studio",
[System.Windows.Forms.MessageBoxButtons]::OK,
[System.Windows.Forms.MessageBoxIcon]::Error
)
}
}
function Quote-ProcessArgument {
param(
[AllowEmptyString()]
[string]$Value
)
if ($null -eq $Value) {
return '""'
}
if (
$Value.Length -gt 0 -and
$Value -notmatch '[\s"]'
) {
return $Value
}
$escaped =
$Value -replace '(\\*)"', '$1$1\"'
$escaped =
$escaped -replace '(\\+)$', '$1$1'
return '"' + $escaped + '"'
}
function Test-BuildRunning {
if ($null -eq $script:activeProcess) {
return $false
}
try {
return -not $script:activeProcess.HasExited
}
catch {
return $false
}
}
function Get-OtherStudioProcesses {
if (
$choice -ne
[System.Windows.Forms.DialogResult]::Yes
) {
$event.Cancel = $true
return
}
$script:stopRequested =
$true
try {
Stop-ProcessTree `
-ProcessId $script:activeProcess.Id
}
catch {
}
})
$form.Add_FormClosed({
$timer.Stop()
$timer.Dispose()
if (
$null -ne $script:activeProcess
) {
try {
if (
-not $script:activeProcess.HasExited
) {
Stop-ProcessTree `
-ProcessId $script:activeProcess.Id
}
}
catch {
}
try {
$script:activeProcess.Dispose()
}
catch {
}
$script:activeProcess =
$null
}
if (
-not [string]::IsNullOrWhiteSpace(
$script:activeInputListPath
) -and
(
Test-Path `
-LiteralPath $script:activeInputListPath `
-PathType Leaf
)
) {
Remove-Item `
-LiteralPath $script:activeInputListPath `
-Force `
-ErrorAction SilentlyContinue
}
$script:activeInputListPath = ""
})
Update-FileList
Set-InterfaceRunning `
-Running $false
$null = $form.ShowDialog()
$form.Dispose()