Use fs-extra for copying files synchronously

Also, sorry about the diff. Turns out some of the files in the repo were CRLF.
This commit is contained in:
CakeLancelot 2021-05-16 21:00:27 -05:00
parent 6f42297102
commit bfac6e9250
7 changed files with 484 additions and 542 deletions

View File

@ -1,80 +1,80 @@
var ipc = require("ipc");
var gameRunning = false;
// Unity invoked methods begin //
// Uncomment and enter credentials to skip login screen
function authDoCallback(param) {
/*var unity = document.getElementById('Unity_embed');
unity.SendMessage("GlobalManager", "SetTEGid", "player");
unity.SendMessage("GlobalManager", "SetAuthid", "0");
unity.SendMessage("GlobalManager", "DoAuth", 0);*/
}
function MarkProgress(param) {}
function redirect(html) {
ipc.send("exit", 0);
}
function HomePage(param) {
ipc.send("exit", 0);
}
function PageOut(param) {
ipc.send("exit", 0);
}
function updateSocialOptions(param) {
ipc.send("exit", 0);
}
function PayPage(param) {
ipc.send("exit", 0);
}
// Unity invoked methods end //
function onResize() {
if (gameRunning == true) {
var unity = document.getElementById('Unity_embed');
unity.style.width = window.innerWidth + 'px';
unity.style.height = window.innerHeight + 'px';
}
}
function launchGame() {
gameRunning = true
var sel = document.getElementById("of-serverselector");
sel.remove()
document.body.style.overflow = "hidden";
var object = document.createElement('object');
object.setAttribute('classid', "clsid:444785F1-DE89-4295-863A-D46C3A781394");
object.setAttribute('codebase', "undefined/UnityWebPlayer.cab#version=2,0,0,0");
object.setAttribute('id', "Unity_object");
object.setAttribute('width', "1264");
object.setAttribute('height', "661");
var embed = document.createElement('embed');
embed.setAttribute('type', "application/vnd.unity");
embed.setAttribute('pluginspage', "http://www.unity3d.com/unity-web-player-2.x");
embed.setAttribute('id', "Unity_embed");
embed.setAttribute('width', "1280");
embed.setAttribute('height', "680");
embed.setAttribute('src', window.asseturl+"main.unity3d");
embed.setAttribute('disablecontdparaextmenu', "true");
embed.setAttribute('bordercolor', "000000");
embed.setAttribute('backgroundcolor', "000000");
embed.setAttribute('disableContextMenu', true);
embed.setAttribute('textcolor', "ccffff");
embed.setAttribute('logoimage', "assets/img/unity_dexlabs.png");
embed.setAttribute('progressbarimage', "assets/img/unity_loadingbar.png");
embed.setAttribute('progressframeimage', "assets/img/unity_loadingframe.png");
embed.setAttribute('autoupdateurlsignature', "42180ee5edc4e3d4dd706bcc17cedd8d6ec7b7ac463071fd34ab97fe181f1a78df31db5feb4526677e4f69ef53acaff44471591e68b87f041c80fd54765f0d5725b08aa28f5acf7716ffb2a04e971269f35925c7e38d57dd78f6a206530caaa3da7e32f07f19810efc0ebf29a4eae976a925ad9cc5beb4dd51564c67dc489033");
embed.setAttribute('autoupdateurl', "http://wp-cartoonnetwork.unity3d.com/ff/big/beta-20111013/autodownload_webplugin_beta");
var div = document.getElementById('client');
object.appendChild(embed);
div.appendChild(object);
document.title = "OpenFusion"
onResize();
var ipc = require("ipc");
var gameRunning = false;
// Unity invoked methods begin //
// Uncomment and enter credentials to skip login screen
function authDoCallback(param) {
/*var unity = document.getElementById('Unity_embed');
unity.SendMessage("GlobalManager", "SetTEGid", "player");
unity.SendMessage("GlobalManager", "SetAuthid", "0");
unity.SendMessage("GlobalManager", "DoAuth", 0);*/
}
function MarkProgress(param) {}
function redirect(html) {
ipc.send("exit", 0);
}
function HomePage(param) {
ipc.send("exit", 0);
}
function PageOut(param) {
ipc.send("exit", 0);
}
function updateSocialOptions(param) {
ipc.send("exit", 0);
}
function PayPage(param) {
ipc.send("exit", 0);
}
// Unity invoked methods end //
function onResize() {
if (gameRunning == true) {
var unity = document.getElementById('Unity_embed');
unity.style.width = window.innerWidth + 'px';
unity.style.height = window.innerHeight + 'px';
}
}
function launchGame() {
gameRunning = true
var sel = document.getElementById("of-serverselector");
sel.remove()
document.body.style.overflow = "hidden";
var object = document.createElement('object');
object.setAttribute('classid', "clsid:444785F1-DE89-4295-863A-D46C3A781394");
object.setAttribute('codebase', "undefined/UnityWebPlayer.cab#version=2,0,0,0");
object.setAttribute('id', "Unity_object");
object.setAttribute('width', "1264");
object.setAttribute('height', "661");
var embed = document.createElement('embed');
embed.setAttribute('type', "application/vnd.unity");
embed.setAttribute('pluginspage', "http://www.unity3d.com/unity-web-player-2.x");
embed.setAttribute('id', "Unity_embed");
embed.setAttribute('width', "1280");
embed.setAttribute('height', "680");
embed.setAttribute('src', window.asseturl+"main.unity3d");
embed.setAttribute('disablecontdparaextmenu', "true");
embed.setAttribute('bordercolor', "000000");
embed.setAttribute('backgroundcolor', "000000");
embed.setAttribute('disableContextMenu', true);
embed.setAttribute('textcolor', "ccffff");
embed.setAttribute('logoimage', "assets/img/unity_dexlabs.png");
embed.setAttribute('progressbarimage', "assets/img/unity_loadingbar.png");
embed.setAttribute('progressframeimage', "assets/img/unity_loadingframe.png");
embed.setAttribute('autoupdateurlsignature', "42180ee5edc4e3d4dd706bcc17cedd8d6ec7b7ac463071fd34ab97fe181f1a78df31db5feb4526677e4f69ef53acaff44471591e68b87f041c80fd54765f0d5725b08aa28f5acf7716ffb2a04e971269f35925c7e38d57dd78f6a206530caaa3da7e32f07f19810efc0ebf29a4eae976a925ad9cc5beb4dd51564c67dc489033");
embed.setAttribute('autoupdateurl', "http://wp-cartoonnetwork.unity3d.com/ff/big/beta-20111013/autodownload_webplugin_beta");
var div = document.getElementById('client');
object.appendChild(embed);
div.appendChild(object);
document.title = "OpenFusion"
onResize();
}

View File

@ -1,155 +1,155 @@
var remote = require("remote");
var remotefs = remote.require('fs');
var userdir = remote.require('app').getPath('userData');
var versionarray
var serverarray
function enableServerListButtons() {
$('#of-connect-button').removeClass('disabled');
$('#of-connect-button').prop('disabled', false);
$('#of-deleteserver-button').removeClass('disabled');
$('#of-deleteserver-button').prop('disabled', false);
}
function disableServerListButtons() {
$('#of-connect-button').addClass('disabled');
$('#of-connect-button').prop('disabled', true);
$('#of-deleteserver-button').addClass('disabled');
$('#of-deleteserver-button').prop('disabled', true);
}
function addServer() {
var jsontomodify = JSON.parse(remotefs.readFileSync(userdir+"\\servers.json"));
var server = {};
server['uuid'] = uuidv4();
server['description'] = $("#addserver-descinput").val().length == 0 ? "My OpenFusion Server" : $("#addserver-descinput").val();
server['ip'] = $("#addserver-ipinput").val().length == 0 ? "127.0.0.1:23000" : $("#addserver-ipinput").val();
server['version'] = $("#addserver-versionselect option:selected").text();
//server['endpoint'] =
jsontomodify['servers'].push(server)
remotefs.writeFileSync(userdir+"\\servers.json", JSON.stringify(jsontomodify, null, 4));
loadServerList();
}
function deleteServer() {
var jsontomodify = JSON.parse(remotefs.readFileSync(userdir+"\\servers.json"));
var result = jsontomodify['servers'].filter(function(obj) {return (obj.uuid === getSelectedServer())})[0];
var resultindex = jsontomodify['servers'].indexOf(result);
jsontomodify['servers'].splice(resultindex, 1);
remotefs.writeFileSync(userdir+"\\servers.json", JSON.stringify(jsontomodify, null, 4));
loadServerList();
}
function loadGameVersions() {
var versionjson = JSON.parse(remotefs.readFileSync(userdir+"\\versions.json"));
versionarray = versionjson['versions'];
$.each(versionarray, function( key, value ) {
$(new Option(value.name, 'val')).appendTo('#addserver-versionselect');
});
}
function loadConfig() {
// TODO: actually use these values
var configjson = JSON.parse(remotefs.readFileSync(userdir+"\\config.json"));
}
function loadServerList() {
var serverjson = JSON.parse(remotefs.readFileSync(userdir+"\\servers.json"));
serverarray = serverjson['servers'];
$(".server-listing-entry").remove(); // Clear out old stuff, if any
disableServerListButtons(); // Disable buttons until another server is selected
if (serverarray.length > 0) {
// Servers were found in the JSON
$("#server-listing-placeholder").attr("hidden",true);
$.each(serverarray, function( key, value ) {
// Create the row, and populate the cells
var row = document.createElement('tr');
row.className = 'server-listing-entry'
row.setAttribute('id', value.uuid);
var cellName = document.createElement('td');
cellName.textContent = value.description
var cellVersion = document.createElement('td');
cellVersion.textContent = value.version
cellVersion.className = 'text-monospace'
row.appendChild(cellName);
row.appendChild(cellVersion);
$("#server-tablebody").append(row);
});
} else {
// No servers are added, make sure placeholder is visible
$("#server-listing-placeholder").attr("hidden",false);
}
}
// For writing loginInfo.php, assetInfo.php, etc.
function setGameInfo(serverUUID) {
var result = serverarray.filter(function(obj) {return (obj.uuid === serverUUID);})[0];
var gameversion = versionarray.filter(function(obj) {return (obj.name === result.version);})[0];
window.asseturl = gameversion.url // gameclient.js needs to access this
remotefs.writeFileSync(__dirname+"\\assetInfo.php", asseturl);
remotefs.writeFileSync(__dirname+"\\loginInfo.php", result.ip);
if (result.hasOwnProperty('endpoint')) {
var httpendpoint = result.endpoint.replace("https://", "http://")
remotefs.writeFileSync(__dirname+"\\rankurl.txt", httpendpoint+"getranks");
// Write these out too
remotefs.writeFileSync(__dirname+"\\sponsor.php", httpendpoint+"upsell/sponsor.png");
remotefs.writeFileSync(__dirname+"\\images.php", httpendpoint+"upsell/");
} else {
// Remove/default the endpoint related stuff, this server won't be using it
if (remotefs.existsSync(__dirname+"\\rankurl.txt")) {
remotefs.unlinkSync(__dirname+"\\rankurl.txt");
remotefs.writeFileSync(__dirname+"\\sponsor.php", "assets/img/welcome.png");
remotefs.writeFileSync(__dirname+"\\images.php", "assets/img/");
}
}
}
// Returns the UUID of the server with the selected background color.
// Yes, there are probably better ways to go about this, but it works well enough.
function getSelectedServer() {
return $("#server-tablebody > tr.bg-primary").prop("id");
}
function connectToServer() {
// Get ID of the selected server, which corresponds to its UUID in the json
console.log("Connecting to server with UUID of " + getSelectedServer());
// Prevent the user from clicking anywhere else during the transition
$('body,html').css('pointer-events','none');
stopEasterEggs();
$('#of-serverselector').fadeOut('slow', function() {
setTimeout(function(){
$('body,html').css('pointer-events','');
setGameInfo(getSelectedServer());
launchGame();
}, 200);
});
}
$('#server-table').on('click', '.server-listing-entry', function(event) {
enableServerListButtons();
$(this).addClass('bg-primary').siblings().removeClass('bg-primary');
});
// QoL feature: if you double click on a server it will connect
$('#server-table').on('dblclick', '.server-listing-entry', function(event) {
$(this).addClass('bg-primary').siblings().removeClass('bg-primary');
connectToServer();
});
$('#of-deleteservermodal').on('show.bs.modal', function (e) {
var result = serverarray.filter(function(obj) {return (obj.uuid === getSelectedServer());})[0];
$("#deleteserver-servername").html(result.description);
});
var remote = require("remote");
var remotefs = remote.require('fs-extra');
var userdir = remote.require('app').getPath('userData');
var versionarray
var serverarray
function enableServerListButtons() {
$('#of-connect-button').removeClass('disabled');
$('#of-connect-button').prop('disabled', false);
$('#of-deleteserver-button').removeClass('disabled');
$('#of-deleteserver-button').prop('disabled', false);
}
function disableServerListButtons() {
$('#of-connect-button').addClass('disabled');
$('#of-connect-button').prop('disabled', true);
$('#of-deleteserver-button').addClass('disabled');
$('#of-deleteserver-button').prop('disabled', true);
}
function addServer() {
var jsontomodify = JSON.parse(remotefs.readFileSync(userdir+"\\servers.json"));
var server = {};
server['uuid'] = uuidv4();
server['description'] = $("#addserver-descinput").val().length == 0 ? "My OpenFusion Server" : $("#addserver-descinput").val();
server['ip'] = $("#addserver-ipinput").val().length == 0 ? "127.0.0.1:23000" : $("#addserver-ipinput").val();
server['version'] = $("#addserver-versionselect option:selected").text();
//server['endpoint'] =
jsontomodify['servers'].push(server)
remotefs.writeFileSync(userdir+"\\servers.json", JSON.stringify(jsontomodify, null, 4));
loadServerList();
}
function deleteServer() {
var jsontomodify = JSON.parse(remotefs.readFileSync(userdir+"\\servers.json"));
var result = jsontomodify['servers'].filter(function(obj) {return (obj.uuid === getSelectedServer())})[0];
var resultindex = jsontomodify['servers'].indexOf(result);
jsontomodify['servers'].splice(resultindex, 1);
remotefs.writeFileSync(userdir+"\\servers.json", JSON.stringify(jsontomodify, null, 4));
loadServerList();
}
function loadGameVersions() {
var versionjson = JSON.parse(remotefs.readFileSync(userdir+"\\versions.json"));
versionarray = versionjson['versions'];
$.each(versionarray, function( key, value ) {
$(new Option(value.name, 'val')).appendTo('#addserver-versionselect');
});
}
function loadConfig() {
// TODO: actually use these values
var configjson = JSON.parse(remotefs.readFileSync(userdir+"\\config.json"));
}
function loadServerList() {
var serverjson = JSON.parse(remotefs.readFileSync(userdir+"\\servers.json"));
serverarray = serverjson['servers'];
$(".server-listing-entry").remove(); // Clear out old stuff, if any
disableServerListButtons(); // Disable buttons until another server is selected
if (serverarray.length > 0) {
// Servers were found in the JSON
$("#server-listing-placeholder").attr("hidden",true);
$.each(serverarray, function( key, value ) {
// Create the row, and populate the cells
var row = document.createElement('tr');
row.className = 'server-listing-entry'
row.setAttribute('id', value.uuid);
var cellName = document.createElement('td');
cellName.textContent = value.description
var cellVersion = document.createElement('td');
cellVersion.textContent = value.version
cellVersion.className = 'text-monospace'
row.appendChild(cellName);
row.appendChild(cellVersion);
$("#server-tablebody").append(row);
});
} else {
// No servers are added, make sure placeholder is visible
$("#server-listing-placeholder").attr("hidden",false);
}
}
// For writing loginInfo.php, assetInfo.php, etc.
function setGameInfo(serverUUID) {
var result = serverarray.filter(function(obj) {return (obj.uuid === serverUUID);})[0];
var gameversion = versionarray.filter(function(obj) {return (obj.name === result.version);})[0];
window.asseturl = gameversion.url // gameclient.js needs to access this
remotefs.writeFileSync(__dirname+"\\assetInfo.php", asseturl);
remotefs.writeFileSync(__dirname+"\\loginInfo.php", result.ip);
if (result.hasOwnProperty('endpoint')) {
var httpendpoint = result.endpoint.replace("https://", "http://")
remotefs.writeFileSync(__dirname+"\\rankurl.txt", httpendpoint+"getranks");
// Write these out too
remotefs.writeFileSync(__dirname+"\\sponsor.php", httpendpoint+"upsell/sponsor.png");
remotefs.writeFileSync(__dirname+"\\images.php", httpendpoint+"upsell/");
} else {
// Remove/default the endpoint related stuff, this server won't be using it
if (remotefs.existsSync(__dirname+"\\rankurl.txt")) {
remotefs.unlinkSync(__dirname+"\\rankurl.txt");
remotefs.writeFileSync(__dirname+"\\sponsor.php", "assets/img/welcome.png");
remotefs.writeFileSync(__dirname+"\\images.php", "assets/img/");
}
}
}
// Returns the UUID of the server with the selected background color.
// Yes, there are probably better ways to go about this, but it works well enough.
function getSelectedServer() {
return $("#server-tablebody > tr.bg-primary").prop("id");
}
function connectToServer() {
// Get ID of the selected server, which corresponds to its UUID in the json
console.log("Connecting to server with UUID of " + getSelectedServer());
// Prevent the user from clicking anywhere else during the transition
$('body,html').css('pointer-events','none');
stopEasterEggs();
$('#of-serverselector').fadeOut('slow', function() {
setTimeout(function(){
$('body,html').css('pointer-events','');
setGameInfo(getSelectedServer());
launchGame();
}, 200);
});
}
$('#server-table').on('click', '.server-listing-entry', function(event) {
enableServerListButtons();
$(this).addClass('bg-primary').siblings().removeClass('bg-primary');
});
// QoL feature: if you double click on a server it will connect
$('#server-table').on('dblclick', '.server-listing-entry', function(event) {
$(this).addClass('bg-primary').siblings().removeClass('bg-primary');
connectToServer();
});
$('#of-deleteservermodal').on('show.bs.modal', function (e) {
var result = serverarray.filter(function(obj) {return (obj.uuid === getSelectedServer());})[0];
$("#deleteserver-servername").html(result.description);
});

View File

@ -1,5 +1,5 @@
{
"autoupdate-check": true,
"cache-swapping": false,
"initial-setup-completed": true
{
"autoupdate-check": true,
"cache-swapping": false,
"initial-setup-completed": true
}

View File

@ -1,19 +1,19 @@
{
"servers": [
{
"uuid": "d9773558-6ddf-4d00-8803-d830a22a842b",
"description": "OpenFusion Public Server - Original",
"ip": "144.202.52.9:23000",
"version": "beta-20100104",
"endpoint": "https://api.dexlabs.systems/"
},
{
"uuid": "b84f6859-f500-41f2-bdfa-8e3746639ee9",
"description": "OpenFusion Public Server - Academy",
"ip": "144.202.52.9:24000",
"version": "beta-20111013",
"endpoint": "https://api.dexlabs.systems/academy/"
}
],
"favorites": []
{
"servers": [
{
"uuid": "d9773558-6ddf-4d00-8803-d830a22a842b",
"description": "OpenFusion Public Server - Original",
"ip": "144.202.52.9:23000",
"version": "beta-20100104",
"endpoint": "https://api.dexlabs.systems/"
},
{
"uuid": "b84f6859-f500-41f2-bdfa-8e3746639ee9",
"description": "OpenFusion Public Server - Academy",
"ip": "144.202.52.9:24000",
"version": "beta-20111013",
"endpoint": "https://api.dexlabs.systems/academy/"
}
],
"favorites": []
}

View File

@ -1,108 +1,108 @@
{
"versions": [
{
"name": "beta-20100104",
"url": "http://ht.cdn.turner.com/ff/big/beta-20100104/"
},
{
"name": "beta-20100119",
"url": "http://ht.cdn.turner.com/ff/big/beta-20100119/"
},
{
"name": "beta-20100207",
"url": "http://ht.cdn.turner.com/ff/big/beta-20100207/"
},
{
"name": "beta-20100307",
"url": "http://ht.cdn.turner.com/ff/big/beta-20100307/"
},
{
"name": "beta-20100322",
"url": "http://ht.cdn.turner.com/ff/big/beta-20100322/"
},
{
"name": "beta-20100413",
"url": "http://ht.cdn.turner.com/ff/big/beta-20100413/"
},
{
"name": "beta-20100502",
"url": "http://ht.cdn.turner.com/ff/big/beta-20100502/"
},
{
"name": "beta-20100524",
"url": "http://ht.cdn.turner.com/ff/big/beta-20100524/"
},
{
"name": "beta-20100604",
"url": "http://ht.cdn.turner.com/ff/big/beta-20100604/"
},
{
"name": "beta-20100616",
"url": "http://ht.cdn.turner.com/ff/big/beta-20100616/"
},
{
"name": "beta-20100711",
"url": "http://ht.cdn.turner.com/ff/big/beta-20100711/"
},
{
"name": "beta-20100728",
"url": "http://ht.cdn.turner.com/ff/big/beta-20100728/"
},
{
"name": "beta-20100909",
"url": "http://ht.cdn.turner.com/ff/big/beta-20100909/"
},
{
"name": "beta-20101003",
"url": "http://ht.cdn.turner.com/ff/big/beta-20101003/"
},
{
"name": "beta-20101011",
"url": "http://ht.cdn.turner.com/ff/big/beta-20101011/"
},
{
"name": "beta-20101028",
"url": "http://ht.cdn.turner.com/ff/big/beta-20101028/"
},
{
"name": "beta-20101123",
"url": "http://ht.cdn.turner.com/ff/big/beta-20101123/"
},
{
"name": "beta-20110213",
"url": "http://ht.cdn.turner.com/ff/big/beta-20110213/"
},
{
"name": "beta-20110314",
"url": "http://ht.cdn.turner.com/ff/big/beta-20110314/"
},
{
"name": "beta-20110330",
"url": "http://ht.cdn.turner.com/ff/big/beta-20110330/"
},
{
"name": "beta-20110424",
"url": "http://ht.cdn.turner.com/ff/big/beta-20110424/"
},
{
"name": "beta-20110523",
"url": "http://ht.cdn.turner.com/ff/big/beta-20110523/"
},
{
"name": "beta-20110725",
"url": "http://ht.cdn.turner.com/ff/big/beta-20110725/"
},
{
"name": "beta-20110818",
"url": "http://ht.cdn.turner.com/ff/big/beta-20110818/"
},
{
"name": "beta-20110912",
"url": "http://ht.cdn.turner.com/ff/big/beta-20110912/"
},
{
"name": "beta-20111013",
"url": "http://ht.cdn.turner.com/ff/big/beta-20111013/"
}
]
}
{
"versions": [
{
"name": "beta-20100104",
"url": "http://ht.cdn.turner.com/ff/big/beta-20100104/"
},
{
"name": "beta-20100119",
"url": "http://ht.cdn.turner.com/ff/big/beta-20100119/"
},
{
"name": "beta-20100207",
"url": "http://ht.cdn.turner.com/ff/big/beta-20100207/"
},
{
"name": "beta-20100307",
"url": "http://ht.cdn.turner.com/ff/big/beta-20100307/"
},
{
"name": "beta-20100322",
"url": "http://ht.cdn.turner.com/ff/big/beta-20100322/"
},
{
"name": "beta-20100413",
"url": "http://ht.cdn.turner.com/ff/big/beta-20100413/"
},
{
"name": "beta-20100502",
"url": "http://ht.cdn.turner.com/ff/big/beta-20100502/"
},
{
"name": "beta-20100524",
"url": "http://ht.cdn.turner.com/ff/big/beta-20100524/"
},
{
"name": "beta-20100604",
"url": "http://ht.cdn.turner.com/ff/big/beta-20100604/"
},
{
"name": "beta-20100616",
"url": "http://ht.cdn.turner.com/ff/big/beta-20100616/"
},
{
"name": "beta-20100711",
"url": "http://ht.cdn.turner.com/ff/big/beta-20100711/"
},
{
"name": "beta-20100728",
"url": "http://ht.cdn.turner.com/ff/big/beta-20100728/"
},
{
"name": "beta-20100909",
"url": "http://ht.cdn.turner.com/ff/big/beta-20100909/"
},
{
"name": "beta-20101003",
"url": "http://ht.cdn.turner.com/ff/big/beta-20101003/"
},
{
"name": "beta-20101011",
"url": "http://ht.cdn.turner.com/ff/big/beta-20101011/"
},
{
"name": "beta-20101028",
"url": "http://ht.cdn.turner.com/ff/big/beta-20101028/"
},
{
"name": "beta-20101123",
"url": "http://ht.cdn.turner.com/ff/big/beta-20101123/"
},
{
"name": "beta-20110213",
"url": "http://ht.cdn.turner.com/ff/big/beta-20110213/"
},
{
"name": "beta-20110314",
"url": "http://ht.cdn.turner.com/ff/big/beta-20110314/"
},
{
"name": "beta-20110330",
"url": "http://ht.cdn.turner.com/ff/big/beta-20110330/"
},
{
"name": "beta-20110424",
"url": "http://ht.cdn.turner.com/ff/big/beta-20110424/"
},
{
"name": "beta-20110523",
"url": "http://ht.cdn.turner.com/ff/big/beta-20110523/"
},
{
"name": "beta-20110725",
"url": "http://ht.cdn.turner.com/ff/big/beta-20110725/"
},
{
"name": "beta-20110818",
"url": "http://ht.cdn.turner.com/ff/big/beta-20110818/"
},
{
"name": "beta-20110912",
"url": "http://ht.cdn.turner.com/ff/big/beta-20110912/"
},
{
"name": "beta-20111013",
"url": "http://ht.cdn.turner.com/ff/big/beta-20111013/"
}
]
}

295
index.js
View File

@ -1,178 +1,117 @@
var app = require('app'); // Module to control application life.
var ipc = require('ipc');
var fs = require('fs');
var os = require('os');
var dialog = require('dialog');
var BrowserWindow = require('browser-window');
var mainWindow = null;
app.commandLine.appendSwitch('--enable-npapi');
// this should be placed at top of main.js to handle setup events quickly
if (handleSquirrelEvent()) {
// squirrel event handled and app will exit in 1000ms, so don't do anything else
return;
}
function handleSquirrelEvent() {
"use strict"
if (process.argv.length === 1) {
return false;
}
const ChildProcess = require('child_process');
const path = require('path');
const appFolder = path.resolve(process.execPath, '..');
const rootAtomFolder = path.resolve(appFolder, '..');
const updateDotExe = path.resolve(path.join(rootAtomFolder, 'Update.exe'));
const exeName = path.basename(process.execPath);
const spawn = function(command, args) {
let spawnedProcess, error;
try {
spawnedProcess = ChildProcess.spawn(command, args, {detached: true});
} catch (error) {}
return spawnedProcess;
};
const spawnUpdate = function(args) {
return spawn(updateDotExe, args);
};
const squirrelEvent = process.argv[1];
switch (squirrelEvent) {
case '--squirrel-install':
case '--squirrel-updated':
// Optionally do things such as:
// - Add your .exe to the PATH
// - Write to the registry for things like file associations and
// explorer context menus
// Install desktop and start menu shortcuts
spawnUpdate(['--createShortcut', exeName]);
setTimeout(app.quit, 1000);
return true;
case '--squirrel-uninstall':
// Undo anything you did in the --squirrel-install and
// --squirrel-updated handlers
// Remove desktop and start menu shortcuts
spawnUpdate(['--removeShortcut', exeName]);
setTimeout(app.quit, 1000);
return true;
case '--squirrel-obsolete':
// This is called on the outgoing version of your app before
// we update to the new version - it's the opposite of
// --squirrel-updated
app.quit();
return true;
}
};
// Node version is too old to have a built-in function
function copyFile(src, dst) {
fs.createReadStream(src).pipe(fs.createWriteStream(dst));
}
function initialSetup() {
// 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.loadUrl('file://' + __dirname + '/initialsetup.html');
// Exec installUnity.bat and wait for it to finish.
var child = require('child_process').spawn('cmd.exe', ['/c', 'utils\\installUnity.bat']);
child.on('exit', function() {
console.log("Unity installed.");
// Copy over files with default values
copyFile(__dirname+"\\defaults\\config.json", app.getPath('userData')+"\\config.json");
copyFile(__dirname+"\\default\\servers.json", app.getPath('userData')+"\\servers.json");
copyFile(__dirname+"\\default\\versions.json", app.getPath('userData')+"\\versions.json");
console.log("JSON files copied.");
setupWindow.destroy();
showMainWindow();
})
}
ipc.on("exit", function(id) {
mainWindow.destroy();
});
// Quit when all windows are closed.
app.on('window-all-closed', function() {
if (process.platform != 'darwin')
app.quit();
});
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 =
("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);
return;
}
// Create the browser window.
mainWindow = new BrowserWindow({width: 1280, height: 720, show: false, "web-preferences": {"plugins": true}});
mainWindow.setMinimumSize(640, 480);
// Check for first run
try {
if (!fs.existsSync(app.getPath('userData')+"\\config.json")) {
console.log("Config file not found. Running initial setup.");
initialSetup();
} else {
showMainWindow();
}
} catch(e) {
console.log("An error occurred while checking for the config.");
}
// Makes it so external links are opened in the system browser, not Electron
mainWindow.webContents.on('new-window', function(e, url) {
e.preventDefault();
require('shell').openExternal(url);
});
mainWindow.on('closed', function() {
mainWindow = null;
});
});
function showMainWindow() {
// and load the index.html of the app.
mainWindow.loadUrl('file://' + __dirname + '/index.html');
// Reduces white flash when opening the program
// Eliminating it entirely requires a newer Electron ver :(
mainWindow.webContents.on('did-finish-load', function() {
mainWindow.show();
mainWindow.webContents.executeJavaScript("loadConfig();");
mainWindow.webContents.executeJavaScript("loadGameVersions();");
mainWindow.webContents.executeJavaScript("loadServerList();");
});
mainWindow.webContents.on('plugin-crashed', function() {
console.log("Unity Web Player crashed.");
});
mainWindow.webContents.on('will-navigate', function(evt, url) {
evt.preventDefault();
console.log(url);
});
//mainWindow.webContents.openDevTools()
}
var app = require('app'); // Module to control application life.
var ipc = require('ipc');
var fs = require('fs-extra');
var os = require('os');
var dialog = require('dialog');
var BrowserWindow = require('browser-window');
var mainWindow = null;
app.commandLine.appendSwitch('--enable-npapi');
function initialSetup() {
// 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.loadUrl('file://' + __dirname + '/initialsetup.html');
// Exec installUnity.bat and wait for it to finish.
var child = require('child_process').spawn('cmd.exe', ['/c', 'utils\\installUnity.bat']);
child.on('exit', function() {
console.log("Unity installed.");
// Copy over files with default values
copySync(__dirname+"\\defaults\\config.json", app.getPath('userData')+"\\config.json");
copySync(__dirname+"\\defaults\\servers.json", app.getPath('userData')+"\\servers.json");
copySync(__dirname+"\\defaults\\versions.json", app.getPath('userData')+"\\versions.json");
console.log("JSON files copied.");
setupWindow.destroy();
showMainWindow();
})
}
ipc.on("exit", function(id) {
mainWindow.destroy();
});
// Quit when all windows are closed.
app.on('window-all-closed', function() {
if (process.platform != 'darwin')
app.quit();
});
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 =
( "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);
return;
}
// Create the browser window.
mainWindow = new BrowserWindow({width: 1280, height: 720, show: false, "web-preferences": {"plugins": true}});
mainWindow.setMinimumSize(640, 480);
// Check for first run
try {
if (!fs.existsSync(app.getPath('userData')+"\\config.json")) {
console.log("Config file not found. Running initial setup.");
initialSetup();
} else {
showMainWindow();
}
} catch(e) {
console.log("An error occurred while checking for the config.");
}
// Makes it so external links are opened in the system browser, not Electron
mainWindow.webContents.on('new-window', function(e, url) {
e.preventDefault();
require('shell').openExternal(url);
});
mainWindow.on('closed', function() {
mainWindow = null;
});
});
function showMainWindow() {
// Load the index.html of the app.
mainWindow.loadUrl('file://' + __dirname + '/index.html');
// Reduces white flash when opening the program
mainWindow.webContents.on('did-finish-load', function() {
mainWindow.show();
// everything's loaded, tell the renderer process to do its thing
mainWindow.webContents.executeJavaScript("loadConfig();");
mainWindow.webContents.executeJavaScript("loadGameVersions();");
mainWindow.webContents.executeJavaScript("loadServerList();");
});
mainWindow.webContents.on('plugin-crashed', function() {
console.log("Unity Web Player crashed.");
});
mainWindow.webContents.on('will-navigate', function(evt, url) {
evt.preventDefault();
// TODO: showMessageBox rather than showErrorBox?
switch (url) {
case "https://audience.fusionfall.com/ff/regWizard.do?_flowId=fusionfall-registration-flow":
errormsg =
( "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);
break;
case "https://audience.fusionfall.com/ff/login.do":
dialog.showErrorBox("Sorry!", "Account management is not available.");
break;
case "http://forums.fusionfall.com/":
require('shell').openExternal("https://discord.gg/DYavckB");
break;
default:
mainWindow.webContents.loadURL(url);
}
});
}

View File

@ -41,5 +41,8 @@
"to": "utils"
}
]
},
"dependencies": {
"fs-extra": "^0.30.0"
}
}