install: more directory power
This commit is contained in:
@@ -118,15 +118,27 @@ Public Class ModpackInstaller
|
||||
End If
|
||||
Case UpdateActionType.Copy
|
||||
Dim srcFilePath As String = Path.Combine(localPath, uaction.SrcPath)
|
||||
If File.Exists(srcFilePath) Then
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(destFilePath))
|
||||
File.Copy(srcFilePath, destFilePath, True)
|
||||
If uaction.IsDirectory Then
|
||||
If Directory.Exists(srcFilePath) Then
|
||||
CopyDirectory(srcFilePath, destFilePath, True)
|
||||
End If
|
||||
Else
|
||||
If File.Exists(srcFilePath) Then
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(destFilePath))
|
||||
File.Copy(srcFilePath, destFilePath, True)
|
||||
End If
|
||||
End If
|
||||
Case UpdateActionType.Move
|
||||
Dim srcFilePath As String = Path.Combine(localPath, uaction.SrcPath)
|
||||
If File.Exists(srcFilePath) Then
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(destFilePath))
|
||||
File.Move(srcFilePath, destFilePath, True)
|
||||
If uaction.IsDirectory Then
|
||||
If Directory.Exists(srcFilePath) Then
|
||||
Directory.Move(srcFilePath, destFilePath)
|
||||
End If
|
||||
Else
|
||||
If File.Exists(srcFilePath) Then
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(destFilePath))
|
||||
File.Move(srcFilePath, destFilePath, True)
|
||||
End If
|
||||
End If
|
||||
End Select
|
||||
Else
|
||||
@@ -137,9 +149,11 @@ Public Class ModpackInstaller
|
||||
RaiseEvent InstallProgessUpdated(checkResult, processed)
|
||||
Next
|
||||
|
||||
'Save new modpack info
|
||||
modpackInfo.Version = checkResult.LatestVersion
|
||||
modpackInfo.Save(localPath)
|
||||
|
||||
'Delete cached zip files
|
||||
For Each task In localZipCache
|
||||
Directory.Delete(task.ExtractedZipPath, True)
|
||||
Next
|
||||
@@ -150,6 +164,7 @@ Public Class ModpackInstaller
|
||||
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))
|
||||
|
||||
'Download
|
||||
Dim fsDestinationPath As String = If(isZip, Path.Combine(Path.GetTempPath(), $"mc_update_file_{Date.Now.ToBinary}.zip"), destFilePath)
|
||||
Dim sRemote As Stream = Await httpClient.GetStreamAsync(sourceUrl)
|
||||
Dim fs As New FileStream(destFilePath, FileMode.Create, FileAccess.ReadWrite)
|
||||
@@ -157,10 +172,17 @@ Public Class ModpackInstaller
|
||||
sRemote.Close()
|
||||
fs.Close()
|
||||
|
||||
'Handle zip file
|
||||
If isZip Then
|
||||
'Extract
|
||||
Dim zipDir As String = $"{Path.GetFileNameWithoutExtension(fsDestinationPath)}_extracted"
|
||||
ZipFile.ExtractToDirectory(fsDestinationPath, zipDir)
|
||||
'...
|
||||
|
||||
'Copy content
|
||||
Dim zipSrc As String = Path.Combine(zipDir, zipPath)
|
||||
CopyDirectory(zipSrc, destFilePath, True)
|
||||
|
||||
'Delete/cache temporary files
|
||||
File.Delete(fsDestinationPath)
|
||||
localZipCache?.Add(New LocalZipCacheEntry With {
|
||||
.DownloadUrl = sourceUrl,
|
||||
|
||||
Reference in New Issue
Block a user