mirror of
https://github.com/OpenFusionProject/Client.git
synced 2024-11-24 06:11:04 +00:00
Compare commits
No commits in common. "4503c9268ed26f1ffdec40f655e07a0ad91e7377" and "451cb4a2aff20bec028d9ed2c49288d327b318a0" have entirely different histories.
4503c9268e
...
451cb4a2af
79
index.js
79
index.js
@ -30,83 +30,28 @@ 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 backup() {
|
|
||||||
if (fs.existsSync(configPath)) fs.copySync(configPath, configPath + ".bak");
|
|
||||||
if (fs.existsSync(serversPath))
|
|
||||||
fs.copySync(serversPath, serversPath + ".bak");
|
|
||||||
if (fs.existsSync(versionsPath))
|
|
||||||
fs.copySync(versionsPath, versionsPath + ".bak");
|
|
||||||
if (fs.existsSync(hashPath)) fs.copySync(hashPath, hashPath + ".bak");
|
|
||||||
}
|
|
||||||
|
|
||||||
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) {
|
function initialSetup(firstTime) {
|
||||||
backup();
|
if (!firstTime) {
|
||||||
|
// Migration from pre-1.6
|
||||||
if (firstTime) {
|
// Back everything up, just in case
|
||||||
|
if (fs.existsSync(configPath))
|
||||||
|
fs.copySync(configPath, configPath + ".bak");
|
||||||
|
if (fs.existsSync(serversPath))
|
||||||
|
fs.copySync(serversPath, serversPath + ".bak");
|
||||||
|
if (fs.existsSync(versionsPath))
|
||||||
|
fs.copySync(versionsPath, versionsPath + ".bak");
|
||||||
|
if (fs.existsSync(hashPath)) fs.copySync(hashPath, hashPath + ".bak");
|
||||||
|
} else {
|
||||||
// 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