Fix irregular Steam cache entries

This commit is contained in:
mtkennerly 2022-05-31 19:55:47 +08:00
parent 086520b791
commit dae2cd5695
No known key found for this signature in database
GPG key ID: E764BE00BE6E6408
5 changed files with 2005 additions and 7292 deletions

File diff suppressed because it is too large Load diff

1685
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -27,7 +27,7 @@
"minimist": "^1.2.5", "minimist": "^1.2.5",
"moment": "^2.27.0", "moment": "^2.27.0",
"nodemw": "^0.13.0", "nodemw": "^0.13.0",
"steam-user": "^4.16.2", "steam-user": "^4.24.3",
"wikiapi": "^1.10.0" "wikiapi": "^1.10.0"
} }
} }

View file

@ -78,7 +78,9 @@ async function main() {
if (args.steam) { if (args.steam) {
await steamCache.refresh( await steamCache.refresh(
{ {
all: args.all,
skipUntil: args.skipUntil, skipUntil: args.skipUntil,
irregularUntagged: args.irregularPathUntagged,
}, },
args.limit ?? 25, args.limit ?? 25,
); );

View file

@ -6,7 +6,8 @@ type SteamGameCache = {
installDir?: string, installDir?: string,
unknown?: boolean, unknown?: boolean,
nameLocalized?: Map<string, string>; nameLocalized?: Map<string, string>;
launch?: object; launch?: Array<object>;
irregular?: boolean;
}; };
}; };
@ -18,6 +19,14 @@ export class SteamGameCacheFile extends YamlFile<SteamGameCache> {
super(); super();
} }
hasIrregularKeys(info: object): boolean {
return Object.keys(info).some(x => x.endsWith('"'));
}
isIrregularString(info: string): boolean {
return info.includes('"\n\t');
}
async getAppInfo(appId: number, update: boolean = false): Promise<SteamGameCache[""] | undefined> { async getAppInfo(appId: number, update: boolean = false): Promise<SteamGameCache[""] | undefined> {
const key = appId.toString(); const key = appId.toString();
if (!update && this.data.hasOwnProperty(key)) { if (!update && this.data.hasOwnProperty(key)) {
@ -34,7 +43,7 @@ export class SteamGameCacheFile extends YamlFile<SteamGameCache> {
this.data[key] = {}; this.data[key] = {};
const installDir = info.apps[key].appinfo.config?.installdir; const installDir = info.apps[key].appinfo.config?.installdir;
if (installDir !== undefined) { if (installDir !== undefined && !this.isIrregularString(installDir)) {
this.data[key].installDir = installDir; this.data[key].installDir = installDir;
} }
@ -46,13 +55,19 @@ export class SteamGameCacheFile extends YamlFile<SteamGameCache> {
const launch = info.apps[key].appinfo.config?.launch; const launch = info.apps[key].appinfo.config?.launch;
if (launch !== undefined) { if (launch !== undefined) {
const keys = Object.keys(launch).sort((x, y) => parseInt(x) - parseInt(y)); const keys = Object.keys(launch).sort((x, y) => parseInt(x) - parseInt(y));
this.data[key].launch = keys.map(x => launch[x]); const launchArray = keys.map(x => launch[x]);
if (launchArray.every(x => !this.hasIrregularKeys(x))) {
// Avoid: https://github.com/DoctorMcKay/node-steam-user/issues/397
this.data[key].launch = launchArray;
} else {
this.data[key].irregular = true;
}
} }
return this.data[key]; return this.data[key];
} }
async refresh(filter: {skipUntil: string | undefined}, limit: number): Promise<void> { async refresh(filter: {all: boolean, skipUntil: string | undefined, irregularUntagged: boolean}, limit: number): Promise<void> {
let i = 0; let i = 0;
let foundSkipUntil = false; let foundSkipUntil = false;
for (const appId of Object.keys(this.data)) { for (const appId of Object.keys(this.data)) {
@ -64,6 +79,24 @@ export class SteamGameCacheFile extends YamlFile<SteamGameCache> {
} }
} }
let check = false;
if (filter.all) {
check = true;
}
if (
filter.irregularUntagged &&
!this.data[appId].irregular &&
(
(this.data[appId].launch ?? []).some(x => this.hasIrregularKeys(x)) ||
this.isIrregularString(this.data[appId].installDir ?? "")
)
) {
check = true;
}
if (!check) {
continue;
}
console.log(`Refreshing Steam app ${appId}`) console.log(`Refreshing Steam app ${appId}`)
await this.getAppInfo(parseInt(appId), true); await this.getAppInfo(parseInt(appId), true);