Add XML parser

This commit is contained in:
C-3PO 2018-06-23 20:20:03 +02:00
parent 2d55189248
commit f01a880ae6
Signed by: c3po
GPG key ID: 62993C4BB4D86F24
4 changed files with 23 additions and 4 deletions

13
package-lock.json generated
View file

@ -8,6 +8,19 @@
"resolved": "https://registry.npmjs.org/@types/node/-/node-10.3.4.tgz",
"integrity": "sha512-YMLlzdeNnAyLrQew39IFRkMacAR5BqKGIEei9ZjdHsIZtv+ZWKYTu1i7QJhetxQ9ReXx8w5f+cixdHZG3zgMQA==",
"dev": true
},
"sax": {
"version": "1.2.4",
"resolved": "https://registry.npmjs.org/sax/-/sax-1.2.4.tgz",
"integrity": "sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw=="
},
"xml-js": {
"version": "1.6.4",
"resolved": "https://registry.npmjs.org/xml-js/-/xml-js-1.6.4.tgz",
"integrity": "sha512-ZJ4DPgx97LzSdZ0NAbd0J5gWeSgWTpL2hIH1j1bOmk6QMyppee0S+vQAv/H+oYY1923kck5msPWOuSs0BDUh/w==",
"requires": {
"sax": "^1.2.4"
}
}
}
}

View file

@ -7,5 +7,8 @@
},
"devDependencies": {
"@types/node": "^10.3.4"
},
"dependencies": {
"xml-js": "^1.6.4"
}
}

View file

@ -4,8 +4,8 @@ import getSolidpkg from './ssn/getSolidpkg';
(async () => {
//----- PATCHMANIFEST -----
//.patchmanifest files contain a single XML file called "manifest.xml"
//const patchmanifestXml = await getPatchmanifest('assets_swtor_de_de');
//console.log(patchmanifestXml);
const patchmanifestJson = await getPatchmanifest('assets_swtor_de_de');
console.log(patchmanifestJson);
//----- SOLIDPKG -----
//.solidpkg files contain a single Bencode file called "metafile.solid"

View file

@ -1,4 +1,5 @@
import { TextDecoder } from 'util';
import * as xmlJs from 'xml-js';
import getUrlContents from '../cdn/getUrlContents';
import { Product } from '../interfaces/ISettings';
import verifyProductName from '../ssn/verifyProductName';
@ -7,7 +8,7 @@ import readSsnFile from './readSsnFile';
const Decoder = new TextDecoder('utf-8');
export default async function getPatchmanifest(product: Product): Promise<string> {
export default async function getPatchmanifest(product: Product): Promise<any> {
//Verify function arguments
if (!verifyProductName(product)) {
throw new Error(`"${product}" is not a valid product.`);
@ -32,5 +33,7 @@ export default async function getPatchmanifest(product: Product): Promise<string
const patchmanifestFile = await extractFile(firstFile, [new DataView(ssnFile)]);
const patchmanifestXml = Decoder.decode(patchmanifestFile);
return patchmanifestXml;
const patchManifestJson = xmlJs.xml2js(patchmanifestXml);
return patchManifestJson;
}