|
| 1 | +# Verificar se está executando como administrador |
| 2 | +if (-not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) { |
| 3 | + Write-Host "Running as a non-administrator. Requesting elevation..." |
| 4 | + |
| 5 | + # Solicitar elevação para administrador |
| 6 | + Start-Process powershell -ArgumentList "-NoProfile -ExecutionPolicy Bypass -File `"$($MyInvocation.MyCommand.Path)`"" -Verb RunAs |
| 7 | + exit |
| 8 | +} |
| 9 | + |
| 10 | +Add-Type -AssemblyName System.Windows.Forms |
| 11 | +Add-Type -AssemblyName System.Drawing |
| 12 | + |
| 13 | +function Show-FolderBrowserDialog { |
| 14 | + $folderBrowser = New-Object System.Windows.Forms.FolderBrowserDialog |
| 15 | + $folderBrowser.Description = "Select the installation folder for Aurora Windows Optimizer" |
| 16 | + |
| 17 | + if ($folderBrowser.ShowDialog() -eq 'OK') { |
| 18 | + $textBox.Text = $folderBrowser.SelectedPath |
| 19 | + } |
| 20 | +} |
| 21 | + |
| 22 | +function Install-AuroraWindowsOptimizer { |
| 23 | + if (-not $textBox.Text) { |
| 24 | + [System.Windows.Forms.MessageBox]::Show("Please select a folder before installing.", "Error", [System.Windows.Forms.MessageBoxButtons]::OK, [System.Windows.Forms.MessageBoxIcon]::Error) |
| 25 | + return |
| 26 | + } |
| 27 | + |
| 28 | + # Set variables |
| 29 | + $repo = "azurejoga/Aurora-Windows-Optimizer" |
| 30 | + $file = "Aurora-Windows-Optimizer.zip" |
| 31 | + $targetDir = $textBox.Text |
| 32 | + $shortcutName = "Aurora Windows Optimizer" |
| 33 | + |
| 34 | + # Determine the latest release |
| 35 | + $releases = "https://api.github.com/repos/$repo/releases" |
| 36 | + $tag = (Invoke-WebRequest -Uri $releases -UseBasicParsing | ConvertFrom-Json)[0].tag_name |
| 37 | + |
| 38 | + # Download the zip file |
| 39 | + $download = "https://github.com/$repo/releases/download/$tag/$file" |
| 40 | + Invoke-WebRequest $download -OutFile $file |
| 41 | + |
| 42 | + # Extract the contents of the zip file |
| 43 | + Expand-Archive $file -DestinationPath $targetDir |
| 44 | + |
| 45 | + # Create a shortcut on the desktop using WScript.Shell |
| 46 | + $shell = New-Object -ComObject WScript.Shell |
| 47 | + $executablePath = Join-Path $targetDir "aurora-windows-optimizer\aurora windows optimizer.exe" |
| 48 | + $shortcutPath = [System.IO.Path]::Combine([System.Environment]::GetFolderPath('Desktop'), "$shortcutName.lnk") |
| 49 | + |
| 50 | + # Remove existing shortcut if any |
| 51 | + if (Test-Path $shortcutPath) { |
| 52 | + Remove-Item $shortcutPath -Force |
| 53 | + } |
| 54 | + |
| 55 | + # Create new shortcut |
| 56 | + $shortcut = $shell.CreateShortcut($shortcutPath) |
| 57 | + $shortcut.TargetPath = $executablePath |
| 58 | + $shortcut.WorkingDirectory = Join-Path $targetDir "aurora-windows-optimizer" |
| 59 | + $shortcut.Save() |
| 60 | + |
| 61 | + # Display a success message |
| 62 | + [System.Windows.Forms.MessageBox]::Show("The latest release of Aurora Windows Optimizer has been successfully downloaded and installed.", "Installation Complete", [System.Windows.Forms.MessageBoxButtons]::OK, [System.Windows.Forms.MessageBoxIcon]::Information) |
| 63 | +} |
| 64 | + |
| 65 | +# Create the main window |
| 66 | +$form = New-Object System.Windows.Forms.Form |
| 67 | +$form.Text = "Aurora Windows Optimizer Installer" |
| 68 | +$form.Size = New-Object System.Drawing.Size(400,150) |
| 69 | +$form.StartPosition = "CenterScreen" |
| 70 | + |
| 71 | +# Create a button to open the folder selector |
| 72 | +$buttonFolder = New-Object System.Windows.Forms.Button |
| 73 | +$buttonFolder.Location = New-Object System.Drawing.Point(50,50) |
| 74 | +$buttonFolder.Size = New-Object System.Drawing.Size(150,30) |
| 75 | +$buttonFolder.Text = "Browse Folder" |
| 76 | +$buttonFolder.Add_Click({ Show-FolderBrowserDialog }) |
| 77 | + |
| 78 | +# Create a button to install |
| 79 | +$buttonInstall = New-Object System.Windows.Forms.Button |
| 80 | +$buttonInstall.Location = New-Object System.Drawing.Point(200,50) |
| 81 | +$buttonInstall.Size = New-Object System.Drawing.Size(150,30) |
| 82 | +$buttonInstall.Text = "Install" |
| 83 | +$buttonInstall.Add_Click({ |
| 84 | + $progressBar.Value = 0 |
| 85 | + $form.Update() |
| 86 | + Install-AuroraWindowsOptimizer |
| 87 | + $progressBar.Value = 100 |
| 88 | +}) |
| 89 | + |
| 90 | +# Create a progress bar |
| 91 | +$progressBar = New-Object System.Windows.Forms.ProgressBar |
| 92 | +$progressBar.Location = New-Object System.Drawing.Point(50, 120) |
| 93 | +$progressBar.Size = New-Object System.Drawing.Size(300, 20) |
| 94 | +$progressBar.Style = [System.Windows.Forms.ProgressBarStyle]::Continuous |
| 95 | + |
| 96 | +# Create a text box to display the folder path |
| 97 | +$textBox = New-Object System.Windows.Forms.TextBox |
| 98 | +$textBox.Location = New-Object System.Drawing.Point(50, 90) |
| 99 | +$textBox.Size = New-Object System.Drawing.Size(300, 20) |
| 100 | + |
| 101 | +# Add controls to the main window |
| 102 | +$form.Controls.Add($buttonFolder) |
| 103 | +$form.Controls.Add($buttonInstall) |
| 104 | +$form.Controls.Add($progressBar) |
| 105 | +$form.Controls.Add($textBox) |
| 106 | + |
| 107 | +# Show the window |
| 108 | +$form.ShowDialog() |
0 commit comments