mirror of
https://github.com/SpotX-Official/SpotX.git
synced 2026-04-11 17:37:21 +10:00
Custom path to Spotify (#819)
* Custom path to Spotify - added an optional parameter -SpotifyPath that changes the path of the installed Spotify - fixed a bug with the SpotX_Temp_ temporary folder * desktopfolder function returned * remove unnecessary comments
This commit is contained in:
103
run.ps1
103
run.ps1
@@ -6,6 +6,9 @@ param
|
|||||||
[Alias("v")]
|
[Alias("v")]
|
||||||
[string]$version,
|
[string]$version,
|
||||||
|
|
||||||
|
[Parameter(HelpMessage = 'Custom path to Spotify installation directory. Default is %APPDATA%\Spotify.')]
|
||||||
|
[string]$SpotifyPath,
|
||||||
|
|
||||||
[Parameter(HelpMessage = "Use github.io mirror instead of raw.githubusercontent.")]
|
[Parameter(HelpMessage = "Use github.io mirror instead of raw.githubusercontent.")]
|
||||||
[Alias("m")]
|
[Alias("m")]
|
||||||
[switch]$mirror,
|
[switch]$mirror,
|
||||||
@@ -299,6 +302,11 @@ function Format-LanguageCode {
|
|||||||
|
|
||||||
$spotifyDirectory = Join-Path $env:APPDATA 'Spotify'
|
$spotifyDirectory = Join-Path $env:APPDATA 'Spotify'
|
||||||
$spotifyDirectory2 = Join-Path $env:LOCALAPPDATA 'Spotify'
|
$spotifyDirectory2 = Join-Path $env:LOCALAPPDATA 'Spotify'
|
||||||
|
|
||||||
|
# Использовать кастомный путь если указан параметр -SpotifyPath
|
||||||
|
if ($SpotifyPath) {
|
||||||
|
$spotifyDirectory = $SpotifyPath
|
||||||
|
}
|
||||||
$spotifyExecutable = Join-Path $spotifyDirectory 'Spotify.exe'
|
$spotifyExecutable = Join-Path $spotifyDirectory 'Spotify.exe'
|
||||||
$spotifyDll = Join-Path $spotifyDirectory 'Spotify.dll'
|
$spotifyDll = Join-Path $spotifyDirectory 'Spotify.dll'
|
||||||
$chrome_elf = Join-Path $spotifyDirectory 'chrome_elf.dll'
|
$chrome_elf = Join-Path $spotifyDirectory 'chrome_elf.dll'
|
||||||
@@ -521,7 +529,7 @@ function Mod-F {
|
|||||||
return $result
|
return $result
|
||||||
}
|
}
|
||||||
|
|
||||||
function downloadSp() {
|
function downloadSp([string]$DownloadFolder) {
|
||||||
|
|
||||||
$webClient = New-Object -TypeName System.Net.WebClient
|
$webClient = New-Object -TypeName System.Net.WebClient
|
||||||
|
|
||||||
@@ -533,7 +541,7 @@ function downloadSp() {
|
|||||||
$arch = if ($short -le $max_x86) { "win32-x86" } else { "win32-x86_64" }
|
$arch = if ($short -le $max_x86) { "win32-x86" } else { "win32-x86_64" }
|
||||||
|
|
||||||
$web_Url = "https://download.scdn.co/upgrade/client/$arch/spotify_installer-$onlineFull.exe"
|
$web_Url = "https://download.scdn.co/upgrade/client/$arch/spotify_installer-$onlineFull.exe"
|
||||||
$local_Url = "$PWD\SpotifySetup.exe"
|
$local_Url = Join-Path $DownloadFolder 'SpotifySetup.exe'
|
||||||
$web_name_file = "SpotifySetup.exe"
|
$web_name_file = "SpotifySetup.exe"
|
||||||
|
|
||||||
try { if (curl.exe -V) { $curl_check = $true } }
|
try { if (curl.exe -V) { $curl_check = $true } }
|
||||||
@@ -565,6 +573,7 @@ function downloadSp() {
|
|||||||
$Error[0].Exception
|
$Error[0].Exception
|
||||||
Write-Host
|
Write-Host
|
||||||
Write-Host ($lang).Download2`n
|
Write-Host ($lang).Download2`n
|
||||||
|
|
||||||
Start-Sleep -Milliseconds 5000
|
Start-Sleep -Milliseconds 5000
|
||||||
try {
|
try {
|
||||||
|
|
||||||
@@ -591,15 +600,27 @@ function downloadSp() {
|
|||||||
$Error[0].Exception
|
$Error[0].Exception
|
||||||
Write-Host
|
Write-Host
|
||||||
Write-Host ($lang).Download4`n
|
Write-Host ($lang).Download4`n
|
||||||
$tempDirectory = $PWD
|
|
||||||
Pop-Location
|
if ($DownloadFolder -and (Test-Path $DownloadFolder)) {
|
||||||
Start-Sleep -Milliseconds 200
|
Start-Sleep -Milliseconds 200
|
||||||
Remove-Item -Recurse -LiteralPath $tempDirectory
|
Remove-Item -Recurse -LiteralPath $DownloadFolder -ErrorAction SilentlyContinue
|
||||||
|
}
|
||||||
Stop-Script
|
Stop-Script
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function Remove-TempDirectory {
|
||||||
|
param(
|
||||||
|
[string]$Directory,
|
||||||
|
[int]$DelayMs = 200
|
||||||
|
)
|
||||||
|
if ($Directory -and (Test-Path $Directory)) {
|
||||||
|
Start-Sleep -Milliseconds $DelayMs
|
||||||
|
Remove-Item -Recurse -LiteralPath $Directory -ErrorAction SilentlyContinue -Force
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function DesktopFolder {
|
function DesktopFolder {
|
||||||
|
|
||||||
# If the default Dekstop folder does not exist, then try to find it through the registry.
|
# If the default Dekstop folder does not exist, then try to find it through the registry.
|
||||||
@@ -719,16 +740,17 @@ if (Test-Path -Path $hostsFilePath) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Unique directory name based on time
|
|
||||||
Push-Location -LiteralPath ([System.IO.Path]::GetTempPath())
|
|
||||||
New-Item -Type Directory -Name "SpotX_Temp-$(Get-Date -UFormat '%Y-%m-%d_%H-%M-%S')" | Convert-Path | Set-Location
|
|
||||||
|
|
||||||
if ($premium) {
|
if ($premium) {
|
||||||
Write-Host ($lang).Prem`n
|
Write-Host ($lang).Prem`n
|
||||||
}
|
}
|
||||||
|
|
||||||
$spotifyInstalled = (Test-Path -LiteralPath $spotifyExecutable)
|
$spotifyInstalled = (Test-Path -LiteralPath $spotifyExecutable)
|
||||||
|
|
||||||
|
if ($SpotifyPath -and -not $spotifyInstalled) {
|
||||||
|
Write-Warning "Spotify not found in custom path: $spotifyDirectory"
|
||||||
|
Stop-Script
|
||||||
|
}
|
||||||
|
|
||||||
if ($spotifyInstalled) {
|
if ($spotifyInstalled) {
|
||||||
|
|
||||||
# Check version Spotify offline
|
# Check version Spotify offline
|
||||||
@@ -752,8 +774,8 @@ if ($spotifyInstalled) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Old version Spotify
|
# Old version Spotify (skip if custom path is used)
|
||||||
if ($oldversion) {
|
if ($oldversion -and -not $SpotifyPath) {
|
||||||
if ($confirm_spoti_recomended_over -or $confirm_spoti_recomended_uninstall) {
|
if ($confirm_spoti_recomended_over -or $confirm_spoti_recomended_uninstall) {
|
||||||
Write-Host ($lang).OldV`n
|
Write-Host ($lang).OldV`n
|
||||||
}
|
}
|
||||||
@@ -804,8 +826,8 @@ if ($spotifyInstalled) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Unsupported version Spotify
|
# Unsupported version Spotify (skip if custom path is used)
|
||||||
if ($testversion) {
|
if ($testversion -and -not $SpotifyPath) {
|
||||||
|
|
||||||
# Submit unsupported version of Spotify to google form for further processing
|
# Submit unsupported version of Spotify to google form for further processing
|
||||||
|
|
||||||
@@ -901,17 +923,14 @@ if ($spotifyInstalled) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($ch -eq 'n') {
|
if ($ch -eq 'n') {
|
||||||
$tempDirectory = $PWD
|
Remove-TempDirectory -Directory $tempDirectory
|
||||||
Pop-Location
|
|
||||||
Start-Sleep -Milliseconds 200
|
|
||||||
Remove-Item -Recurse -LiteralPath $tempDirectory
|
|
||||||
Stop-Script
|
Stop-Script
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
# If there is no client or it is outdated, then install
|
# If there is no client or it is outdated, then install (skip if custom path is used)
|
||||||
if (-not $spotifyInstalled -or $upgrade_client) {
|
if (-not $SpotifyPath -and (-not $spotifyInstalled -or $upgrade_client)) {
|
||||||
|
|
||||||
Write-Host ($lang).DownSpoti"" -NoNewline
|
Write-Host ($lang).DownSpoti"" -NoNewline
|
||||||
Write-Host $online -ForegroundColor Green
|
Write-Host $online -ForegroundColor Green
|
||||||
@@ -926,14 +945,19 @@ if (-not $spotifyInstalled -or $upgrade_client) {
|
|||||||
Get-ChildItem $spotifyDirectory -Exclude 'Users', 'prefs' | Remove-Item -Recurse -Force
|
Get-ChildItem $spotifyDirectory -Exclude 'Users', 'prefs' | Remove-Item -Recurse -Force
|
||||||
Start-Sleep -Milliseconds 200
|
Start-Sleep -Milliseconds 200
|
||||||
|
|
||||||
|
$tempDirName = "SpotX_Temp-$(Get-Date -UFormat '%Y-%m-%d_%H-%M-%S')"
|
||||||
|
$tempDirectory = Join-Path ([System.IO.Path]::GetTempPath()) $tempDirName
|
||||||
|
if (-not (Test-Path -LiteralPath $tempDirectory)) { New-Item -ItemType Directory -Path $tempDirectory | Out-Null }
|
||||||
|
|
||||||
# Client download
|
# Client download
|
||||||
downloadSp
|
downloadSp -DownloadFolder $tempDirectory
|
||||||
Write-Host
|
Write-Host
|
||||||
|
|
||||||
Start-Sleep -Milliseconds 200
|
Start-Sleep -Milliseconds 200
|
||||||
|
|
||||||
# Client installation
|
# Client installation
|
||||||
Start-Process -FilePath explorer.exe -ArgumentList $PWD\SpotifySetup.exe
|
$setupExe = Join-Path $tempDirectory 'SpotifySetup.exe'
|
||||||
|
Start-Process -FilePath explorer.exe -ArgumentList $setupExe
|
||||||
while (-not (get-process | Where-Object { $_.ProcessName -eq 'SpotifySetup' })) {}
|
while (-not (get-process | Where-Object { $_.ProcessName -eq 'SpotifySetup' })) {}
|
||||||
wait-process -name SpotifySetup
|
wait-process -name SpotifySetup
|
||||||
Kill-Spotify
|
Kill-Spotify
|
||||||
@@ -1034,10 +1058,7 @@ $webjson = Get -Url (Get-Link -e "/patches/patches.json") -RetrySeconds 5
|
|||||||
if ($webjson -eq $null) {
|
if ($webjson -eq $null) {
|
||||||
Write-Host
|
Write-Host
|
||||||
Write-Host "Failed to get patches.json" -ForegroundColor Red
|
Write-Host "Failed to get patches.json" -ForegroundColor Red
|
||||||
$tempDirectory = $PWD
|
Remove-TempDirectory -Directory $tempDirectory
|
||||||
Pop-Location
|
|
||||||
Start-Sleep -Milliseconds 200
|
|
||||||
Remove-Item -Recurse -LiteralPath $tempDirectory
|
|
||||||
Stop-Script
|
Stop-Script
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1480,13 +1501,13 @@ function extract ($counts, $method, $name, $helper, $add, $patch) {
|
|||||||
"one" {
|
"one" {
|
||||||
if ($method -eq "zip") {
|
if ($method -eq "zip") {
|
||||||
Add-Type -Assembly 'System.IO.Compression.FileSystem'
|
Add-Type -Assembly 'System.IO.Compression.FileSystem'
|
||||||
$xpui_spa_patch = Join-Path (Join-Path $env:APPDATA 'Spotify\Apps') 'xpui.spa'
|
$xpui_spa_patch = Join-Path (Join-Path $spotifyDirectory 'Apps') 'xpui.spa'
|
||||||
$zip = [System.IO.Compression.ZipFile]::Open($xpui_spa_patch, 'update')
|
$zip = [System.IO.Compression.ZipFile]::Open($xpui_spa_patch, 'update')
|
||||||
$file = $zip.GetEntry($name)
|
$file = $zip.GetEntry($name)
|
||||||
$reader = New-Object System.IO.StreamReader($file.Open())
|
$reader = New-Object System.IO.StreamReader($file.Open())
|
||||||
}
|
}
|
||||||
if ($method -eq "nonezip") {
|
if ($method -eq "nonezip") {
|
||||||
$file = get-item $env:APPDATA\Spotify\Apps\xpui\$name
|
$file = Get-Item (Join-Path (Join-Path (Join-Path $spotifyDirectory 'Apps') 'xpui') $name)
|
||||||
$reader = New-Object -TypeName System.IO.StreamReader -ArgumentList $file
|
$reader = New-Object -TypeName System.IO.StreamReader -ArgumentList $file
|
||||||
}
|
}
|
||||||
$xpui = $reader.ReadToEnd()
|
$xpui = $reader.ReadToEnd()
|
||||||
@@ -1502,7 +1523,7 @@ function extract ($counts, $method, $name, $helper, $add, $patch) {
|
|||||||
}
|
}
|
||||||
"more" {
|
"more" {
|
||||||
Add-Type -Assembly 'System.IO.Compression.FileSystem'
|
Add-Type -Assembly 'System.IO.Compression.FileSystem'
|
||||||
$xpui_spa_patch = Join-Path (Join-Path $env:APPDATA 'Spotify\Apps') 'xpui.spa'
|
$xpui_spa_patch = Join-Path (Join-Path $spotifyDirectory 'Apps') 'xpui.spa'
|
||||||
$zip = [System.IO.Compression.ZipFile]::Open($xpui_spa_patch, 'update')
|
$zip = [System.IO.Compression.ZipFile]::Open($xpui_spa_patch, 'update')
|
||||||
$zip.Entries | Where-Object { $_.FullName -like $name -and $_.FullName.Split('/') -notcontains 'spotx-helper' } | foreach {
|
$zip.Entries | Where-Object { $_.FullName -like $name -and $_.FullName.Split('/') -notcontains 'spotx-helper' } | foreach {
|
||||||
$reader = New-Object System.IO.StreamReader($_.Open())
|
$reader = New-Object System.IO.StreamReader($_.Open())
|
||||||
@@ -2054,14 +2075,10 @@ function Update-ZipEntry {
|
|||||||
|
|
||||||
Write-Host ($lang).ModSpoti`n
|
Write-Host ($lang).ModSpoti`n
|
||||||
|
|
||||||
$tempDirectory = $PWD
|
Remove-TempDirectory -Directory $tempDirectory
|
||||||
Pop-Location
|
|
||||||
|
|
||||||
Start-Sleep -Milliseconds 200
|
$xpui_spa_patch = Join-Path (Join-Path $spotifyDirectory 'Apps') 'xpui.spa'
|
||||||
Remove-Item -Recurse -LiteralPath $tempDirectory
|
$xpui_js_patch = Join-Path (Join-Path (Join-Path $spotifyDirectory 'Apps') 'xpui') 'xpui.js'
|
||||||
|
|
||||||
$xpui_spa_patch = Join-Path (Join-Path $env:APPDATA 'Spotify\Apps') 'xpui.spa'
|
|
||||||
$xpui_js_patch = Join-Path (Join-Path (Join-Path $env:APPDATA 'Spotify\Apps') 'xpui') 'xpui.js'
|
|
||||||
$test_spa = Test-Path -Path $xpui_spa_patch
|
$test_spa = Test-Path -Path $xpui_spa_patch
|
||||||
$test_js = Test-Path -Path $xpui_js_patch
|
$test_js = Test-Path -Path $xpui_js_patch
|
||||||
|
|
||||||
@@ -2150,7 +2167,7 @@ if ($test_spa) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$bak_spa = Join-Path (Join-Path $env:APPDATA 'Spotify\Apps') 'xpui.bak'
|
$bak_spa = Join-Path (Join-Path $spotifyDirectory 'Apps') 'xpui.bak'
|
||||||
$test_bak_spa = Test-Path -Path $bak_spa
|
$test_bak_spa = Test-Path -Path $bak_spa
|
||||||
|
|
||||||
# Make a backup copy of xpui.spa if it is original
|
# Make a backup copy of xpui.spa if it is original
|
||||||
@@ -2393,9 +2410,9 @@ if (!($no_shortcut)) {
|
|||||||
$desktop_folder = DesktopFolder
|
$desktop_folder = DesktopFolder
|
||||||
|
|
||||||
If (!(Test-Path $desktop_folder\Spotify.lnk)) {
|
If (!(Test-Path $desktop_folder\Spotify.lnk)) {
|
||||||
$source = Join-Path $env:APPDATA 'Spotify\Spotify.exe'
|
$source = $spotifyExecutable
|
||||||
$target = "$desktop_folder\Spotify.lnk"
|
$target = "$desktop_folder\Spotify.lnk"
|
||||||
$WorkingDir = "$env:APPDATA\Spotify"
|
$WorkingDir = $spotifyDirectory
|
||||||
$WshShell = New-Object -comObject WScript.Shell
|
$WshShell = New-Object -comObject WScript.Shell
|
||||||
$Shortcut = $WshShell.CreateShortcut($target)
|
$Shortcut = $WshShell.CreateShortcut($target)
|
||||||
$Shortcut.WorkingDirectory = $WorkingDir
|
$Shortcut.WorkingDirectory = $WorkingDir
|
||||||
@@ -2406,9 +2423,9 @@ if (!($no_shortcut)) {
|
|||||||
|
|
||||||
# Create shortcut in start menu
|
# Create shortcut in start menu
|
||||||
If (!(Test-Path $start_menu)) {
|
If (!(Test-Path $start_menu)) {
|
||||||
$source = Join-Path $env:APPDATA 'Spotify\Spotify.exe'
|
$source = $spotifyExecutable
|
||||||
$target = $start_menu
|
$target = $start_menu
|
||||||
$WorkingDir = "$env:APPDATA\Spotify"
|
$WorkingDir = $spotifyDirectory
|
||||||
$WshShell = New-Object -comObject WScript.Shell
|
$WshShell = New-Object -comObject WScript.Shell
|
||||||
$Shortcut = $WshShell.CreateShortcut($target)
|
$Shortcut = $WshShell.CreateShortcut($target)
|
||||||
$Shortcut.WorkingDirectory = $WorkingDir
|
$Shortcut.WorkingDirectory = $WorkingDir
|
||||||
@@ -2457,13 +2474,13 @@ extract -counts 'exe' -helper 'Binary'
|
|||||||
|
|
||||||
# fix login for old versions
|
# fix login for old versions
|
||||||
if ([version]$offline -ge [version]"1.1.87.612" -and [version]$offline -le [version]"1.2.5.1006") {
|
if ([version]$offline -ge [version]"1.1.87.612" -and [version]$offline -le [version]"1.2.5.1006") {
|
||||||
$login_spa = Join-Path (Join-Path $env:APPDATA 'Spotify\Apps') 'login.spa'
|
$login_spa = Join-Path (Join-Path $spotifyDirectory 'Apps') 'login.spa'
|
||||||
Get -Url (Get-Link -e "/res/login.spa") -OutputPath $login_spa
|
Get -Url (Get-Link -e "/res/login.spa") -OutputPath $login_spa
|
||||||
}
|
}
|
||||||
|
|
||||||
# Disable Startup client
|
# Disable Startup client
|
||||||
if ($DisableStartup) {
|
if ($DisableStartup) {
|
||||||
$prefsPath = "$env:APPDATA\Spotify\prefs"
|
$prefsPath = Join-Path $spotifyDirectory 'prefs'
|
||||||
$keyPath = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Run"
|
$keyPath = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Run"
|
||||||
$keyName = "Spotify"
|
$keyName = "Spotify"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user