-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSetup.ps1
145 lines (134 loc) Β· 6.52 KB
/
Setup.ps1
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
<#
.SYNOPSIS
HyperFast Settup
.DESCRIPTION
Install HyperFast from its Github repo onto your computer, and Uninstall it
.NOTES
Author: AARMN The LIMITLESS
Contact: [email protected]
Date published: 21-2-2022
Current version: 1.2
.LINK
https://github.com/aarmn/hyperfast
#>
param([switch]$ScriptMode=$false)
# Repititve Info
Write-Output "" > hyperfast.log
# Self-elevate the script if required
if (-Not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] 'Administrator')) {
if ([int](Get-CimInstance -Class Win32_OperatingSystem | Select-Object -ExpandProperty BuildNumber) -ge 6000) {
$CommandLine = "-File `"" + $MyInvocation.MyCommand.Path + "`" " + $MyInvocation.UnboundArguments
Start-Process -FilePath PowerShell.exe -Verb Runas -ArgumentList $CommandLine
Exit
}
$host.ui.WriteLine("Windows is outdated, please update to Windows 10 or newer for a better experience!")
Exit 1
}
Function Create-Shortcut-HyperFast ($sourcePath, $shortcutPath, $GUIMode) {
# script mode ifs
$shell = New-Object -ComObject WScript.Shell
$shortcut = $shell.CreateShortcut($shortcutPath)
$shortcut.TargetPath = "$SourcePath"
$shortcut.IconLocation = "$SourcePath"
$shortcut.WindowStyle = 3
$shortcut.Arguments = "$GUIMode" # dollar
$shortcut.Save()
$lnkBytes = [System.IO.File]::ReadAllBytes($shortcutPath)
$lnkBytes[21] = 34
[System.IO.File]::WriteAllBytes($shortcutPath, $lnkBytes)
}
Function Ask-Shortcut-HyperFast($question) {
$yes = New-Object System.Management.Automation.Host.ChoiceDescription "&Yes", "Add the asked Shortcut"
$no = New-Object System.Management.Automation.Host.ChoiceDescription "&No", "Do Not add the asked Shortcut"
$options = [System.Management.Automation.Host.ChoiceDescription[]]($yes, $no)
$action = $host.ui.PromptForChoice("Make Shortcut", "Make a shortcut on $($question) ?", $options, 0) # dollar
if ($action -eq 0) { return $True } else { return $False }
}
Function Uninstall-HyperFast () {
$host.ui.WriteLine("Uninstalling HyperFast...")
Remove-Item -Force -Recurse $psfolderpath, $desktoplink, $startmenulink 2>> hyperfast.log
$host.ui.WriteLine("HyperFast removed successfully!")
}
Function Install-HyperFast () {
$host.ui.WriteLine("Installing HyperFast...")
if (!($psf_exist)) {
New-Item $psfolderpath -itemtype Directory
}
if (!($pss_exist)) {
if ($ScriptMode){ Invoke-WebRequest -Uri "https://raw.githubusercontent.com/aarmn/HyperFast/master/HyperFast.ps1" -OutFile $psscriptpath 2>> hyperfast.log }
else { Invoke-WebRequest -Uri "https://raw.githubusercontent.com/aarmn/HyperFast/master/out/HyperFast.exe" -OutFile $psscriptpath 2>> hyperfast.log }
$success = $?
If (!($success)) {
$host.ui.WriteLine("Couldn't download the file. Check the Internet connection")
Exit 1
}
}
if ( (!($sml_exist)) -or (!($dl_exist)) ) {
$GUIModeIndex = $host.ui.PromptForChoice(
"Run Mode",
"Should this script verify things in GUI or Terminal?",
[System.Management.Automation.Host.ChoiceDescription[]](
(New-Object System.Management.Automation.Host.ChoiceDescription "&GUI", "Run in GUI Mode"),
(New-Object System.Management.Automation.Host.ChoiceDescription "&TUI", "Run in TUI Mode")
),
0)
if ($GUIModeIndex -eq 0) { $GUIMode = " -GUIMode" } else { $GUIMode = "" }
if (!($dl_exist)) {
if (Ask-Shortcut-HyperFast "Desktop") {
Create-Shortcut-HyperFast $psscriptpath $desktoplink $GUIMode
}
}
If (!($sml_exist)) {
if ( Ask-Shortcut-HyperFast "Start Menu") {
Create-Shortcut-HyperFast $psscriptpath $startmenulink $GUIMode
}
}
}
$host.ui.WriteLine("HyperFast installed successfully!")
}
$psfolderpath = "$((Get-Childitem Env:LOCALAPPDATA).Value)\HyperFast"
if ($ScriptMode) { $psscriptpath = "$((Get-Childitem Env:LOCALAPPDATA).Value)\HyperFast\HyperFast.ps1" }
else { $psscriptpath = "$((Get-Childitem Env:LOCALAPPDATA).Value)\HyperFast\HyperFast.exe" }
$desktoplink = "$((Get-Childitem Env:USERPROFILE).Value)\Desktop\HyperFast On-Off.lnk"
$startmenulink = "$((Get-Childitem Env:USERPROFILE).Value)\Start Menu\HyperFast On-Off.lnk"
$psf_exist = Test-Path -Path $psfolderpath -PathType Container
$pss_exist = Test-Path -Path $psscriptpath -PathType Leaf
$dl_exist = Test-Path -Path $desktoplink -PathType Leaf
$sml_exist = Test-Path -Path $startmenulink -PathType Leaf
$install = New-Object System.Management.Automation.Host.ChoiceDescription "&Install", "Install the tool (Download the most recent version)"
$uninstall = New-Object System.Management.Automation.Host.ChoiceDescription "&Uninstall", "Uninstall the tool"
$reinstall = New-Object System.Management.Automation.Host.ChoiceDescription "&Reinstall", "Uninstall and then Install it again (Download the most recent version)"
$cancel = New-Object System.Management.Automation.Host.ChoiceDescription "&Exit", "Won't change anything and exit"
If (($pss_exist) -or ($dl_exist) -or ($sml_exist)) {
$options = [System.Management.Automation.Host.ChoiceDescription[]]($reinstall, $uninstall, $cancel)
}
Else {
$options = [System.Management.Automation.Host.ChoiceDescription[]]($install, $cancel)
}
$actionIndex = $host.ui.PromptForChoice(
"HyperFast Setup",
"Welcome to HyperFast Setup, What do you want to do?",
$options,
0
)
$action = $options[$actionIndex].Label
$host.ui.WriteLine("You chose $action")
Switch ($action) {
"&Install" {
Install-HyperFast
}
"&Uninstall" {
Uninstall-HyperFast
}
"&Reinstall" {
$host.ui.WriteLine("Reinstalling HyperFast...")
Uninstall-HyperFast
Start-Sleep 3
Install-HyperFast
}
Default {
Exit
}
}
Start-Sleep 3
Exit