mirror of
				https://github.com/OpenFusionProject/Client.git
				synced 2025-10-31 03:10:11 +00:00 
			
		
		
		
	implemented delete as ipc, adjusted for cache swap
This commit is contained in:
		| @@ -260,8 +260,6 @@ function startHashCheck(versionString, cacheMode) { | |||||||
| } | } | ||||||
|  |  | ||||||
| function loadCacheList() { | function loadCacheList() { | ||||||
|     resetCacheNames(); |  | ||||||
|  |  | ||||||
|     var versionjson = remotefs.readJsonSync(versionsPath); |     var versionjson = remotefs.readJsonSync(versionsPath); | ||||||
|     versionArray = versionjson["versions"]; |     versionArray = versionjson["versions"]; | ||||||
|  |  | ||||||
| @@ -293,19 +291,11 @@ function loadCacheList() { | |||||||
| } | } | ||||||
|  |  | ||||||
| function deletePlayableCache(versionString) { | function deletePlayableCache(versionString) { | ||||||
|     if (versionString === "Offline") { |     ipc.send("delete-files", { | ||||||
|         console.log("Cannot delete Offline directory!"); |         localDir: cacheRoot, | ||||||
|         return; |         cacheMode: "playable", | ||||||
|     } |         versionString: versionString, | ||||||
|  |     }); | ||||||
|     // 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"); |  | ||||||
| } | } | ||||||
|  |  | ||||||
| function downloadOfflineCache(versionString) { | function downloadOfflineCache(versionString) { | ||||||
| @@ -323,27 +313,11 @@ function downloadOfflineCache(versionString) { | |||||||
| } | } | ||||||
|  |  | ||||||
| function deleteOfflineCache(versionString) { | function deleteOfflineCache(versionString) { | ||||||
|     remotefs.removeSync(path.join(offlineRoot, versionString)); |     ipc.send("delete-files", { | ||||||
|     console.log("Offline cache " + versionString + " has been removed!"); |         localDir: offlineRoot, | ||||||
|  |         cacheMode: "offline", | ||||||
|     // this updates the labels etc. properly |         versionString: versionString, | ||||||
|     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."); |  | ||||||
| } | } | ||||||
|  |  | ||||||
| function performCacheSwap(newVersion) { | function performCacheSwap(newVersion) { | ||||||
|   | |||||||
							
								
								
									
										48
									
								
								index.js
									
									
									
									
									
								
							
							
						
						
									
										48
									
								
								index.js
									
									
									
									
									
								
							| @@ -160,7 +160,7 @@ app.on("ready", function () { | |||||||
|  |  | ||||||
|         downloadFiles( |         downloadFiles( | ||||||
|             arg.cdnDir, |             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], |             versionHashes[arg.versionString][arg.cacheMode], | ||||||
|             function (sizes) { |             function (sizes) { | ||||||
|                 currentSizes.intact += sizes.intact; |                 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) { |     ipc.on("hash-check", function (event, arg) { | ||||||
|         var currentSizes = versionSizes[arg.versionString][arg.cacheMode]; |         var currentSizes = versionSizes[arg.versionString][arg.cacheMode]; | ||||||
|         currentSizes.intact = 0; |         currentSizes.intact = 0; | ||||||
| @@ -197,7 +225,7 @@ app.on("ready", function () { | |||||||
|         }); |         }); | ||||||
|  |  | ||||||
|         checkHashes( |         checkHashes( | ||||||
|             path.join(arg.localDir, arg.versionString), |             getSwappedPathSync(arg.localDir, arg.versionString), | ||||||
|             versionHashes[arg.versionString][arg.cacheMode], |             versionHashes[arg.versionString][arg.cacheMode], | ||||||
|             function (sizes) { |             function (sizes) { | ||||||
|                 currentSizes.intact += sizes.intact; |                 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) { | function downloadFile(cdnDir, localDir, relativePath, fileHash, callback, updateCallback) { | ||||||
|     var nginxUrl = cdnDir + "/" + relativePath; |     var nginxUrl = cdnDir + "/" + relativePath; | ||||||
|     var localPath = path.join(localDir, relativePath); |     var localPath = path.join(localDir, relativePath); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 FinnHornhoover
					FinnHornhoover