mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-25 08:23: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
+37
-29
+37
-29
@@ -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 splitData = data.split(/\r?\n/);
|
let final = [];
|
||||||
// split on newlines
|
let splitData = data.split(/\r?\n/);
|
||||||
let filtered = splitData.filter((value) => !(value[0] === "#")).filter((a) => a);
|
// split on newlines
|
||||||
// the last filter removes empty elements left by the first. Not done on one line due to readability.
|
let filtered = splitData.filter((value) => !(value[0] === "#")).filter((a) => a);
|
||||||
let final = [];
|
// the last filter removes empty elements left by the first. Not done on one line due to readability.
|
||||||
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();
|
||||||
// trim whitespace and put in final array for processing
|
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
|
||||||
}
|
}
|
||||||
for (let element in final) {
|
}
|
||||||
if (element in final) {
|
print("final", final);
|
||||||
libLink.messages.setMasterConfigField.send(control, {
|
for (let element in final) {
|
||||||
field: element,
|
if (element in final) {
|
||||||
value: final[element],
|
print("parsing", element, final[element], ":", typeof final[element]);
|
||||||
});
|
await libLink.messages.setMasterConfigField.send(control, {
|
||||||
}
|
field: element,
|
||||||
|
value: final[element],
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
}
|
emmiter.emit("dot_on_done");
|
||||||
editorSpawn.once("exit", (exit) => {
|
|
||||||
print("once");
|
|
||||||
readTmpFile(control);
|
|
||||||
});
|
});
|
||||||
|
await events.once(emmiter, "dot_on_done");
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user