mirror of
https://github.com/OpenFusionProject/Client.git
synced 2024-11-22 13:40:06 +00:00
implemented delete as ipc, adjusted for cache swap
This commit is contained in:
parent
a1678cb1e9
commit
f7d1b73806
@ -260,8 +260,6 @@ function startHashCheck(versionString, cacheMode) {
|
||||
}
|
||||
|
||||
function loadCacheList() {
|
||||
resetCacheNames();
|
||||
|
||||
var versionjson = remotefs.readJsonSync(versionsPath);
|
||||
versionArray = versionjson["versions"];
|
||||
|
||||
@ -293,19 +291,11 @@ function loadCacheList() {
|
||||
}
|
||||
|
||||
function deletePlayableCache(versionString) {
|
||||
if (versionString === "Offline") {
|
||||
console.log("Cannot delete Offline directory!");
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: remove this function
|
||||
resetCacheNames();
|
||||
|
||||
remotefs.removeSync(path.join(cacheRoot, versionString));
|
||||
console.log("Playable cache " + versionString + " has been removed!");
|
||||
|
||||
// this updates the labels etc. properly
|
||||
startHashCheck(versionString, "playable");
|
||||
ipc.send("delete-files", {
|
||||
localDir: cacheRoot,
|
||||
cacheMode: "playable",
|
||||
versionString: versionString,
|
||||
});
|
||||
}
|
||||
|
||||
function downloadOfflineCache(versionString) {
|
||||
@ -323,27 +313,11 @@ function downloadOfflineCache(versionString) {
|
||||
}
|
||||
|
||||
function deleteOfflineCache(versionString) {
|
||||
remotefs.removeSync(path.join(offlineRoot, versionString));
|
||||
console.log("Offline cache " + versionString + " has been removed!");
|
||||
|
||||
// this updates the labels etc. properly
|
||||
startHashCheck(versionString, "offline");
|
||||
}
|
||||
|
||||
function resetCacheNames() {
|
||||
var currentCache = path.join(cacheRoot, "Fusionfall");
|
||||
var record = path.join(userData, ".lastver");
|
||||
|
||||
if (!remotefs.existsSync(currentCache)) {
|
||||
return;
|
||||
}
|
||||
|
||||
var lastVersion = remotefs.readFileSync(record, (encoding = "utf8"));
|
||||
remotefs.renameSync(
|
||||
currentCache,
|
||||
path.join(cacheRoot, lastVersion)
|
||||
);
|
||||
console.log("Current cache " + lastVersion + " has been renamed to its original name.");
|
||||
ipc.send("delete-files", {
|
||||
localDir: offlineRoot,
|
||||
cacheMode: "offline",
|
||||
versionString: versionString,
|
||||
});
|
||||
}
|
||||
|
||||
function performCacheSwap(newVersion) {
|
||||
|
48
index.js
48
index.js
@ -160,7 +160,7 @@ app.on("ready", function () {
|
||||
|
||||
downloadFiles(
|
||||
arg.cdnDir,
|
||||
path.join(arg.localDir, arg.versionString),
|
||||
getSwappedPathSync(arg.localDir, arg.versionString), // this shouldn't matter, for consistency only
|
||||
versionHashes[arg.versionString][arg.cacheMode],
|
||||
function (sizes) {
|
||||
currentSizes.intact += sizes.intact;
|
||||
@ -185,6 +185,34 @@ app.on("ready", function () {
|
||||
);
|
||||
});
|
||||
|
||||
ipc.on("delete-files", function (event, arg) {
|
||||
var deleteDir = getSwappedPathSync(arg.localDir, arg.versionString);
|
||||
|
||||
if (arg.cacheMode === "playable" && path.basename(deleteDir) === "Offline") {
|
||||
dialog.showErrorBox("Error!", "Cannot delete Offline directory as a playable cache!");
|
||||
return;
|
||||
}
|
||||
|
||||
var currentSizes = versionSizes[arg.versionString][arg.cacheMode];
|
||||
currentSizes.intact = 0;
|
||||
currentSizes.altered = 0;
|
||||
|
||||
mainWindow.webContents.send("storage-loading-start", {
|
||||
cacheMode: arg.cacheMode,
|
||||
versionString: arg.versionString,
|
||||
sizes: currentSizes,
|
||||
});
|
||||
|
||||
fs.removeSync(deleteDir);
|
||||
console.log(arg.versionString + " (" + arg.cacheMode + ") has been removed!");
|
||||
|
||||
mainWindow.webContents.send("storage-loading-complete", {
|
||||
cacheMode: arg.cacheMode,
|
||||
versionString: arg.versionString,
|
||||
sizes: currentSizes,
|
||||
});
|
||||
});
|
||||
|
||||
ipc.on("hash-check", function (event, arg) {
|
||||
var currentSizes = versionSizes[arg.versionString][arg.cacheMode];
|
||||
currentSizes.intact = 0;
|
||||
@ -197,7 +225,7 @@ app.on("ready", function () {
|
||||
});
|
||||
|
||||
checkHashes(
|
||||
path.join(arg.localDir, arg.versionString),
|
||||
getSwappedPathSync(arg.localDir, arg.versionString),
|
||||
versionHashes[arg.versionString][arg.cacheMode],
|
||||
function (sizes) {
|
||||
currentSizes.intact += sizes.intact;
|
||||
@ -272,6 +300,22 @@ function showMainWindow() {
|
||||
});
|
||||
}
|
||||
|
||||
function getSwappedPathSync(localDir, versionString) {
|
||||
var currentCache = path.join(localDir, "FusionFall");
|
||||
var versionCache = path.join(localDir, versionString);
|
||||
var record = path.join(userData, ".lastver");
|
||||
|
||||
if (!fs.existsSync(versionCache) &&
|
||||
fs.existsSync(currentCache) &&
|
||||
fs.existsSync(record) &&
|
||||
versionString === fs.readFileSync(record, (encoding = "utf8"))) {
|
||||
|
||||
versionCache = currentCache;
|
||||
}
|
||||
|
||||
return versionCache;
|
||||
}
|
||||
|
||||
function downloadFile(cdnDir, localDir, relativePath, fileHash, callback, updateCallback) {
|
||||
var nginxUrl = cdnDir + "/" + relativePath;
|
||||
var localPath = path.join(localDir, relativePath);
|
||||
|
Loading…
Reference in New Issue
Block a user