-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.ps1
More file actions
144 lines (107 loc) · 3.69 KB
/
Copy pathinstall.ps1
File metadata and controls
144 lines (107 loc) · 3.69 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
$ErrorActionPreference = "Stop"
$Repo = "Plutonium-Net/CustomNew"
$InstallDir = Join-Path $env:LOCALAPPDATA "CustomNew"
$ApiUrl = "https://api.github.com/repos/$Repo/releases/latest"
Write-Host ""
Write-Host "======================================" -ForegroundColor Cyan
Write-Host " CustomNew Installer " -ForegroundColor Cyan
Write-Host "======================================" -ForegroundColor Cyan
Write-Host ""
# Check Windows
if ($env:OS -ne "Windows_NT") {
throw "CustomNew is only supported on Windows."
}
# Detect architecture
if ([Environment]::Is64BitOperatingSystem) {
$Architecture = "win-x64"
}
else {
throw "32-bit Windows is not supported."
}
Write-Host "[1/5] Checking latest release..." -ForegroundColor Yellow
$Headers = @{
"User-Agent" = "CustomNew-Installer"
}
$Release = Invoke-RestMethod `
-Uri $ApiUrl `
-Headers $Headers
if (-not $Release.assets) {
throw "The latest GitHub release does not contain any downloadable assets."
}
$Asset = $Release.assets |
Where-Object { $_.name -eq "CustomNew-$Architecture.zip" } |
Select-Object -First 1
if (-not $Asset) {
throw "Could not find CustomNew-$Architecture.zip in the latest release."
}
Write-Host "Found version $($Release.tag_name)." -ForegroundColor Green
# Temporary download location
$TempDir = Join-Path $env:TEMP "CustomNew-Install"
$ZipPath = Join-Path $TempDir $Asset.name
Write-Host "[2/5] Downloading CustomNew..." -ForegroundColor Yellow
if (Test-Path $TempDir) {
Remove-Item $TempDir -Recurse -Force
}
New-Item -ItemType Directory -Path $TempDir | Out-Null
Invoke-WebRequest `
-Uri $Asset.browser_download_url `
-OutFile $ZipPath `
-Headers $Headers
Write-Host "Download complete." -ForegroundColor Green
# Install
Write-Host "[3/5] Installing CustomNew..." -ForegroundColor Yellow
if (Test-Path $InstallDir) {
Remove-Item $InstallDir -Recurse -Force
}
New-Item -ItemType Directory -Path $InstallDir | Out-Null
Expand-Archive `
-Path $ZipPath `
-DestinationPath $InstallDir `
-Force
$ExePath = Join-Path $InstallDir "CustomNew.exe"
if (-not (Test-Path $ExePath)) {
throw "CustomNew.exe was not found after extraction."
}
Write-Host "Installed to:" -ForegroundColor Green
Write-Host " $InstallDir"
# Registry
Write-Host "[4/5] Registering File Explorer integration..." -ForegroundColor Yellow
$ShellKey = "HKCU:\Software\Classes\Directory\Background\shell\CustomNew"
$CommandKey = "$ShellKey\command"
if (Test-Path $ShellKey) {
Remove-Item $ShellKey -Recurse -Force
}
New-Item -Path $ShellKey -Force | Out-Null
New-Item -Path $CommandKey -Force | Out-Null
Set-ItemProperty `
-Path $ShellKey `
-Name "(Default)" `
-Value "Custom File..."
$Command = "`"$ExePath`" `"%V`""
Set-ItemProperty `
-Path $CommandKey `
-Name "(Default)" `
-Value $Command
# Cleanup
Write-Host "[5/5] Cleaning up..." -ForegroundColor Yellow
Remove-Item $TempDir -Recurse -Force -ErrorAction SilentlyContinue
Write-Host ""
Write-Host "======================================" -ForegroundColor Green
Write-Host " CustomNew installed! " -ForegroundColor Green
Write-Host "======================================" -ForegroundColor Green
Write-Host ""
Write-Host "Right-click inside a File Explorer folder"
Write-Host "and select:"
Write-Host ""
Write-Host " Custom File..." -ForegroundColor Cyan
Write-Host ""
Write-Host "Installed version: $($Release.tag_name)"
Write-Host ""
# Restart Explorer
Write-Host "Restarting File Explorer..." -ForegroundColor Yellow
Stop-Process -Name explorer -Force -ErrorAction SilentlyContinue
Start-Sleep -Milliseconds 500
Start-Process explorer.exe
Write-Host ""
Write-Host "Done!" -ForegroundColor Green
Write-Host ""