Skip to content

Commit 8956581

Browse files
committed
Delete mods we don't want and download only if needed
1 parent d2fe3b7 commit 8956581

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
#node stuff
22
node_modules/
3-
factorio*
3+
factorio*
4+
clusterio-client*

index.js

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,20 +94,39 @@ ipc.on("launchFactorio", function(event, data){
9494
console.log('Connected!');
9595
console.log('RCON confirmed!');
9696
// download mods
97+
let installedMods = fs.readdirSync("factorio/mods/")
98+
for(let i = 0; i < installedMods.length; i++){
99+
let x = false;
100+
for(let key in data.mods){
101+
if(installedMods[i] == data.mods[key].modName) {
102+
x = true;
103+
}
104+
}
105+
if (!x) {
106+
console.log("Deleting: " + installedMods[i])
107+
fs.unlinkSync("factorio/mods/"+installedMods[i])
108+
}
109+
110+
}
97111
let counter = 0;
98112
for(let key in data.mods) {
99-
console.log(data.mods[key]);
100-
download("http://"+config.get("masterAddress")+"/"+data.mods[key].modName, "factorio/mods/"+data.mods[key].modName, launch(data.mods[key].modName));
113+
if(fs.existsSync("factorio/mods/"+data.mods[key].modName)){
114+
console.log("Installed: " + data.mods[key].modName);
115+
} else {
116+
console.log("Downloading: " + data.mods[key].modName);
117+
download("http://"+config.get("masterAddress")+"/"+data.mods[key].modName, "factorio/mods/"+data.mods[key].modName, launch(data.mods[key].modName));
118+
console.log("Downloaded: " + data.mods[key].modName);
119+
}
101120
}
102121
function launch(modName) {
103122
counter++;
104123
console.log("Downloaded: " + modName);
105124
if(counter == data.mods.length) {
106125
//spawn factorio and tell it to connect to a server directly
107126
console.log("Starting factorio...");
108-
var gameprocess = child_process.spawn("./factorio/bin/x64/factorio", [
127+
/*var gameprocess = child_process.spawn("factorio/bin/x64/factorio", [
109128
"--mp-connect", data.ip+":"+data.port,
110-
]);
129+
]);*/
111130
}
112131
}
113132

0 commit comments

Comments
 (0)