From f1b11ea3c6addd4eea33fea7f0ab2d8514a6d0b0 Mon Sep 17 00:00:00 2001 From: Pilzinsel64 Date: Mon, 17 Jun 2024 18:40:30 +0200 Subject: [PATCH] install: use local zip cache --- ModpackUpdater.Manager/ModpackInstaller.vb | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/ModpackUpdater.Manager/ModpackInstaller.vb b/ModpackUpdater.Manager/ModpackInstaller.vb index 0d0950f..980420a 100644 --- a/ModpackUpdater.Manager/ModpackInstaller.vb +++ b/ModpackUpdater.Manager/ModpackInstaller.vb @@ -1,12 +1,16 @@ Imports System.IO Imports System.IO.Compression -Imports System.Net Imports System.Net.Http Imports ModpackUpdater.Model Public Class ModpackInstaller + Private Class LocalZipCacheEntry + Public Property DownloadUrl As String + Public Property ExtractedZipPath As String + End Class + Public Event InstallProgessUpdated(result As UpdateCheckResult, processedSyncs As Integer) Public Event CheckingProgressUpdated(toCheck As Integer, processed As Integer) @@ -85,6 +89,7 @@ Public Class ModpackInstaller Public Async Function Install(checkResult As UpdateCheckResult) As Task(Of Boolean?) Dim modpackInfo As ModpackInfo Dim processed As Integer = 0 + Dim localZipCache As New List(Of LocalZipCacheEntry) If ModpackInfo.HasModpackInfo(localPath) Then modpackInfo = ModpackInfo.Load(localPath) @@ -100,7 +105,7 @@ Public Class ModpackInstaller Select Case uaction.Type Case UpdateActionType.Update - Await InstallFile(destFilePath, uaction.DownloadUrl, uaction.IsZip, uaction.ZipPath) + Await InstallFile(destFilePath, uaction.DownloadUrl, uaction.IsZip, uaction.ZipPath, localZipCache) Case UpdateActionType.Delete If uaction.IsDirectory Then If Directory.Exists(destFilePath) Then @@ -125,7 +130,7 @@ Public Class ModpackInstaller End If End Select Else - Await InstallFile(destFilePath, iaction.DownloadUrl, iaction.IsZip, iaction.ZipPath) + Await InstallFile(destFilePath, iaction.DownloadUrl, iaction.IsZip, iaction.ZipPath, localZipCache) End If processed += 1 @@ -135,10 +140,14 @@ Public Class ModpackInstaller modpackInfo.Version = checkResult.LatestVersion modpackInfo.Save(localPath) + For Each task In localZipCache + Directory.Delete(task.ExtractedZipPath, True) + Next + Return True End Function - Private Async Function InstallFile(destFilePath As String, sourceUrl As String, isZip As Boolean, zipPath As String) As Task + Private Async Function InstallFile(destFilePath As String, sourceUrl As String, isZip As Boolean, zipPath As String, localZipCache As List(Of LocalZipCacheEntry)) As Task Directory.CreateDirectory(Path.GetDirectoryName(destFilePath)) Dim fsDestinationPath As String = If(isZip, Path.Combine(Path.GetTempPath(), $"mc_update_file_{Date.Now.ToBinary}.zip"), destFilePath) @@ -153,7 +162,10 @@ Public Class ModpackInstaller ZipFile.ExtractToDirectory(fsDestinationPath, zipDir) '... File.Delete(fsDestinationPath) - Directory.Delete(zipDir, True) + localZipCache?.Add(New LocalZipCacheEntry With { + .DownloadUrl = sourceUrl, + .ExtractedZipPath = zipDir + }) End If End Function