mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-29 19:02:55 +02:00
Merge pull request #74 from birarda/console-migrate-sm
add option to migrate Stack Manager content
This commit is contained in:
commit
5784b81290
3 changed files with 149 additions and 12 deletions
|
@ -27,7 +27,7 @@
|
||||||
"always-tail": "0.2.0",
|
"always-tail": "0.2.0",
|
||||||
"cheerio": "^0.19.0",
|
"cheerio": "^0.19.0",
|
||||||
"extend": "^3.0.0",
|
"extend": "^3.0.0",
|
||||||
"mkdirp": "^0.5.1",
|
"fs-extra": "^0.26.4",
|
||||||
"node-notifier": "^4.4.0",
|
"node-notifier": "^4.4.0",
|
||||||
"os-homedir": "^1.0.1",
|
"os-homedir": "^1.0.1",
|
||||||
"request": "2.67.0",
|
"request": "2.67.0",
|
||||||
|
|
|
@ -13,7 +13,7 @@ const shell = require('shell');
|
||||||
const os = require('os');
|
const os = require('os');
|
||||||
const childProcess = require('child_process');
|
const childProcess = require('child_process');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const fs = require('fs');
|
const fs = require('fs-extra');
|
||||||
const Tail = require('always-tail');
|
const Tail = require('always-tail');
|
||||||
const http = require('http');
|
const http = require('http');
|
||||||
const unzip = require('unzip');
|
const unzip = require('unzip');
|
||||||
|
@ -75,7 +75,6 @@ const buildInfo = getBuildInfo();
|
||||||
|
|
||||||
console.log("build info", buildInfo);
|
console.log("build info", buildInfo);
|
||||||
|
|
||||||
|
|
||||||
function getRootHifiDataDirectory() {
|
function getRootHifiDataDirectory() {
|
||||||
var organization = "High Fidelity";
|
var organization = "High Fidelity";
|
||||||
if (buildInfo.releaseType != "PRODUCTION") {
|
if (buildInfo.releaseType != "PRODUCTION") {
|
||||||
|
@ -302,12 +301,6 @@ global.domainServer = null;
|
||||||
global.acMonitor = null;
|
global.acMonitor = null;
|
||||||
global.userConfig = userConfig;
|
global.userConfig = userConfig;
|
||||||
|
|
||||||
const GO_HOME_INDEX = 2;
|
|
||||||
const SERVER_LABEL_INDEX = 0;
|
|
||||||
const RESTART_INDEX = 4;
|
|
||||||
const STOP_INDEX = 5;
|
|
||||||
const SETTINGS_INDEX = 6;
|
|
||||||
|
|
||||||
var LogWindow = function(ac, ds) {
|
var LogWindow = function(ac, ds) {
|
||||||
this.ac = ac;
|
this.ac = ac;
|
||||||
this.ds = ds;
|
this.ds = ds;
|
||||||
|
@ -350,6 +343,134 @@ function goHomeClicked() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function stackManagerBasePath() {
|
||||||
|
var dataPath = 'High Fidelity/Stack Manager/resources';
|
||||||
|
|
||||||
|
if (process.platform == "win32") {
|
||||||
|
return path.resolve(osHomeDir(), 'AppData/Local', dataPath);
|
||||||
|
} else if (process.platform == "darwin") {
|
||||||
|
return path.resolve(osHomeDir(), 'Library/Application Support', dataPath);
|
||||||
|
} else {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function isStackManagerContentPresent() {
|
||||||
|
var modelsPath = path.resolve(stackManagerBasePath(), 'models.json.gz');
|
||||||
|
|
||||||
|
try {
|
||||||
|
var stats = fs.lstatSync(modelsPath);
|
||||||
|
|
||||||
|
if (stats.isFile()) {
|
||||||
|
console.log("Stack Manager entities file discovered at " + modelsPath)
|
||||||
|
// we found a content file
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.log("Stack Manager entities file not found at " + modelsPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function promptToMigrateContent() {
|
||||||
|
dialog.showMessageBox({
|
||||||
|
type: 'question',
|
||||||
|
buttons: ['Yes', 'No'],
|
||||||
|
title: 'Migrate Content',
|
||||||
|
message: 'Are you sure?\n\nThis will stop your home server and replace everything in your home with your content from Stack Manager.'
|
||||||
|
}, function(index) {
|
||||||
|
if (index == 0) {
|
||||||
|
if (homeServer.state != ProcessGroupStates.STOPPED) {
|
||||||
|
var stopThenMigrateCallback = function(processGroup) {
|
||||||
|
if (isShuttingDown) {
|
||||||
|
homeServer.removeListener('state-update', stopThenMigrateCallback);
|
||||||
|
} else if (processGroup.state == ProcessGroupStates.STOPPED) {
|
||||||
|
performContentMigration();
|
||||||
|
|
||||||
|
homeServer.removeListener('state-update', stopThenMigrateCallback);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
homeServer.on('state-update', stopThenMigrateCallback);
|
||||||
|
homeServer.stop();
|
||||||
|
|
||||||
|
} else {
|
||||||
|
performContentMigration();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function performContentMigration() {
|
||||||
|
// check if there is a models file to migrate
|
||||||
|
var modelsPath = path.resolve(stackManagerBasePath(), 'models.json.gz');
|
||||||
|
|
||||||
|
try {
|
||||||
|
var stats = fs.lstatSync(modelsPath);
|
||||||
|
} catch (e) {
|
||||||
|
// no entities file
|
||||||
|
dialog.showMessageBox({
|
||||||
|
type: 'info',
|
||||||
|
buttons: ['OK'],
|
||||||
|
title: 'Models File Not Found',
|
||||||
|
message: 'There is no models file at ' + modelsPath + '\n\nStack Manager content migration can not proceed.'
|
||||||
|
}, null);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
function showMigrationCompletionDialog(copyError) {
|
||||||
|
if (!copyError) {
|
||||||
|
// show message for successful migration
|
||||||
|
dialog.showMessageBox({
|
||||||
|
type: 'info',
|
||||||
|
buttons: ['OK'],
|
||||||
|
title: 'Migration Complete',
|
||||||
|
message: 'Your Stack Manager content has been migrated.\n\nYour home server will now be restarted.'
|
||||||
|
}, null);
|
||||||
|
} else {
|
||||||
|
// show error message for copy fail
|
||||||
|
dialog.showMessageBox({
|
||||||
|
type: 'info',
|
||||||
|
buttons: ['OK'],
|
||||||
|
title: 'Migration Failed',
|
||||||
|
message: 'There was an error copying your Stack Manager content: ' + copyError + '\n\nPlease try again.'
|
||||||
|
}, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// we have a models file, try and copy it
|
||||||
|
var newModelsPath = path.resolve(getAssignmentClientResourcesDirectory(), 'entities/models.json.gz')
|
||||||
|
console.log("Copying Stack Manager entity file from " + modelsPath + " to " + newModelsPath);
|
||||||
|
|
||||||
|
try {
|
||||||
|
fs.copySync(modelsPath, newModelsPath);
|
||||||
|
|
||||||
|
// check if there are any assets to copy
|
||||||
|
var oldAssetsPath = path.resolve(stackManagerBasePath(), 'assets');
|
||||||
|
|
||||||
|
var assets = fs.readdirSync(oldAssetsPath);
|
||||||
|
|
||||||
|
if (assets.length > 0) {
|
||||||
|
// assume this means the directory is not empty
|
||||||
|
// and that we should copy it
|
||||||
|
var newAssetsPath = path.resolve(getAssignmentClientResourcesDirectory(), 'assets');
|
||||||
|
|
||||||
|
console.log("Copying Stack Manager assets from " + oldAssetsPath + " to " + newAssetsPath);
|
||||||
|
|
||||||
|
// attempt to copy the assets folder
|
||||||
|
fs.copySync(oldAssetsPath, newAssetsPath, {
|
||||||
|
preserveTimestamps: true
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
showMigrationCompletionDialog(null);
|
||||||
|
} catch (error) {
|
||||||
|
showMigrationCompletionDialog(error);
|
||||||
|
}
|
||||||
|
|
||||||
|
homeServer.start();
|
||||||
|
}
|
||||||
|
|
||||||
var logWindow = null;
|
var logWindow = null;
|
||||||
|
|
||||||
function buildMenuArray(serverState) {
|
function buildMenuArray(serverState) {
|
||||||
|
@ -414,12 +535,29 @@ function buildMenuArray(serverState) {
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
var foundStackManagerContent = isStackManagerContentPresent();
|
||||||
|
if (foundStackManagerContent) {
|
||||||
|
// add a separator and the stack manager content migration option
|
||||||
|
menuArray.splice(menuArray.length - 1, 0, {
|
||||||
|
label: 'Migrate Stack Manager Content',
|
||||||
|
click: function() { promptToMigrateContent(); }
|
||||||
|
}, {
|
||||||
|
type: 'separator'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
updateMenuArray(menuArray, serverState);
|
updateMenuArray(menuArray, serverState);
|
||||||
}
|
}
|
||||||
|
|
||||||
return menuArray;
|
return menuArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const GO_HOME_INDEX = 2;
|
||||||
|
const SERVER_LABEL_INDEX = 0;
|
||||||
|
const RESTART_INDEX = 4;
|
||||||
|
const STOP_INDEX = 5;
|
||||||
|
const SETTINGS_INDEX = 6;
|
||||||
|
|
||||||
function updateMenuArray(menuArray, serverState) {
|
function updateMenuArray(menuArray, serverState) {
|
||||||
// update the tray menu state
|
// update the tray menu state
|
||||||
var running = serverState == ProcessGroupStates.STARTED;
|
var running = serverState == ProcessGroupStates.STARTED;
|
||||||
|
|
|
@ -5,8 +5,7 @@ const extend = require('extend');
|
||||||
const util = require('util');
|
const util = require('util');
|
||||||
const events = require('events');
|
const events = require('events');
|
||||||
const childProcess = require('child_process');
|
const childProcess = require('child_process');
|
||||||
const fs = require('fs');
|
const fs = require('fs-extra');
|
||||||
const mkdirp = require('mkdirp');
|
|
||||||
const os = require('os');
|
const os = require('os');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
|
@ -133,7 +132,7 @@ Process.prototype = extend(Process.prototype, {
|
||||||
var logDirectoryCreated = false;
|
var logDirectoryCreated = false;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
mkdirp.sync(this.logDirectory);
|
fs.mkdirsSync(this.logDirectory);
|
||||||
logDirectoryCreated = true;
|
logDirectoryCreated = true;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e.code == 'EEXIST') {
|
if (e.code == 'EEXIST') {
|
||||||
|
|
Loading…
Reference in a new issue