mirror of
https://github.com/OpenFusionProject/Client.git
synced 2024-11-24 06:11:04 +00:00
Compare commits
3 Commits
451cb4a2af
...
4503c9268e
Author | SHA1 | Date | |
---|---|---|---|
4503c9268e | |||
947c231b12 | |||
37699e38f8 |
71
index.js
71
index.js
@ -30,28 +30,83 @@ var serversPath = path.join(userData, "servers.json");
|
|||||||
var versionsPath = path.join(userData, "versions.json");
|
var versionsPath = path.join(userData, "versions.json");
|
||||||
var hashPath = path.join(userData, "hashes.json");
|
var hashPath = path.join(userData, "hashes.json");
|
||||||
|
|
||||||
function initialSetup(firstTime) {
|
function backup() {
|
||||||
if (!firstTime) {
|
if (fs.existsSync(configPath)) fs.copySync(configPath, configPath + ".bak");
|
||||||
// Migration from pre-1.6
|
|
||||||
// Back everything up, just in case
|
|
||||||
if (fs.existsSync(configPath))
|
|
||||||
fs.copySync(configPath, configPath + ".bak");
|
|
||||||
if (fs.existsSync(serversPath))
|
if (fs.existsSync(serversPath))
|
||||||
fs.copySync(serversPath, serversPath + ".bak");
|
fs.copySync(serversPath, serversPath + ".bak");
|
||||||
if (fs.existsSync(versionsPath))
|
if (fs.existsSync(versionsPath))
|
||||||
fs.copySync(versionsPath, versionsPath + ".bak");
|
fs.copySync(versionsPath, versionsPath + ".bak");
|
||||||
if (fs.existsSync(hashPath)) fs.copySync(hashPath, hashPath + ".bak");
|
if (fs.existsSync(hashPath)) fs.copySync(hashPath, hashPath + ".bak");
|
||||||
} else {
|
}
|
||||||
|
|
||||||
|
function patchVersions() {
|
||||||
|
var current = fs.readJsonSync(versionsPath);
|
||||||
|
var newDefaults = fs.readJsonSync(
|
||||||
|
path.join(__dirname, "/defaults/versions.json")
|
||||||
|
);
|
||||||
|
for (var i = 0; i < newDefaults["versions"].length; i++) {
|
||||||
|
var newDefault = newDefaults["versions"][i];
|
||||||
|
var found = false;
|
||||||
|
for (var j = 0; j < current["versions"].length; j++) {
|
||||||
|
var version = current["versions"][j];
|
||||||
|
if (newDefault["name"] === version["name"]) {
|
||||||
|
current["versions"][j] = newDefault;
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!found) {
|
||||||
|
current["versions"].push(newDefault);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fs.writeFileSync(versionsPath, JSON.stringify(current, null, 4));
|
||||||
|
}
|
||||||
|
|
||||||
|
function patchServers() {
|
||||||
|
var current = fs.readJsonSync(serversPath);
|
||||||
|
var newDefaults = fs.readJsonSync(
|
||||||
|
path.join(__dirname, "/defaults/servers.json")
|
||||||
|
);
|
||||||
|
for (var i = 0; i < newDefaults["servers"].length; i++) {
|
||||||
|
var newDefault = newDefaults["servers"][i];
|
||||||
|
var found = false;
|
||||||
|
for (var j = 0; j < current["servers"].length; j++) {
|
||||||
|
var server = current["servers"][j];
|
||||||
|
if (newDefault["uuid"] === server["uuid"]) {
|
||||||
|
current["servers"][j] = newDefault;
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!found) {
|
||||||
|
current["servers"].push(newDefault);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fs.writeFileSync(serversPath, JSON.stringify(current, null, 4));
|
||||||
|
}
|
||||||
|
|
||||||
|
function initialSetup(firstTime) {
|
||||||
|
backup();
|
||||||
|
|
||||||
|
if (firstTime) {
|
||||||
// First-time setup
|
// First-time setup
|
||||||
// Copy default servers
|
// Copy default servers
|
||||||
fs.copySync(
|
fs.copySync(
|
||||||
path.join(__dirname, "/defaults/servers.json"),
|
path.join(__dirname, "/defaults/servers.json"),
|
||||||
serversPath
|
serversPath
|
||||||
);
|
);
|
||||||
|
fs.copySync(
|
||||||
|
path.join(__dirname, "/defaults/versions.json"),
|
||||||
|
versionsPath
|
||||||
|
);
|
||||||
|
} else if (fs.existsSync(serversPath)) {
|
||||||
|
// Migration
|
||||||
|
// Update default servers and versions
|
||||||
|
patchVersions();
|
||||||
|
patchServers();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy default versions and config
|
// Copy default versions and config
|
||||||
fs.copySync(path.join(__dirname, "/defaults/versions.json"), versionsPath);
|
|
||||||
fs.copySync(path.join(__dirname, "/defaults/config.json"), configPath);
|
fs.copySync(path.join(__dirname, "/defaults/config.json"), configPath);
|
||||||
fs.copySync(path.join(__dirname, "/defaults/hashes.json"), hashPath);
|
fs.copySync(path.join(__dirname, "/defaults/hashes.json"), hashPath);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user