mirror of
https://github.com/OpenFusionProject/Client.git
synced 2024-11-14 18:50:04 +00:00
Migration server list patching
This commit is contained in:
parent
451cb4a2af
commit
37699e38f8
50
index.js
50
index.js
@ -30,24 +30,52 @@ 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 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) {
|
function initialSetup(firstTime) {
|
||||||
if (!firstTime) {
|
backup();
|
||||||
// Migration from pre-1.6
|
|
||||||
// Back everything up, just in case
|
if (firstTime) {
|
||||||
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
|
||||||
);
|
);
|
||||||
|
} else if (fs.existsSync(serversPath)) {
|
||||||
|
// Migration
|
||||||
|
// Update default servers by replacing their entries
|
||||||
|
updateDefaults();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy default versions and config
|
// Copy default versions and config
|
||||||
|
Loading…
Reference in New Issue
Block a user