added config modal, bumped version

This commit is contained in:
FinnHornhoover 2023-11-13 00:15:45 +03:00
parent 171177b606
commit 6a7b029539
5 changed files with 154 additions and 8 deletions

View File

@ -115,6 +115,11 @@ body {
border-color: #6699ff; border-color: #6699ff;
} }
#of-editconfigmodal > .modal-dialog > .modal-content {
background-color: #093363;
border-color: #6699ff;
}
#of-addversionmodal > .modal-dialog > .modal-content { #of-addversionmodal > .modal-dialog > .modal-content {
background-color: #093363; background-color: #093363;
border-color: #6699ff; border-color: #6699ff;

View File

@ -14,7 +14,8 @@ var cacheRoot = path.join(
userData, userData,
"/../../LocalLow/Unity/Web Player/Cache" "/../../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"; var cdnString = "http://cdn.dexlabs.systems/ff/big";
@ -292,6 +293,38 @@ function restoreDefaultVersions() {
handleCache("hash-check"); 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() { function loadGameVersions() {
var versionJson = remotefs.readJsonSync(versionsPath); var versionJson = remotefs.readJsonSync(versionsPath);
versionArray = versionJson["versions"]; versionArray = versionJson["versions"];
@ -304,6 +337,16 @@ function loadGameVersions() {
function loadConfig() { function loadConfig() {
// Load config object globally // Load config object globally
config = remotefs.readJsonSync(configPath); 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() { 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 // if we always ignore the offline cache, just use the URL
setGameInfo(serverInfo, versionInfo.url); setGameInfo(serverInfo, versionInfo.url);
return; return;
@ -898,3 +941,8 @@ $("#of-deleteversionmodal").on("show.bs.modal", function (e) {
$("#of-editcacheconfigmodal").on("show.bs.modal", function (e) { $("#of-editcacheconfigmodal").on("show.bs.modal", function (e) {
if (!cacheSizes) handleCache("hash-check"); if (!cacheSizes) handleCache("hash-check");
}); });
$("#of-editconfigmodal").on("show.bs.modal", function (e) {
// best to keep this synced on modal show
loadConfig();
});

View File

@ -1,7 +1,7 @@
{ {
"autoupdate-check": true, "autoupdate-check": true,
"cache-swapping": true, "cache-swapping": true,
"always-use-cdn": true, "enable-offline-cache": false,
"verify-offline-cache": false, "verify-offline-cache": false,
"last-version-initialized": "1.5" "last-version-initialized": "1.6"
} }

View File

@ -108,6 +108,18 @@
</button> </button>
</div> </div>
<div class="col-4 d-inline-flex justify-content-end"> <div class="col-4 d-inline-flex justify-content-end">
<button
class="btn btn-primary mr-1"
data-toggle="modal"
data-bs-tooltip=""
data-placement="bottom"
id="of-editconfig-button"
type="button"
title="Edit Configuration"
data-target="#of-editconfigmodal"
>
<i class="fas fa-cog"></i>
</button>
<button <button
class="btn btn-primary mr-1" class="btn btn-primary mr-1"
data-toggle="modal" data-toggle="modal"
@ -469,6 +481,87 @@
</div> </div>
</div> </div>
</div> </div>
<div
class="modal fade"
role="dialog"
tabindex="-1"
id="of-editconfigmodal"
>
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Edit Configuration</h4>
<button
type="button"
class="close"
data-dismiss="modal"
aria-label="Close"
>
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form id="editconfig-form" class="needs-validation">
<label for="editconfig-autoupdate"
>Automatically update the client:</label
><input
class="form-control form-row w-75"
type="checkbox"
id="editconfig-autoupdate"
/>
<label for="editconfig-cacheswapping"
>Swap game caches to avoid unnecessary downloads:</label
><input
class="form-control form-row w-75"
type="checkbox"
id="editconfig-cacheswapping"
/>
<label for="editconfig-enableofflinecache"
>Use offline caches when they are available:</label
><input
class="form-control form-row w-75"
type="checkbox"
id="editconfig-enableofflinecache"
/>
<label for="editconfig-verifyofflinecache"
>Verify offline caches every time they are loaded:</label
><input
class="form-control form-row w-75"
type="checkbox"
id="editconfig-verifyofflinecache"
/>
<label for="editconfig-offlinecachelocation"
>Select Offline Cache Location:</label
><input
class="form-control form-row w-75"
id="editconfig-offlinecachelocation"
type="text"
oninput="validateCacheLocator()"
/>
</form>
</div>
<div class="modal-footer">
<button
class="btn btn-primary border rounded border-primary btn-danger border-danger"
id="editconfig-cancel"
type="button"
data-dismiss="modal"
>
Cancel</button
><button
class="btn btn-primary border rounded border-primary btn-success border-success"
id="editconfig-savebutton"
type="submit"
data-dismiss="modal"
form="editconfig-form"
onclick="editConfig();"
>
Save
</button>
</div>
</div>
</div>
</div>
<div <div
class="modal fade" class="modal fade"
role="dialog" role="dialog"
@ -478,7 +571,7 @@
<div class="modal-dialog modal-dialog-centered modal-lg" role="document"> <div class="modal-dialog modal-dialog-centered modal-lg" role="document">
<div class="modal-content"> <div class="modal-content">
<div class="modal-header"> <div class="modal-header">
<h4 class="modal-title">Edit Cache Config</h4> <h4 class="modal-title">Edit Game Builds</h4>
<button <button
type="button" type="button"
class="close" class="close"

View File

@ -32,7 +32,7 @@ var hashPath = path.join(userData, "hashes.json");
function initialSetup(firstTime) { function initialSetup(firstTime) {
if (!firstTime) { if (!firstTime) {
// Migration from pre-1.5 // Migration from pre-1.6
// 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");
@ -93,8 +93,8 @@ app.on("ready", function () {
initialSetup(true); initialSetup(true);
} else { } else {
var config = fs.readJsonSync(configPath); var config = fs.readJsonSync(configPath);
if (config["last-version-initialized"] !== "1.5") { if (config["last-version-initialized"] !== "1.6") {
console.log("Pre-1.5 config detected. Running migration."); console.log("Pre-1.6 config detected. Running migration.");
initialSetup(false); initialSetup(false);
} else { } else {
showMainWindow(); showMainWindow();