-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall.ps1
More file actions
160 lines (147 loc) · 5.33 KB
/
install.ps1
File metadata and controls
160 lines (147 loc) · 5.33 KB
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#Requires -RunAsAdministrator
# #Requires -Version 7.0
using namespace System.Runtime.InteropServices;
using namespace System.IO;
# Version: Specify a version to install.
# Overwrite: Reinstall WinPath or force an update.
# WinPath_Dir: Directory of new pre-downloaded WinPath file.
param([string]$version="0.0.0",[switch]$overwrite=$false,[string]$winpath_dir="")
[Console]::Clear();
if ($IsWindows -eq $false)
{
[Console]::WriteLine("You must be on Windows to run this script! Press any key to continue...");
[Console]::ReadKey() | Out-Null;
return;
}
Start-Sleep -Milliseconds 5000 # Wait for WinPath to exit.
$Is32or64BitOperatingSystem = ([RuntimeInformation]::OSArchitecture -eq [Architecture]::X64 -or [Architecture]::X86);
$iwr_header = @{ "User-Agent" = "WinPath_install_script" };
$64BitOutput = "C:\Program Files\WinPath\";
$32BitOutput = "C:\Program Files (x86)\WinPath\";
$repo = "ANF-Studios/WinPath"
$installed = $false;
if ($version -eq "0.0.0")
{
$releases = (((Invoke-WebRequest -Method "GET" -Headers $iwr_header -Uri "https://api.github.com/repos/$repo/releases").Content) | ConvertFrom-Json);
if ($releases[0].tag_name[0] -eq "0")
{
$version = $releases[0].tag_name;
}
else
{
for ($i = 0; i -lt releases.Length; $i++)
{
if (releases[$i].prerelease -eq $false)
{
$version = releases[$i].tag_name;
break;
}
}
}
}
if ($overwrite -eq $false)
{
if ([System.Environment]::Is64BitOperatingSystem)
{
if (Test-Path -Path ([Path]::Combine($64BitOutput, "WinPath.exe")))
{
[Console]::Write("WinPath is already installed, run winpath update instead of this script!");
[Console]::ReadKey() | Out-Null;
return;
}
}
else
{
if (Test-Path -Path ([Path]::Combine($32BitOutput, "WinPath.exe")))
{
[Console]::Write("WinPath is already installed, run winpath update instead of this script!");
[Console]::ReadKey() | Out-Null;
return;
}
}
}
if ([string]::IsNullOrEmpty($winpath_dir) -eq $false)
{
$destination = "";
if ([Environment]::Is64BitOperatingSystem)
{
$destination = $64BitOutput;
}
else
{
$destination = $32BitOutput;
}
Move-Item -Path $winpath_dir -Destination $destination -Force;
$installed = $true;
}
try
{
if ($installed -eq $false)
{
if ($Is32or64BitOperatingSystem)
{
if ([Environment]::Is64BitOperatingSystem) # x64
{
if ([Environment]::OSVersion.Version.Major -eq 10)
{
[Directory]::CreateDirectory($64BitOutput) | Out-Null;
Invoke-WebRequest -Method "GET" -Headers $iwr_header -Uri "https://github.com/$repo/releases/download/$version/WinPath_win10-x64.exe" -OutFile ($64BitOutput + "WinPath.exe");
$installed = $true;
}
else
{
[Directory]::CreateDirectory($64BitOutput) | Out-Null;
Invoke-WebRequest -Method "GET" -Headers $iwr_header -Uri "https://github.com/$repo/releases/download/$version/WinPath_win-x64.exe" -OutFile ($64BitOutput + "WinPath.exe");
$installed = $true;
}
}
else # x86
{
[Directory]::CreateDirectory($32BitOutput) | Out-Null;
Invoke-WebRequest -Method "GET" -Headers $iwr_header -Uri "https://github.com/$repo/releases/download/$version/WinPath_win-x86.exe" -OutFile ($32BitOutput + "WinPath.exe");
$installed = $true;
}
}
else
{
if ([Environment]::Is64BitOperatingSystem) # Arm64
{
[Directory]::CreateDirectory($64BitOutput) | Out-Null;
Invoke-WebRequest -Method "GET" -Headers $iwr_header -Uri "https://github.com/$repo/releases/download/$version/WinPath_win-arm64.exe" -OutFile ($64BitOutput + "WinPath.exe");
$installed = $true;
}
else # Arm
{
[Directory]::CreateDirectory($32BitOutput) | Out-Null;
Invoke-WebRequest -Method "GET" -Headers $iwr_header -Uri "https://github.com/$repo/releases/download/$version/WinPath_win-arm.exe" -OutFile ($32BitOutput + "WinPath.exe");
$installed = $true;
}
}
}
}
catch [System.Exception]
{
$installed = $false;
[Console]::WriteLine("An error occured while installing WinPath:");
[Console]::WriteLine($_);
[Console]::ReadKey() | Out-Null;
}
if ($installed)
{
$path = [Environment]::GetEnvironmentVariable("Path", [System.EnvironmentVariableTarget]::Machine);
if ($path.EndsWith(";") -eq $false)
{
$path += ";";
}
if ([Environment]::Is64BitOperatingSystem)
{
[Environment]::SetEnvironmentVariable("Path", ($path + $64BitOutput), [System.EnvironmentVariableTarget]::Machine);
}
else
{
[Environment]::SetEnvironmentVariable("Path", ($path + $32BitOutput), [System.EnvironmentVariableTarget]::Machine);
}
[Console]::Write("WinPath is installed successfully! To ensure WinPath does work, restart your computer (optional).");
[Console]::ReadKey() | Out-Null;
return;
}