Skip to content

Instantly share code, notes, and snippets.

@FormallyMyles
Created March 19, 2023 12:04
Show Gist options
  • Save FormallyMyles/46673cb34b61691a1835650f7474dbf5 to your computer and use it in GitHub Desktop.
Save FormallyMyles/46673cb34b61691a1835650f7474dbf5 to your computer and use it in GitHub Desktop.
Fix blank steam icons (if you reinstalled steam) on Windows
// Script based on https://github.com/mrsimb/steam_blank_icon_fix
// This version uses the embedded URLs to avoid using steamdb.info (and use the CDN)
// See original repo for usage
const steamIconsPath = "C:/Program Files (x86)/Steam/steam/games";
const searchPath = String(Deno.args[0] || ".");
console.log(`Steam icons path: "${steamIconsPath}"`);
console.log(`Searching shortcuts in: "${searchPath}"\n`);
for await (const entry of Deno.readDir(searchPath)) {
if (!entry.isFile || !entry.name.endsWith(".url")) {
continue;
}
const linkContent = await Deno.readTextFile(entry.name);
const gameId = linkContent.match(/rungameid\/(.+)/m)?.[1];
const hash = linkContent.match(/games\\(.+)/m)?.[1];
console.info("hash: " + hash);
if (!gameId) {
continue;
}
const iconUrl = "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/apps/" + gameId + "/" + hash;
const iconName = iconUrl?.match(/(\w|\d)+.ico/)?.[0];
const hasIconPath = !!linkContent.match(/IconFile=.+/m);
const hasIconFile = iconName &&
await Deno.stat(steamIconsPath + "/" + iconName).catch(() => {});
const status = [!hasIconPath && "unlinked", !hasIconFile && "file missing"]
.filter(Boolean)
.join(", ") || "ok";
if (!hasIconPath) {
const linkContentFixed = linkContent.replace(
/IconFile=$/m,
`IconFile=${steamIconsPath}/${iconName}`,
);
await Deno.writeTextFile(entry.name, linkContentFixed);
}
if (!hasIconFile && iconUrl) {
const iconBuffer = await fetch(iconUrl).then((res) => res.arrayBuffer());
await Deno.writeFile(
steamIconsPath + "/" + iconName,
new Uint8Array(iconBuffer),
);
}
console.group(entry.name);
console.log(gameId, iconName);
console.log(status + "\n");
console.groupEnd();
}
console.log("Done!");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment