-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInstall_Everything.ps1
58 lines (50 loc) · 1.95 KB
/
Install_Everything.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
Set-ExecutionPolicy RemoteSigned -Scope Process -Force
function CheckNonSystemPath {
$windowsDir = [Environment]::GetFolderPath("Windows")
$programFilesDir = [Environment]::GetFolderPath("ProgramFiles")
$programFilesX86Dir = [Environment]::GetFolderPath("ProgramFilesX86")
$systemDir = [Environment]::SystemDirectory
$_p = $pwd.Path
if ($_p.StartsWith($windowsDir, [StringComparison]::OrdinalIgnoreCase) -or
$_p.StartsWith($programFilesDir, [StringComparison]::OrdinalIgnoreCase) -or
$_p.StartsWith($programFilesX86Dir, [StringComparison]::OrdinalIgnoreCase) -or
$_p.StartsWith($systemDir, [StringComparison]::OrdinalIgnoreCase)) {
Write-Host "Please switch to another non-system folder and retry" -ForegroundColor Red
exit 1
}
}
function DownloadAndRun($downloadUrl, $binaryUrl) {
Start-BitsTransfer -Source $downloadUrl -Destination $binaryPath
if (Test-Path $binaryPath -PathType Leaf) {
Start-Process -FilePath $binaryPath
}
else {
Write-Host "$binaryUrl download failed." -ForegroundColor Red
exit 1
}
}
function MainEntry {
$pageUrl = "https://www.voidtools.com/downloads/"
$response = Invoke-WebRequest -Uri $pageUrl
$pattern = "Everything-(\d+\.\d+\.\d+\.\d+)\.x64\.Lite-Setup\.exe"
$binary = "Everything-1.4.1.1024.x64.Lite-Setup.exe"
if ($response.Content -match $pattern) {
$binary = $matches[0]
}
$binaryPath = Join-Path -Path $pwd -ChildPath $binary
$downloadUrl = "https://www.voidtools.com/" + $binary
CheckNonSystemPath
DownloadAndRun $downloadUrl $binaryPath
}
try {
MainEntry
}
catch {
Write-Host "Exception:" -ForegroundColor Red
Write-Host $_.Exception.Message -ForegroundColor Red
Write-Host $_.Exception.StackTrace -ForegroundColor Red
exit 1
}
# Delete Self
$myPsPath = $MyInvocation.MyCommand.Path
Start-Process powershell -ArgumentList "Remove-Item `"$myPsPath`" -Force"