Skip to content

Commit 5a894f3

Browse files
authored
Add install script (#86)
* Added initial install script * Added new item in changelog
1 parent 0b73b96 commit 5a894f3

File tree

2 files changed

+113
-0
lines changed

2 files changed

+113
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* Running `winpath backup create` will now give the correct error instead of "Something went wrong!" (#56).
88
* Minor bug fix when prerelease flag was not run (#72).
99
* [Other/Non-bug fix change] `WinPath.Updater` now has backwards compatibility support with v0.2.0 and v0.3.0 (#78).
10+
* [Other/Non-bug fix change] You can now simply download `install.ps1` instead of going through a mess of manual downloading for your first installation! (#85).
1011

1112
## [v0.3.0](https://github.com/ANF-Studios/WinPath/releases/tag/0.3.0)
1213
* WinPath.Library.UserPath now targets async tasks instead of sync voids.

install.ps1

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
#Requires -RunAsAdministrator
2+
3+
using namespace System.Runtime.InteropServices;
4+
using namespace System.IO;
5+
6+
if ($IsWindows -eq $false)
7+
{
8+
[Console]::WriteLine("You must be on Windows to run this script! Press any key to continue...");
9+
[Console]::ReadKey();
10+
[System.Environment]::Exit(-1);
11+
}
12+
13+
$Is32or64BitOperatingSystem = ([RuntimeInformation]::OSArchitecture -eq [Architecture]::X64 -or [Architecture]::X86);
14+
$iwr_header = @{ "User-Agent" = "WinPath_install_script" };
15+
$64BitOutput = "C:\Program Files\WinPath\";
16+
$32BitOutput = "C:\Program Files (x86)\WinPath\";
17+
$version = "0.3.1" # Change this every new release.
18+
$installed = $false;
19+
20+
21+
if ([System.Environment]::Is64BitOperatingSystem)
22+
{
23+
if (Test-Path -Path ([Path]::Combine($64BitOutput, "WinPath.exe")))
24+
{
25+
[Console]::WriteLine("WinPath is already installed, run winpath update instead of this script!");
26+
[Console]::ReadKey();
27+
[System.Environment]::Exit(-1);
28+
}
29+
}
30+
else
31+
{
32+
if (Test-Path -Path ([Path]::Combine($32BitOutput, "WinPath.exe")))
33+
{
34+
[Console]::WriteLine("WinPath is already installed, run winpath update instead of this script!");
35+
[Console]::ReadKey();
36+
[System.Environment]::Exit(-1);
37+
}
38+
}
39+
40+
try
41+
{
42+
if ($Is32or64BitOperatingSystem)
43+
{
44+
if ([Environment]::Is64BitOperatingSystem) # x64
45+
{
46+
if ([Environment]::OSVersion.Version.Major -eq 10)
47+
{
48+
[Directory]::CreateDirectory($64BitOutput);
49+
Invoke-WebRequest -Method "GET" -Headers $iwr_header -Uri "https://github.com/ANF-Studios/WinPath/releases/download/$version/WinPath_win10-x64.exe" -OutFile $64BitOutput;
50+
$installed = true;
51+
}
52+
else
53+
{
54+
[Directory]::CreateDirectory($64BitOutput);
55+
Invoke-WebRequest -Method "GET" -Headers $iwr_header -Uri "https://github.com/ANF-Studios/WinPath/releases/download/$version/WinPath_win-x64.exe" -OutFile $64BitOutput;
56+
$installed = true;
57+
}
58+
}
59+
else # x86
60+
{
61+
[Directory]::CreateDirectory($32BitOutput);
62+
Invoke-WebRequest -Method "GET" -Headers $iwr_header -Uri "https://github.com/ANF-Studios/WinPath/releases/download/$version/WinPath_win-x86.exe" -OutFile $32BitOutput;
63+
$installed = true;
64+
}
65+
}
66+
else
67+
{
68+
if ([Environment]::Is64BitOperatingSystem) # Arm64
69+
{
70+
[Directory]::CreateDirectory($64BitOutput);
71+
Invoke-WebRequest -Method "GET" -Headers $iwr_header -Uri "https://github.com/ANF-Studios/WinPath/releases/download/$version/WinPath_win-arm64.exe" -OutFile $64BitOutput;
72+
$installed = true;
73+
}
74+
else # Arm
75+
{
76+
[Directory]::CreateDirectory($32BitOutput);
77+
Invoke-WebRequest -Method "GET" -Headers $iwr_header -Uri "https://github.com/ANF-Studios/WinPath/releases/download/$version/WinPath_win-arm.exe" -OutFile $32BitOutput;
78+
$installed = true;
79+
}
80+
}
81+
82+
83+
}
84+
catch [System.Exception]
85+
{
86+
$installed = $false;
87+
[Console]::WriteLine("An error occured while installing WinPath:");
88+
[Console]::WriteLine($_);
89+
[Console]::ReadKey();
90+
}
91+
92+
if ($installed)
93+
{
94+
$path = [Environment]::GetEnvironmentVariable("Path", [System.EnvironmentVariableTarget]::Machine);
95+
if ($path.EndsWith(";") -eq $false)
96+
{
97+
$path += ";";
98+
}
99+
100+
if ([Environment]::Is64BitOperatingSystem)
101+
{
102+
[Environment]::SetEnvironmentVariable("Path", ("$path" + $64BitOutput), [System.EnvironmentVariableTarget]::Machine);
103+
}
104+
else
105+
{
106+
[Environment]::SetEnvironmentVariable("Path", ("$path" + $32BitOutput), [System.EnvironmentVariableTarget]::Machine);
107+
}
108+
109+
[Console]::WriteLine("Congrats! WinPath is installed successfully! To ensure WinPath does work, restart your computer (optional).");
110+
[Console]::ReadKey();
111+
[Environment]::Exit(0);
112+
}

0 commit comments

Comments
 (0)