diff --git a/assets/css/openfusion.css b/assets/css/openfusion.css index c8bc8d8..a357719 100644 --- a/assets/css/openfusion.css +++ b/assets/css/openfusion.css @@ -115,6 +115,11 @@ body { border-color: #6699ff; } +#of-editconfigmodal > .modal-dialog > .modal-content { + background-color: #093363; + border-color: #6699ff; +} + #of-addversionmodal > .modal-dialog > .modal-content { background-color: #093363; border-color: #6699ff; diff --git a/assets/js/server-selector.js b/assets/js/server-selector.js index 149a6e7..6a1f1b0 100644 --- a/assets/js/server-selector.js +++ b/assets/js/server-selector.js @@ -14,7 +14,8 @@ var cacheRoot = path.join( userData, "/../../LocalLow/Unity/Web Player/Cache" ); -var offlineRoot = path.join(cacheRoot, "Offline"); +var offlineRootDefault = path.join(cacheRoot, "Offline"); +var offlineRoot = offlineRootDefault; var cdnString = "http://cdn.dexlabs.systems/ff/big"; @@ -292,6 +293,38 @@ function restoreDefaultVersions() { handleCache("hash-check"); } +function editConfig() { + var jsonToModify = JSON.parse(remotefs.readJsonSync(configPath)); + + jsonToModify["autoupdate-check"] = $("#editconfig-autoupdate").prop("checked"); + jsonToModify["cache-swapping"] = $("#editconfig-cacheswapping").prop("checked"); + jsonToModify["enable-offline-cache"] = $("#editconfig-enableofflinecache").prop("checked"); + jsonToModify["verify-offline-cache"] = $("#editconfig-verifyofflinecache").prop("checked"); + + var dirInput = $("#editconfig-offlinecachelocation:text").val(); + + jsonToModify["offline-cache-location"] = ( + remotefs.existsSync(dirInput) && + remotefs.statSync(dirInput).isDirectory() + ) ? dirInput : offlineRoot; + + remotefs.writeFileSync(configPath, JSON.stringify(jsonToModify, null, 4)); + loadConfig(); +} + +function validateCacheLocation() { + var input = document.getElementById("editconfig-offlinecachelocation"); + var button = document.getElementById("editconfig-savebutton"); + + input.classList.remove("invalidinput"); + button.removeAttribute("disabled"); + + if (!remotefs.existsSync(input.value) || !remotefs.statSync(input.value).isDirectory()) { + input.classList.add("invalidinput"); + button.setAttribute("disabled", ""); + } +} + function loadGameVersions() { var versionJson = remotefs.readJsonSync(versionsPath); versionArray = versionJson["versions"]; @@ -304,6 +337,16 @@ function loadGameVersions() { function loadConfig() { // Load config object globally config = remotefs.readJsonSync(configPath); + + $("#editconfig-autoupdate").prop("checked", config["autoupdate-check"]); + $("#editconfig-cacheswapping").prop("checked", config["cache-swapping"]); + $("#editconfig-enableofflinecache").prop("checked", config["enable-offline-cache"]); + $("#editconfig-verifyofflinecache").prop("checked", config["verify-offline-cache"]); + + offlineRoot = config["offline-cache-location"] || offlineRootDefault; + $("#editconfig-offlinecachelocation:text").val(offlineRoot); + + validateCacheLocation(); } function loadServerList() { @@ -685,7 +728,7 @@ function prepGameInfo(serverUUID) { } } - if (config["always-use-cdn"]) { + if (!config["enable-offline-cache"]) { // if we always ignore the offline cache, just use the URL setGameInfo(serverInfo, versionInfo.url); return; @@ -898,3 +941,8 @@ $("#of-deleteversionmodal").on("show.bs.modal", function (e) { $("#of-editcacheconfigmodal").on("show.bs.modal", function (e) { if (!cacheSizes) handleCache("hash-check"); }); + +$("#of-editconfigmodal").on("show.bs.modal", function (e) { + // best to keep this synced on modal show + loadConfig(); +}); diff --git a/defaults/config.json b/defaults/config.json index 86e3078..d8b71ae 100644 --- a/defaults/config.json +++ b/defaults/config.json @@ -1,7 +1,7 @@ { "autoupdate-check": true, "cache-swapping": true, - "always-use-cdn": true, + "enable-offline-cache": false, "verify-offline-cache": false, - "last-version-initialized": "1.5" + "last-version-initialized": "1.6" } diff --git a/index.html b/index.html index f16863f..c057b6b 100644 --- a/index.html +++ b/index.html @@ -108,6 +108,18 @@