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
var today = new Date();
// Check Christmas season: Date constructor in Javascript uses an index
// so 11 is Dec. of this year, and 12 is Jan. of the next
var christmasBegin = new Date(today.getFullYear(), 11, 23);
var christmasEnd = new Date(today.getFullYear(), 12, 8);
var christmasBegin = new Date(today.getFullYear(), 11, 21);
var christmasEnd = new Date(today.getFullYear(), 11, 31);
var sf;
if (today >= christmasBegin && today <= christmasEnd) {

View File

@ -33,7 +33,7 @@ function disableServerListButtons() {
function getAppVersion() {
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
if (appVersion.endsWith(".0")) {
return appVersion.substr(0, appVersion.length - 2);
@ -48,7 +48,7 @@ function setAppVersionText() {
}
function addServer() {
var jsonToModify = JSON.parse(remotefs.readFileSync(serversPath));
var jsonToModify = remotefs.readJsonSync(serversPath);
var server = {};
server["uuid"] = uuidv4();
@ -70,7 +70,7 @@ function addServer() {
}
function editServer() {
var jsonToModify = JSON.parse(remotefs.readFileSync(serversPath));
var jsonToModify = remotefs.readJsonSync(serversPath);
$.each(jsonToModify["servers"], function (key, value) {
if (value["uuid"] == getSelectedServer()) {
value["description"] =
@ -92,7 +92,7 @@ function editServer() {
}
function deleteServer() {
var jsonToModify = JSON.parse(remotefs.readFileSync(serversPath));
var jsonToModify = remotefs.readJsonSync(serversPath);
var result = jsonToModify["servers"].filter(function (obj) {
return obj.uuid === getSelectedServer();
})[0];
@ -114,7 +114,7 @@ function restoreDefaultServers() {
}
function loadGameVersions() {
var versionJson = JSON.parse(remotefs.readFileSync(versionsPath));
var versionJson = remotefs.readJsonSync(versionsPath);
versionArray = versionJson["versions"];
$.each(versionArray, function (key, value) {
$(new Option(value.name, "val")).appendTo("#addserver-versionselect");
@ -123,12 +123,12 @@ function loadGameVersions() {
}
function loadConfig() {
// load config object globally
config = JSON.parse(remotefs.readFileSync(configPath));
// Load config object globally
config = remotefs.readJsonSync(configPath);
}
function loadServerList() {
var serverJson = JSON.parse(remotefs.readFileSync(serversPath));
var serverJson = remotefs.readJsonSync(serversPath);
serverArray = serverJson["servers"];
$(".server-listing-entry").remove(); // Clear out old stuff, if any
@ -168,16 +168,16 @@ function performCacheSwap(newVersion) {
var record = path.join(userData, ".lastver");
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);
// 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)
var skip = false;
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 (lastVersion != newVersion) {
// Remove the directory we're trying to store the
@ -214,7 +214,7 @@ function setGameInfo(serverUUID) {
return obj.name === result.version;
})[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"]) {
try {
performCacheSwap(gameVersion.name);
@ -333,9 +333,7 @@ $("#server-table").on("dblclick", ".server-listing-entry", function (event) {
});
$("#of-editservermodal").on("show.bs.modal", function (e) {
var jsonToModify = JSON.parse(
remotefs.readFileSync(path.join(userData, "servers.json"))
);
var jsonToModify = remotefs.readJsonSync(path.join(userData, "servers.json"));
$.each(jsonToModify["servers"], function (key, value) {
if (value["uuid"] == getSelectedServer()) {
$("#editserver-descinput")[0].value = value["description"];

View File

@ -9,7 +9,7 @@ var BrowserWindow = require("browser-window");
var mainWindow = null;
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) {
unityHomeDir = path.join(app.getAppPath(), "/build/WebPlayer");
}
@ -31,13 +31,13 @@ var versionsPath = path.join(userData, "versions.json");
function initialSetup(firstTime) {
if (!firstTime) {
// migration from pre-1.4
// Migration from pre-1.4
// Back everything up, just in case
fs.copySync(configPath, configPath + ".bak");
fs.copySync(serversPath, serversPath + ".bak");
fs.copySync(versionsPath, versionsPath + ".bak");
} else {
// first-time setup
// First-time setup
// Copy default servers
fs.copySync(
path.join(__dirname, "/defaults/servers.json"),
@ -141,7 +141,6 @@ function showMainWindow() {
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":
var errorMessage =