Code optimization

This commit is contained in:
amd64fox
2021-09-12 00:10:24 +03:00
committed by GitHub
parent 6c3f82acaa
commit 9024b8e552

View File

@@ -10,9 +10,7 @@ if (!($tsl_check -match '^tls12$' )) {
Write-Host "*****************"
Write-Host "Author: " -NoNewline
Write-Host "@Nuzair46" -ForegroundColor DarkYellow
Write-Host "Modified: " -NoNewline
Write-Host "@Amd64fox" -ForegroundColor DarkYellow
Write-Host "@amd64fox" -ForegroundColor DarkYellow
Write-Host "*****************"
@@ -164,11 +162,23 @@ Remove-Item -Recurse -LiteralPath $tempDirectory
# Removing an empty block, "Upgrade button", "Upgrade to premium" menu
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
if (Test-Path $env:APPDATA\Spotify\Apps\temporary) {
Remove-item $env:APPDATA\Spotify\Apps\temporary -Recurse
}
New-Item -Path $env:APPDATA\Spotify\Apps\temporary -ItemType Directory | Out-Null
# Достаем из архива 2 файла
$shell = New-Object -Com Shell.Application
$shell.NameSpace("$(resolve-path $env:APPDATA\Spotify\Apps\xpui.zip)").Items() | where Name -eq "xpui.js" | ? {
$shell.NameSpace("$env:APPDATA\Spotify\Apps\temporary").copyhere($_) }
$shell.NameSpace("$(resolve-path $env:APPDATA\Spotify\Apps\xpui.zip)").Items() | where Name -eq "xpui-routes-offline-browse.css" | ? {
$shell.NameSpace("$env:APPDATA\Spotify\Apps\temporary").copyhere($_) }
# Делает резервную копию xpui.spa, также если бейкап устарел то заменяет старую на новую версию
$xpui_js_last_write_time = dir $env:APPDATA\Spotify\Apps\temporary\xpui.js -File -Recurse
$xpui_licenses_last_write_time = dir $env:APPDATA\Spotify\Apps\temporary\licenses.html -File -Recurse
$xpui_licenses_last_write_time = dir $env:APPDATA\Spotify\Apps\temporary\xpui-routes-offline-browse.css -File -Recurse
if ($xpui_licenses_last_write_time.LastWriteTime -eq $xpui_js_last_write_time.LastWriteTime) {
@@ -178,6 +188,7 @@ if ($xpui_licenses_last_write_time.LastWriteTime -eq $xpui_js_last_write_time.La
Copy $env:APPDATA\Spotify\Apps\xpui.zip $env:APPDATA\Spotify\Apps\xpui.bak
}
$file_js = Get-Content $env:APPDATA\Spotify\Apps\temporary\xpui.js -Raw
If (!($file_js -match 'patched by spotx')) {
$file_js -match 'visible:!e}[)]{1}[,]{1}[A-Za-z]{1}[(]{1}[)]{1}.createElement[(]{1}[A-Za-z]{2}[,]{1}null[)]{1}[,]{1}[A-Za-z]{1}[(]{1}[)]{1}.' | Out-Null
@@ -191,6 +202,7 @@ If (!($file_js -match 'patched by spotx')) {
Compress-Archive -Path $env:APPDATA\Spotify\Apps\temporary\xpui.js -Update -DestinationPath $env:APPDATA\Spotify\Apps\xpui.zip
}
<#
# Удаление меню (РЕЗЕРВНЫЙ)
$file_css = Get-Content $env:APPDATA\Spotify\Apps\temporary\xpui.css -Raw
@@ -205,10 +217,12 @@ If (!($file_css -match 'patched by spotx')) {
}
#>
Rename-Item -path $env:APPDATA\Spotify\Apps\xpui.zip -NewName $env:APPDATA\Spotify\Apps\xpui.spa
Remove-item $env:APPDATA\Spotify\Apps\temporary -Recurse
# Shortcut bug
$ErrorActionPreference = 'SilentlyContinue'
@@ -227,7 +241,6 @@ If (!(Test-Path $env:USERPROFILE\Desktop\Spotify.lnk)) {
# Block updates
$ErrorActionPreference = 'SilentlyContinue' # Команда гасит легкие ошибки
@@ -375,7 +388,6 @@ if ($ch -eq 'y') {
$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 = "$env:USERPROFILE\Desktop\Spotify.lnk"
@@ -388,9 +400,6 @@ if ($ch -eq 'y') {
$Shortcut2.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$") {
@@ -468,9 +477,6 @@ if ($ch -eq 'u') {
If (!($test_cache_spotify_ps -and $test_spotify_vbs)) {
Write-Host "Oops, no cache clearing script found"
Write-Host "Installation completed" -ForegroundColor Green