-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuilder.ps1
More file actions
547 lines (470 loc) · 24.2 KB
/
Copy pathbuilder.ps1
File metadata and controls
547 lines (470 loc) · 24.2 KB
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
# ==========================================
# GUI DE BUILD PS2EXE (COMPLETO - PS 5.1)
# ==========================================
Add-Type -AssemblyName PresentationFramework
Add-Type -AssemblyName System.Drawing
# ── CARREGAR LICENÇAS DO JSON ────────────────────────────────────────────────
$jsonPath = ".\licenses-complete.json"
if (Test-Path $jsonPath) {
$licensesData = (Get-Content $jsonPath -Raw | ConvertFrom-Json).licenses
} else {
Write-Warning "Arquivo $jsonPath não encontrado. Nenhuma licença carregada."
$licensesData = @()
}
# ── XAML DA INTERFACE (Usando @' para PS 5.1 evitar erro de chaves) ────────
[xml]$xaml = @'
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="1nst4ll3r Builder" Height="650" Width="720"
WindowStartupLocation="CenterScreen" ResizeMode="CanMinimize"
Background="#2D2D30" Foreground="#FFFFFF" FontFamily="Segoe UI"
UseLayoutRounding="True" SnapsToDevicePixels="True">
<Window.Resources>
<Style TargetType="Button">
<Setter Property="Background" Value="#007ACC"/>
<Setter Property="Foreground" Value="White"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="Padding" Value="8,3"/>
<Setter Property="Cursor" Value="Hand"/>
<Setter Property="FontSize" Value="12"/>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="#005A9E"/>
</Trigger>
</Style.Triggers>
</Style>
<Style TargetType="TextBox">
<Setter Property="Background" Value="#3E3E42"/>
<Setter Property="Foreground" Value="#FFFFFF"/>
<Setter Property="BorderBrush" Value="#555"/>
<Setter Property="Padding" Value="3,1"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="MinHeight" Value="21"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
</Style>
<Style TargetType="Label">
<Setter Property="Padding" Value="0"/>
<Setter Property="MinHeight" Value="21"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
</Style>
</Window.Resources>
<Grid Margin="14">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<StackPanel Grid.Row="0">
<TextBlock Text="Configuração do Build" FontSize="16" FontWeight="Bold" Margin="0,0,0,10" Foreground="#4EC9B0"/>
<Grid Margin="0,3">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="110"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Label Content="Pasta Fonte:" Grid.Column="0" VerticalAlignment="Center"/>
<TextBox Name="txtSource" Grid.Column="1" Text=".\bin" VerticalAlignment="Center"/>
<Button Name="btnBrowseSource" Content="..." Grid.Column="2" Margin="4,0,0,0" Width="36"/>
</Grid>
<Grid Margin="0,3">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="110"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Label Content="EXE Principal:" Grid.Column="0" VerticalAlignment="Center"/>
<TextBox Name="txtMainExe" Grid.Column="1" Text="" VerticalAlignment="Center"/>
<Button Name="btnBrowseMainExe" Content="..." Grid.Column="2" Margin="4,0,0,0" Width="36"/>
</Grid>
<Grid Margin="0,3">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="110"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Label Content="Script PS1:" Grid.Column="0" VerticalAlignment="Center"/>
<TextBox Name="txtScript" Grid.Column="1" Text=".\1nst4ll3r.ps1" VerticalAlignment="Center"/>
<Button Name="btnBrowseScript" Content="..." Grid.Column="2" Margin="4,0,0,0" Width="36"/>
</Grid>
<Grid Margin="0,3">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="110"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Label Content="Ícone (.ico):" Grid.Column="0" VerticalAlignment="Center"/>
<TextBox Name="txtIcon" Grid.Column="1" Text="" VerticalAlignment="Center"/>
<Button Name="btnBrowseIcon" Content="..." Grid.Column="2" Margin="4,0,0,0" Width="36"/>
</Grid>
<Grid Margin="0,3">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="110"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Label Content="Nome do EXE:" Grid.Column="0" VerticalAlignment="Center"/>
<TextBox Name="txtOutput" Grid.Column="1" Text="Setup.exe" VerticalAlignment="Center"/>
</Grid>
<Grid Margin="0,3">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="110"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Label Content="Nome do App:" Grid.Column="0" VerticalAlignment="Center"/>
<TextBox Name="txtAppName" Grid.Column="1" Text="MeuApp" VerticalAlignment="Center"/>
</Grid>
<!-- Checkbox de Admin -->
<CheckBox Name="chkRequireAdmin" Content="Modo Administrador (Pede UAC e instala em Program Files)"
Margin="0,10,0,0" Foreground="#FFFFFF" Background="#2D2D30"
BorderBrush="#4EC9B0" VerticalContentAlignment="Center"/>
<Separator Margin="0,10,0,10" Background="#555"/>
<TextBlock Text="Configuração de Licença (EULA)" FontSize="14" FontWeight="Bold" Foreground="#CE9178"/>
<!-- Overlay do ComboBox -->
<Grid Margin="0,7,0,3">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Label Content="Modelo de Licença:" Grid.Column="0" VerticalAlignment="Center"/>
<Canvas Grid.Column="1" Height="21" VerticalAlignment="Center">
<ComboBox Name="cboLicense" Width="300" Height="21" Foreground="#3E3E42" BorderBrush="#555"/>
<TextBox Name="txtLicenseDisplay" Width="275" Height="21" Text="Nenhuma (Sem EULA)" IsReadOnly="True"
Background="#3E3E42" Foreground="#FFFFFF" BorderThickness="0"
VerticalContentAlignment="Center" Padding="3,0"/>
</Canvas>
<Button Name="btnLoadFile" Content="Carregar Arquivo" Grid.Column="2" Margin="4,0,0,0"/>
</Grid>
<Label Content="Conteúdo da Licença (Pré-visualização):" FontSize="10" Foreground="#AAA"/>
<TextBox Name="txtLicenseContent" Height="120" TextWrapping="Wrap" AcceptsReturn="True"
VerticalScrollBarVisibility="Auto" Margin="0,0,0,7" FontSize="10" Background="#252526"/>
<Button Name="btnBuild" Content="GERAR INSTALADOR (BUILD)" Height="34" FontSize="14" FontWeight="Bold"/>
</StackPanel>
<GroupBox Header="Log de Saída" Grid.Row="1" Margin="0,0,0,0" Foreground="#AAA" BorderBrush="#555">
<TextBox Name="txtLog" IsReadOnly="True" Background="#1E1E1E" Foreground="#CCC"
Height="80" TextWrapping="Wrap" VerticalScrollBarVisibility="Auto"/>
</GroupBox>
</Grid>
</Window>
'@
# ── INICIALIZAÇÃO ─────────────────────────────────────────────────────────────
$reader = (New-Object System.Xml.XmlNodeReader $xaml)
try {
$window = [Windows.Markup.XamlReader]::Load($reader)
} catch {
Write-Error "Erro ao carregar XAML: $_"
return
}
# Mapeamento de elementos
$txtSource = $window.FindName("txtSource")
$txtMainExe = $window.FindName("txtMainExe")
$txtScript = $window.FindName("txtScript")
$txtIcon = $window.FindName("txtIcon")
$txtOutput = $window.FindName("txtOutput")
$txtLicense = $window.FindName("txtLicenseContent")
$txtLog = $window.FindName("txtLog")
$cboLicense = $window.FindName("cboLicense")
$txtLicenseDisplay = $window.FindName("txtLicenseDisplay")
$txtAppName = $window.FindName("txtAppName")
$tempLicensePath = $null
# ── FUNÇÕES ───────────────────────────────────────────────────────────────────
function Write-Log {
param([string]$msg, [string]$color = "#CCC")
$txtLog.AppendText("[$(Get-Date -Format 'HH:mm:ss')] $msg`r`n")
$txtLog.ScrollToEnd()
}
function Select-Folder {
param([string]$InitialPath)
$resolvedPath = Resolve-Path $InitialPath -ErrorAction SilentlyContinue
if ($resolvedPath) {
$InitialPath = $resolvedPath.Path
} else {
$InitialPath = (Get-Location).Path
}
$shell = New-Object -ComObject Shell.Application
$browseFlags = 0x1 + 0x10 + 0x40
$folder = $shell.BrowseForFolder(0, "Escolha a pasta fonte", $browseFlags, 0)
if ($folder) {
return $folder.Self.Path
}
return $null
}
function Get-RelativePath {
param([string]$BasePath, [string]$Path)
$baseFullPath = [System.IO.Path]::GetFullPath($BasePath).TrimEnd('\') + '\'
$targetFullPath = [System.IO.Path]::GetFullPath($Path)
$baseUri = New-Object System.Uri($baseFullPath)
$targetUri = New-Object System.Uri($targetFullPath)
return [System.Uri]::UnescapeDataString($baseUri.MakeRelativeUri($targetUri).ToString()).Replace('/', '\')
}
function Get-MainExeCandidate {
param([string]$SourcePath)
$resolvedSource = Resolve-Path $SourcePath -ErrorAction SilentlyContinue
if (-not $resolvedSource) { return $null }
$exeFiles = @(Get-ChildItem -Path $resolvedSource.Path -Recurse -File -Filter *.exe)
if ($exeFiles.Count -eq 1) {
return (Get-RelativePath $resolvedSource.Path $exeFiles[0].FullName)
}
return $null
}
function Resolve-MainExePath {
param([string]$SourcePath, [string]$MainExe)
if ([string]::IsNullOrWhiteSpace($MainExe)) { return $null }
if ([System.IO.Path]::IsPathRooted($MainExe)) { return $MainExe }
return (Join-Path $SourcePath $MainExe)
}
function Export-AssociatedIcon {
param([string]$ExePath, [string]$IconPath)
$icon = [System.Drawing.Icon]::ExtractAssociatedIcon($ExePath)
if (-not $icon) { return $false }
$stream = [System.IO.File]::Create($IconPath)
try {
$icon.Save($stream)
} finally {
$stream.Close()
$icon.Dispose()
}
return $true
}
# ── PREENCHER COMBO ───────────────────────────────────────────────────────────
[void]$cboLicense.Items.Add("Nenhuma (Sem EULA)")
foreach ($lic in $licensesData) {
[void]$cboLicense.Items.Add($lic.name)
}
$cboLicense.SelectedIndex = 0
# ── EVENTOS ───────────────────────────────────────────────────────────────────
$window.FindName("btnBrowseSource").Add_Click({
$selectedPath = Select-Folder $txtSource.Text
if ($selectedPath) {
$txtSource.Text = $selectedPath
$mainExeCandidate = Get-MainExeCandidate $txtSource.Text
if ($mainExeCandidate) {
$txtMainExe.Text = $mainExeCandidate
}
}
})
$window.FindName("btnBrowseMainExe").Add_Click({
$ofd = New-Object Microsoft.Win32.OpenFileDialog
$ofd.Filter = "Executáveis (*.exe)|*.exe"
$sourcePath = Resolve-Path $txtSource.Text -ErrorAction SilentlyContinue
if ($sourcePath) {
$ofd.InitialDirectory = $sourcePath.Path
} else {
$ofd.InitialDirectory = (Get-Location).Path
}
if ($ofd.ShowDialog() -eq $true) {
if ($sourcePath -and $ofd.FileName.StartsWith($sourcePath.Path, [System.StringComparison]::OrdinalIgnoreCase)) {
$txtMainExe.Text = Get-RelativePath $sourcePath.Path $ofd.FileName
} else {
$txtMainExe.Text = $ofd.FileName
}
}
})
$window.FindName("btnBrowseScript").Add_Click({
$ofd = New-Object Microsoft.Win32.OpenFileDialog
$ofd.Filter = "PowerShell Scripts (*.ps1)|*.ps1"
$ofd.InitialDirectory = (Get-Location).Path
if ($ofd.ShowDialog() -eq $true) { $txtScript.Text = $ofd.FileName }
})
$window.FindName("btnBrowseIcon").Add_Click({
$ofd = New-Object Microsoft.Win32.OpenFileDialog
$ofd.Filter = "Icon Files (*.ico)|*.ico"
$ofd.InitialDirectory = (Get-Location).Path
if ($ofd.ShowDialog() -eq $true) { $txtIcon.Text = $ofd.FileName }
})
# Sincronizar Overlay do ComboBox
$cboLicense.Add_SelectionChanged({
if ($cboLicense.SelectedItem -ne $null) {
$selected = $cboLicense.SelectedItem
$txtLicenseDisplay.Text = $selected
if ($selected -eq "Nenhuma (Sem EULA)") {
$txtLicense.Text = ""
} else {
# Busca o texto da licença no JSON carregado baseado no nome selecionado
$selectedLic = $licensesData | Where-Object { $_.name -eq $selected }
if ($selectedLic) {
$txtLicense.Text = $selectedLic.licenseText
}
}
if ($script:tempLicensePath) { $script:tempLicensePath = $null }
}
})
$window.FindName("btnLoadFile").Add_Click({
$ofd = New-Object Microsoft.Win32.OpenFileDialog
$ofd.Filter = "Text Files (*.txt;*.rtf)|*.txt;*.rtf|All Files (*.*)|*.*"
$ofd.InitialDirectory = (Get-Location).Path
if ($ofd.ShowDialog() -eq $true) {
$txtLicense.Text = [IO.File]::ReadAllText($ofd.FileName)
$txtLicenseDisplay.Text = (Split-Path $ofd.FileName -Leaf)
$tempLicensePath = $ofd.FileName
$cboLicense.SelectedIndex = -1
Write-Log "Licença carregada do arquivo: $($ofd.FileName)"
}
})
# ── BOTÃO BUILD ───────────────────────────────────────────────────────────────
$window.FindName("btnBuild").Add_Click({
if (-not (Test-Path $txtSource.Text)) { Write-Log "Erro: Pasta fonte não encontrada." "#FF5555"; return }
if (-not (Test-Path $txtScript.Text)) { Write-Log "Erro: Script de instalação não encontrado." "#FF5555"; return }
if ([string]::IsNullOrWhiteSpace($txtMainExe.Text)) {
$mainExeCandidate = Get-MainExeCandidate $txtSource.Text
if ($mainExeCandidate) {
$txtMainExe.Text = $mainExeCandidate
Write-Log "EXE principal detectado automaticamente: $mainExeCandidate" "#4EC9B0"
} else {
Write-Log "Erro: escolha o EXE principal. Há zero ou múltiplos executáveis na pasta fonte." "#FF5555"
return
}
}
$mainExePath = Resolve-MainExePath $txtSource.Text $txtMainExe.Text
if (-not (Test-Path $mainExePath)) {
Write-Log "Erro: EXE principal não encontrado: $($txtMainExe.Text)" "#FF5555"
return
}
$resolvedSource = Resolve-Path $txtSource.Text
$sourceFullPath = [System.IO.Path]::GetFullPath($resolvedSource.Path).TrimEnd('\') + '\'
$mainExeFullPath = [System.IO.Path]::GetFullPath($mainExePath)
if (-not $mainExeFullPath.StartsWith($sourceFullPath, [System.StringComparison]::OrdinalIgnoreCase)) {
Write-Log "Erro: o EXE principal precisa estar dentro da pasta fonte." "#FF5555"
return
}
$txtMainExe.Text = Get-RelativePath $resolvedSource.Path $mainExeFullPath
$destFolder = $txtAppName.Text
$tempIconPath = $null
$tempPayloadPath = $null
$tempUninstallScriptPath = $null
$btn = $window.FindName("btnBuild")
$btn.IsEnabled = $false
$btn.Content = "PROCESSANDO..."
try {
Write-Log "Iniciando Build..." "#4EC9B0"
# 1. Payload temporario com o app + Uninstall.exe
$src = $txtSource.Text.TrimEnd('\')
$tempPayloadPath = Join-Path (Get-Location) "temp_payload_build"
if (Test-Path $tempPayloadPath) { Remove-Item $tempPayloadPath -Recurse -Force }
New-Item -ItemType Directory -Path $tempPayloadPath -Force | Out-Null
Write-Log "Preparando payload temporario..."
Copy-Item -Path "$src\*" -Destination $tempPayloadPath -Recurse -Force
$uninstallTemplatePath = Join-Path (Get-Location) "uninstall-template.ps1"
if (-not (Test-Path $uninstallTemplatePath)) {
Write-Log "Erro: template do desinstalador nao encontrado: $uninstallTemplatePath" "#FF5555"
return
}
$tempUninstallScriptPath = Join-Path (Get-Location) "temp_uninstall_script.ps1"
$uninstallContent = Get-Content $uninstallTemplatePath -Raw
$uninstallContent = $uninstallContent.Replace('{{APP_NAME}}', $txtAppName.Text)
$uninstallContent | Set-Content $tempUninstallScriptPath -Encoding UTF8
$uninstallExePath = Join-Path $tempPayloadPath "Uninstall.exe"
$uninstallParams = @{
inputFile = $tempUninstallScriptPath
outputFile = $uninstallExePath
noConsole = $true
}
if (-not [string]::IsNullOrWhiteSpace($txtIcon.Text) -and (Test-Path $txtIcon.Text)) {
$uninstallParams['iconFile'] = $txtIcon.Text
}
Write-Log "Compilando Uninstall.exe..."
& ps2exe @uninstallParams 2>&1 | ForEach-Object { Write-Log "$_" }
if (-not (Test-Path $uninstallExePath)) {
Write-Log "Erro: Uninstall.exe nao foi gerado." "#FF5555"
return
}
Write-Log "Uninstall.exe adicionado ao payload." "#4EC9B0"
# 2. Zip
$zipName = "payload.zip"
$zipPath = Join-Path (Get-Location) $zipName
if (Test-Path $zipPath) { Remove-Item $zipPath -Force }
Write-Log "Compactando arquivos de $tempPayloadPath..."
Compress-Archive -Path "$tempPayloadPath\*" -DestinationPath $zipPath -Force
if (-not (Test-Path $zipPath)) {
Write-Log "Erro ao criar ZIP." "#FF5555"
$btn.IsEnabled = $true; $btn.Content = "GERAR INSTALADOR (BUILD)"
return
}
Write-Log "ZIP criado." "#4EC9B0"
# 3. Licença
$licenseFile = $null
if ($cboLicense.SelectedIndex -ne -1 -and $cboLicense.SelectedItem -ne "Nenhuma (Sem EULA)") {
# Salva na pasta atual junto com o zip, apenas para o build
$licenseFile = Join-Path (Get-Location) "temp_eula.rtf"
$txtLicense.Text | Out-File -FilePath $licenseFile -Encoding UTF8
Write-Log "Licença preset salva temporariamente."
} elseif ($tempLicensePath) {
$licenseFile = $tempLicensePath
Write-Log "Licença de arquivo externo definida."
}
# 4. Hash Table (O Segredo)
$embedHash = @{
"%TEMP%\payload.zip" = $zipPath
}
if ($licenseFile) {
$embedHash["%TEMP%\eula.rtf"] = $licenseFile
Write-Log "EULA adicionada ao pacote de embarque."
}
# Injeta o Nome do App no script antes de compilar
Write-Log "Injetando Nome do App no script..."
$tempScriptPath = Join-Path (Get-Location) "temp_build_script.ps1"
$scriptContent = Get-Content $txtScript.Text -Raw
$scriptContent = $scriptContent.Replace('{{DEST_FOLDER}}', $txtAppName.Text)
$scriptContent = $scriptContent.Replace('{{MAIN_EXE}}', $txtMainExe.Text)
$scriptContent = $scriptContent.Replace('{{SHORTCUT_NAME}}', $txtAppName.Text)
$scriptContent | Set-Content $tempScriptPath -Encoding UTF8
# 5. Params (PS 5.1 Safe)
$buildParams = @{}
$buildParams['inputFile'] = $tempScriptPath
$buildParams['outputFile'] = (Join-Path (Get-Location) $txtOutput.Text)
$buildParams['embedFiles'] = $embedHash
$buildParams['noConsole'] = $true
if (-not [string]::IsNullOrWhiteSpace($txtIcon.Text) -and (Test-Path $txtIcon.Text)) {
$buildParams['iconFile'] = $txtIcon.Text
Write-Log "Ícone do setup definido pelo arquivo .ico."
} else {
$tempIconPath = Join-Path (Get-Location) "temp_main_icon.ico"
if (Export-AssociatedIcon $mainExePath $tempIconPath) {
$buildParams['iconFile'] = $tempIconPath
Write-Log "Ícone do setup extraído do EXE principal."
} else {
Write-Log "Aviso: não foi possível extrair ícone do EXE principal." "#CE9178"
}
}
# Checkbox Admin
$chkRequireAdmin = $window.FindName("chkRequireAdmin")
if ($chkRequireAdmin.IsChecked -eq $true) {
$buildParams['requireAdmin'] = $true
Write-Log "Modo ADMIN habilitado. O instalador pedirá UAC." "#CE9178"
} else {
Write-Log "Modo USUÁRIO habilitado. Instalará silenciosamente em AppData." "#4EC9B0"
}
# 6. Executar
Write-Log "Rodando PS2EXE..."
& ps2exe @buildParams 2>&1 | ForEach-Object { Write-Log "$_" }
$finalExe = $buildParams['outputFile']
if (Test-Path $finalExe) {
$size = [math]::Round((Get-Item $finalExe).Length / 1KB, 2)
Write-Log "BUILD CONCLUÍDO COM SUCESSO!" "#4EC9B0"
Write-Log "Arquivo gerado: $finalExe ($size KB)"
} else {
Write-Log "Falha: EXE não gerado. Verifique o log acima." "#FF5555"
}
# 7. Limpeza
if (Test-Path $zipPath) { Remove-Item $zipPath -Force }
# Apaga o rtf temporário, mas NÃO apaga o arquivo original do usuário
if ($licenseFile -and $licenseFile -ne $tempLicensePath -and (Test-Path $licenseFile)) {
Remove-Item $licenseFile -Force
}
if (Test-Path $tempScriptPath) { Remove-Item $tempScriptPath -Force }
if ($tempUninstallScriptPath -and (Test-Path $tempUninstallScriptPath)) { Remove-Item $tempUninstallScriptPath -Force }
if ($tempPayloadPath -and (Test-Path $tempPayloadPath)) { Remove-Item $tempPayloadPath -Recurse -Force }
if ($tempIconPath -and (Test-Path $tempIconPath)) { Remove-Item $tempIconPath -Force }
} catch {
Write-Log "ERRO CRÍTICO: $_" "#FF5555"
} finally {
if ($zipPath -and (Test-Path $zipPath)) { Remove-Item $zipPath -Force -ErrorAction SilentlyContinue }
if ($licenseFile -and $licenseFile -ne $tempLicensePath -and (Test-Path $licenseFile)) { Remove-Item $licenseFile -Force -ErrorAction SilentlyContinue }
if ($tempScriptPath -and (Test-Path $tempScriptPath)) { Remove-Item $tempScriptPath -Force -ErrorAction SilentlyContinue }
if ($tempUninstallScriptPath -and (Test-Path $tempUninstallScriptPath)) { Remove-Item $tempUninstallScriptPath -Force -ErrorAction SilentlyContinue }
if ($tempPayloadPath -and (Test-Path $tempPayloadPath)) { Remove-Item $tempPayloadPath -Recurse -Force -ErrorAction SilentlyContinue }
if ($tempIconPath -and (Test-Path $tempIconPath)) { Remove-Item $tempIconPath -Force -ErrorAction SilentlyContinue }
$btn.IsEnabled = $true
$btn.Content = "GERAR INSTALADOR (BUILD)"
}
})
# ── MOSTRAR JANELA ───────────────────────────────────────────────────────────
$window.ShowDialog() | Out-Null