Skip to content

Commit a59751a

Browse files
Nuzair46ohmree
andauthored
Updated bat file. (#36)
* Patch installed completely with powershell. * Overhauled installation script * Pause and exit on failure to create directory * optimised powershell script by @omrisim210 * Delete BlockTheSpot.ps1 * Add files via upload * Delete BlockTheSpot.ps1 Co-authored-by: Animo <omrisim@gmail.com>
1 parent 413a990 commit a59751a

File tree

1 file changed

+55
-35
lines changed

1 file changed

+55
-35
lines changed

BlockTheSpot.bat

Lines changed: 55 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
;;;===,,,PowerShell.exe -ExecutionPolicy Bypass -Command "& '%~dp0ps.ps1'"
44
;;;===,,,del /s /q "%~dp0ps.ps1" >NUL 2>&1
55
;;;===,,,pause
6-
76
# Ignore errors from `Stop-Process`
87
$PSDefaultParameterValues['Stop-Process:ErrorAction'] = 'SilentlyContinue'
98

@@ -16,8 +15,7 @@ Author: @rednek46
1615
$SpotifyDirectory = "$env:APPDATA\Spotify"
1716
$SpotifyExecutable = "$SpotifyDirectory\Spotify.exe"
1817

19-
Write-Host 'Terminating Spotify...'
20-
Write-Host("")
18+
Write-Host 'Stopping Spotify...'
2119
Stop-Process -Name Spotify
2220
Stop-Process -Name SpotifyWebHelper
2321

@@ -32,58 +30,80 @@ To uninstall, search for Spotify in the start menu and right-click on the result
3230
exit
3331
}
3432

35-
mkdir $env:TEMP/BlockTheSpotTEMP `
33+
34+
Push-Location -LiteralPath $env:TEMP
35+
try {
36+
# Unique directory name based on time
37+
New-Item -Type Directory -Name "BlockTheSpot-$(Get-Date -UFormat '%Y-%m-%d_%H-%M-%S')" `
3638
| Convert-Path `
3739
| Set-Location
40+
} catch {
41+
Write-Output $_
42+
Pause
43+
exit
44+
}
3845

39-
Write-Host("Downloading latest patch (chrome_elf.zip)")
40-
Write-Host("")
41-
46+
Write-Host 'Downloading latest patch (chrome_elf.zip)...'`n
4247
$webClient = New-Object -TypeName System.Net.WebClient
4348
try {
4449
$webClient.DownloadFile(
50+
# Remote file URL
4551
'https://github.com/mrpond/BlockTheSpot/releases/latest/download/chrome_elf.zip',
52+
# Local file path
4653
"$PWD\chrome_elf.zip"
4754
)
4855
} catch {
4956
Write-Output $_
5057
Sleep
5158
}
59+
Expand-Archive -Force -LiteralPath "$PWD\chrome_elf.zip" -DestinationPath $PWD
60+
Remove-Item -LiteralPath "$PWD\chrome_elf.zip"
5261

53-
if (test-path $SpotifyDirectory/Spotify.exe){
54-
55-
if (!(test-path $SpotifyDirectory/chrome_elf.dll.bak)){
56-
57-
move $SpotifyDirectory\chrome_elf.dll $SpotifyDirectory\chrome_elf.dll.bak >$null 2>&1
58-
}
59-
60-
} else {
61-
write-host @'
62-
Spotify installation was not detected. Downloading Latest Spotify full setup.
63-
Please wait..
62+
$spotifyInstalled = (Test-Path -LiteralPath $SpotifyExecutable)
63+
if (-not $spotifyInstalled) {
64+
Write-Host @'
65+
Spotify installation was not detected.
66+
Downloading Latest Spotify full setup, please wait...
6467
'@
65-
try {
68+
try {
6669
$webClient.DownloadFile(
70+
# Remote file URL
6771
'https://download.scdn.co/SpotifyFullSetup.exe',
72+
# Local file path
6873
"$PWD\SpotifyFullSetup.exe"
6974
)
70-
} catch {
71-
Write-Output $_
72-
Sleep
73-
}
74-
75-
write-host("Running installation...")
76-
77-
.\SpotifyFullSetup.exe | Out-Null
75+
} catch {
76+
Write-Output $_
77+
Pause
78+
exit
79+
}
80+
mkdir $SpotifyDirectory >$null 2>&1
81+
Write-Host 'Running installation...'
82+
Start-Process -FilePath "$PWD\SpotifyFullSetup.exe"
83+
Write-Host 'Stopping Spotify...Again'
84+
while ((Get-Process -name Spotify -ErrorAction SilentlyContinue) -eq $null){
85+
#waiting until installation complete
86+
}
87+
Stop-Process -Name Spotify >$null 2>&1
88+
Stop-Process -Name SpotifyWebHelper >$null 2>&1
89+
Stop-Process -Name SpotifyFullSetup >$null 2>&1
90+
}
7891

79-
rm $pwd/SpotifyFullSetup.exe >$null 2>&1
80-
move $SpotifyDirectory\chrome_elf.dll $SpotifyDirectory\chrome_elf.dll.bak >$null 2>&1
92+
if (!(test-path $SpotifyDirectory/chrome_elf.dll.bak)){
93+
move $SpotifyDirectory\chrome_elf.dll $SpotifyDirectory\chrome_elf.dll.bak >$null 2>&1
8194
}
82-
Write-Host("Patching Spotify..")
83-
Expand-Archive -Force 'chrome_elf.zip' $pwd
95+
96+
Write-Host 'Patching Spotify...'
8497
$patchFiles = "$PWD\chrome_elf.dll", "$PWD\config.ini"
8598
Copy-Item -LiteralPath $patchFiles -Destination "$SpotifyDirectory"
86-
cd $env:HOMEPATH
87-
rm -Recurse $env:TEMP\BlockTheSpotTEMP
88-
Write-Host("Patching Completed.")
89-
exit
99+
100+
$tempDirectory = $PWD
101+
Pop-Location
102+
103+
Remove-Item -Recurse -LiteralPath $tempDirectory
104+
105+
Write-Host 'Patching Complete, starting Spotify...'
106+
Start-Process -WorkingDirectory $SpotifyDirectory -FilePath $SpotifyExecutable
107+
Write-Host 'Done.'
108+
pause
109+
exit

0 commit comments

Comments
 (0)