mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-28 00:47:13 +09:00
Fixed config editing, fixed child spawning, fixed config setting
Using an event emmiter, the fields can now be set correctly in the master config. Null values are now handled correctly, and numbers are also set correctly.
This commit is contained in:
1 parent
bcc25047f2
commit
86de5ae151
1 file changed
+20
-12
+20
-12
@@ -147,7 +147,7 @@ masterConfigCommands.add(new libCommand.Command({
|
|||||||
}
|
}
|
||||||
// use same method as master config list to grab values, with a small modification to add quotes around strings
|
// use same method as master config list to grab values, with a small modification to add quotes around strings
|
||||||
// this could be shorter but the lines would have to be very long, so imo this is better for readability
|
// this could be shorter but the lines would have to be very long, so imo this is better for readability
|
||||||
fs.writeFile(tmpFile, allConfigElements, (err) => {
|
await fs.writeFile(tmpFile, allConfigElements, (err) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
@@ -159,38 +159,46 @@ masterConfigCommands.add(new libCommand.Command({
|
|||||||
editorSpawn.on("data", (data) => {
|
editorSpawn.on("data", (data) => {
|
||||||
process.stdout.pipe(data);
|
process.stdout.pipe(data);
|
||||||
});
|
});
|
||||||
function readTmpFile(c2) {
|
let emmiter = new events.EventEmitter();
|
||||||
fs.readFile(tmpFile, "utf8", (err, data) => {
|
editorSpawn.on("exit", async (exit) => {
|
||||||
if (err) { throw err; }
|
const data = await fs.readFile(tmpFile, "utf8");
|
||||||
|
let final = [];
|
||||||
let splitData = data.split(/\r?\n/);
|
let splitData = data.split(/\r?\n/);
|
||||||
// split on newlines
|
// split on newlines
|
||||||
let filtered = splitData.filter((value) => !(value[0] === "#")).filter((a) => a);
|
let filtered = splitData.filter((value) => !(value[0] === "#")).filter((a) => a);
|
||||||
// the last filter removes empty elements left by the first. Not done on one line due to readability.
|
// the last filter removes empty elements left by the first. Not done on one line due to readability.
|
||||||
let final = [];
|
|
||||||
for (let index in filtered) {
|
for (let index in filtered) {
|
||||||
if (index in filtered) {
|
if (index in filtered) {
|
||||||
filtered[index] = filtered[index].split("=");
|
filtered[index] = filtered[index].split("=");
|
||||||
// split on the = we added eariler
|
// split on the = we added eariler
|
||||||
filtered[index][1] = filtered[index][1].replace(/['"]+/g, "");
|
filtered[index][1] = filtered[index][1].replace(/['"]+/g, "");
|
||||||
// remove quotes we added eariler
|
// remove quotes we added eariler
|
||||||
final[filtered[index][0].trim()] = filtered[index][1].trim();
|
let part = filtered[index][1].trim();
|
||||||
|
let finalIndex = filtered[index][0].trim();
|
||||||
|
if (part === "undefined") {
|
||||||
|
} else if (part === "null") {
|
||||||
|
print("null", part);
|
||||||
|
final[finalIndex] = "";
|
||||||
|
} else {
|
||||||
|
print("string", part);
|
||||||
|
final[finalIndex] = part;
|
||||||
|
}
|
||||||
// trim whitespace and put in final array for processing
|
// trim whitespace and put in final array for processing
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
print("final", final);
|
||||||
for (let element in final) {
|
for (let element in final) {
|
||||||
if (element in final) {
|
if (element in final) {
|
||||||
libLink.messages.setMasterConfigField.send(control, {
|
print("parsing", element, final[element], ":", typeof final[element]);
|
||||||
|
await libLink.messages.setMasterConfigField.send(control, {
|
||||||
field: element,
|
field: element,
|
||||||
value: final[element],
|
value: final[element],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
emmiter.emit("dot_on_done");
|
||||||
});
|
});
|
||||||
}
|
await events.once(emmiter, "dot_on_done");
|
||||||
editorSpawn.once("exit", (exit) => {
|
|
||||||
print("once");
|
|
||||||
readTmpFile(control);
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user