Misc comment cleanup, correct holiday date range, simplify JSON loading

This commit is contained in:
CakeLancelot 2023-09-19 08:51:19 -05:00
parent 76f4a05287
commit 71e4694ff6
3 changed files with 18 additions and 23 deletions

View File

@ -1,10 +1,8 @@
// You're kind of ruining the surprise by reading this, but whatever // You're kind of ruining the surprise by reading this, but whatever
var today = new Date(); var today = new Date();
// Check Christmas season: Date constructor in Javascript uses an index var christmasBegin = new Date(today.getFullYear(), 11, 21);
// so 11 is Dec. of this year, and 12 is Jan. of the next var christmasEnd = new Date(today.getFullYear(), 11, 31);
var christmasBegin = new Date(today.getFullYear(), 11, 23);
var christmasEnd = new Date(today.getFullYear(), 12, 8);
var sf; var sf;
if (today >= christmasBegin && today <= christmasEnd) { if (today >= christmasBegin && today <= christmasEnd) {

View File

@ -33,7 +33,7 @@ function disableServerListButtons() {
function getAppVersion() { function getAppVersion() {
appVersion = remote.require("app").getVersion(); appVersion = remote.require("app").getVersion();
// simplify version, ex. 1.4.0 -> 1.4, // Simplify version, ex. 1.4.0 -> 1.4,
// but only if a revision number isn't present // but only if a revision number isn't present
if (appVersion.endsWith(".0")) { if (appVersion.endsWith(".0")) {
return appVersion.substr(0, appVersion.length - 2); return appVersion.substr(0, appVersion.length - 2);
@ -48,7 +48,7 @@ function setAppVersionText() {
} }
function addServer() { function addServer() {
var jsonToModify = JSON.parse(remotefs.readFileSync(serversPath)); var jsonToModify = remotefs.readJsonSync(serversPath);
var server = {}; var server = {};
server["uuid"] = uuidv4(); server["uuid"] = uuidv4();
@ -70,7 +70,7 @@ function addServer() {
} }
function editServer() { function editServer() {
var jsonToModify = JSON.parse(remotefs.readFileSync(serversPath)); var jsonToModify = remotefs.readJsonSync(serversPath);
$.each(jsonToModify["servers"], function (key, value) { $.each(jsonToModify["servers"], function (key, value) {
if (value["uuid"] == getSelectedServer()) { if (value["uuid"] == getSelectedServer()) {
value["description"] = value["description"] =
@ -92,7 +92,7 @@ function editServer() {
} }
function deleteServer() { function deleteServer() {
var jsonToModify = JSON.parse(remotefs.readFileSync(serversPath)); var jsonToModify = remotefs.readJsonSync(serversPath);
var result = jsonToModify["servers"].filter(function (obj) { var result = jsonToModify["servers"].filter(function (obj) {
return obj.uuid === getSelectedServer(); return obj.uuid === getSelectedServer();
})[0]; })[0];
@ -114,7 +114,7 @@ function restoreDefaultServers() {
} }
function loadGameVersions() { function loadGameVersions() {
var versionJson = JSON.parse(remotefs.readFileSync(versionsPath)); var versionJson = remotefs.readJsonSync(versionsPath);
versionArray = versionJson["versions"]; versionArray = versionJson["versions"];
$.each(versionArray, function (key, value) { $.each(versionArray, function (key, value) {
$(new Option(value.name, "val")).appendTo("#addserver-versionselect"); $(new Option(value.name, "val")).appendTo("#addserver-versionselect");
@ -123,12 +123,12 @@ function loadGameVersions() {
} }
function loadConfig() { function loadConfig() {
// load config object globally // Load config object globally
config = JSON.parse(remotefs.readFileSync(configPath)); config = remotefs.readJsonSync(configPath);
} }
function loadServerList() { function loadServerList() {
var serverJson = JSON.parse(remotefs.readFileSync(serversPath)); var serverJson = remotefs.readJsonSync(serversPath);
serverArray = serverJson["servers"]; serverArray = serverJson["servers"];
$(".server-listing-entry").remove(); // Clear out old stuff, if any $(".server-listing-entry").remove(); // Clear out old stuff, if any
@ -168,16 +168,16 @@ function performCacheSwap(newVersion) {
var record = path.join(userData, ".lastver"); var record = path.join(userData, ".lastver");
var lastVersion = remotefs.readFileSync(record, (encoding = "utf8")); var lastVersion = remotefs.readFileSync(record, (encoding = "utf8"));
// make note of what version we are launching for next launch // Make note of what version we are launching for next launch
remotefs.writeFileSync(record, newVersion); remotefs.writeFileSync(record, newVersion);
// If cache renaming would result in a no-op (ex. launching the same version // If cache renaming would result in a no-op (ex. launching the same version
// two times), then skip it. this avoids permissions errors with multiple clients // two times), then skip it. This avoids permissions errors with multiple clients
// (file/folder is already open in another process) // (file/folder is already open in another process)
var skip = false; var skip = false;
if (remotefs.existsSync(currentCache)) { if (remotefs.existsSync(currentCache)) {
// cache already exists, find out what version it belongs to // Cache already exists, find out what version it belongs to
if (remotefs.existsSync(record)) { if (remotefs.existsSync(record)) {
if (lastVersion != newVersion) { if (lastVersion != newVersion) {
// Remove the directory we're trying to store the // Remove the directory we're trying to store the
@ -214,7 +214,7 @@ function setGameInfo(serverUUID) {
return obj.name === result.version; return obj.name === result.version;
})[0]; })[0];
// if cache swapping property exists AND is `true`, run cache swapping logic // If cache swapping property exists AND is `true`, run cache swapping logic
if (config["cache-swapping"]) { if (config["cache-swapping"]) {
try { try {
performCacheSwap(gameVersion.name); performCacheSwap(gameVersion.name);
@ -333,9 +333,7 @@ $("#server-table").on("dblclick", ".server-listing-entry", function (event) {
}); });
$("#of-editservermodal").on("show.bs.modal", function (e) { $("#of-editservermodal").on("show.bs.modal", function (e) {
var jsonToModify = JSON.parse( var jsonToModify = remotefs.readJsonSync(path.join(userData, "servers.json"));
remotefs.readFileSync(path.join(userData, "servers.json"))
);
$.each(jsonToModify["servers"], function (key, value) { $.each(jsonToModify["servers"], function (key, value) {
if (value["uuid"] == getSelectedServer()) { if (value["uuid"] == getSelectedServer()) {
$("#editserver-descinput")[0].value = value["description"]; $("#editserver-descinput")[0].value = value["description"];

View File

@ -9,7 +9,7 @@ var BrowserWindow = require("browser-window");
var mainWindow = null; var mainWindow = null;
var unityHomeDir = path.join(__dirname, "../../WebPlayer"); var unityHomeDir = path.join(__dirname, "../../WebPlayer");
// if running in non-packaged / development mode, this dir will be slightly different // If running in non-packaged / development mode, this dir will be slightly different
if (process.env.npm_node_execpath) { if (process.env.npm_node_execpath) {
unityHomeDir = path.join(app.getAppPath(), "/build/WebPlayer"); unityHomeDir = path.join(app.getAppPath(), "/build/WebPlayer");
} }
@ -31,13 +31,13 @@ var versionsPath = path.join(userData, "versions.json");
function initialSetup(firstTime) { function initialSetup(firstTime) {
if (!firstTime) { if (!firstTime) {
// migration from pre-1.4 // Migration from pre-1.4
// Back everything up, just in case // Back everything up, just in case
fs.copySync(configPath, configPath + ".bak"); fs.copySync(configPath, configPath + ".bak");
fs.copySync(serversPath, serversPath + ".bak"); fs.copySync(serversPath, serversPath + ".bak");
fs.copySync(versionsPath, versionsPath + ".bak"); fs.copySync(versionsPath, versionsPath + ".bak");
} else { } else {
// first-time setup // First-time setup
// Copy default servers // Copy default servers
fs.copySync( fs.copySync(
path.join(__dirname, "/defaults/servers.json"), path.join(__dirname, "/defaults/servers.json"),
@ -141,7 +141,6 @@ function showMainWindow() {
mainWindow.webContents.on("will-navigate", function (event, url) { mainWindow.webContents.on("will-navigate", function (event, url) {
event.preventDefault(); event.preventDefault();
// TODO: showMessageBox rather than showErrorBox?
switch (url) { switch (url) {
case "https://audience.fusionfall.com/ff/regWizard.do?_flowId=fusionfall-registration-flow": case "https://audience.fusionfall.com/ff/regWizard.do?_flowId=fusionfall-registration-flow":
var errorMessage = var errorMessage =