Hardened NaN checks, added file read delay for research-sync so factorio has time to finish writing to the file

This commit is contained in:
psihius committed 2018-04-19 23:33:09 +03:00
1 parent ed9b4bbafa
commit 03511fc240
4 files changed
+47 -33

No files matched your search

+17 -11
View File
@@ -476,17 +476,23 @@ function instanceManagement() {
// send file contents to plugin for processing
function fileChangeHandler(eventType, filename) {
if(filename != null){
// get array of lines in file
let stuff = fs.readFileSync(instancedirectory + "/script-output/" + filename, "utf8").split("\n");
// if you found anything, reset the file
if (stuff[0]) {
fs.writeFileSync(instancedirectory + "/script-output/" + filename, "");
}
for(let i = 0; i < stuff.length; i++) {
if(stuff[i] && !stuff[i].includes('\u0000\u0000')) {
plugins[I].scriptOutput(stuff[i]);
}
}
setTimeout(
()=>{
// get array of lines in file
let stuff = fs.readFileSync(instancedirectory + "/script-output/" + filename, "utf8").split("\n");
// if you found anything, reset the file
if (stuff[0]) {
fs.writeFileSync(instancedirectory + "/script-output/" + filename, "");
}
for(let i = 0; i < stuff.length; i++) {
if(stuff[i] && !stuff[i].includes('\u0000\u0000')) {
plugins[I].scriptOutput(stuff[i]);
}
}
},
pluginConfig.fileReadDelay || 0
);
}
}
}