|
| 1 | +# Console styling functions |
| 2 | +function Write-ColorText { |
| 3 | + param ( |
| 4 | + [string]$Text, |
| 5 | + [string]$ForegroundColor = "White" |
| 6 | + ) |
| 7 | + Write-Host $Text -ForegroundColor $ForegroundColor |
| 8 | +} |
| 9 | + |
| 10 | +function Write-ThemeLine { |
| 11 | + param ( |
| 12 | + [string]$Text = "", |
| 13 | + [int]$Width = 70, |
| 14 | + [string]$Color = "DarkYellow" |
| 15 | + ) |
| 16 | + $pad = [Math]::Max(0, [Math]::Floor(($Width - $Text.Length)/2)) |
| 17 | + Write-ColorText ("-" * $Width) $Color |
| 18 | + if ($Text) { |
| 19 | + Write-ColorText (" " * $pad + $Text) $Color |
| 20 | + Write-ColorText ("-" * $Width) $Color |
| 21 | + } |
| 22 | +} |
| 23 | + |
| 24 | +function Write-ThemeMsg { |
| 25 | + param ( |
| 26 | + [string]$Text, |
| 27 | + [int]$Width = 70, |
| 28 | + [string]$Color = "White" |
| 29 | + ) |
| 30 | + $pad = [Math]::Max(0, [Math]::Floor(($Width - $Text.Length)/2)) |
| 31 | + Write-ColorText (" " * $pad + $Text) $Color |
| 32 | +} |
| 33 | + |
| 34 | +function Write-StatusMsg { |
| 35 | + param ( |
| 36 | + [string]$Text, |
| 37 | + [string]$Status, |
| 38 | + [string]$StatusColor = "Green" |
| 39 | + ) |
| 40 | + Write-Host " $Text " -NoNewline |
| 41 | + Write-Host "[$Status]" -ForegroundColor $StatusColor |
| 42 | +} |
| 43 | + |
| 44 | +# ====================================================================== |
| 45 | +# MTechware's Hub Installer Script |
| 46 | +# Created by MTechware |
| 47 | +# Version: 1.0.0 |
| 48 | +# ====================================================================== |
| 49 | +# This script will: |
| 50 | +# - Download the latest MTechware's Hub executable |
| 51 | +# - Create the installation directory (%LOCALAPPDATA%\MTechWare\MTechWare's Hub) |
| 52 | +# - Create a desktop shortcut |
| 53 | +# - Launch the application |
| 54 | +# |
| 55 | +# Installation Directory: %LOCALAPPDATA%\MTechWare\MTechWare's Hub |
| 56 | +# - Application executable: MTechware-Hub.exe |
| 57 | +# - Settings and data: settings.json |
| 58 | +# ====================================================================== |
| 59 | + |
| 60 | +# Configuration |
| 61 | +$appName = "MTechware's Hub" |
| 62 | +$companyName = "MTechWare" |
| 63 | +$version = "0.0.1" |
| 64 | +$installDir = "$env:LOCALAPPDATA\MTechWare\MTechWare's Hub" |
| 65 | +$exeUrl = "https://github.com/MTechWare/My-App/releases/download/latest/MTechware-Hub.exe" |
| 66 | +$desktop = [Environment]::GetFolderPath("Desktop") |
| 67 | +$shortcutPath = Join-Path $desktop "$appName.lnk" |
| 68 | +$exeName = "MTechware-Hub.exe" |
| 69 | +$targetExePath = Join-Path $installDir $exeName |
| 70 | + |
| 71 | +# System information |
| 72 | +$osInfo = Get-CimInstance Win32_OperatingSystem |
| 73 | +$osName = $osInfo.Caption |
| 74 | +$osVersion = $osInfo.Version |
| 75 | +$computerName = $env:COMPUTERNAME |
| 76 | +$userName = $env:USERNAME |
| 77 | + |
| 78 | +# Clear the console and set title |
| 79 | +Clear-Host |
| 80 | +$host.UI.RawUI.WindowTitle = "$appName Installer - $companyName" |
| 81 | + |
| 82 | +# Hub |
| 83 | +Write-ThemeLine "$appName Installer" -Color "DarkYellow" |
| 84 | + |
| 85 | +Write-ThemeMsg " __ __ _____ _ __ __ " -Color "Yellow" |
| 86 | +Write-ThemeMsg "| \/ |_ _|__ __| |_ \ \ / /_ _ _ __ ___ " -Color "Yellow" |
| 87 | +Write-ThemeMsg "| |\/| | | |/ _ \/ _` | '_ \ \ \ /\ / / _` | '__/ _ \ " -Color "Yellow" |
| 88 | +Write-ThemeMsg "| | | | | | __/ (_| | | | | \ V V / (_| | | | __/ " -Color "Yellow" |
| 89 | +Write-ThemeMsg "|_| |_| |_|\___|\__,_|_| |_| \_/\_/ \__,_|_| \___| " -Color "Yellow" |
| 90 | +Write-ThemeMsg "" -Color "Yellow" |
| 91 | +Write-ThemeMsg " _ _ _ " -Color "Yellow" |
| 92 | +Write-ThemeMsg " | | | |_ _| |__ " -Color "Yellow" |
| 93 | +Write-ThemeMsg " | |_| | | | | '_ \ " -Color "Yellow" |
| 94 | +Write-ThemeMsg " | _ | |_| | |_) | " -Color "Yellow" |
| 95 | +Write-ThemeMsg " |_| |_|\__,_|_.__/ " -Color "Yellow" |
| 96 | +#Write-ThemeMsg "by $companyName" -Color "White" |
| 97 | +Write-ThemeLine "" -Color "DarkYellow" |
| 98 | + |
| 99 | +# Display system information |
| 100 | +Write-Host "" |
| 101 | +Write-StatusMsg "System" "$osName ($osVersion)" "Yellow" |
| 102 | +Write-StatusMsg "Computer" "$computerName" "Yellow" |
| 103 | +Write-StatusMsg "User" "$userName" "Yellow" |
| 104 | +Write-StatusMsg "Installing to" "$installDir" "Yellow" |
| 105 | +Write-Host "" |
| 106 | + |
| 107 | +# Check internet connection |
| 108 | +Write-StatusMsg "Checking internet connection" "PENDING" "Yellow" |
| 109 | +try { |
| 110 | + $testConnection = Test-NetConnection -ComputerName "github.com" -Port 443 -InformationLevel Quiet -WarningAction SilentlyContinue |
| 111 | + if ($testConnection) { |
| 112 | + Write-StatusMsg "Internet connection" "AVAILABLE" "Green" |
| 113 | + } else { |
| 114 | + throw "Connection failed" |
| 115 | + } |
| 116 | +} catch { |
| 117 | + Write-StatusMsg "Internet connection" "FAILED" "Red" |
| 118 | + Write-Host " Error: Unable to connect to GitHub. Please check your internet connection." -ForegroundColor "Red" |
| 119 | + exit 1 |
| 120 | +} |
| 121 | + |
| 122 | +# Installation steps |
| 123 | +Write-ThemeLine "Installation Process" -Color "DarkYellow" |
| 124 | +Write-Host "" |
| 125 | + |
| 126 | +# Create install directory if it doesn't exist |
| 127 | +Write-StatusMsg "Installation directory" "CHECKING" "Yellow" |
| 128 | +if (!(Test-Path $installDir)) { |
| 129 | + New-Item -ItemType Directory -Path $installDir -Force | Out-Null |
| 130 | + Write-StatusMsg "Creating directory" "SUCCESS" "Green" |
| 131 | +} else { |
| 132 | + Write-StatusMsg "Installation directory" "EXISTS" "Green" |
| 133 | +} |
| 134 | + |
| 135 | +# Download the executable |
| 136 | +Write-StatusMsg "Downloading $appName" "DOWNLOADING..." "Yellow" |
| 137 | +try { |
| 138 | + $ProgressPreference = 'SilentlyContinue' |
| 139 | + Invoke-WebRequest -Uri $exeUrl -OutFile $targetExePath -UseBasicParsing -ErrorAction Stop |
| 140 | + $ProgressPreference = 'Continue' |
| 141 | + |
| 142 | + if (Test-Path $targetExePath) { |
| 143 | + Write-StatusMsg "Download" "COMPLETE" "Green" |
| 144 | + } else { |
| 145 | + throw "File was not downloaded successfully" |
| 146 | + } |
| 147 | +} catch { |
| 148 | + Write-StatusMsg "Download" "FAILED" "Red" |
| 149 | + Write-Host " Error: $_" -ForegroundColor "Red" |
| 150 | + Write-Host " Please check your internet connection or the download URL." -ForegroundColor "Red" |
| 151 | + exit 1 |
| 152 | +} |
| 153 | + |
| 154 | +# Create desktop shortcut |
| 155 | +Write-StatusMsg "Creating shortcut" "PENDING" "Yellow" |
| 156 | +try { |
| 157 | + $WScriptShell = New-Object -ComObject WScript.Shell |
| 158 | + $Shortcut = $WScriptShell.CreateShortcut($shortcutPath) |
| 159 | + $Shortcut.TargetPath = $targetExePath |
| 160 | + $Shortcut.WorkingDirectory = $installDir |
| 161 | + $Shortcut.Description = "$appName - A modern application for managing and installing your favorite apps" |
| 162 | + $Shortcut.IconLocation = "$targetExePath,0" |
| 163 | + $Shortcut.Save() |
| 164 | + Write-StatusMsg "Desktop shortcut" "CREATED" "Green" |
| 165 | +} catch { |
| 166 | + Write-StatusMsg "Desktop shortcut" "FAILED" "Red" |
| 167 | + Write-Host " Error: $_" -ForegroundColor "Red" |
| 168 | +} |
| 169 | + |
| 170 | +# Installation Complete |
| 171 | +Write-Host "" |
| 172 | +Write-ThemeLine "Installation Complete" -Color "DarkYellow" |
| 173 | +Write-Host "" |
| 174 | +Write-ThemeMsg "$appName has been successfully installed!" -Color "Cyan" |
| 175 | +Write-ThemeMsg "A desktop shortcut has been created" -Color "Cyan" |
| 176 | +Write-ThemeMsg "The application will start momentarily" -Color "Cyan" |
| 177 | +Write-Host "" |
| 178 | + |
| 179 | +# Display helpful information |
| 180 | +Write-ThemeLine "Helpful Information" -Color "DarkYellow" |
| 181 | +Write-Host "" |
| 182 | +Write-Host " * Installation Directory: " -NoNewline -ForegroundColor "White" |
| 183 | +Write-Host "$installDir" -ForegroundColor "Yellow" |
| 184 | +Write-Host " * Settings & Data: " -NoNewline -ForegroundColor "White" |
| 185 | +Write-Host "$installDir\settings.json" -ForegroundColor "Yellow" |
| 186 | +Write-Host " * Desktop Shortcut: " -NoNewline -ForegroundColor "White" |
| 187 | +Write-Host "$shortcutPath" -ForegroundColor "Yellow" |
| 188 | +Write-Host " * Version: " -NoNewline -ForegroundColor "White" |
| 189 | +Write-Host "$version" -ForegroundColor "Yellow" |
| 190 | +Write-Host " * Support: " -NoNewline -ForegroundColor "White" |
| 191 | +Write-Host "https://github.com/MTechWare" -ForegroundColor "Yellow" |
| 192 | +Write-Host "" |
| 193 | + |
| 194 | +Write-ThemeLine "Thank you for choosing $appName!" -Color "DarkYellow" |
| 195 | +Write-Host "" |
| 196 | +Write-ThemeMsg "Starting $appName..." -Color "Cyan" |
| 197 | +Write-Host "" |
| 198 | +Write-ThemeMsg "You can close this window after the application launches." -Color "White" |
| 199 | + |
| 200 | +# Countdown before starting the app |
| 201 | +for ($i = 3; $i -gt 0; $i--) { |
| 202 | + Write-Host "`rLaunching in $i..." -NoNewline -ForegroundColor "Yellow" |
| 203 | + Start-Sleep -Seconds 1 |
| 204 | +} |
| 205 | +Write-Host "`rLaunching now! " -ForegroundColor "Yellow" |
| 206 | + |
| 207 | +# Start the app |
| 208 | +Start-Process -FilePath $targetExePath |
| 209 | + |
| 210 | +Write-Host "" |
| 211 | +Write-Host "Installation completed successfully!" -ForegroundColor "Green" |
| 212 | +Write-Host "Press any key to exit..." -ForegroundColor "Gray" |
| 213 | +$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") |
0 commit comments