Add 'name_localized' and 'launch' to Steam cache (part 1)
This commit is contained in:
parent
1fe83ec8c5
commit
dd63a8248f
5 changed files with 138861 additions and 280 deletions
139027
data/steam-game-cache.yaml
139027
data/steam-game-cache.yaml
File diff suppressed because it is too large
Load diff
|
@ -11,7 +11,8 @@
|
|||
"schema": "npm run schema:normal && npm run schema:strict",
|
||||
"schema:normal": "ajv validate -s ./data/schema.yaml -d ./data/manifest.yaml",
|
||||
"schema:strict": "ajv validate -s ./data/schema.strict.yaml -d ./data/manifest.yaml",
|
||||
"stats": "ts-node ./src/bin.ts --stats"
|
||||
"stats": "ts-node ./src/bin.ts --stats",
|
||||
"steam": "ts-node ./src/bin.ts --steam"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/js-yaml": "^3.12.4",
|
||||
|
|
16
src/bin.ts
16
src/bin.ts
|
@ -23,6 +23,7 @@ interface Cli {
|
|||
skipUntil?: string,
|
||||
recent?: boolean,
|
||||
limit?: number,
|
||||
steam?: boolean,
|
||||
}
|
||||
|
||||
async function main() {
|
||||
|
@ -41,7 +42,11 @@ async function main() {
|
|||
"irregularPathUntagged",
|
||||
"tooBroad",
|
||||
"tooBroadUntagged",
|
||||
]
|
||||
"steam",
|
||||
],
|
||||
string: [
|
||||
"skipUntil",
|
||||
],
|
||||
});
|
||||
|
||||
const wikiCache = new WikiGameCacheFile();
|
||||
|
@ -70,6 +75,15 @@ async function main() {
|
|||
}
|
||||
}
|
||||
|
||||
if (args.steam) {
|
||||
await steamCache.refresh(
|
||||
{
|
||||
skipUntil: args.skipUntil,
|
||||
},
|
||||
args.limit ?? 25,
|
||||
);
|
||||
}
|
||||
|
||||
if (args.manifest) {
|
||||
await manifest.updateGames(
|
||||
wikiCache.data,
|
||||
|
|
|
@ -148,12 +148,12 @@ export class ManifestFile extends YamlFile<Manifest> {
|
|||
continue;
|
||||
}
|
||||
if (game.steam?.id !== undefined) {
|
||||
const installDir = await steamCache.getAppInstallDir(game.steam.id);
|
||||
if (installDir !== undefined) {
|
||||
const appInfo = await steamCache.getAppInfo(game.steam.id);
|
||||
if (appInfo.installDir !== undefined) {
|
||||
if (game.installDir === undefined) {
|
||||
game.installDir = {}
|
||||
}
|
||||
game.installDir[installDir] = {}
|
||||
game.installDir[appInfo.installDir] = {}
|
||||
}
|
||||
}
|
||||
this.data[verifiedTitle] = game;
|
||||
|
|
89
src/steam.ts
89
src/steam.ts
|
@ -1,10 +1,12 @@
|
|||
import { REPO, YamlFile } from ".";
|
||||
import { DELAY_BETWEEN_GAMES_MS, REPO, YamlFile } from ".";
|
||||
import * as SteamUser from "steam-user";
|
||||
|
||||
type SteamGameCache = {
|
||||
[appId: string]: {
|
||||
installDir?: string,
|
||||
unknown?: boolean,
|
||||
nameLocalized?: Map<string, string>;
|
||||
launch?: object;
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -16,25 +18,68 @@ export class SteamGameCacheFile extends YamlFile<SteamGameCache> {
|
|||
super();
|
||||
}
|
||||
|
||||
async getAppInstallDir(appId: number): Promise<string | undefined> {
|
||||
async getAppInfo(appId: number, update: boolean = false): Promise<SteamGameCache[""] | undefined> {
|
||||
const key = appId.toString();
|
||||
if (this.data.hasOwnProperty(key)) {
|
||||
return this.data[key].installDir;
|
||||
} else {
|
||||
const info: SteamProductInfoResponse = await this.steamClient.getProductInfo([appId], []);
|
||||
if (!update && this.data.hasOwnProperty(key)) {
|
||||
return this.data[key];
|
||||
}
|
||||
|
||||
if (info.unknownApps.includes(appId)) {
|
||||
this.data[key] = { unknown: true };
|
||||
return undefined;
|
||||
const info: SteamProductInfoResponse = await this.steamClient.getProductInfo([appId], []);
|
||||
|
||||
if (info.unknownApps.includes(appId)) {
|
||||
this.data[key] = { unknown: true };
|
||||
return undefined;
|
||||
}
|
||||
|
||||
this.data[key] = {};
|
||||
|
||||
const installDir = info.apps[key].appinfo.config?.installdir;
|
||||
if (installDir !== undefined) {
|
||||
this.data[key].installDir = installDir;
|
||||
}
|
||||
|
||||
const nameLocalized = info.apps[key].appinfo.common?.name_localized;
|
||||
if (nameLocalized !== undefined && Object.keys(nameLocalized).length > 0) {
|
||||
this.data[key].nameLocalized = nameLocalized;
|
||||
}
|
||||
|
||||
const launch = info.apps[key].appinfo.config?.launch;
|
||||
if (launch !== undefined) {
|
||||
const keys = Object.keys(launch).sort((x, y) => parseInt(x) - parseInt(y));
|
||||
this.data[key].launch = keys.map(x => launch[x]);
|
||||
}
|
||||
|
||||
return this.data[key];
|
||||
}
|
||||
|
||||
async refresh(filter: {skipUntil: string | undefined}, limit: number): Promise<void> {
|
||||
let i = 0;
|
||||
let foundSkipUntil = false;
|
||||
for (const appId of Object.keys(this.data)) {
|
||||
if (filter.skipUntil && !foundSkipUntil) {
|
||||
if (appId === filter.skipUntil) {
|
||||
foundSkipUntil = true;
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
const installDir = info.apps[key].appinfo.config?.installdir;
|
||||
if (installDir !== undefined) {
|
||||
this.data[key] = { installDir };
|
||||
} else {
|
||||
this.data[key] = {};
|
||||
console.log(`Refreshing Steam app ${appId}`)
|
||||
await this.getAppInfo(parseInt(appId), true);
|
||||
|
||||
i++;
|
||||
if (limit > 0 && i >= limit) {
|
||||
break;
|
||||
}
|
||||
return installDir;
|
||||
|
||||
// main() will save at the end, but we do a period save as well
|
||||
// in case something goes wrong or the script gets cancelled:
|
||||
if (i % 250 === 0) {
|
||||
this.save();
|
||||
console.log(":: saved");
|
||||
}
|
||||
|
||||
await new Promise(resolve => setTimeout(resolve, DELAY_BETWEEN_GAMES_MS));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -43,11 +88,15 @@ interface SteamProductInfoResponse {
|
|||
apps: {
|
||||
[appId: string]: {
|
||||
appinfo: {
|
||||
common?: {
|
||||
name_localized?: Map<string, string>,
|
||||
},
|
||||
config?: {
|
||||
installdir?: string
|
||||
}
|
||||
}
|
||||
}
|
||||
installdir?: string,
|
||||
launch?: object,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
unknownApps: Array<number>,
|
||||
}
|
||||
|
@ -55,7 +104,7 @@ interface SteamProductInfoResponse {
|
|||
export async function getSteamClient(): Promise<SteamUser> {
|
||||
const client = new SteamUser();
|
||||
client.logOn();
|
||||
await new Promise(resolve => {
|
||||
await new Promise<void>(resolve => {
|
||||
client.on("loggedOn", () => {
|
||||
resolve();
|
||||
});
|
||||
|
|
Reference in a new issue