🚧 导出整合包:压缩包

This commit is contained in:
youzi-2333
2024-07-09 10:50:49 +08:00
parent f264f82b4b
commit 09e896dc26
7 changed files with 155 additions and 1 deletions
+1
View File
@@ -1053,6 +1053,7 @@ Install:
VersionSetup = 1
VersionMod = 2
VersionModDisabled = 3
VersionExport = 4
End Enum
''' <summary>
''' 获取次级页面的名称。若并非次级页面则返回空字符串,故可以以此判断是否为次级页面。
@@ -2,6 +2,7 @@
Public Module ModModpack
#Region "安装"
'触发整合包安装的外部接口
''' <summary>
''' 弹窗要求选择一个整合包文件并进行安装。
@@ -849,6 +850,113 @@ Retry:
Hint("已加入游戏文件夹列表:" & NewName, HintType.Finish)
End Sub
#End Region
#End Region
#Region "导出"
Private ExpTempDir As String = PathTemp & "PackExport\"
''' <summary>
''' 整合包类型。
''' </summary>
Public Enum ModpackType
CurseForge = 0
HMCL = 1
MMC = 2
MCBBS = 3
Modrinth = 4
Compressed = 9
End Enum
''' <summary>
''' 导出整合包的选项。
''' </summary>
Public Class ExportOptions
''' <summary>
''' 要导出的版本。
''' </summary>
Public Version As McVersion
''' <summary>
''' 要保存整合包的位置。
''' </summary>
Public Dest As String
''' <summary>
''' 整合包类型。
''' </summary>
Public Type As ModpackType
''' <summary>
''' 要保留到整合包的存档。
''' </summary>
Public Saves As String()
End Class
''' <summary>
''' 导出整合包。
''' </summary>
''' <returns>是否成功。</returns>
Public Function ModpackExport(Options As ExportOptions)
Select Case Options.Type
Case ModpackType.Compressed
ExportCompressed(Options.Version, Options.Dest)
End Select
End Function
#Region "冗余"
Private VersionRedundant As String() = {"saves", "screenshots", "backups", "command_history\.txt", '个人文件
".*-natives", "server-resource-packs", "user.*cache\.json", "\.optifine", "\.fabric", '缓存
".*\.jar", "downloads", "realms_persistence.json", "\$\{natives_directory\}", '可联网更新
"logs", "crash-reports", ".*\.log", '日志
".*\.dat_old", ".*\.old", '备份
"\$\{quickPlayPath\}", '服务器
"\.replay_cache", "replay_recordings", "replay_videos", 'ReplayMod
"irisUpdateInfo\.json", 'Iris
".*\.BakaCoreInfo" 'BakaXL
}
Private Function IsVerRedundant(FileName As String) As Boolean
For Each regex In VersionRedundant
If RegexCheck(FileName, regex) Then Return True
Next
Return False
End Function
#End Region
#Region "不同类型整合包的导出方法"
Private Sub ExportCompressed(Version As McVersion, DestPath As String, Optional Saves As String() = Nothing, Optional PCLSetup As Boolean = True)
Try
Dim tempDir As String = $"{ExpTempDir}{GetUuid()}\"
Directory.CreateDirectory(tempDir)
Dim tempVerPath As String = $"{tempDir}{Version.Path.Replace(GetPathFromFullPath(Version.PathIndie), "")}"
For Each f In Directory.EnumerateFiles(Version.Path)
If Not IsVerRedundant(GetFileNameFromPath(f)) Then CopyFile(f, tempVerPath & GetFileNameFromPath(f))
Next
For Each d In Directory.EnumerateDirectories(Version.Path)
If Not IsVerRedundant(GetFolderNameFromPath(d)) Then CopyDirectory(d, tempVerPath & GetFileNameFromPath(d))
Next
If Saves IsNot Nothing Then
For Each s In Saves
Dim saveFullPath As String = Version.Path & "saves" & s
If Not Directory.Exists(saveFullPath) Then Continue For
CopyDirectory(saveFullPath, $"{tempVerPath}saves\{s}")
Next
End If
If PCLSetup Then
If File.Exists(Path & "PCL\Setup.ini") Then CopyFile("PCL\Setup.ini", tempDir & "PCL\Setup.ini")
If File.Exists(Path & "PCL\Custom.xaml") Then CopyFile("PCL\Custom.xaml", tempDir & "PCL\Custom.xaml")
If Directory.Exists(Path & "PCL\Pictures") Then CopyDirectory(Path & "PCL\Pictures", tempDir & "PCL\Pictures")
If Directory.Exists(Path & "PCL\Musics") Then CopyDirectory(Path & "PCL\Musics", tempDir & "PCL\Musics")
End If
CopyFile(PathWithName, tempDir & GetFileNameFromPath(PathWithName))
If File.Exists(DestPath) Then File.Delete(DestPath) '选择文件的时候已经确认了要替换
ZipFile.CreateFromDirectory(tempDir, DestPath)
DeleteDirectory(tempDir)
Catch ex As Exception
Log(ex, "导出整合包失败", LogLevel.Msgbox)
End Try
End Sub
#End Region
#End Region
End Module
@@ -427,6 +427,7 @@ EndHint:
Public FrmVersionMod As PageVersionMod
Public FrmVersionModDisabled As PageVersionModDisabled
Public FrmVersionSetup As PageVersionSetup
Public FrmVersionExport As PageVersionExport
'资源信息分页声明
Public FrmDownloadCompDetail As PageDownloadCompDetail
@@ -0,0 +1,33 @@
<local:MyPageRight
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:PCL" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:System="clr-namespace:System;assembly=mscorlib"
mc:Ignorable="d" x:Class="PageVersionExport"
PanScroll="{Binding ElementName=PanBack}">
<local:MyScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled">
<StackPanel Margin="25,10">
<local:MyCard Margin="0,0,0,15" Title="导出选项">
<StackPanel Margin="25,40,25,21">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" SharedSizeGroup="Name" />
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="60" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="28" />
<RowDefinition Height="9" />
<RowDefinition Height="28" />
<RowDefinition Height="9" />
<RowDefinition Height="28" />
<RowDefinition Height="9" />
<RowDefinition Height="28" />
</Grid.RowDefinitions>
<local:MyButton x:Name="BtnExportExport" Margin="0,0,0,0" Text="导出整合包" Grid.Column="0" Grid.Row="0" Width="150" />
</Grid>
</StackPanel>
</local:MyCard>
</StackPanel>
</local:MyScrollViewer>
</local:MyPageRight>
@@ -0,0 +1,5 @@
Public Class PageVersionExport
Public Sub BtnExportExport_Click() Handles BtnExportExport.Click
ModpackExport(New ExportOptions With {.Version = McVersionCurrent, .Type = ModpackType.Compressed, .Dest = Path & "export.zip"})
End Sub
End Class
@@ -23,5 +23,8 @@
</local:MyListItem>
<local:MyListItem x:Name="ItemModDisabled" IsScaleAnimationEnabled="False" Type="RadioBox" Tag="3" MinPaddingRight="35" Height="36" VerticalAlignment="Top" Title="Mod 管理"
Logo="M789.504 912.896h-195.072a35.328 35.328 0 0 1-34.816-35.328v-77.312a39.936 39.936 0 0 0-40.448-39.936H481.28a40.448 40.448 0 0 0-40.448 39.936v77.312a34.816 34.816 0 0 1-34.816 35.328H204.8a41.984 41.984 0 0 1-40.448-42.496v-200.192a35.328 35.328 0 0 1 35.328-35.328h72.704a39.936 39.936 0 0 0 39.936-39.936v-37.888a39.936 39.936 0 0 0-39.936-40.448H199.68a35.328 35.328 0 0 1-35.328-35.328V287.744A41.984 41.984 0 0 1 204.8 245.76h176.64v-32.768a102.4 102.4 0 0 1 102.4-102.4h33.792a102.4 102.4 0 0 1 102.4 102.4v32.768h170.496a41.984 41.984 0 0 1 41.984 41.984V460.8h28.672a102.4 102.4 0 0 1 102.4 102.4v33.792a102.4 102.4 0 0 1-102.4 102.4h-28.672V870.4a41.984 41.984 0 0 1-43.008 42.496z m-159.744-70.144h131.584V665.6a34.304 34.304 0 0 1 34.816-34.816h64a31.744 31.744 0 0 0 31.744-31.744V563.2a31.744 31.744 0 0 0-31.744-31.744h-64a34.816 34.816 0 0 1-34.816-35.328V316.416h-177.152a35.328 35.328 0 0 1-35.328-35.328V212.992a31.744 31.744 0 0 0-31.744-31.744h-33.792a31.744 31.744 0 0 0-31.744 31.744v68.096a35.328 35.328 0 0 1-34.816 35.328H234.496v130.048h37.888a110.592 110.592 0 0 1 110.08 110.592v37.888a110.592 110.592 0 0 1-110.08 110.592h-37.888v137.216h136.192v-42.496a110.592 110.592 0 0 1 110.592-110.08h37.888a110.592 110.592 0 0 1 110.592 110.08z" />
<local:MyListItem x:Name="ItemExport" IsScaleAnimationEnabled="False" Type="RadioBox" Tag="4" MinPaddingRight="35" Height="36" VerticalAlignment="Top" Title="导出整合包"
Logo="M789.504 912.896h-195.072a35.328 35.328 0 0 1-34.816-35.328v-77.312a39.936 39.936 0 0 0-40.448-39.936H481.28a40.448 40.448 0 0 0-40.448 39.936v77.312a34.816 34.816 0 0 1-34.816 35.328H204.8a41.984 41.984 0 0 1-40.448-42.496v-200.192a35.328 35.328 0 0 1 35.328-35.328h72.704a39.936 39.936 0 0 0 39.936-39.936v-37.888a39.936 39.936 0 0 0-39.936-40.448H199.68a35.328 35.328 0 0 1-35.328-35.328V287.744A41.984 41.984 0 0 1 204.8 245.76h176.64v-32.768a102.4 102.4 0 0 1 102.4-102.4h33.792a102.4 102.4 0 0 1 102.4 102.4v32.768h170.496a41.984 41.984 0 0 1 41.984 41.984V460.8h28.672a102.4 102.4 0 0 1 102.4 102.4v33.792a102.4 102.4 0 0 1-102.4 102.4h-28.672V870.4a41.984 41.984 0 0 1-43.008 42.496z m-159.744-70.144h131.584V665.6a34.304 34.304 0 0 1 34.816-34.816h64a31.744 31.744 0 0 0 31.744-31.744V563.2a31.744 31.744 0 0 0-31.744-31.744h-64a34.816 34.816 0 0 1-34.816-35.328V316.416h-177.152a35.328 35.328 0 0 1-35.328-35.328V212.992a31.744 31.744 0 0 0-31.744-31.744h-33.792a31.744 31.744 0 0 0-31.744 31.744v68.096a35.328 35.328 0 0 1-34.816 35.328H234.496v130.048h37.888a110.592 110.592 0 0 1 110.08 110.592v37.888a110.592 110.592 0 0 1-110.08 110.592h-37.888v137.216h136.192v-42.496a110.592 110.592 0 0 1 110.592-110.08h37.888a110.592 110.592 0 0 1 110.592 110.08z" >
</local:MyListItem>
</StackPanel>
</local:MyPageLeft>
@@ -25,7 +25,7 @@
''' <summary>
''' 勾选事件改变页面。
''' </summary>
Private Sub PageCheck(sender As MyListItem, e As RouteEventArgs) Handles ItemOverall.Check, ItemMod.Check, ItemModDisabled.Check, ItemSetup.Check
Private Sub PageCheck(sender As MyListItem, e As RouteEventArgs) Handles ItemOverall.Check, ItemMod.Check, ItemModDisabled.Check, ItemSetup.Check, ItemExport.Check
'尚未初始化控件属性时,sender.Tag 为 Nothing,会导致切换到页面 0
'若使用 IsLoaded,则会导致模拟点击不被执行(模拟点击切换页面时,控件的 IsLoaded 为 False)
If sender.Tag IsNot Nothing Then PageChange(Val(sender.Tag))
@@ -46,6 +46,9 @@
Case FormMain.PageSubType.VersionSetup
If IsNothing(FrmVersionSetup) Then FrmVersionSetup = New PageVersionSetup
Return FrmVersionSetup
Case FormMain.PageSubType.VersionExport
If FrmVersionExport Is Nothing Then FrmVersionExport = New PageVersionExport
Return FrmVersionExport
Case Else
Throw New Exception("未知的版本设置子页面种类:" & ID)
End Select