Update Install.ps1

This commit is contained in:
amd64fox
2021-10-11 13:03:31 +03:00
committed by GitHub
parent 9a92c5776b
commit d8c20b3b69

View File

@@ -8,14 +8,22 @@ if (!($tsl_check -match '^tls12$' )) {
}
Write-Host "*****************"
Write-Host "Author: " -NoNewline
Write-Host "@Amd64fox" -ForegroundColor DarkYellow
Write-Host "*****************"
Write-Host "*****************" -ForegroundColor DarkYellow
Write-Host "Rollback Spotify" -ForegroundColor DarkYellow
Write-Host "*****************" -ForegroundColor DarkYellow
$SpotifyexePatch = "$env:APPDATA\Spotify\Spotify.exe"
$SpotifyDirectory = "$env:APPDATA\Spotify"
$SpotifyExecutable = "$SpotifyDirectory\Spotify.exe"
Stop-Process -Name Spotify
@@ -58,6 +66,118 @@ Exiting...
}
if (Test-Path $SpotifyexePatch) {
do {
$verlast = (Get-Item $SpotifyexePatch).VersionInfo.FileVersion
Write-Host "Client was found"
"`n"
Write-Host "You have version installed " -NoNewline
Write-Host $verlast -ForegroundColor Green
"`n"
$ch = Read-Host -Prompt "Want to remove (y) or replace (r) ? "
"`n"
if (!($ch -eq 'y' -or $ch -eq 'r')) {
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$|^r$')
}
If ($ch -eq 'y') {
"`n"
Write-Host "Click Ok to delete Spotify"
"`n"
Start-Process -FilePath $SpotifyexePatch /UNINSTALL
Start-Sleep -Milliseconds 1500
wait-process -Name SpotifyUninstall
Start-Sleep -Milliseconds 1100
}
$wget = Invoke-WebRequest -UseBasicParsing -Uri https://docs.google.com/spreadsheets/d/1wztO1L4zvNykBRw7X4jxP8pvo11oQjT0O5DvZ_-S4Ok/edit#gid=0
$result = $wget.RawContent | Select-String "1.\d.\d{1,2}.\d{1,5}.g[0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z]" -AllMatches
$version1 = $result.Matches.Value[3]
$version2 = $result.Matches.Value[5]
$version3 = $result.Matches.Value[7]
$version4 = $result.Matches.Value[9]
$version5 = $result.Matches.Value[11]
do {
$ch2 = Read-Host -Prompt "1) $version1
2) $version2
3) $version3
4) $version4
5) $version5
Select the version to rollback"
"`n"
if (!($ch2 -match '^1$|^2$|^3$|^4$|^5$')) {
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 ($ch2 -notmatch '^1$|^2$|^3$|^4$|^5$')
if ($ch2 -eq 1) {
$result2 = $wget.RawContent | Select-String "https:[/][/]upgrade.scdn.co[/]upgrade[/]client[/]win32-x86[/]spotify_installer-$version1-\d{1,3}.exe" -AllMatches
$vernew = $version1
}
if ($ch2 -eq 2) {
$result2 = $wget.RawContent | Select-String "https:[/][/]upgrade.scdn.co[/]upgrade[/]client[/]win32-x86[/]spotify_installer-$version2-\d{1,3}.exe" -AllMatches
$vernew = $version2
}
if ($ch2 -eq 3) {
$result2 = $wget.RawContent | Select-String "https:[/][/]upgrade.scdn.co[/]upgrade[/]client[/]win32-x86[/]spotify_installer-$version3-\d{1,3}.exe" -AllMatches
$vernew = $version3
}
if ($ch2 -eq 4) {
$result2 = $wget.RawContent | Select-String "https:[/][/]upgrade.scdn.co[/]upgrade[/]client[/]win32-x86[/]spotify_installer-$version4-\d{1,3}.exe" -AllMatches
$vernew = $version4
}
if ($ch2 -eq 5) {
$result2 = $wget.RawContent | Select-String "https:[/][/]upgrade.scdn.co[/]upgrade[/]client[/]win32-x86[/]spotify_installer-$version5-\d{1,3}.exe" -AllMatches
$vernew = $version5
}
Push-Location -LiteralPath $env:TEMP
try {
# Unique directory name based on time
@@ -92,59 +212,64 @@ catch {
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 >$null 2>&1
# Check version Spotify
$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..."
Start-Process -FilePath $PWD\SpotifySetup.exe; wait-process -name SpotifySetup
Stop-Process -Name Spotify >$null 2>&1
Stop-Process -Name SpotifyWebHelper >$null 2>&1
Stop-Process -Name SpotifyFullSetup >$null 2>&1
$ErrorActionPreference = 'SilentlyContinue' # Команда гасит легкие ошибки
# Удалить инсталятор после установки
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
}
Write-Host "Downloading Spotify"
"`n"
Write-Host "Please wait..."
"`n"
try {
Start-BitsTransfer -Source $result2.Matches.Value[0] -Destination "$PWD\SpotifySetup.exe" -DisplayName "Downloading Spotify" -Description "$vernew "
}
catch {
Write-Output ''
Start-Sleep
}
mkdir $SpotifyDirectory >$null 2>&1
If ($ch -eq 'r') {
if ($vernew -lt $verlast) {
Write-Host "Please confirm reinstallation"
"`n"
}
}
Start-Process -FilePath $PWD\SpotifySetup.exe; wait-process -name SpotifySetup; Write-Host "Installing Spotify..."
"`n"
Stop-Process -Name Spotify >$null 2>&1
Stop-Process -Name SpotifyWebHelper >$null 2>&1
Stop-Process -Name SpotifySetup >$null 2>&1
if (!(test-path $SpotifyDirectory/chrome_elf.dll.bak)) {
Move-Item $SpotifyDirectory\chrome_elf.dll $SpotifyDirectory\chrome_elf.dll.bak >$null 2>&1
}
Write-Host 'Patching Spotify...'
"`n"
$patchFiles = "$PWD\chrome_elf.dll", "$PWD\config.ini"
Copy-Item -LiteralPath $patchFiles -Destination "$SpotifyDirectory"
@@ -156,8 +281,6 @@ Start-Sleep -Milliseconds 200
Remove-Item -Recurse -LiteralPath $tempDirectory
# Removing an empty block, "Upgrade button", "Upgrade to premium" menu
$zipFilePath = "$env:APPDATA\Spotify\Apps\xpui.zip"
@@ -222,6 +345,7 @@ Rename-Item -path $env:APPDATA\Spotify\Apps\xpui.zip -NewName $env:APPDATA\Spoti
Remove-item $env:APPDATA\Spotify\Apps\temporary -Recurse
# Если папки по умолчанию Dekstop не существует, то попытаться найти её через реестр.
$ErrorActionPreference = 'SilentlyContinue'
@@ -256,276 +380,84 @@ If (!(Test-Path $env:USERPROFILE\Desktop\Spotify.lnk)) {
$Shortcut.Save()
}
# Block updates
$ErrorActionPreference = 'SilentlyContinue' # Команда гасит легкие ошибки
$update_directory = Test-Path -Path $env:LOCALAPPDATA\Spotify
$update_directory_file = Test-Path -Path $env:LOCALAPPDATA\Spotify\Update
$migrator_bak = Test-Path -Path $env:APPDATA\Spotify\SpotifyMigrator.bak
$migrator_exe = Test-Path -Path $env:APPDATA\Spotify\SpotifyMigrator.exe
$Check_folder_file = Get-ItemProperty -Path $env:LOCALAPPDATA\Spotify\Update | Select-Object Attributes
$folder_update_access = Get-Acl $env:LOCALAPPDATA\Spotify\Update
do {
$ch = Read-Host -Prompt "Want to block updates ? (Y/N), Unlock updates (U)"
if (!($ch -eq 'n' -or $ch -eq 'y' -or $ch -eq 'u')) {
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
# Если была установка клиента
if (!($update_directory)) {
# Создать папку Spotify в Local
New-Item -Path $env:LOCALAPPDATA -Name "Spotify" -ItemType "directory" | Out-Null
#Создать файл Update
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"
# Если оба файлав мигратора существуют то .bak удалить, а .exe переименовать в .bak
If ($migrator_exe -and $migrator_bak) {
Remove-item $env:APPDATA\Spotify\SpotifyMigrator.bak -Recurse -Force
Rename-Item -path $env:APPDATA\Spotify\SpotifyMigrator.exe -NewName $env:APPDATA\Spotify\SpotifyMigrator.bak
}
# Если есть только мигратор .exe то переименовать его в .bak
if ($migrator_exe) {
Rename-Item -path $env:APPDATA\Spotify\SpotifyMigrator.exe -NewName $env:APPDATA\Spotify\SpotifyMigrator.bak
}
}
while ($ch -notmatch '^y$|^n$|^u$')
if ($ch -eq 'y') {
# Если клиент уже был
If ($update_directory) {
# Если была установка клиента
if (!($update_directory)) {
# Создать папку Spotify в Local
New-Item -Path $env:LOCALAPPDATA -Name "Spotify" -ItemType "directory" | Out-Null
#Удалить папку Update если она есть
if ($Check_folder_file -match '\bDirectory\b') {
#Создать файл Update
#Если у папки Update заблокированы права то разблокировать
if ($folder_update_access.AccessToString -match 'Deny') {
($ACL = Get-Acl $env:LOCALAPPDATA\Spotify\Update).access | ForEach-Object {
$Users = $_.IdentityReference
$ACL.PurgeAccessRules($Users) }
$ACL | Set-Acl $env:LOCALAPPDATA\Spotify\Update
}
Remove-item $env:LOCALAPPDATA\Spotify\Update -Recurse -Force
}
#Создать файл Update если его нет
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
$file.Attributes = "ReadOnly", "System"
# Если оба файлав мигратора существуют то .bak удалить, а .exe переименовать в .bak
If ($migrator_exe -and $migrator_bak) {
Remove-item $env:APPDATA\Spotify\SpotifyMigrator.bak -Recurse -Force
Rename-Item -path $env:APPDATA\Spotify\SpotifyMigrator.exe -NewName $env:APPDATA\Spotify\SpotifyMigrator.bak
}
# Если есть только мигратор .exe то переименовать его в .bak
if ($migrator_exe) {
Rename-Item -path $env:APPDATA\Spotify\SpotifyMigrator.exe -NewName $env:APPDATA\Spotify\SpotifyMigrator.bak
}
}
# Если оба файлав мигратора существуют то .bak удалить, а .exe переименовать в .bak
If ($migrator_exe -and $migrator_bak) {
Remove-item $env:APPDATA\Spotify\SpotifyMigrator.bak -Recurse -Force
Rename-Item -path $env:APPDATA\Spotify\SpotifyMigrator.exe -NewName $env:APPDATA\Spotify\SpotifyMigrator.bak
}
# Если клиент уже был
If ($update_directory) {
#Удалить папку Update если она есть
if ($Check_folder_file -match '\bDirectory\b') {
#Если у папки Update заблокированы права то разблокировать
if ($folder_update_access.AccessToString -match 'Deny') {
($ACL = Get-Acl $env:LOCALAPPDATA\Spotify\Update).access | ForEach-Object {
$Users = $_.IdentityReference
$ACL.PurgeAccessRules($Users) }
$ACL | Set-Acl $env:LOCALAPPDATA\Spotify\Update
}
Remove-item $env:LOCALAPPDATA\Spotify\Update -Recurse -Force
}
#Создать файл Update если его нет
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
$file.Attributes = "ReadOnly", "System"
}
# Если оба файлав мигратора существуют то .bak удалить, а .exe переименовать в .bak
If ($migrator_exe -and $migrator_bak) {
Remove-item $env:APPDATA\Spotify\SpotifyMigrator.bak -Recurse -Force
Rename-Item -path $env:APPDATA\Spotify\SpotifyMigrator.exe -NewName $env:APPDATA\Spotify\SpotifyMigrator.bak
}
# Если есть только мигратор .exe то переименовать его в .bak
if ($migrator_exe) {
Rename-Item -path $env:APPDATA\Spotify\SpotifyMigrator.exe -NewName $env:APPDATA\Spotify\SpotifyMigrator.bak
}
# Если есть только мигратор .exe то переименовать его в .bak
if ($migrator_exe) {
Rename-Item -path $env:APPDATA\Spotify\SpotifyMigrator.exe -NewName $env:APPDATA\Spotify\SpotifyMigrator.bak
}
}
Write-Host "Updates blocked successfully" -ForegroundColor Green
}
Write-Host "Updates blocked successfully" -ForegroundColor Green
if ($ch -eq 'n') {
Write-Host "Left unchanged"
}
if ($ch -eq 'u') {
If ($migrator_bak -or $Check_folder_file -match '\bSystem\b|\bReadOnly\b') {
If ($update_directory_file) {
Remove-item $env:LOCALAPPDATA\Spotify\Update -Recurse -Force
}
If ($migrator_bak -and $migrator_exe ) {
Remove-item $env:APPDATA\Spotify\SpotifyMigrator.bak -Recurse -Force
}
if ($migrator_bak) {
Rename-Item -path $env:APPDATA\Spotify\SpotifyMigrator.bak -NewName $env:APPDATA\Spotify\SpotifyMigrator.exe
}
Write-Host "Updates unlocked" -ForegroundColor Green
}
If (!($migrator_bak -or $Check_folder_file -match '\bSystem\b|\bReadOnly\b')) {
Write-Host "Oops, updates are not blocked"
}
}
# automatic cache clearing
do {
$ch = Read-Host -Prompt "Want to set up automatic cache cleanup? (Y/N) Delete script (U)"
if (!($ch -eq 'n' -or $ch -eq 'y' -or $ch -eq 'u')) {
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$|^u$')
if ($ch -eq 'y') {
$test_cache_spotify_ps = Test-Path -Path $env:APPDATA\Spotify\cache-spotify.ps1
$test_spotify_vbs = Test-Path -Path $env:APPDATA\Spotify\Spotify.vbs
If ($test_cache_spotify_ps) {
Remove-item $env:APPDATA\Spotify\cache-spotify.ps1 -Recurse -Force
}
If ($test_spotify_vbs) {
Remove-item $env:APPDATA\Spotify\Spotify.vbs -Recurse -Force
}
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")
# Spotify.vbs
$webClient.DownloadFile('https://raw.githubusercontent.com/amd64fox/SpotX/main/Spotify.vbs', "$env:APPDATA\Spotify\Spotify.vbs")
# Spotify.lnk
$source2 = "$env:APPDATA\Spotify\Spotify.vbs"
$target2 = "$desktop_folder\Spotify.lnk"
$WorkingDir2 = "$env:APPDATA\Spotify"
$WshShell2 = New-Object -comObject WScript.Shell
$Shortcut2 = $WshShell2.CreateShortcut($target2)
$Shortcut2.WorkingDirectory = $WorkingDir2
$Shortcut2.IconLocation = "$env:APPDATA\Spotify\Spotify.exe"
$Shortcut2.TargetPath = $source2
$Shortcut2.Save()
do {
$ch = Read-Host -Prompt "Cache files that have not been used for more than XX days will be deleted.
Enter the number of days from 1 to 100"
if (!($ch -match "^[1-9][0-9]?$|^100$")) {
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 '^[1-9][0-9]?$|^100$')
if ($ch -match "^[1-9][0-9]?$|^100$") {
$file_cache_spotify_ps1 = Get-Content $env:APPDATA\Spotify\cache-spotify.ps1 -Raw
$new_file_cache_spotify_ps1 = $file_cache_spotify_ps1 -replace 'seven', $ch -replace '-7', - $ch
Set-Content -Path $env:APPDATA\Spotify\cache-spotify.ps1 -Force -Value $new_file_cache_spotify_ps1
$contentcache_spotify_ps1 = [System.IO.File]::ReadAllText("$env:APPDATA\Spotify\cache-spotify.ps1")
$contentcache_spotify_ps1 = $contentcache_spotify_ps1.Trim()
[System.IO.File]::WriteAllText("$env:APPDATA\Spotify\cache-spotify.ps1", $contentcache_spotify_ps1)
Write-Host "Clearing the cache has been successfully installed" -ForegroundColor Green
Write-Host "installation completed" -ForegroundColor Green
exit
}
}
if ($ch -eq 'n') {
Write-Host "installation completed" -ForegroundColor Green
exit
}
if ($ch -eq 'u') {
$test_cache_spotify_ps = Test-Path -Path $env:APPDATA\Spotify\cache-spotify.ps1
$test_spotify_vbs = Test-Path -Path $env:APPDATA\Spotify\Spotify.vbs
If ($test_cache_spotify_ps -and $test_spotify_vbs) {
Remove-item $env:APPDATA\Spotify\cache-spotify.ps1 -Recurse -Force
Remove-item $env:APPDATA\Spotify\Spotify.vbs -Recurse -Force
$source3 = "$env:APPDATA\Spotify\Spotify.exe"
$target3 = "$desktop_folder\Spotify.lnk"
$WorkingDir3 = "$env:APPDATA\Spotify"
$WshShell3 = New-Object -comObject WScript.Shell
$Shortcut3 = $WshShell3.CreateShortcut($target3)
$Shortcut3.WorkingDirectory = $WorkingDir3
$Shortcut3.IconLocation = "$env:APPDATA\Spotify\Spotify.exe"
$Shortcut3.TargetPath = $source3
$Shortcut3.Save()
Write-Host "Cache cleanup script removed" -ForegroundColor Green
Write-Host "Installation completed" -ForegroundColor Green
exit
}
If (!($test_cache_spotify_ps -and $test_spotify_vbs)) {
Write-Host "Oops, no cache clearing script found"
Write-Host "Installation completed" -ForegroundColor Green
exit
}
}
exit
Write-Host "Rollback completed" -ForegroundColor Green