mirror of
https://github.com/SpotX-Official/SpotX.git
synced 2026-06-18 21:30:05 +10:00
Client update, error starting with administrator rights, code and file optimization
- Added the ability to update the Spotify client if a newer version is found for your region - Fixed error if the script was run with administrator rights - Fixed error when updating backup copy of chrome_elf_bak.dll - Fixed bug with chrome_elf_bak.dll - Optimization of code and files
This commit is contained in:
+136
-55
@@ -1,5 +1,5 @@
|
||||
# Ignore errors from `Stop-Process`
|
||||
$PSDefaultParameterValues['Stop-Process:ErrorAction'] = 'SilentlyContinue'
|
||||
$PSDefaultParameterValues['Stop-Process:ErrorAction'] = [System.Management.Automation.ActionPreference]::SilentlyContinue
|
||||
|
||||
# Check Tls12
|
||||
$tsl_check = [Net.ServicePointManager]::SecurityProtocol
|
||||
@@ -14,9 +14,12 @@ Write-Host "@Amd64fox" -ForegroundColor DarkYellow
|
||||
Write-Host "*****************"`n
|
||||
|
||||
|
||||
$SpotifyDirectory = "$env:APPDATA\Spotify"
|
||||
$SpotifyExecutable = "$SpotifyDirectory\Spotify.exe"
|
||||
$Podcasts_off = $false
|
||||
$spotifyDirectory = "$env:APPDATA\Spotify"
|
||||
$spotifyExecutable = "$spotifyDirectory\Spotify.exe"
|
||||
$chrome_elf = "$spotifyDirectory\chrome_elf.dll"
|
||||
$chrome_elf_bak = "$spotifyDirectory\chrome_elf_bak.dll"
|
||||
$upgrade_client = $false
|
||||
$podcasts_off = $false
|
||||
|
||||
|
||||
Stop-Process -Name Spotify
|
||||
@@ -36,7 +39,7 @@ $win8 = $win_os -match "\windows 8\b"
|
||||
if ($win11 -or $win10 -or $win8_1 -or $win8) {
|
||||
|
||||
|
||||
# Check and del Windows Store
|
||||
# Remove Spotify Windows Store If Any
|
||||
if (Get-AppxPackage -Name SpotifyAB.SpotifyMusic) {
|
||||
Write-Host 'The Microsoft Store version of Spotify has been detected which is not supported.'`n
|
||||
$ch = Read-Host -Prompt "Uninstall Spotify Windows Store edition (Y/N) "
|
||||
@@ -45,8 +48,7 @@ if ($win11 -or $win10 -or $win8_1 -or $win8) {
|
||||
Get-AppxPackage -Name SpotifyAB.SpotifyMusic | Remove-AppxPackage
|
||||
}
|
||||
else {
|
||||
Write-Host 'Exiting...'`n
|
||||
Pause
|
||||
Read-Host "Exiting...`nPress any key to exit..."
|
||||
exit
|
||||
}
|
||||
}
|
||||
@@ -61,8 +63,8 @@ try {
|
||||
| Set-Location
|
||||
}
|
||||
catch {
|
||||
Write-Output ''
|
||||
Pause
|
||||
Write-Output $_
|
||||
Read-Host 'Press any key to exit...'
|
||||
exit
|
||||
}
|
||||
|
||||
@@ -80,68 +82,147 @@ try {
|
||||
)
|
||||
}
|
||||
catch {
|
||||
Write-Output ''
|
||||
Write-Output $_
|
||||
Read-Host "An error occurred while downloading the chrome_elf.zip file`nPress any key to exit..."
|
||||
Start-Sleep
|
||||
}
|
||||
|
||||
Expand-Archive -Force -LiteralPath "$PWD\chrome_elf.zip" -DestinationPath $PWD
|
||||
Remove-Item -LiteralPath "$PWD\chrome_elf.zip"
|
||||
|
||||
$spotifyInstalled = (Test-Path -LiteralPath $SpotifyExecutable)
|
||||
if (-not $spotifyInstalled) {
|
||||
|
||||
try {
|
||||
$webClient.DownloadFile(
|
||||
# Remote file URL
|
||||
'https://download.scdn.co/SpotifySetup.exe',
|
||||
# Local file path
|
||||
"$PWD\SpotifySetup.exe"
|
||||
)
|
||||
}
|
||||
catch {
|
||||
Write-Output ''
|
||||
Pause
|
||||
exit
|
||||
}
|
||||
mkdir $SpotifyDirectory | Out-Null
|
||||
|
||||
# Check version Spotify
|
||||
|
||||
try {
|
||||
$webClient.DownloadFile(
|
||||
# Remote file URL
|
||||
'https://download.scdn.co/SpotifySetup.exe',
|
||||
# Local file path
|
||||
"$PWD\SpotifySetup.exe"
|
||||
)
|
||||
}
|
||||
catch {
|
||||
Write-Output $_
|
||||
Read-Host "An error occurred while downloading the SpotifySetup.exe file`nPress any key to exit..."
|
||||
exit
|
||||
}
|
||||
|
||||
|
||||
|
||||
$spotifyInstalled = (Test-Path -LiteralPath $spotifyExecutable)
|
||||
|
||||
if ($spotifyInstalled) {
|
||||
|
||||
|
||||
|
||||
# Check last version Spotify online
|
||||
$version_client_check = (get-item $PWD\SpotifySetup.exe).VersionInfo.ProductVersion
|
||||
$online_version = $version_client_check -split '.\w\w\w\w\w\w\w\w\w'
|
||||
|
||||
|
||||
# Check last version Spotify ofline
|
||||
$ofline_version = (Get-Item $spotifyExecutable).VersionInfo.FileVersion
|
||||
|
||||
|
||||
if ($online_version -gt $ofline_version) {
|
||||
|
||||
|
||||
do {
|
||||
$ch = Read-Host -Prompt "Your Spotify $ofline_version version is outdated, it is recommended to upgrade to $online_version `nWant to update ? (Y/N)"
|
||||
Write-Output $_
|
||||
if (!($ch -eq 'n' -or $ch -eq 'y')) {
|
||||
|
||||
Write-Host "Oops, an incorrect value, " -ForegroundColor Red -NoNewline
|
||||
Write-Host "enter again through..." -NoNewline
|
||||
Start-Sleep -Milliseconds 1000
|
||||
Write-Host "3" -NoNewline
|
||||
Start-Sleep -Milliseconds 1000
|
||||
Write-Host ".2" -NoNewline
|
||||
Start-Sleep -Milliseconds 1000
|
||||
Write-Host ".1"
|
||||
Start-Sleep -Milliseconds 1000
|
||||
Clear-Host
|
||||
}
|
||||
}
|
||||
while ($ch -notmatch '^y$|^n$')
|
||||
if ($ch -eq 'y') { $upgrade_client = $true }
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# If there is no client or it is outdated, then install
|
||||
|
||||
if (-not $spotifyInstalled -or $upgrade_client) {
|
||||
|
||||
$version_client_check = (get-item $PWD\SpotifySetup.exe).VersionInfo.ProductVersion
|
||||
$version_client = $version_client_check -split '.\w\w\w\w\w\w\w\w\w'
|
||||
|
||||
|
||||
Write-Host "Downloading and installing Spotify " -NoNewline
|
||||
Write-Host $version_client -ForegroundColor Green
|
||||
Write-Host "Please wait..."`n
|
||||
|
||||
Start-Process -FilePath $PWD\SpotifySetup.exe; wait-process -name SpotifySetup
|
||||
|
||||
|
||||
|
||||
|
||||
# Correcting the error if the spotify installer was launched from the administrator
|
||||
|
||||
[System.Security.Principal.WindowsPrincipal] $principal = [System.Security.Principal.WindowsIdentity]::GetCurrent()
|
||||
$isUserAdmin = $principal.IsInRole([System.Security.Principal.WindowsBuiltInRole]::Administrator)
|
||||
|
||||
|
||||
if ($isUserAdmin) {
|
||||
Write-Host 'Startup detected with administrator rights'`n
|
||||
$apppath = 'powershell.exe'
|
||||
$taskname = 'Spotify install'
|
||||
$action = New-ScheduledTaskAction -Execute $apppath -Argument "-NoLogo -NoProfile -Command & `'$PWD\SpotifySetup.exe`'"
|
||||
$trigger = New-ScheduledTaskTrigger -Once -At (Get-Date)
|
||||
$settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -WakeToRun
|
||||
Register-ScheduledTask -Action $action -Trigger $trigger -TaskName $taskname -Settings $settings -Force | Write-Verbose
|
||||
Start-ScheduledTask -TaskName $taskname
|
||||
Start-Sleep -Seconds 2
|
||||
Unregister-ScheduledTask -TaskName $taskname -Confirm:$false
|
||||
Start-Sleep -Seconds 2
|
||||
wait-process -name SpotifySetup
|
||||
}
|
||||
else {
|
||||
|
||||
Start-Process -FilePath $PWD\SpotifySetup.exe; wait-process -name SpotifySetup
|
||||
}
|
||||
|
||||
|
||||
|
||||
Stop-Process -Name Spotify
|
||||
Stop-Process -Name SpotifyWebHelper
|
||||
Stop-Process -Name SpotifyFullSetup
|
||||
|
||||
|
||||
$ErrorActionPreference = 'SilentlyContinue' # Команда гасит легкие ошибки
|
||||
$ErrorActionPreference = 'SilentlyContinue' # extinguishes light mistakes
|
||||
|
||||
# Удалить инсталятор после установки
|
||||
# Update backup chrome_elf.dll
|
||||
if (Test-Path -LiteralPath $chrome_elf_bak) {
|
||||
Remove-item $spotifyDirectory/chrome_elf_bak.dll
|
||||
Move-Item $chrome_elf $chrome_elf_bak
|
||||
}
|
||||
|
||||
# Remove spotify installer
|
||||
if (test-path "$env:LOCALAPPDATA\Microsoft\Windows\Temporary Internet Files\") {
|
||||
get-childitem -path "$env:LOCALAPPDATA\Microsoft\Windows\Temporary Internet Files\" -Recurse -Force -Filter "SpotifyFullSetup*" | remove-item -Force
|
||||
}
|
||||
if (test-path $env:LOCALAPPDATA\Microsoft\Windows\INetCache\) {
|
||||
get-childitem -path "$env:LOCALAPPDATA\Microsoft\Windows\INetCache\" -Recurse -Force -Filter "SpotifyFullSetup*" | remove-item -Force
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
if (!(test-path $SpotifyDirectory/chrome_elf_bak.dll)) {
|
||||
Move-Item $SpotifyDirectory\chrome_elf.dll $SpotifyDirectory\chrome_elf_bak.dll
|
||||
|
||||
# Create backup chrome_elf.dll
|
||||
if (!(Test-Path -LiteralPath $chrome_elf_bak)) {
|
||||
Move-Item $chrome_elf $chrome_elf_bak
|
||||
}
|
||||
|
||||
Write-Host 'Patching Spotify...'`n
|
||||
$patchFiles = "$PWD\chrome_elf.dll", "$PWD\config.ini"
|
||||
Copy-Item -LiteralPath $patchFiles -Destination "$SpotifyDirectory"
|
||||
Copy-Item -LiteralPath $patchFiles -Destination "$spotifyDirectory"
|
||||
|
||||
$tempDirectory = $PWD
|
||||
Pop-Location
|
||||
@@ -170,10 +251,10 @@ do {
|
||||
}
|
||||
}
|
||||
while ($ch -notmatch '^y$|^n$')
|
||||
if ($ch -eq 'y') { $Podcasts_off = $true }
|
||||
if ($ch -eq 'y') { $podcasts_off = $true }
|
||||
|
||||
|
||||
# Мофифицируем файлы
|
||||
# Modify files
|
||||
|
||||
$xpui_spa_patch = "$env:APPDATA\Spotify\Apps\xpui.spa"
|
||||
$xpui_js_patch = "$env:APPDATA\Spotify\Apps\xpui\xpui.js"
|
||||
@@ -241,7 +322,7 @@ If (Test-Path $xpui_spa_patch) {
|
||||
|
||||
If (!($patched_by_spotx -match 'patched by spotx')) {
|
||||
|
||||
# Делаем резервную копию xpui.spa если он оригинальный
|
||||
# Make a backup copy of xpui.spa if it is original
|
||||
|
||||
$zip.Dispose()
|
||||
Copy-Item $xpui_spa_patch $env:APPDATA\Spotify\Apps\xpui.bak
|
||||
@@ -284,7 +365,7 @@ If (Test-Path $xpui_spa_patch) {
|
||||
-replace '(Enables new playlist creation flow in Web Player and DesktopX",default:)(!1)', '$1!0'
|
||||
|
||||
# Disable Podcast
|
||||
if ($Podcasts_off) {
|
||||
if ($podcasts_off) {
|
||||
$xpuiContents = $xpuiContents `
|
||||
-replace '"album,playlist,artist,show,station,episode"', '"album,playlist,artist,station"' -replace ',this[.]enableShows=[a-z]', ""
|
||||
}
|
||||
@@ -351,7 +432,7 @@ If (Test-Path $xpui_spa_patch) {
|
||||
}
|
||||
|
||||
|
||||
# Если папки по умолчанию Dekstop не существует, то попытаться найти её через реестр.
|
||||
# If the default Dekstop folder does not exist, then try to find it through the registry.
|
||||
$ErrorActionPreference = 'SilentlyContinue'
|
||||
|
||||
if (Test-Path "$env:USERPROFILE\Desktop") {
|
||||
@@ -390,7 +471,7 @@ If (!(Test-Path $env:USERPROFILE\Desktop\Spotify.lnk)) {
|
||||
|
||||
# Block updates
|
||||
|
||||
$ErrorActionPreference = 'SilentlyContinue' # Команда гасит легкие ошибки
|
||||
$ErrorActionPreference = 'SilentlyContinue'
|
||||
|
||||
|
||||
|
||||
@@ -422,13 +503,13 @@ while ($ch -notmatch '^y$|^n$|^u$')
|
||||
|
||||
if ($ch -eq 'y') {
|
||||
|
||||
# Если была установка клиента
|
||||
# If there was a client installation
|
||||
if (!($update_directory)) {
|
||||
|
||||
# Создать папку Spotify в Local
|
||||
# Create Spotify folder in Localappdata
|
||||
New-Item -Path $env:LOCALAPPDATA -Name "Spotify" -ItemType "directory" | Out-Null
|
||||
|
||||
#Создать файл Update
|
||||
# Create Update file
|
||||
New-Item -Path $env:LOCALAPPDATA\Spotify\ -Name "Update" -ItemType "file" -Value "STOPIT" | Out-Null
|
||||
$file = Get-ItemProperty -Path $env:LOCALAPPDATA\Spotify\Update
|
||||
$file.Attributes = "ReadOnly", "System"
|
||||
@@ -447,14 +528,14 @@ if ($ch -eq 'y') {
|
||||
}
|
||||
|
||||
|
||||
# Если клиент уже был
|
||||
# If the client has already been
|
||||
If ($update_directory) {
|
||||
|
||||
|
||||
#Удалить папку Update если она есть
|
||||
# Delete the Update folder if it exists
|
||||
if ($Check_folder_file -match '\bDirectory\b') {
|
||||
|
||||
#Если у папки Update заблокированы права то разблокировать
|
||||
# If the rights of the Update folder are blocked, then unblock
|
||||
if ($folder_update_access.AccessToString -match 'Deny') {
|
||||
|
||||
($ACL = Get-Acl $env:LOCALAPPDATA\Spotify\Update).access | ForEach-Object {
|
||||
@@ -465,7 +546,7 @@ if ($ch -eq 'y') {
|
||||
Remove-item $env:LOCALAPPDATA\Spotify\Update -Recurse -Force
|
||||
}
|
||||
|
||||
#Создать файл Update если его нет
|
||||
# Create Update file if it doesn't exist
|
||||
if (!($Check_folder_file -match '\bSystem\b' -and $Check_folder_file -match '\bReadOnly\b')) {
|
||||
New-Item -Path $env:LOCALAPPDATA\Spotify\ -Name "Update" -ItemType "file" -Value "STOPIT" | Out-Null
|
||||
$file = Get-ItemProperty -Path $env:LOCALAPPDATA\Spotify\Update
|
||||
@@ -562,10 +643,10 @@ if ($ch -eq 'y') {
|
||||
Start-Sleep -Milliseconds 200
|
||||
|
||||
# cache-spotify.ps1
|
||||
$webClient.DownloadFile('https://raw.githubusercontent.com/amd64fox/SpotX/main/cache-spotify.ps1', "$env:APPDATA\Spotify\cache-spotify.ps1")
|
||||
$webClient.DownloadFile('https://raw.githubusercontent.com/amd64fox/SpotX/main/Cache/cache-spotify.ps1', "$env:APPDATA\Spotify\cache-spotify.ps1")
|
||||
|
||||
# Spotify.vbs
|
||||
$webClient.DownloadFile('https://raw.githubusercontent.com/amd64fox/SpotX/main/Spotify.vbs', "$env:APPDATA\Spotify\Spotify.vbs")
|
||||
$webClient.DownloadFile('https://raw.githubusercontent.com/amd64fox/SpotX/main/Cache/Spotify.vbs', "$env:APPDATA\Spotify\Spotify.vbs")
|
||||
|
||||
|
||||
# Spotify.lnk
|
||||
|
||||
Reference in New Issue
Block a user