From 4607e00ab4ef4c0fb5d39c2d6b3f27acad9705a7 Mon Sep 17 00:00:00 2001 From: amd64fox <62529699+amd64fox@users.noreply.github.com> Date: Sat, 9 Oct 2021 16:45:49 +0300 Subject: [PATCH] bug fix of the moved desktop folder --- Install.ps1 | 129 ++++++++++++++++++++++++++++------------------------ 1 file changed, 69 insertions(+), 60 deletions(-) diff --git a/Install.ps1 b/Install.ps1 index 00bc3e7..49b66a1 100644 --- a/Install.ps1 +++ b/Install.ps1 @@ -222,6 +222,24 @@ Rename-Item -path $env:APPDATA\Spotify\Apps\xpui.zip -NewName $env:APPDATA\Spoti Remove-item $env:APPDATA\Spotify\Apps\temporary -Recurse +# Если папки по умолчанию Dekstop не существует, то попытаться найти её через реестр. +$ErrorActionPreference = 'SilentlyContinue' + +if (Test-Path "$env:USERPROFILE\Desktop") { + + $desktop_folder = "$env:USERPROFILE\Desktop" + +} + +$regedit_desktop_folder = Get-ItemProperty -Path "Registry::HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders\" +$regedit_desktop = $regedit_desktop_folder.'{754AC886-DF64-4CBA-86B5-F7FBF4FBCEF5}' + +if (!(Test-Path "$env:USERPROFILE\Desktop")) { + $desktop_folder = $regedit_desktop + +} + + # Shortcut bug $ErrorActionPreference = 'SilentlyContinue' @@ -229,7 +247,7 @@ $ErrorActionPreference = 'SilentlyContinue' If (!(Test-Path $env:USERPROFILE\Desktop\Spotify.lnk)) { $source = "$env:APPDATA\Spotify\Spotify.exe" - $target = "$env:USERPROFILE\Desktop\Spotify.lnk" + $target = "$desktop_folder\Spotify.lnk" $WorkingDir = "$env:APPDATA\Spotify" $WshShell = New-Object -comObject WScript.Shell $Shortcut = $WshShell.CreateShortcut($target) @@ -396,87 +414,78 @@ 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 - $desktop_folder = Get-ItemProperty -Path $env:USERPROFILE\Desktop | Select-Object Attributes - - - # Если папки по умолчанию Dekstop не существует, то установку кэша отменить. - if ($desktop_folder -match '\bDirectory\b') { - 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 + + 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") + # 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.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 = "$env:USERPROFILE\Desktop\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() + # 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. + 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$")) { + 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 - } + 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 - } - } + while ($ch -notmatch '^[1-9][0-9]?$|^100$') - else { - Write-Host "Oops, default desktop folder not found, cache clearing installation stopped" + + 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 } + + } @@ -497,7 +506,7 @@ if ($ch -eq 'u') { Remove-item $env:APPDATA\Spotify\Spotify.vbs -Recurse -Force $source3 = "$env:APPDATA\Spotify\Spotify.exe" - $target3 = "$env:USERPROFILE\Desktop\Spotify.lnk" + $target3 = "$desktop_folder\Spotify.lnk" $WorkingDir3 = "$env:APPDATA\Spotify" $WshShell3 = New-Object -comObject WScript.Shell $Shortcut3 = $WshShell3.CreateShortcut($target3)