removed async, adjusted load logic, and hash check

This commit is contained in:
FinnHornhoover 2023-10-22 00:30:35 +03:00
parent 11f0c61a67
commit 6bae0d1ff6
4 changed files with 39 additions and 10 deletions

View File

@ -18,6 +18,7 @@ var offlineRoot = path.join(cacheRoot, "Offline");
var versionArray; var versionArray;
var serverArray; var serverArray;
var cacheSizes;
var config; var config;
function enableServerListButtons() { function enableServerListButtons() {
@ -288,7 +289,13 @@ function storageLoadingUpdate(allSizes) {
$.each(allSizes, function (versionString, vSizes) { $.each(allSizes, function (versionString, vSizes) {
$.each(vSizes, function (cacheMode, sizes) { $.each(vSizes, function (cacheMode, sizes) {
var label = document.getElementById(getCacheElemID(versionString, cacheMode, "label")); var label = document.getElementById(getCacheElemID(versionString, cacheMode, "label"));
cacheSizes = cacheSizes || {};
cacheSizes[versionString] = cacheSizes[versionString] || {};
cacheSizes[versionString][cacheMode] = sizes || {};
if (!label) return; if (!label) return;
label.innerHTML = getCacheLabelText(sizes); label.innerHTML = getCacheLabelText(sizes);
}); });
}); });
@ -417,6 +424,12 @@ function loadCacheList() {
}); });
} }
function startHashCheck() {
// only run once
if (!cacheSizes)
handleCache("hash-check");
}
function performCacheSwap(newVersion) { function performCacheSwap(newVersion) {
var currentCache = path.join(cacheRoot, "FusionFall"); var currentCache = path.join(cacheRoot, "FusionFall");
var newCache = path.join(cacheRoot, newVersion); var newCache = path.join(cacheRoot, newVersion);
@ -479,19 +492,34 @@ function prepGameInfo(serverUUID) {
} }
} }
handleCache("hash-check", versionInfo.name, "offline", function (sizes) { if (config["always-use-cdn"]) {
var versionURL = (sizes.intact < sizes.total) ? // if we always ignore the offline cache, just use the URL
versionInfo.url : setGameInfo(serverInfo, versionInfo.url);
"file:///" + path.join(offlineRoot, versionInfo.name).replace(/\\/g, "/") + "/"; return;
console.log("Cache will expand from " + versionURL); }
var offlinePath = path.join(offlineRoot, versionInfo.name);
var offlineURL = "file:///" + offlinePath.replace(/\\/g, "/") + "/";
if (config["verify-offline-cache"]) {
// if required, do a full hash check, and use the offline cache only if it is fully intact
handleCache("hash-check", versionInfo.name, "offline", function (sizes) {
var versionURL = (sizes.intact < sizes.total) ? versionInfo.url : offlineURL;
setGameInfo(serverInfo, versionURL); setGameInfo(serverInfo, versionURL);
}); });
return;
}
// if main.unity3d is present, use the offline cache
var mainPath = path.join(offlinePath, "main.unity3d");
var versionURL = remotefs.existsSync(mainPath) ? versionInfo.url : offlineURL;
setGameInfo(serverInfo, versionURL);
} }
// For writing loginInfo.php, assetInfo.php, etc. // For writing loginInfo.php, assetInfo.php, etc.
function setGameInfo(serverInfo, versionURL) { function setGameInfo(serverInfo, versionURL) {
window.assetUrl = versionURL; // game-client.js needs to access this window.assetUrl = versionURL; // game-client.js needs to access this
console.log("Cache will expand from " + versionURL);
remotefs.writeFileSync(path.join(__dirname, "assetInfo.php"), assetUrl); remotefs.writeFileSync(path.join(__dirname, "assetInfo.php"), assetUrl);
if (serverInfo.hasOwnProperty("endpoint")) { if (serverInfo.hasOwnProperty("endpoint")) {

View File

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

View File

@ -117,7 +117,7 @@
type="button" type="button"
title="Edit Cache Storage" title="Edit Cache Storage"
data-target="#of-editcacheconfigmodal" data-target="#of-editcacheconfigmodal"
onclick="handleCache('hash-check')" onclick="startHashCheck()"
> >
<i class="fas fa-cog"></i> <i class="fas fa-cog"></i>
</button> </button>

View File

@ -74,7 +74,6 @@
"afterPack": "./build/after-pack.js" "afterPack": "./build/after-pack.js"
}, },
"dependencies": { "dependencies": {
"fs-extra": "2.0.0", "fs-extra": "2.0.0"
"async": "1.5.2"
} }
} }