Last active
October 6, 2023 14:11
-
-
Save roose/a8eb195afcfe1639802baa109b1330e5 to your computer and use it in GitHub Desktop.
Repairing Steam Desktop Icons
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$cdnUrl = "https://cdn.cloudflare.steamstatic.com/steamcommunity/public/images/apps/" | |
$steamFolder = (Get-Item HKCU:\Software\Valve\Steam).GetValue("SteamPath") + "/steam/games/" | |
# $steamFolder = "C:/Program Files (x86)/Steam/steam/games" | |
$desktopPath = [Environment]::GetFolderPath("Desktop") | |
$currentDirectory = $PWD | |
# Check if we have write access to $steamFolder | |
if (Test-Path -Path $steamFolder) { | |
try { | |
$testFile = Join-Path -Path $steamFolder -ChildPath "test.txt" | |
"Write test" | Out-File -FilePath $testFile -Force | |
Remove-Item -Path $testFile -Force | |
} catch { | |
# If we can't write to $steamFolder, request admin rights | |
Start-Process powershell -Verb runAs -ArgumentList "-NoProfile -c cd '$currentDirectory'; .\getsteamicons.ps1" | |
exit | |
} | |
} | |
# Get all .url files | |
$urlFiles = Get-ChildItem -Path $desktopPath -Filter *.url | |
# Walk through all .url files | |
foreach ($urlFile in $urlFiles) { | |
# Read content of .url | |
$urlContent = Get-Content -Path $urlFile.FullName | |
# Create hash table for appID and iconFile | |
$urlData = @{} | |
# if it is steam game link | |
if ($urlContent -match "steam://rungameid") { | |
# Walk through all lines in .url | |
foreach ($line in $urlContent) { | |
if ($line -match '^\s*([^=]+)\s*=\s*(.+)') { | |
$key = $Matches[1].Trim() | |
$value = $Matches[2].Trim() | |
# Extract appID and iconFile | |
if ($key -eq "URL") { | |
$urlData["appID"] = $value.Split("/")[-1] | |
} | |
if ($key -eq "IconFile") { | |
$urlData["iconFile"] = (Split-Path -Path $value -Leaf) | |
} | |
} | |
} | |
$appID = $urlData['appID'] | |
$iconFile = $urlData['iconFile'] | |
Write-Host "Downloading icon for $($urlFile.Name)..." | |
Invoke-WebRequest -Uri "$cdnUrl$appID/$iconFile" -OutFile "$steamFolder/$iconFile" | |
Write-Host "...done." | |
} | |
} | |
Read-Host "Please press Enter to exit" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You may need to run
Set-ExecutionPolicy RemoteSigned
first if it's your first time running a PowerShell script.getsteamicons.ps1
.getsteamicons.ps1
in Explorer.