Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load additional configs specified in commandline.txt #57

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 37 additions & 10 deletions src/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {queryConfigPath, queryModels} from './compiler';
import * as vscode from 'vscode';
import * as fs from 'fs';
const xml2js = require('xml2js');
const readline = require('readline');

export interface Argument {
type: string;
Expand Down Expand Up @@ -148,6 +149,28 @@ export class GTA3ScriptController {
});
}

private async loadAdditionalConfigs(configpath: string): Promise<Array<string>> {
const rl = readline.createInterface({
input: fs.createReadStream(`${configpath}/commandline.txt`),
crlfDelay: Infinity
});
const addConfigs = new Array<string>();

try {
for await (const line of rl) {
const arg = line.split("=");

if (arg.length == 2 && arg[0].trim() === "--add-config") {
addConfigs.push(arg[1].trim());
}
}
} catch (err) {
return Promise.resolve([]);
}

return addConfigs;
}

private loadConfigPath(configpath: string): Promise<ConfigData> {
let promiseList = [];

Expand All @@ -165,21 +188,25 @@ export class GTA3ScriptController {
});
};

promiseList.push(tryParsingConfigFile("../gta3sc.xml"));
promiseList.push(tryParsingConfigFile("alternators.xml"));
promiseList.push(tryParsingConfigFile("commands.xml"));
promiseList.push(tryParsingConfigFile("constants.xml"));
promiseList.push(tryParsingConfigFile("cleo.xml"));

return Promise.all(promiseList).then(cfgList => {
let allCommands = cfgList.map(c => c.commands);
let allAlternators = cfgList.map(c => c.alternators);
let allEnums = cfgList.map(c => c.enums);

return { // ConfigData
commands: Object.assign({}, ...allCommands),
alternators: Object.assign({}, ...allAlternators),
enums: Object.assign({}, ...allEnums),
};
return this.loadAdditionalConfigs(configpath).then(addConfigs => {
promiseList.push(...addConfigs.map(configFile => tryParsingConfigFile(configFile)));
return Promise.all(promiseList).then(cfgList => {
let allCommands = cfgList.map(c => c.commands);
let allAlternators = cfgList.map(c => c.alternators);
let allEnums = cfgList.map(c => c.enums);

return { // ConfigData
commands: Object.assign({}, ...allCommands),
alternators: Object.assign({}, ...allAlternators),
enums: Object.assign({}, ...allEnums),
};
});
});
}

Expand Down