Fix handling for irregular paths, P vs Path template invocation, and variadic uses of P template

This commit is contained in:
mtkennerly 2020-07-15 21:21:57 -04:00
parent 1c1ed6c525
commit 9b87fb9356
5 changed files with 143 additions and 67 deletions

View file

@ -1620,7 +1620,7 @@ A Rite from the Stars:
id: 792370
A Robot Named Fight!:
files:
'<home>/.config/unity3d/Matt Bitner/A Robot Named Fight/<ref>{{Refurl|url=https://steamcommunity.com/app/603530/discussions/1/1473096694440794319/#c3377008022026160641/|title=Where is my save file? :: A Robot Named Fight Bug Reporting|date=2019-05-28}}</ref>':
<home>/.config/unity3d/Matt Bitner/A Robot Named Fight:
tags:
- save
when:
@ -2522,7 +2522,12 @@ AI War 2:
id: 438020
'AI: The Somnium Files':
files:
'<winLocalAppData>/SpikeChunsoft/AI The Somnium Files/PSYNCAUTOSAVE<br/><winLocalAppData>/SpikeChunsoft/AI The Somnium Files/PSYNCDEF{{code|XX}}':
<winLocalAppData>/SpikeChunsoft/AI The Somnium Files/PSYNCAUTOSAVE:
tags:
- save
when:
- os: windows
<winLocalAppData>/SpikeChunsoft/AI The Somnium Files/PSYNCDEF*:
tags:
- save
when:
@ -2534,6 +2539,10 @@ AI War 2:
- os: windows
installDir:
AI The Somnium Files: {}
registry:
HKEY_CURRENT_USER/Software/SpikeChunsoft/AI_TheSomniumFiles:
tags:
- config
steam:
id: 948740
AIDS Simulator:
@ -96936,7 +96945,7 @@ Graveyard Keeper:
- save
when:
- os: mac
'<home>/Library/Preferences/{{file|unity.Lazy Bear Games.Graveyard Keeper.plist}}':
<home>/Library/Preferences/unity.Lazy Bear Games.Graveyard Keeper.plist:
tags:
- config
when:
@ -104793,13 +104802,9 @@ Her Story:
when:
- os: windows
<home>/Library/Application Support/unity.Sam Barlow.HerStory:
tags:
- save
when:
- os: mac
'<home>/Library/Application Support/unity.Sam Barlow.HerStory/{{cn|Windows path was for save only, is this legit OS X versions config path?|date=January 15, 2016}}':
tags:
- config
- save
when:
- os: mac
installDir:

View file

@ -1653,6 +1653,7 @@ A Rite from the Stars:
pageId: 103285
revId: 841573
A Robot Named Fight!:
irregularPath: true
pageId: 66273
revId: 934101
A Roll-Back Story:
@ -2109,8 +2110,9 @@ AI War 2:
pageId: 44800
revId: 841706
'AI: The Somnium Files':
irregularPath: true
pageId: 132809
revId: 963156
revId: 983332
AIDS Simulator:
pageId: 96877
revId: 841708
@ -47163,7 +47165,7 @@ Graveyard Defender:
revId: 839908
Graveyard Keeper:
pageId: 58471
revId: 962811
revId: 983342
Graveyard Shift:
pageId: 51951
revId: 855328
@ -50952,6 +50954,7 @@ Her Majesty's Ship:
pageId: 88894
revId: 887258
Her Story:
irregularPath: true
pageId: 26295
revId: 975631
Her War:

View file

