Updating the installation process, minor edits.

This commit is contained in:
amd64fox
2021-08-13 08:50:03 +03:00
committed by GitHub
parent 4ac756f459
commit 16bf1dd7fb
+338 -259
View File
@@ -1,6 +1,13 @@
# Ignore errors from `Stop-Process` # Ignore errors from `Stop-Process`
$PSDefaultParameterValues['Stop-Process:ErrorAction'] = 'SilentlyContinue' $PSDefaultParameterValues['Stop-Process:ErrorAction'] = 'SilentlyContinue'
# Check Tls12
$tsl_check = [Net.ServicePointManager]::SecurityProtocol
if (!($tsl_check -match '^tls12$' )) {
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
}
Write-Host "*****************" Write-Host "*****************"
Write-Host "Author: " -NoNewline Write-Host "Author: " -NoNewline
Write-Host "@Nuzair46" -ForegroundColor DarkYellow Write-Host "@Nuzair46" -ForegroundColor DarkYellow
@@ -11,14 +18,12 @@ Write-Host "*****************"
$SpotifyDirectory = "$env:APPDATA\Spotify" $SpotifyDirectory = "$env:APPDATA\Spotify"
$SpotifyExecutable = "$SpotifyDirectory\Spotify.exe" $SpotifyExecutable = "$SpotifyDirectory\Spotify.exe"
$SpotifyApps = "$SpotifyDirectory\Apps"
Stop-Process -Name Spotify Stop-Process -Name Spotify
Stop-Process -Name SpotifyWebHelper Stop-Process -Name SpotifyWebHelper
if ($PSVersionTable.PSVersion.Major -ge 7) if ($PSVersionTable.PSVersion.Major -ge 7) {
{
Import-Module Appx -UseWindowsPowerShell Import-Module Appx -UseWindowsPowerShell
} }
# Check version Windows # Check version Windows
@@ -27,43 +32,46 @@ $win11 = $win_os -match "\windows 11\b"
$win10 = $win_os -match "\windows 10\b" $win10 = $win_os -match "\windows 10\b"
$win8_1 = $win_os -match "\windows 8.1\b" $win8_1 = $win_os -match "\windows 8.1\b"
$win8 = $win_os -match "\windows 8\b" $win8 = $win_os -match "\windows 8\b"
$win7 = $win_os -match "\windows 7\b"
if ($win11 -or $win10 -or $win8_1 -or $win8){ if ($win11 -or $win10 -or $win8_1 -or $win8) {
# Check and del Windows Store # Check and del Windows Store
if (Get-AppxPackage -Name SpotifyAB.SpotifyMusic) { if (Get-AppxPackage -Name SpotifyAB.SpotifyMusic) {
Write-Host @' Write-Host @'
The Microsoft Store version of Spotify has been detected which is not supported. The Microsoft Store version of Spotify has been detected which is not supported.
'@`n '@`n
$ch = Read-Host -Prompt "Uninstall Spotify Windows Store edition (Y/N) " $ch = Read-Host -Prompt "Uninstall Spotify Windows Store edition (Y/N) "
if ($ch -eq 'y'){ if ($ch -eq 'y') {
Write-Host @' Write-Host @'
Uninstalling Spotify. Uninstalling Spotify.
'@`n '@`n
Get-AppxPackage -Name SpotifyAB.SpotifyMusic | Remove-AppxPackage Get-AppxPackage -Name SpotifyAB.SpotifyMusic | Remove-AppxPackage
} else{ }
Write-Host @' else {
Write-Host @'
Exiting... Exiting...
'@`n '@`n
Pause Pause
exit exit
}
} }
} }
}
Push-Location -LiteralPath $env:TEMP Push-Location -LiteralPath $env:TEMP
try { try {
# Unique directory name based on time # Unique directory name based on time
New-Item -Type Directory -Name "BlockTheSpot-$(Get-Date -UFormat '%Y-%m-%d_%H-%M-%S')" ` New-Item -Type Directory -Name "BlockTheSpot-$(Get-Date -UFormat '%Y-%m-%d_%H-%M-%S')" `
| Convert-Path ` | Convert-Path `
| Set-Location | Set-Location
} catch { }
Write-Output '' catch {
Pause Write-Output ''
exit Pause
exit
} }
@@ -72,15 +80,16 @@ Write-Host 'Downloading latest patch BTS...'`n
$webClient = New-Object -TypeName System.Net.WebClient $webClient = New-Object -TypeName System.Net.WebClient
try { try {
$webClient.DownloadFile( $webClient.DownloadFile(
# Remote file URL # Remote file URL
'https://github.com/mrpond/BlockTheSpot/releases/latest/download/chrome_elf.zip', 'https://github.com/mrpond/BlockTheSpot/releases/latest/download/chrome_elf.zip',
# Local file path # Local file path
"$PWD\chrome_elf.zip" "$PWD\chrome_elf.zip"
) )
} catch { }
Write-Output '' catch {
Sleep Write-Output ''
Sleep
} }
Expand-Archive -Force -LiteralPath "$PWD\chrome_elf.zip" -DestinationPath $PWD Expand-Archive -Force -LiteralPath "$PWD\chrome_elf.zip" -DestinationPath $PWD
@@ -88,36 +97,53 @@ Remove-Item -LiteralPath "$PWD\chrome_elf.zip"
$spotifyInstalled = (Test-Path -LiteralPath $SpotifyExecutable) $spotifyInstalled = (Test-Path -LiteralPath $SpotifyExecutable)
if (-not $spotifyInstalled) { if (-not $spotifyInstalled) {
Write-Host @'
Spotify desktop application not found.
Downloading latest Spotify full setup, please wait...
'@
try {
$webClient.DownloadFile(
# Remote file URL
'https://download.scdn.co/SpotifyFullSetup.exe',
# Local file path
"$PWD\SpotifyFullSetup.exe"
)
} catch {
Write-Output ''
Pause
exit
}
mkdir $SpotifyDirectory >$null 2>&1
Write-Host 'Running installation...'
Start-Process -FilePath "$PWD\SpotifyFullSetup.exe"
while ((Get-Process -name Spotify -ErrorAction SilentlyContinue) -eq $null){ try {
#waiting until installation complete $webClient.DownloadFile(
} # Remote file URL
Stop-Process -Name Spotify >$null 2>&1 'https://download.scdn.co/SpotifySetup.exe',
Stop-Process -Name SpotifyWebHelper >$null 2>&1 # Local file path
Stop-Process -Name SpotifyFullSetup >$null 2>&1 "$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 ($win7) {
get-childitem -path "$env:LOCALAPPDATA\Microsoft\Windows\Temporary Internet Files\" -Recurse -Force -Filter "SpotifyFullSetup*" | remove-item -Force
}
if ($win10) {
get-childitem -path "$env:LOCALAPPDATA\Microsoft\Windows\INetCache\" -Recurse -Force -Filter "SpotifyFullSetup*" | remove-item -Force
}
} }
if (!(test-path $SpotifyDirectory/chrome_elf.dll.bak)){ if (!(test-path $SpotifyDirectory/chrome_elf.dll.bak)) {
move $SpotifyDirectory\chrome_elf.dll $SpotifyDirectory\chrome_elf.dll.bak >$null 2>&1 move $SpotifyDirectory\chrome_elf.dll $SpotifyDirectory\chrome_elf.dll.bak >$null 2>&1
} }
Write-Host 'Patching Spotify...' Write-Host 'Patching Spotify...'
@@ -133,250 +159,303 @@ Remove-Item -Recurse -LiteralPath $tempDirectory
# Removing an empty block and button # Removing an empty block and button
if(!(test-path $env:APPDATA\Spotify\Apps\xpui.bak)){ if (!(test-path $env:APPDATA\Spotify\Apps\xpui.bak)) {
Copy $env:APPDATA\Spotify\Apps\xpui.spa $env:APPDATA\Spotify\Apps\xpui.bak Copy $env:APPDATA\Spotify\Apps\xpui.spa $env:APPDATA\Spotify\Apps\xpui.bak
} }
Rename-Item -path $env:APPDATA\Spotify\Apps\xpui.spa -NewName $env:APPDATA\Spotify\Apps\xpui.zip Rename-Item -path $env:APPDATA\Spotify\Apps\xpui.spa -NewName $env:APPDATA\Spotify\Apps\xpui.zip
Expand-Archive $env:APPDATA\Spotify\Apps\xpui.zip -DestinationPath $env:APPDATA\Spotify\Apps\temporary Expand-Archive $env:APPDATA\Spotify\Apps\xpui.zip -DestinationPath $env:APPDATA\Spotify\Apps\temporary
$file_js = Get-Content $env:APPDATA\Spotify\Apps\temporary\xpui.js -Raw $file_js = Get-Content $env:APPDATA\Spotify\Apps\temporary\xpui.js -Raw
$new_js = $file_js -replace ".........................................Z.UpgradeButton.......", "" -replace 'e.ads.leaderboard.isEnabled', 'e.ads.leaderboard.isDisabled' If (!($file_js -match 'patched by spotx')) {
Set-Content -Path $env:APPDATA\Spotify\Apps\temporary\xpui.js -Force -Value $new_js $new_js = $file_js -replace ".........................................Z.UpgradeButton.......", "" -replace 'e.ads.leaderboard.isEnabled', 'e.ads.leaderboard.isDisabled'
$contentjs = [System.IO.File]::ReadAllText("$env:APPDATA\Spotify\Apps\temporary\xpui.js") Set-Content -Path $env:APPDATA\Spotify\Apps\temporary\xpui.js -Force -Value $new_js
$contentjs = $contentjs.Trim() add-content -Path $env:APPDATA\Spotify\Apps\temporary\xpui.js -Value '// Patched by SpotX' -passthru | Out-Null
[System.IO.File]::WriteAllText("$env:APPDATA\Spotify\Apps\temporary\xpui.js", $contentjs) $contentjs = [System.IO.File]::ReadAllText("$env:APPDATA\Spotify\Apps\temporary\xpui.js")
Compress-Archive -Path $env:APPDATA\Spotify\Apps\temporary\xpui.js -Update -DestinationPath $env:APPDATA\Spotify\Apps\xpui.zip $contentjs = $contentjs.Trim()
[System.IO.File]::WriteAllText("$env:APPDATA\Spotify\Apps\temporary\xpui.js", $contentjs)
Compress-Archive -Path $env:APPDATA\Spotify\Apps\temporary\xpui.js -Update -DestinationPath $env:APPDATA\Spotify\Apps\xpui.zip
}
# Remove "Upgrade to premium" menu # Remove "Upgrade to premium" menu
$file_css = Get-Content $env:APPDATA\Spotify\Apps\temporary\xpui.css -Raw $file_css = Get-Content $env:APPDATA\Spotify\Apps\temporary\xpui.css -Raw
$new_css = $file_css -replace 'table{border-collapse:collapse;border-spacing:0}', 'table{border-collapse:collapse;border-spacing:0}[target="_blank"]{display:none !important;}' If (!($file_css -match 'patched by spotx')) {
Set-Content -Path $env:APPDATA\Spotify\Apps\temporary\xpui.css -Force -Value $new_css $new_css = $file_css -replace 'table{border-collapse:collapse;border-spacing:0}', 'table{border-collapse:collapse;border-spacing:0}[target="_blank"]{display:none !important;}'
$contentcss = [System.IO.File]::ReadAllText("$env:APPDATA\Spotify\Apps\temporary\xpui.css") Set-Content -Path $env:APPDATA\Spotify\Apps\temporary\xpui.css -Force -Value $new_css
$contentcss = $contentcss.Trim() add-content -Path $env:APPDATA\Spotify\Apps\temporary\xpui.css -Value '/* Patched by SpotX */' -passthru | Out-Null
[System.IO.File]::WriteAllText("$env:APPDATA\Spotify\Apps\temporary\xpui.css", $contentcss) $contentcss = [System.IO.File]::ReadAllText("$env:APPDATA\Spotify\Apps\temporary\xpui.css")
Compress-Archive -Path $env:APPDATA\Spotify\Apps\temporary\xpui.css -Update -DestinationPath $env:APPDATA\Spotify\Apps\xpui.zip $contentcss = $contentcss.Trim()
[System.IO.File]::WriteAllText("$env:APPDATA\Spotify\Apps\temporary\xpui.css", $contentcss)
Compress-Archive -Path $env:APPDATA\Spotify\Apps\temporary\xpui.css -Update -DestinationPath $env:APPDATA\Spotify\Apps\xpui.zip
}
Rename-Item -path $env:APPDATA\Spotify\Apps\xpui.zip -NewName $env:APPDATA\Spotify\Apps\xpui.spa Rename-Item -path $env:APPDATA\Spotify\Apps\xpui.zip -NewName $env:APPDATA\Spotify\Apps\xpui.spa
Remove-item $env:APPDATA\Spotify\Apps\temporary -Recurse Remove-item $env:APPDATA\Spotify\Apps\temporary -Recurse
# Shortcut bug # Shortcut bug
If(!(Test-Path $env:USERPROFILE\Desktop\Spotify.lnk)) { If (!(Test-Path $env:USERPROFILE\Desktop\Spotify.lnk)) {
$source = "$env:APPDATA\Spotify\Spotify.exe" $source = "$env:APPDATA\Spotify\Spotify.exe"
$target = "$env:USERPROFILE\Desktop\Spotify.lnk" $target = "$env:USERPROFILE\Desktop\Spotify.lnk"
$WshShell = New-Object -comObject WScript.Shell $WshShell = New-Object -comObject WScript.Shell
$Shortcut = $WshShell.CreateShortcut($target) $Shortcut = $WshShell.CreateShortcut($target)
$Shortcut.TargetPath = $source $Shortcut.TargetPath = $source
$Shortcut.Save() $Shortcut.Save()
} }
# Block updates # Block updates
$ErrorActionPreference = 'SilentlyContinue' # Команда гасит легкие ошибки
$update_directory = Test-Path -Path $env:LOCALAPPDATA\Spotify $update_directory = Test-Path -Path $env:LOCALAPPDATA\Spotify
$update_directory_file = Test-Path -Path $env:LOCALAPPDATA\Spotify\Update $update_directory_file = Test-Path -Path $env:LOCALAPPDATA\Spotify\Update
$migrator_bak = Test-Path -Path $env:APPDATA\Spotify\SpotifyMigrator.bak $migrator_bak = Test-Path -Path $env:APPDATA\Spotify\SpotifyMigrator.bak
$migrator_exe = Test-Path -Path $env:APPDATA\Spotify\SpotifyMigrator.exe $migrator_exe = Test-Path -Path $env:APPDATA\Spotify\SpotifyMigrator.exe
$Check_folder_file = Get-ItemProperty -Path $env:LOCALAPPDATA\Spotify\Update | SELECT Attributes
$ch = Read-Host -Prompt "Want to block updates ? (Y/N), Unlock again (U)" $ch = Read-Host -Prompt "Want to block updates ? (Y/N), Unlock again (U)"
if ($ch -eq 'y'){ if ($ch -eq 'y') {
If(!($update_directory)) {
New-Item -Path $env:LOCALAPPDATA -Name "Spotify" -ItemType "directory" | Out-Null # Создать папку Spotify если ее нет
If (!($update_directory)) {
New-Item -Path $env:LOCALAPPDATA -Name "Spotify" -ItemType "directory" | Out-Null
}
#Удалить папку Update если она есть.
if ($Check_folder_file -match '\bDirectory\b') {
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"
Write-Host "Updates blocked successfully" -ForegroundColor Green
}
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
}
elseif ($migrator_exe) {
Rename-Item -path $env:APPDATA\Spotify\SpotifyMigrator.exe -NewName $env:APPDATA\Spotify\SpotifyMigrator.bak
}
if ($Check_folder_file -match '\bSystem\b' -and $Check_folder_file -match '\bReadOnly\b' -and $migrator_bak ) {
$ch = Read-Host -Prompt 'Wow, your updates are already blocked, Do you want to delete ? (Y/N)'
if ($ch -eq 'y') {
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
}
elseif ($migrator_bak) {
Rename-Item -path $env:APPDATA\Spotify\SpotifyMigrator.bak -NewName $env:APPDATA\Spotify\SpotifyMigrator.exe
}
Write-Host "Updates unlocked" -ForegroundColor Green
}
if ($ch -eq 'n') {
Write-Host "installation completed" -ForegroundColor Green
}
else {
Write-Host "Oops, unsuccessful" -ForegroundColor Red
Write-Host "installation completed" -ForegroundColor Green
}
}
} }
If($update_directory_file) { elseif ($ch -eq 'u') {
Remove-item $env:LOCALAPPDATA\Spotify\Update -Recurse -Force 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
}
elseif ($migrator_bak) {
Rename-Item -path $env:APPDATA\Spotify\SpotifyMigrator.bak -NewName $env:APPDATA\Spotify\SpotifyMigrator.exe
}
Write-Host "Updates unlocked" -ForegroundColor Green
} }
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"
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
}
elseif ($migrator_exe){
Rename-Item -path $env:APPDATA\Spotify\SpotifyMigrator.exe -NewName $env:APPDATA\Spotify\SpotifyMigrator.bak
}
Write-Host "Updates blocked successfully" -ForegroundColor Green
}
elseif ($ch -eq 'u'){
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
}
elseif($migrator_bak) {
Rename-Item -path $env:APPDATA\Spotify\SpotifyMigrator.bak -NewName $env:APPDATA\Spotify\SpotifyMigrator.exe
}
Write-Host "Updates unlocked" -ForegroundColor Green
}
# automatic cache clearing # automatic cache clearing
$ch = Read-Host -Prompt "Want to set up automatic cache cleanup? (Y/N) Delete script (U)" $ch = Read-Host -Prompt "Want to set up automatic cache cleanup? (Y/N) Delete script (U)"
if ($ch -eq 'y'){ if ($ch -eq 'y') {
$test_cache_spotify_ps = Test-Path -Path $env:APPDATA\Spotify\cache-spotify.ps1 $test_cache_spotify_ps = Test-Path -Path $env:APPDATA\Spotify\cache-spotify.ps1
$test_spotify_vbs = Test-Path -Path $env:APPDATA\Spotify\Spotify.vbs $test_spotify_vbs = Test-Path -Path $env:APPDATA\Spotify\Spotify.vbs
If($test_cache_spotify_ps -and $test_spotify_vbs){ If ($test_cache_spotify_ps -and $test_spotify_vbs) {
$ch = Read-Host -Prompt "Clearing the cache is already installed, want to uninstall it? (Y/N)" $ch = Read-Host -Prompt "Clearing the cache is already installed, want to uninstall it? (Y/N)"
if ($ch -eq 'y'){ if ($ch -eq 'y') {
Remove-item $env:APPDATA\Spotify\cache-spotify.ps1 -Recurse -Force Remove-item $env:APPDATA\Spotify\cache-spotify.ps1 -Recurse -Force
Remove-item $env:APPDATA\Spotify\Spotify.vbs -Recurse -Force Remove-item $env:APPDATA\Spotify\Spotify.vbs -Recurse -Force
$source = "$env:APPDATA\Spotify\Spotify.exe"
$target = "$env:USERPROFILE\Desktop\Spotify.lnk"
$WshShell = New-Object -comObject WScript.Shell
$Shortcut = $WshShell.CreateShortcut($target)
$Shortcut.IconLocation = "$env:APPDATA\Spotify\Spotify.exe"
$Shortcut.TargetPath = $source
$Shortcut.Save()
Write-Host "Cache cleanup script removed" -ForegroundColor Green
Write-Host "Installation completed" -ForegroundColor Green
exit
}
if ($ch -eq 'n') {
Write-Host "Installation completed" -ForegroundColor Green
exit
}
else {
Write-Host "Installation completed" -ForegroundColor Green
exit
}
}
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
}
sleep -Milliseconds 200
# cache-spotify.ps1
New-Item -Path $env:APPDATA\Spotify\ -Name "cache-spotify.ps1" -ItemType "file" | Out-Null
add-content -Path $env:APPDATA\Spotify\cache-spotify.ps1 -Value '# Launch Spotify.exe and wait for the process to stop' -passthru | Out-Null
add-content -Path $env:APPDATA\Spotify\cache-spotify.ps1 -Value 'Start-Process -FilePath $env:APPDATA\Spotify\Spotify.exe; wait-process -name Spotify' -passthru | Out-Null
add-content -Path $env:APPDATA\Spotify\cache-spotify.ps1 -Value '' -passthru | Out-Null
add-content -Path $env:APPDATA\Spotify\cache-spotify.ps1 -Value '# This block deletes files by the last access time to it, files that have not been changed and have not been opened for more than the number of days you have selected will be deleted. (number of days = seven)' -passthru | Out-Null
add-content -Path $env:APPDATA\Spotify\cache-spotify.ps1 -Value 'If(Test-Path -Path $env:LOCALAPPDATA\Spotify\Data){' -passthru | Out-Null
add-content -Path $env:APPDATA\Spotify\cache-spotify.ps1 -Value 'dir $env:LOCALAPPDATA\Spotify\Data -File -Recurse |? lastaccesstime -lt (get-date).AddDays(-7) |del' -passthru | Out-Null
add-content -Path $env:APPDATA\Spotify\cache-spotify.ps1 -Value '}' -passthru | Out-Null
add-content -Path $env:APPDATA\Spotify\cache-spotify.ps1 -Value '' -passthru | Out-Null
add-content -Path $env:APPDATA\Spotify\cache-spotify.ps1 -Value '# Delete the file mercury.db if its size exceeds 100 MB.' -passthru | Out-Null
add-content -Path $env:APPDATA\Spotify\cache-spotify.ps1 -Value 'If(Test-Path -Path $env:LOCALAPPDATA\Spotify\mercury.db){' -passthru | Out-Null
add-content -Path $env:APPDATA\Spotify\cache-spotify.ps1 -Value '$file_mercury = Get-Item "$env:LOCALAPPDATA\Spotify\mercury.db"' -passthru | Out-Null
add-content -Path $env:APPDATA\Spotify\cache-spotify.ps1 -Value 'if ($file_mercury.length -gt 100MB) {dir $env:LOCALAPPDATA\Spotify\mercury.db -File -Recurse|del}' -passthru | Out-Null
add-content -Path $env:APPDATA\Spotify\cache-spotify.ps1 -Value '}' -passthru | Out-Null
$cache_spotify = [System.IO.File]::ReadAllText("$env:APPDATA\Spotify\cache-spotify.ps1")
$cache_spotify = $cache_spotify.Trim()
[System.IO.File]::WriteAllText("$env:APPDATA\Spotify\cache-spotify.ps1", $cache_spotify)
# Spotify.vbs
New-Item -Path $env:APPDATA\Spotify\ -Name "Spotify.vbs" -ItemType "file" | Out-Null
add-content -Path $env:APPDATA\Spotify\Spotify.vbs -Value 'command = "powershell.exe -nologo -noninteractive -command %appdata%\Spotify\cache-spotify.ps1"' -passthru | Out-Null
add-content -Path $env:APPDATA\Spotify\Spotify.vbs -Value 'set shell = CreateObject("WScript.Shell")' -passthru | Out-Null
add-content -Path $env:APPDATA\Spotify\Spotify.vbs -Value 'shell.Run command,0, false' -passthru | Out-Null
$spoti_vbs = [System.IO.File]::ReadAllText("$env:APPDATA\Spotify\Spotify.vbs")
$spoti_vbs = $spoti_vbs.Trim()
[System.IO.File]::WriteAllText("$env:APPDATA\Spotify\Spotify.vbs", $spoti_vbs)
# Spotify.lnk
$source = "$env:APPDATA\Spotify\Spotify.vbs"
$target = "$env:USERPROFILE\Desktop\Spotify.lnk"
$WshShell = New-Object -comObject WScript.Shell
$Shortcut = $WshShell.CreateShortcut($target)
$Shortcut.IconLocation = "$env:APPDATA\Spotify\Spotify.exe"
$Shortcut.TargetPath = $source
$Shortcut.Save()
$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$") {
$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 -match "^[1-9][0-9]?$|^100$")) {
$ch = Read-Host -Prompt "Oops, bad luck, let's try again
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$") {
$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
}
}
else {
Write-Host "Unsuccessful again" -ForegroundColor Red
Write-Host 'Please open the cache-spotify.ps1 file in this path "AppData\Roaming\Spotify" and enter your number of days'
Write-Host "Installation completed" -ForegroundColor Green
exit
}
$source = "$env:APPDATA\Spotify\Spotify.exe"
$target = "$env:USERPROFILE\Desktop\Spotify.lnk"
$WshShell = New-Object -comObject WScript.Shell
$Shortcut = $WshShell.CreateShortcut($target)
$Shortcut.IconLocation = "$env:APPDATA\Spotify\Spotify.exe"
$Shortcut.TargetPath = $source
$Shortcut.Save()
Write-Host "Cache cleanup script removed" -ForegroundColor Green
Write-Host "Installation completed" -ForegroundColor Green
exit
} }
if ($ch -eq 'n'){
Write-Host "Installation completed" -ForegroundColor Green if ($ch -eq 'n') {
exit
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
$source = "$env:APPDATA\Spotify\Spotify.exe"
$target = "$env:USERPROFILE\Desktop\Spotify.lnk"
$WshShell = New-Object -comObject WScript.Shell
$Shortcut = $WshShell.CreateShortcut($target)
$Shortcut.IconLocation = "$env:APPDATA\Spotify\Spotify.exe"
$Shortcut.TargetPath = $source
$Shortcut.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
}
} }
else { else {
Write-Host "Installation completed" -ForegroundColor Green Write-Host "Oops, unsuccessful" -ForegroundColor Red
exit Write-Host "installation completed" -ForegroundColor Green
}
}
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
}
sleep -Milliseconds 200
# cache-spotify.ps1
New-Item -Path $env:APPDATA\Spotify\ -Name "cache-spotify.ps1" -ItemType "file" | Out-Null
add-content -Path $env:APPDATA\Spotify\cache-spotify.ps1 -Value '# Launch Spotify.exe and wait for the process to stop' -passthru | Out-Null
add-content -Path $env:APPDATA\Spotify\cache-spotify.ps1 -Value 'Start-Process -FilePath $env:APPDATA\Spotify\Spotify.exe; wait-process -name Spotify' -passthru | Out-Null
add-content -Path $env:APPDATA\Spotify\cache-spotify.ps1 -Value '' -passthru | Out-Null
add-content -Path $env:APPDATA\Spotify\cache-spotify.ps1 -Value '# This block deletes files by the last access time to it, files that have not been changed and have not been opened for more than the number of days you have selected will be deleted. (number of days = seven)' -passthru | Out-Null
add-content -Path $env:APPDATA\Spotify\cache-spotify.ps1 -Value 'If(Test-Path -Path $env:LOCALAPPDATA\Spotify\Data){' -passthru | Out-Null
add-content -Path $env:APPDATA\Spotify\cache-spotify.ps1 -Value 'dir $env:LOCALAPPDATA\Spotify\Data -File -Recurse |? lastaccesstime -lt (get-date).AddDays(-7) |del' -passthru | Out-Null
add-content -Path $env:APPDATA\Spotify\cache-spotify.ps1 -Value '}' -passthru | Out-Null
add-content -Path $env:APPDATA\Spotify\cache-spotify.ps1 -Value '' -passthru | Out-Null
add-content -Path $env:APPDATA\Spotify\cache-spotify.ps1 -Value '# Delete the file mercury.db if its size exceeds 100 MB.' -passthru | Out-Null
add-content -Path $env:APPDATA\Spotify\cache-spotify.ps1 -Value 'If(Test-Path -Path $env:LOCALAPPDATA\Spotify\mercury.db){' -passthru | Out-Null
add-content -Path $env:APPDATA\Spotify\cache-spotify.ps1 -Value '$file_mercury = Get-Item "$env:LOCALAPPDATA\Spotify\mercury.db"' -passthru | Out-Null
add-content -Path $env:APPDATA\Spotify\cache-spotify.ps1 -Value 'if ($file_mercury.length -gt 100MB) {dir $env:LOCALAPPDATA\Spotify\mercury.db -File -Recurse|del}' -passthru | Out-Null
add-content -Path $env:APPDATA\Spotify\cache-spotify.ps1 -Value '}' -passthru | Out-Null
$cache_spotify = [System.IO.File]::ReadAllText("$env:APPDATA\Spotify\cache-spotify.ps1")
$cache_spotify = $cache_spotify.Trim()
[System.IO.File]::WriteAllText("$env:APPDATA\Spotify\cache-spotify.ps1", $cache_spotify)
# Spotify.vbs
New-Item -Path $env:APPDATA\Spotify\ -Name "Spotify.vbs" -ItemType "file" | Out-Null
add-content -Path $env:APPDATA\Spotify\Spotify.vbs -Value 'command = "powershell.exe -nologo -noninteractive -command %appdata%\Spotify\cache-spotify.ps1"' -passthru | Out-Null
add-content -Path $env:APPDATA\Spotify\Spotify.vbs -Value 'set shell = CreateObject("WScript.Shell")' -passthru | Out-Null
add-content -Path $env:APPDATA\Spotify\Spotify.vbs -Value 'shell.Run command,0, false' -passthru | Out-Null
$spoti_vbs = [System.IO.File]::ReadAllText("$env:APPDATA\Spotify\Spotify.vbs")
$spoti_vbs = $spoti_vbs.Trim()
[System.IO.File]::WriteAllText("$env:APPDATA\Spotify\Spotify.vbs", $spoti_vbs)
# Spotify.lnk
$source = "$env:APPDATA\Spotify\Spotify.vbs"
$target = "$env:USERPROFILE\Desktop\Spotify.lnk"
$WshShell = New-Object -comObject WScript.Shell
$Shortcut = $WshShell.CreateShortcut($target)
$Shortcut.IconLocation = "$env:APPDATA\Spotify\Spotify.exe"
$Shortcut.TargetPath = $source
$Shortcut.Save()
$ch = Read-Host -Prompt "Files that have not been used for more than xx days will be deleted.
Please enter the number of days (from 1 to 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 -match "^[1-9][0-9]?$|^100$")){
$ch = Read-Host -Prompt "Oops, bad luck, let's try again
Files that have not been used for more than xx days will be deleted.
Please enter the number of days (from 1 to 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
}
}
else {
Write-Host "Unsuccessful again" -ForegroundColor Red
Write-Host 'Please open the cache-spotify.ps1 file in this path "AppData\Roaming\Spotify" and enter your number of days'
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
$source = "$env:APPDATA\Spotify\Spotify.exe"
$target = "$env:USERPROFILE\Desktop\Spotify.lnk"
$WshShell = New-Object -comObject WScript.Shell
$Shortcut = $WshShell.CreateShortcut($target)
$Shortcut.IconLocation = "$env:APPDATA\Spotify\Spotify.exe"
$Shortcut.TargetPath = $source
$Shortcut.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
}
}
else {
Write-Host "Oops, unsuccessful" -ForegroundColor Red
Write-Host 'Please open the cache-spotify.ps1 file in this path "AppData\Roaming\Spotify" and enter your number of days' -ForegroundColor Red
Write-Host "installation completed" -ForegroundColor Green
} }
exit exit