|
| 1 | +function Write-ThemeLine($text, $width=60) { |
| 2 | + $pad = [Math]::Max(0, [Math]::Floor(($width - $text.Length)/2)) |
| 3 | + Write-Host ("=" * $width) |
| 4 | + Write-Host (" " * $pad + $text) |
| 5 | + Write-Host ("=" * $width) |
| 6 | +} |
| 7 | + |
| 8 | +function Write-ThemeMsg($text, $width=60) { |
| 9 | + $pad = [Math]::Max(0, [Math]::Floor(($width - $text.Length)/2)) |
| 10 | + Write-Host (" " * $pad + $text) |
| 11 | +} |
| 12 | + |
| 13 | +# WinTool Installer Script |
| 14 | +# This script will create the install directory, download the app exe, and create a desktop shortcut. |
| 15 | + |
| 16 | +$installDir = "$env:LOCALAPPDATA\MTechTool" |
| 17 | +$exeUrl = "https://github.com/MTechWare/wintool/releases/download/release/WinTool.exe" |
| 18 | +$desktop = [Environment]::GetFolderPath("Desktop") |
| 19 | +$shortcutPath = Join-Path $desktop "WinTool.lnk" |
| 20 | +$exePath = Join-Path $installDir "WinTool.exe" |
| 21 | + |
| 22 | +# Check for winget |
| 23 | +Write-ThemeMsg "Checking for winget (Windows Package Manager)..." |
| 24 | +$wingetInstalled = $false |
| 25 | +try { |
| 26 | + $wingetVersion = winget --version 2>&1 |
| 27 | + if ($wingetVersion -match "\d+\.\d+\.\d+") { |
| 28 | + $wingetInstalled = $true |
| 29 | + Write-ThemeMsg "winget is installed: $wingetVersion" |
| 30 | + } |
| 31 | +} catch { |
| 32 | + $wingetInstalled = $false |
| 33 | +} |
| 34 | +if (-not $wingetInstalled) { |
| 35 | + Write-ThemeMsg "winget is not installed. Attempting to install App Installer from Microsoft..." |
| 36 | + $appInstallerUrl = "https://aka.ms/getwinget" |
| 37 | + $appInstallerPath = Join-Path $env:TEMP "AppInstaller.msixbundle" |
| 38 | + try { |
| 39 | + Invoke-WebRequest -Uri $appInstallerUrl -OutFile $appInstallerPath -UseBasicParsing -ErrorAction Stop |
| 40 | + Add-AppxPackage -Path $appInstallerPath |
| 41 | + Remove-Item $appInstallerPath -Force |
| 42 | + # Re-check winget |
| 43 | + $wingetVersion = winget --version 2>&1 |
| 44 | + if ($wingetVersion -match "\d+\.\d+\.\d+") { |
| 45 | + $wingetInstalled = $true |
| 46 | + Write-ThemeMsg "winget installed successfully: $wingetVersion" |
| 47 | + } else { |
| 48 | + Write-ThemeMsg "ERROR: winget installation failed. Please install 'App Installer' from the Microsoft Store manually and re-run this installer." |
| 49 | + exit 1 |
| 50 | + } |
| 51 | + } catch { |
| 52 | + Write-ThemeMsg "ERROR: winget installation failed. Please install 'App Installer' from the Microsoft Store manually and re-run this installer." |
| 53 | + exit 1 |
| 54 | + } |
| 55 | +} |
| 56 | + |
| 57 | +# [PYTHON CHECK REMOVED - No longer required] |
| 58 | + |
| 59 | +Write-ThemeLine "WinTool Installer" |
| 60 | +Write-ThemeMsg "_ ___ ______ __" |
| 61 | +Write-ThemeMsg "| | /| / (_)__/_ __/__ ___ / /" |
| 62 | +Write-ThemeMsg "| |/ |/ / / _ \/ / / _ \/ _ \/ / " |
| 63 | +Write-ThemeMsg "|__/|__/_/_//_/_/ \___/\___/_/ " |
| 64 | +Write-ThemeLine "" |
| 65 | +Write-ThemeMsg "Thank you for choosing WinTool!" |
| 66 | +Write-ThemeMsg "Installer will guide you through setup." |
| 67 | +Start-Sleep -Milliseconds 700 |
| 68 | + |
| 69 | +# Create install directory if it doesn't exist |
| 70 | +if (!(Test-Path $installDir)) { |
| 71 | + Write-ThemeMsg "Creating installation directory..." |
| 72 | + New-Item -ItemType Directory -Path $installDir | Out-Null |
| 73 | + Start-Sleep -Milliseconds 400 |
| 74 | +} |
| 75 | + |
| 76 | +# Download the exe file |
| 77 | +Write-ThemeMsg "Downloading WinTool..." |
| 78 | +try { |
| 79 | + Invoke-WebRequest -Uri $exeUrl -OutFile $exePath -ErrorAction Stop |
| 80 | + Write-ThemeMsg "Download complete!" |
| 81 | +} catch { |
| 82 | + Write-ThemeMsg "ERROR: Download failed. Please check your internet connection or the download URL." |
| 83 | + exit 1 |
| 84 | +} |
| 85 | +Start-Sleep -Milliseconds 400 |
| 86 | + |
| 87 | +# Confirm the exe exists |
| 88 | +if (!(Test-Path $exePath)) { |
| 89 | + Write-ThemeMsg "ERROR: WinTool.exe not found after download." |
| 90 | + exit 1 |
| 91 | +} |
| 92 | + |
| 93 | +Write-ThemeMsg "Creating desktop shortcut..." |
| 94 | +$WScriptShell = New-Object -ComObject WScript.Shell |
| 95 | +$Shortcut = $WScriptShell.CreateShortcut($shortcutPath) |
| 96 | +$Shortcut.TargetPath = $exePath |
| 97 | +$Shortcut.WorkingDirectory = $installDir |
| 98 | +$Shortcut.IconLocation = "$exePath,0" |
| 99 | +$Shortcut.Save() |
| 100 | +Write-ThemeMsg "Shortcut created!" |
| 101 | + |
| 102 | +Write-ThemeLine "WinTool is installed." |
| 103 | +Write-ThemeLine "You can now close this window." |
| 104 | + |
| 105 | +Start-Sleep -Milliseconds 800 |
| 106 | + |
| 107 | +# Optionally, start the app automatically |
| 108 | +Start-Process -FilePath $exePath |
0 commit comments