diff --git a/.github/ISSUE_TEMPLATE/installer-translation.md b/.github/ISSUE_TEMPLATE/installer-translation.md index 183fcf1..51cd205 100644 --- a/.github/ISSUE_TEMPLATE/installer-translation.md +++ b/.github/ISSUE_TEMPLATE/installer-translation.md @@ -84,4 +84,6 @@ Good luck to you. UpdateError = "Failed to block updates" NoSpotifyExe = "Could not find Spotify.exe" InstallComplete = "installation completed" + HostDel = "Unwanted URLs found in hosts file, trying to remove them..." + HostError = "Something went wrong while editing the hosts file, edit it manually" ``` diff --git a/Install.ps1 b/Install.ps1 index 0253e7b..92ac73b 100644 --- a/Install.ps1 +++ b/Install.ps1 @@ -209,6 +209,8 @@ function Set-ScriptLanguageStrings { UpdateError = "Failed to block updates" NoSpotifyExe = "Could not find Spotify.exe" InstallComplete = "installation completed" + HostDel = "Unwanted URLs found in hosts file, trying to remove them..." + HostError = "Something went wrong while editing the hosts file, edit it manually" } $langStringsRU = [PSCustomObject]@{ @@ -269,6 +271,8 @@ function Set-ScriptLanguageStrings { UpdateError = "Не удалось заблокировать обновления" NoSpotifyExe = "Spotify.exe не найден" InstallComplete = "Установка завершена" + HostDel = "В файле hosts найдены нежелательные Url-адреса, попытка их удалить..." + HostError = "Что-то пошло не так при редактировании файла hosts, отредактируйте его вручную" } } @@ -552,6 +556,28 @@ if ($win11 -or $win10 -or $win8_1 -or $win8) { } } +# Attempt to fix the hosts file +$pathHosts = "$Env:windir\System32\Drivers\Etc\hosts" +$ErrorActionPreference = 'SilentlyContinue' +$testHosts = Test-Path -Path $pathHosts + +if ($testHosts) { + $hosts = Get-Content -Path $pathHosts + + if ($hosts -match '.+scdn.+' -or $hosts -match '.+spotify.+' ) { + Write-Host ($lang).HostDel`n + + try { + $hosts = $hosts -replace '.+scdn.+', '' -replace '.+spotify.+', '' + Set-Content -Path $pathHosts -Value $hosts -Force + $hosts | Where-Object { $_.trim() -ne "" } | Set-Content -Path $pathHosts -Force + } + catch { + Write-Host ($lang).HostError`n -ForegroundColor Red + } + } +} + # Unique directory name based on time Push-Location -LiteralPath $env:TEMP New-Item -Type Directory -Name "SpotX_Temp-$(Get-Date -UFormat '%Y-%m-%d_%H-%M-%S')" | Convert-Path | Set-Location