install: use local zip cache
This commit is contained in:
@@ -1,12 +1,16 @@
|
|||||||
Imports System.IO
|
Imports System.IO
|
||||||
Imports System.IO.Compression
|
Imports System.IO.Compression
|
||||||
Imports System.Net
|
|
||||||
Imports System.Net.Http
|
Imports System.Net.Http
|
||||||
|
|
||||||
Imports ModpackUpdater.Model
|
Imports ModpackUpdater.Model
|
||||||
|
|
||||||
Public Class ModpackInstaller
|
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 InstallProgessUpdated(result As UpdateCheckResult, processedSyncs As Integer)
|
||||||
Public Event CheckingProgressUpdated(toCheck As Integer, processed 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?)
|
Public Async Function Install(checkResult As UpdateCheckResult) As Task(Of Boolean?)
|
||||||
Dim modpackInfo As ModpackInfo
|
Dim modpackInfo As ModpackInfo
|
||||||
Dim processed As Integer = 0
|
Dim processed As Integer = 0
|
||||||
|
Dim localZipCache As New List(Of LocalZipCacheEntry)
|
||||||
|
|
||||||
If ModpackInfo.HasModpackInfo(localPath) Then
|
If ModpackInfo.HasModpackInfo(localPath) Then
|
||||||
modpackInfo = ModpackInfo.Load(localPath)
|
modpackInfo = ModpackInfo.Load(localPath)
|
||||||
@@ -100,7 +105,7 @@ Public Class ModpackInstaller
|
|||||||
|
|
||||||
Select Case uaction.Type
|
Select Case uaction.Type
|
||||||
Case UpdateActionType.Update
|
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
|
Case UpdateActionType.Delete
|
||||||
If uaction.IsDirectory Then
|
If uaction.IsDirectory Then
|
||||||
If Directory.Exists(destFilePath) Then
|
If Directory.Exists(destFilePath) Then
|
||||||
@@ -125,7 +130,7 @@ Public Class ModpackInstaller
|
|||||||
End If
|
End If
|
||||||
End Select
|
End Select
|
||||||
Else
|
Else
|
||||||
Await InstallFile(destFilePath, iaction.DownloadUrl, iaction.IsZip, iaction.ZipPath)
|
Await InstallFile(destFilePath, iaction.DownloadUrl, iaction.IsZip, iaction.ZipPath, localZipCache)
|
||||||
End If
|
End If
|
||||||
|
|
||||||
processed += 1
|
processed += 1
|
||||||
@@ -135,10 +140,14 @@ Public Class ModpackInstaller
|
|||||||
modpackInfo.Version = checkResult.LatestVersion
|
modpackInfo.Version = checkResult.LatestVersion
|
||||||
modpackInfo.Save(localPath)
|
modpackInfo.Save(localPath)
|
||||||
|
|
||||||
|
For Each task In localZipCache
|
||||||
|
Directory.Delete(task.ExtractedZipPath, True)
|
||||||
|
Next
|
||||||
|
|
||||||
Return True
|
Return True
|
||||||
End Function
|
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))
|
Directory.CreateDirectory(Path.GetDirectoryName(destFilePath))
|
||||||
|
|
||||||
Dim fsDestinationPath As String = If(isZip, Path.Combine(Path.GetTempPath(), $"mc_update_file_{Date.Now.ToBinary}.zip"), 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)
|
ZipFile.ExtractToDirectory(fsDestinationPath, zipDir)
|
||||||
'...
|
'...
|
||||||
File.Delete(fsDestinationPath)
|
File.Delete(fsDestinationPath)
|
||||||
Directory.Delete(zipDir, True)
|
localZipCache?.Add(New LocalZipCacheEntry With {
|
||||||
|
.DownloadUrl = sourceUrl,
|
||||||
|
.ExtractedZipPath = zipDir
|
||||||
|
})
|
||||||
End If
|
End If
|
||||||
End Function
|
End Function
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user