mirror of
https://github.com/OpenFusionProject/Client.git
synced 2024-11-22 13:40:06 +00:00
Migration server list patching
This commit is contained in:
parent
451cb4a2af
commit
37699e38f8
42
index.js
42
index.js
@ -30,24 +30,52 @@ var serversPath = path.join(userData, "servers.json");
|
||||
var versionsPath = path.join(userData, "versions.json");
|
||||
var hashPath = path.join(userData, "hashes.json");
|
||||
|
||||
function initialSetup(firstTime) {
|
||||
if (!firstTime) {
|
||||
// Migration from pre-1.6
|
||||
// Back everything up, just in case
|
||||
if (fs.existsSync(configPath))
|
||||
fs.copySync(configPath, configPath + ".bak");
|
||||
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");
|
||||
} else {
|
||||
}
|
||||
|
||||
function updateDefaults() {
|
||||
let current = fs.readJsonSync(serversPath);
|
||||
let newDefaults = fs.readJsonSync(
|
||||
path.join(__dirname, "/defaults/servers.json")
|
||||
);
|
||||
for (let i = 0; i < newDefaults["servers"].length; i++) {
|
||||
const newDefault = newDefaults["servers"][i];
|
||||
let found = false;
|
||||
for (let j = 0; j < current["servers"].length; j++) {
|
||||
let 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
|
||||
// Copy default servers
|
||||
fs.copySync(
|
||||
path.join(__dirname, "/defaults/servers.json"),
|
||||
serversPath
|
||||
);
|
||||
} else if (fs.existsSync(serversPath)) {
|
||||
// Migration
|
||||
// Update default servers by replacing their entries
|
||||
updateDefaults();
|
||||
}
|
||||
|
||||
// Copy default versions and config
|
||||
|
Loading…
Reference in New Issue
Block a user