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")]
|
||||
[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.")]
|
||||
[Alias("m")]
|
||||
[switch]$mirror,
|
||||
@@ -299,6 +302,11 @@ function Format-LanguageCode {
|
||||
|
||||
$spotifyDirectory = Join-Path $env:APPDATA 'Spotify'
|
||||
$spotifyDirectory2 = Join-Path $env:LOCALAPPDATA 'Spotify'
|
||||
|
||||
# Использовать кастомный путь если указан параметр -SpotifyPath
|
||||
if ($SpotifyPath) {
|
||||
$spotifyDirectory = $SpotifyPath
|
||||
}
|
||||
$spotifyExecutable = Join-Path $spotifyDirectory 'Spotify.exe'
|
||||
$spotifyDll = Join-Path $spotifyDirectory 'Spotify.dll'
|
||||
$chrome_elf = Join-Path $spotifyDirectory 'chrome_elf.dll'
|
||||
@@ -521,7 +529,7 @@ function Mod-F {
|
||||
return $result
|
||||
}
|
||||
|
||||
function downloadSp() {
|
||||
function downloadSp([string]$DownloadFolder) {
|
||||
|
||||
$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" }
|
||||
|
||||
$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"
|
||||
|
||||
try { if (curl.exe -V) { $curl_check = $true } }
|
||||
@@ -565,6 +573,7 @@ function downloadSp() {
|
||||
$Error[0].Exception
|
||||
Write-Host
|
||||
Write-Host ($lang).Download2`n
|
||||
|
||||
Start-Sleep -Milliseconds 5000
|
||||
try {
|
||||
|
||||
@@ -591,15 +600,27 @@ function downloadSp() {
|
||||
$Error[0].Exception
|
||||
Write-Host
|
||||
Write-Host ($lang).Download4`n
|
||||
$tempDirectory = $PWD
|
||||
Pop-Location
|
||||
Start-Sleep -Milliseconds 200
|
||||
Remove-Item -Recurse -LiteralPath $tempDirectory
|
||||
|
||||
if ($DownloadFolder -and (Test-Path $DownloadFolder)) {
|
||||
Start-Sleep -Milliseconds 200
|
||||
Remove-Item -Recurse -LiteralPath $DownloadFolder -ErrorAction SilentlyContinue
|
||||
}
|
||||
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 {
|
||||
|
||||
# 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) {
|
||||
Write-Host ($lang).Prem`n
|
||||
}
|
||||
|
||||
$spotifyInstalled = (Test-Path -LiteralPath $spotifyExecutable)
|
||||
|
||||
if ($SpotifyPath -and -not $spotifyInstalled) {
|
||||
Write-Warning "Spotify not found in custom path: $spotifyDirectory"
|
||||
Stop-Script
|
||||
}
|
||||
|
||||
if ($spotifyInstalled) {
|
||||
|
||||
# Check version Spotify offline
|
||||
@@ -752,8 +774,8 @@ if ($spotifyInstalled) {
|
||||
}
|
||||
}
|
||||
|
||||
# Old version Spotify
|
||||
if ($oldversion) {
|
||||
# Old version Spotify (skip if custom path is used)
|
||||
if ($oldversion -and -not $SpotifyPath) {
|
||||
if ($confirm_spoti_recomended_over -or $confirm_spoti_recomended_uninstall) {
|
||||
Write-Host ($lang).OldV`n
|
||||
}
|
||||
@@ -804,8 +826,8 @@ if ($spotifyInstalled) {
|
||||
}
|
||||
}
|
||||
|
||||
# Unsupported version Spotify
|
||||
if ($testversion) {
|
||||
# Unsupported version Spotify (skip if custom path is used)
|
||||
if ($testversion -and -not $SpotifyPath) {
|
||||
|
||||
# Submit unsupported version of Spotify to google form for further processing
|
||||
|
||||
@@ -901,17 +923,14 @@ if ($spotifyInstalled) {
|
||||
}
|
||||
|
||||
if ($ch -eq 'n') {
|
||||
$tempDirectory = $PWD
|
||||
Pop-Location
|
||||
Start-Sleep -Milliseconds 200
|
||||
Remove-Item -Recurse -LiteralPath $tempDirectory
|
||||
Remove-TempDirectory -Directory $tempDirectory
|
||||
Stop-Script
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
# If there is no client or it is outdated, then install
|
||||
if (-not $spotifyInstalled -or $upgrade_client) {
|
||||
# If there is no client or it is outdated, then install (skip if custom path is used)
|
||||
if (-not $SpotifyPath -and (-not $spotifyInstalled -or $upgrade_client)) {
|
||||
|
||||
Write-Host ($lang).DownSpoti"" -NoNewline
|
||||
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
|
||||
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
|
||||
downloadSp
|
||||
downloadSp -DownloadFolder $tempDirectory
|
||||
Write-Host
|
||||
|
||||
Start-Sleep -Milliseconds 200
|
||||
|
||||
# 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' })) {}
|
||||
wait-process -name SpotifySetup
|
||||
Kill-Spotify
|
||||
@@ -1034,10 +1058,7 @@ $webjson = Get -Url (Get-Link -e "/patches/patches.json") -RetrySeconds 5
|
||||
if ($webjson -eq $null) {
|
||||
Write-Host
|
||||
Write-Host "Failed to get patches.json" -ForegroundColor Red
|
||||
$tempDirectory = $PWD
|
||||
Pop-Location
|
||||
Start-Sleep -Milliseconds 200
|
||||
Remove-Item -Recurse -LiteralPath $tempDirectory
|
||||
Remove-TempDirectory -Directory $tempDirectory
|
||||
Stop-Script
|
||||
}
|
||||
|
||||
@@ -1480,13 +1501,13 @@ function extract ($counts, $method, $name, $helper, $add, $patch) {
|
||||
"one" {
|
||||
if ($method -eq "zip") {
|
||||
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')
|
||||
$file = $zip.GetEntry($name)
|
||||
$reader = New-Object System.IO.StreamReader($file.Open())
|
||||
}
|
||||
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
|
||||
}
|
||||
$xpui = $reader.ReadToEnd()
|
||||
@@ -1502,7 +1523,7 @@ function extract ($counts, $method, $name, $helper, $add, $patch) {
|
||||
}
|
||||
"more" {
|
||||
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.Entries | Where-Object { $_.FullName -like $name -and $_.FullName.Split('/') -notcontains 'spotx-helper' } | foreach {
|
||||
$reader = New-Object System.IO.StreamReader($_.Open())
|
||||
@@ -2054,14 +2075,10 @@ function Update-ZipEntry {
|
||||
|
||||
Write-Host ($lang).ModSpoti`n
|
||||
|
||||
$tempDirectory = $PWD
|
||||
Pop-Location
|
||||
Remove-TempDirectory -Directory $tempDirectory
|
||||
|
||||
Start-Sleep -Milliseconds 200
|
||||
Remove-Item -Recurse -LiteralPath $tempDirectory
|
||||
|
||||
$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'
|
||||
$xpui_spa_patch = Join-Path (Join-Path $spotifyDirectory 'Apps') 'xpui.spa'
|
||||
$xpui_js_patch = Join-Path (Join-Path (Join-Path $spotifyDirectory 'Apps') 'xpui') 'xpui.js'
|
||||
$test_spa = Test-Path -Path $xpui_spa_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
|
||||
|
||||
# Make a backup copy of xpui.spa if it is original
|
||||
@@ -2393,9 +2410,9 @@ if (!($no_shortcut)) {
|
||||
$desktop_folder = DesktopFolder
|
||||
|
||||
If (!(Test-Path $desktop_folder\Spotify.lnk)) {
|
||||
$source = Join-Path $env:APPDATA 'Spotify\Spotify.exe'
|
||||
$source = $spotifyExecutable
|
||||
$target = "$desktop_folder\Spotify.lnk"
|
||||
$WorkingDir = "$env:APPDATA\Spotify"
|
||||
$WorkingDir = $spotifyDirectory
|
||||
$WshShell = New-Object -comObject WScript.Shell
|
||||
$Shortcut = $WshShell.CreateShortcut($target)
|
||||
$Shortcut.WorkingDirectory = $WorkingDir
|
||||
@@ -2406,9 +2423,9 @@ if (!($no_shortcut)) {
|
||||
|
||||
# Create shortcut in start menu
|
||||
If (!(Test-Path $start_menu)) {
|
||||
$source = Join-Path $env:APPDATA 'Spotify\Spotify.exe'
|
||||
$source = $spotifyExecutable
|
||||
$target = $start_menu
|
||||
$WorkingDir = "$env:APPDATA\Spotify"
|
||||
$WorkingDir = $spotifyDirectory
|
||||
$WshShell = New-Object -comObject WScript.Shell
|
||||
$Shortcut = $WshShell.CreateShortcut($target)
|
||||
$Shortcut.WorkingDirectory = $WorkingDir
|
||||
@@ -2457,13 +2474,13 @@ extract -counts 'exe' -helper 'Binary'
|
||||
|
||||
# fix login for old versions
|
||||
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
|
||||
}
|
||||
|
||||
# Disable Startup client
|
||||
if ($DisableStartup) {
|
||||
$prefsPath = "$env:APPDATA\Spotify\prefs"
|
||||
$prefsPath = Join-Path $spotifyDirectory 'prefs'
|
||||
$keyPath = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Run"
|
||||
$keyName = "Spotify"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user