Add routine for migration from pre-1.4

This commit is contained in:
gsemaj 2021-09-18 17:59:15 -04:00
parent 71d3b970fc
commit 17ca1f3c24

View File

@ -9,7 +9,7 @@ var mainWindow = null;
app.commandLine.appendSwitch('--enable-npapi'); app.commandLine.appendSwitch('--enable-npapi');
function initialSetup() { function initialSetup(firstTime) {
// Display a small window to inform the user that the app is working // Display a small window to inform the user that the app is working
setupWindow = new BrowserWindow({width: 275, height: 450, resizable: false, center:true, frame:false}); setupWindow = new BrowserWindow({width: 275, height: 450, resizable: false, center:true, frame:false});
setupWindow.loadUrl('file://' + __dirname + '/initialsetup.html'); setupWindow.loadUrl('file://' + __dirname + '/initialsetup.html');
@ -17,10 +17,20 @@ function initialSetup() {
var child = require('child_process').spawn('cmd.exe', ['/c', 'utils\\installUnity.bat']); var child = require('child_process').spawn('cmd.exe', ['/c', 'utils\\installUnity.bat']);
child.on('exit', function() { child.on('exit', function() {
console.log("Unity installed."); console.log("Unity installed.");
// Copy over files with default values if(!firstTime) { // migration from pre-1.4
copySync(__dirname+"\\defaults\\config.json", app.getPath('userData')+"\\config.json"); // Back everything up, just in case
copySync(app.getPath('userData')+"\\config.json", app.getPath('userData')+"\\config.json.bak");
copySync(app.getPath('userData')+"\\servers.json", app.getPath('userData')+"\\servers.json.bak");
copySync(app.getPath('userData')+"\\versions.json", app.getPath('userData')+"\\versions.json.bak");
} else { // first-time setup
// Copy default servers
copySync(__dirname+"\\defaults\\servers.json", app.getPath('userData')+"\\servers.json"); copySync(__dirname+"\\defaults\\servers.json", app.getPath('userData')+"\\servers.json");
}
// Copy default versions and config
copySync(__dirname+"\\defaults\\versions.json", app.getPath('userData')+"\\versions.json"); copySync(__dirname+"\\defaults\\versions.json", app.getPath('userData')+"\\versions.json");
copySync(__dirname+"\\defaults\\config.json", app.getPath('userData')+"\\config.json");
console.log("JSON files copied."); console.log("JSON files copied.");
setupWindow.destroy(); setupWindow.destroy();
showMainWindow(); showMainWindow();
@ -54,13 +64,20 @@ app.on('ready', function() {
mainWindow.setMinimumSize(640, 480); mainWindow.setMinimumSize(640, 480);
// Check for first run // Check for first run
var configPath = app.getPath('userData') + "\\config.json";
try { try {
if (!fs.existsSync(app.getPath('userData')+"\\config.json")) { if (!fs.existsSync(configPath)) {
console.log("Config file not found. Running initial setup."); console.log("Config file not found. Running initial setup.");
initialSetup(); initialSetup(true);
} else {
var config = fs.readJsonSync(configPath);
if(!config['last-version-initialized']) {
console.log("Pre-1.4 config detected. Running migration.");
initialSetup(false);
} else { } else {
showMainWindow(); showMainWindow();
} }
}
} catch(e) { } catch(e) {
console.log("An error occurred while checking for the config."); console.log("An error occurred while checking for the config.");
} }