@ -15,6 +15,7 @@ interface Cli {
unchecked?: boolean,
unsupportedOs?: boolean,
unsupportedPath?: boolean,
irregularPath?: boolean,
tooBroad?: boolean,
tooBroadUntagged?: boolean,
game?: string,
@ -61,6 +62,7 @@ async function main() {
unsupportedPath: args.unsupportedPath ?? false,
tooBroad: args.tooBroad ?? false,
tooBroadUntagged: args.tooBroadUntagged ?? false,
irregularPath: args.irregularPath ?? false,
game: args.game,
recent: args.recent,
},

View file

@ -51,6 +51,7 @@ export class ManifestFile extends YamlFile<Manifest> {
unchecked: boolean,
unsupportedOs: boolean,
unsupportedPath: boolean,
irregularPath: boolean,
tooBroad: boolean,
tooBroadUntagged: boolean,
game: string | undefined,
@ -80,6 +81,9 @@ export class ManifestFile extends YamlFile<Manifest> {
if (filter.unsupportedPath && info.unsupportedPath) {
check = true;
}
if (filter.irregularPath && (wikiCache[title].irregularPath || Object.keys(this.data[title]?.files ?? []).some(x => x.includes("{{") || x.includes("</") || x.includes("<br>") || x.includes("<br/>")))) {
check = true;
}
if (filter.game === title) {
check = true;
}

View file

@ -15,6 +15,7 @@ export type WikiGameCache = {
tooBroad?: boolean,
recentlyChanged?: boolean,
renamedFrom?: Array<string>,
irregularPath?: boolean,
};
};
@ -176,7 +177,7 @@ const PATH_ARGS: { [arg: string]: { mapped: string, when?: Constraint, registry?
}
function makePathArgRegex(arg: string): RegExp {
const escaped = `{{P|${arg}}}`
const escaped = `{{P(ath)?|${arg}}}`
.replace("\\", "\\\\")
.replace("|", "\\|")
.replace("{", "\\{")
@ -184,6 +185,48 @@ function makePathArgRegex(arg: string): RegExp {
return new RegExp(escaped, "gi");
}
// Examples:
// [ [["p"], "linuxhome"], ".config" ]
// [ [["cn"], "Is this right?", "date=January 1, 2000"] ]
type PathSegment = string | [[string], ...Array<string>];
function stringifyPathSegment(segment: PathSegment): [string, boolean] {
if (typeof segment === "string") {
return [segment, true];
}
const templateName = segment[0][0];
switch (templateName.toLowerCase()) {
case "p":
case "path":
return [`{{${templateName}|${segment[1]}}}`, true];
case "code":
case "file":
return ["*", false];
case "localizedpath":
return [segment[1], false];
default:
return ["", false];
}
}
function getRawPathFromCell(cell: string | Array<PathSegment> | undefined): [string | undefined, boolean] {
let regular = true;
if (cell === undefined) {
return [undefined, regular];
} else if (typeof cell === "string") {
return [cell.replace(/<ref>.*?<\ref>/, ""), regular];
} else {
return [cell.map(x => {
const [stringified, segmentRegular] = stringifyPathSegment(x);
if (!segmentRegular) {
regular = false;
}
return stringified;
}).join("").replace(/<ref>.*?<\ref>/, ""), regular];
}
}
/**
* https://www.pcgamingwiki.com/wiki/Template:Path
*/
@ -401,6 +444,7 @@ export async function getGame(pageTitle: string, cache: WikiGameCache): Promise<
let unsupportedOs = 0;
let unsupportedPath = 0;
let tooBroad = 0;
let irregularPath = 0;
page.parse().each("template", template => {
if (template.name === "Infobox game") {
const steamId = Number(template.parameters["steam appid"]);
@ -408,15 +452,26 @@ export async function getGame(pageTitle: string, cache: WikiGameCache): Promise<
game.steam = { id: steamId };
}
} else if (template.name === "Game data/saves" || template.name === "Game data/config") {
const rawPath = typeof template.parameters[2] === "string" ? template.parameters[2] : template.parameters[2]?.toString();
if (rawPath === undefined || rawPath.length === 0) {
return;
for (const cellKey of Object.getOwnPropertyNames(template.parameters)) {
if (cellKey === "0" || cellKey === "1") {
continue;
}
const cell = template.parameters[cellKey];
const [rawPath, regular] = getRawPathFromCell(cell);
if (!regular) {
irregularPath += 1;
}
if (rawPath === undefined || rawPath.length === 0) {
continue;
}
try {
const [path, pathType] = parsePath(rawPath);
if (pathIsTooBroad(path)) {
tooBroad += 1;
return;
continue;
}
if (pathType === PathType.FileSystem) {
const constraint = getConstraintFromSystem(template.parameters[1], rawPath);
@ -466,12 +521,13 @@ export async function getGame(pageTitle: string, cache: WikiGameCache): Promise<
if (e instanceof UnsupportedOsError) {
unsupportedOs += 1;
return;
continue;
} else if (e instanceof UnsupportedPathError) {
unsupportedPath += 1;
return;
continue;
} else {
return;
continue;
}
}
}
}
@ -521,6 +577,12 @@ export async function getGame(pageTitle: string, cache: WikiGameCache): Promise<
delete cache[pageTitle].tooBroad;
}
if (irregularPath > 0) {
cache[pageTitle].irregularPath = true;
} else {
delete cache[pageTitle].irregularPath;
}
cache[pageTitle].revId = page.revisions?.[0]?.revid ?? 0;
return game;
}