mirror of
https://github.com/OpenFusionProject/Client.git
synced 2024-11-22 05:30:05 +00:00
Migration version list patching
This commit is contained in:
parent
37699e38f8
commit
947c231b12
35
index.js
35
index.js
@ -39,7 +39,30 @@ function backup() {
|
||||
if (fs.existsSync(hashPath)) fs.copySync(hashPath, hashPath + ".bak");
|
||||
}
|
||||
|
||||
function updateDefaults() {
|
||||
function patchVersions() {
|
||||
let current = fs.readJsonSync(versionsPath);
|
||||
let newDefaults = fs.readJsonSync(
|
||||
path.join(__dirname, "/defaults/versions.json")
|
||||
);
|
||||
for (let i = 0; i < newDefaults["versions"].length; i++) {
|
||||
const newDefault = newDefaults["versions"][i];
|
||||
let found = false;
|
||||
for (let j = 0; j < current["versions"].length; j++) {
|
||||
let 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() {
|
||||
let current = fs.readJsonSync(serversPath);
|
||||
let newDefaults = fs.readJsonSync(
|
||||
path.join(__dirname, "/defaults/servers.json")
|
||||
@ -72,14 +95,18 @@ function initialSetup(firstTime) {
|
||||
path.join(__dirname, "/defaults/servers.json"),
|
||||
serversPath
|
||||
);
|
||||
fs.copySync(
|
||||
path.join(__dirname, "/defaults/versions.json"),
|
||||
versionsPath
|
||||
);
|
||||
} else if (fs.existsSync(serversPath)) {
|
||||
// Migration
|
||||
// Update default servers by replacing their entries
|
||||
updateDefaults();
|
||||
// Update default servers and versions
|
||||
patchVersions();
|
||||
patchServers();
|
||||
}
|
||||
|
||||
// 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/hashes.json"), hashPath);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user