Skip to content

Instantly share code, notes, and snippets.

@mkg20001
Last active August 24, 2017 13:21
Show Gist options
  • Save mkg20001/5c22119dfc5382029afefcfea1dc244c to your computer and use it in GitHub Desktop.
Save mkg20001/5c22119dfc5382029afefcfea1dc244c to your computer and use it in GitHub Desktop.
Steam Appmanifest Parser
const fs = require("fs")
module.exports = AppManifestParser
function isNumeric(n) {
return !isNaN(parseFloat(n)) && isFinite(n);
}
function recInt(obj) { //replace numeric strings with integers
for (var p in obj)
if (typeof obj[p] == "object") obj[p] = recInt(obj[p]);
else if (typeof obj[p] == "string" && isNumeric(obj[p])) obj[p] = parseInt(obj[p], 10)
return obj
}
function AppManifestParser(file) { // to be honest that code looks complicated.
// but it's basically a drm-workaround so I guess it has to
let c = fs.readFileSync(file).toString()
c = c.split("\n").filter(e => !!e).map(line => line.replace(/^\t*/g, "").replace(/\t\t/g, ":")).map(line => {
if (line.indexOf("}") != -1 || line.indexOf("{") != -1) return line
if (line.indexOf(":") != -1) return line + ","
else return line + ":"
})
c = "{" + c.join("").replace(/,\}/g, "}").replace(/\}\"/g, "},\"") + "}"
return recInt(JSON.parse(c))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment