mirror of
https://github.com/OpenFusionProject/Client.git
synced 2026-02-05 16:20:04 +00:00
Consistency pass and small tweaks
**Formatting going forward** Variables: camelCase (capitalization of two letter abbreviations is OK, e.g. playerID) Classes: PascalCase CSS: kebab-case Files: kebab-case **Other miscellaneous changes** * The WebPlayer crashing as well as failing to load the config file are now fatal errors and will quit the app * Moved some style attributes from index.html into openfusion.css
This commit is contained in:
80
index.js
80
index.js
@@ -7,46 +7,55 @@ var BrowserWindow = require("browser-window");
|
||||
|
||||
var mainWindow = null;
|
||||
|
||||
app.commandLine.appendSwitch("--enable-npapi");
|
||||
app.commandLine.appendSwitch("enable-npapi");
|
||||
|
||||
function verifyUnity() {
|
||||
var dllpath =
|
||||
app.getPath("appData") +
|
||||
"\\..\\LocalLow\\Unity\\WebPlayer\\player\\fusion-2.x.x\\webplayer_win.dll";
|
||||
|
||||
if (fs.existsSync(dllpath)) {
|
||||
var buff = fs.readFileSync(dllpath);
|
||||
var hash = require("crypto")
|
||||
function verifyMD5Hash(file, hash) {
|
||||
if (fs.existsSync(file)) {
|
||||
var buffer = fs.readFileSync(file);
|
||||
var computedHash = require("crypto")
|
||||
.createHash("md5")
|
||||
.update(buff)
|
||||
.update(buffer)
|
||||
.digest("hex");
|
||||
if (hash == "e5028405b4483de9e5e5fe9cd5f1e98f") {
|
||||
if (hash == computedHash) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function verifyUnity() {
|
||||
var loaderPath =
|
||||
app.getPath("appData") +
|
||||
"\\..\\LocalLow\\Unity\\WebPlayer\\loader\\npUnity3D32.dll";
|
||||
var playerPath =
|
||||
app.getPath("appData") +
|
||||
"\\..\\LocalLow\\Unity\\WebPlayer\\player\\fusion-2.x.x\\webplayer_win.dll";
|
||||
|
||||
return (
|
||||
verifyMD5Hash(loaderPath, "dbbac62d8379d2d870479b04b8157b99") &&
|
||||
verifyMD5Hash(playerPath, "e5028405b4483de9e5e5fe9cd5f1e98f")
|
||||
);
|
||||
}
|
||||
|
||||
function installUnity(callback) {
|
||||
var utilsdir = __dirname + "\\..\\..\\utils";
|
||||
var utilsDir = __dirname + "\\..\\..\\utils";
|
||||
|
||||
// if running in non-packaged / development mode, this dir will be slightly different
|
||||
if (process.env.npm_node_execpath) {
|
||||
utilsdir = app.getAppPath() + "\\build\\utils";
|
||||
utilsDir = app.getAppPath() + "\\build\\utils";
|
||||
}
|
||||
|
||||
// run the installer silently
|
||||
var child = require("child_process").spawn(
|
||||
utilsdir + "\\UnityWebPlayer.exe",
|
||||
utilsDir + "\\UnityWebPlayer.exe",
|
||||
["/quiet", "/S"]
|
||||
);
|
||||
child.on("exit", function () {
|
||||
// overwrite 3.5.2 loader/player with FF's custom version
|
||||
var dstfolder =
|
||||
app.getPath("appData") + "\\..\\LocalLow\\Unity\\WebPlayer";
|
||||
fs.copySync(utilsdir + "\\WebPlayer", dstfolder, { clobber: true });
|
||||
var dest = app.getPath("appData") + "\\..\\LocalLow\\Unity\\WebPlayer";
|
||||
fs.copySync(utilsDir + "\\WebPlayer", dest, { clobber: true });
|
||||
// avoids error reporter popping up when closing Electron
|
||||
fs.removeSync(dstfolder + "\\UnityBugReporter.exe");
|
||||
fs.removeSync(dest + "\\UnityBugReporter.exe");
|
||||
console.log("Unity Web Player installed successfully.");
|
||||
callback();
|
||||
});
|
||||
@@ -61,7 +70,7 @@ function initialSetup(firstTime) {
|
||||
center: true,
|
||||
frame: false,
|
||||
});
|
||||
setupWindow.loadUrl("file://" + __dirname + "/initialsetup.html");
|
||||
setupWindow.loadUrl("file://" + __dirname + "/initial-setup.html");
|
||||
installUnity(function () {
|
||||
if (!firstTime) {
|
||||
// migration from pre-1.4
|
||||
@@ -114,12 +123,12 @@ app.on("window-all-closed", function () {
|
||||
|
||||
app.on("ready", function () {
|
||||
// Check just in case the user forgot to extract the zip.
|
||||
zip_check = app.getPath("exe").includes(os.tmpdir());
|
||||
if (zip_check) {
|
||||
errormsg =
|
||||
zipCheck = app.getPath("exe").includes(os.tmpdir());
|
||||
if (zipCheck) {
|
||||
var errorMessage =
|
||||
"It has been detected that OpenFusionClient is running from the TEMP folder.\n\n" +
|
||||
"Please extract the entire Client folder to a location of your choice before starting OpenFusionClient.";
|
||||
dialog.showErrorBox("Error!", errormsg);
|
||||
dialog.showErrorBox("Error!", errorMessage);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -152,12 +161,16 @@ app.on("ready", function () {
|
||||
}
|
||||
}
|
||||
} catch (ex) {
|
||||
console.log("An error occurred while checking for the config");
|
||||
dialog.showErrorBox(
|
||||
"Error!",
|
||||
"An error occurred while checking for the config. Make sure you have sufficent permissions."
|
||||
);
|
||||
app.quit();
|
||||
}
|
||||
|
||||
// Makes it so external links are opened in the system browser, not Electron
|
||||
mainWindow.webContents.on("new-window", function (e, url) {
|
||||
e.preventDefault();
|
||||
mainWindow.webContents.on("new-window", function (event, url) {
|
||||
event.preventDefault();
|
||||
require("shell").openExternal(url);
|
||||
});
|
||||
|
||||
@@ -181,19 +194,24 @@ function showMainWindow() {
|
||||
});
|
||||
|
||||
mainWindow.webContents.on("plugin-crashed", function () {
|
||||
console.log("Unity Web Player crashed.");
|
||||
var errorMessage =
|
||||
"Unity Web Player has crashed - please re-open the application.\n" +
|
||||
"If this error persists, please read the FAQ or ask for support in our Discord server.";
|
||||
dialog.showErrorBox("Error!", errorMessage);
|
||||
mainWindow.destroy();
|
||||
app.quit();
|
||||
});
|
||||
|
||||
mainWindow.webContents.on("will-navigate", function (evt, url) {
|
||||
evt.preventDefault();
|
||||
mainWindow.webContents.on("will-navigate", function (event, url) {
|
||||
event.preventDefault();
|
||||
// TODO: showMessageBox rather than showErrorBox?
|
||||
switch (url) {
|
||||
case "https://audience.fusionfall.com/ff/regWizard.do?_flowId=fusionfall-registration-flow":
|
||||
errormsg =
|
||||
var errorMessage =
|
||||
"The register page is currently unimplemented.\n\n" +
|
||||
'You can still create an account: type your desired username and password into the provided boxes and click "Log In". ' +
|
||||
"Your account will then be automatically created on the server. \nBe sure to remember these details!";
|
||||
dialog.showErrorBox("Sorry!", errormsg);
|
||||
dialog.showErrorBox("Sorry!", errorMessage);
|
||||
break;
|
||||
case "https://audience.fusionfall.com/ff/login.do":
|
||||
dialog.showErrorBox(
|
||||
|
||||
Reference in New Issue
Block a user