@@ -1,12 +1,28 @@
Public Class PageDownloadResourceDetail
Private ResourceItem As MyResourceItem = Nothing
''' <summary>
''' 当前页面应展示的内容类别。
''' 若当前页面是在查看前置时进入,则为 Any;这也能用于指示当前是否在查看前置。
''' </summary>
Private TargetResourceType As ResourceTypes
Private Project As ResourceProject
Private TargetVersion As String
Private TargetLoaders As ModLoaders
Public Sub LoadPageArguments ( ) Handles Me . Loaded
Project = FrmMain . PageCurrent . Additional ( 0 )
TargetVersion = FrmMain . PageCurrent . Additional ( 2 )
TargetLoaders = CType ( FrmMain . PageCurrent . Additional ( 3 ) , ModLoaders )
If TargetLoaders <> ModLoaders . None AndAlso Not TargetLoaders . Flags . IsSingle Then TargetLoaders = TargetLoaders . Flags . First ( ) '强制取第一个
TargetResourceType = FrmMain . PageCurrent . Additional ( 4 )
End Sub
#Region "加载器"
Private ResourceFileLoader As New LoaderTask ( Of Integer , List ( Of ResourceVersion ) ) (
" Resource File " ,
Sub ( Task )
LoadTargetFromAdditional ( )
LoadPageArguments ( )
Dim Result = ResourceVersion . FromProjectId ( Project . Id , Project . Platform )
If Task . IsInterrupted Then Return
Task . Output = Result
@@ -14,22 +30,9 @@
'初始化加载器信息
Private Sub PageDownloadResourceDetail_Inited ( sender As Object , e As EventArgs ) Handles Me . Initialized
LoadTargetFromAdditional ( )
LoadPageArguments ( )
PageLoaderInit ( Load , PanLoad , PanMain , CardIntro , ResourceFileLoader , AddressOf Load_OnFinish )
End Sub
Public Sub LoadTargetFromAdditional ( ) Handles Me . Loaded
Project = FrmMain . PageCurrent . Additional ( 0 )
TargetInstance = FrmMain . PageCurrent . Additional ( 2 )
TargetLoader = FrmMain . PageCurrent . Additional ( 3 )
TargetType = FrmMain . PageCurrent . Additional ( 4 )
End Sub
Private Project As ResourceProject
Private TargetInstance As String , TargetLoader As ModLoaderTypes
''' <summary>
''' 当前页面应展示的内容类别。
''' 若当前页面是在查看前置时进入,则也可能为 Any。
''' </summary>
Private TargetType As ResourceTypes
'自动重试
Private Sub Load_State ( sender As Object , state As MyLoading . MyLoadingState , oldState As MyLoading . MyLoadingState ) Handles Load . StateChanged
Select Case ResourceFileLoader . State
@@ -37,7 +40,7 @@
Dim ErrorMessage As String = " "
If ResourceFileLoader . Error IsNot Nothing Then ErrorMessage = ResourceFileLoader . Error . Message
If ErrorMessage . Contains ( " 不是有效的 json 文件 " ) Then
Log ( " [Resource] 下载的文件 json 列表损坏,已自动重试" , NotifyLevel . DebugModeOnly )
Logger . Warn ( " 下载的文件 json 列表损坏,已自动重试 " )
PageLoaderRestart ( )
End If
End Select
@@ -75,13 +78,13 @@
'筛选类型相同的结果(Modrinth 会返回 Mod、服务端插件、数据包混合的列表)
Private Function GetResults ( ) As List ( Of ResourceVersion )
Dim Results As List ( Of ResourceVersion ) = ResourceFileLoader . Output
Select Case TargetType
Select Case TargetResourceType
Case ResourceTypes . Any
Results = Results . Where ( Function ( r ) r . ResourceType <> ResourceTypes . Plugin ) . ToList
Case ResourceTypes . Shader , ResourceTypes . ResourcePack
'不筛选光影和资源包,否则原版光影会因为是资源包格式而被过滤(#6473)
Case Else
Results = Results . Where ( Function ( r ) r . ResourceType = TargetType ) . ToList
Results = Results . Where ( Function ( r ) r . ResourceType = TargetResourceType ) . ToList
End Select
Return Results
End Function
@@ -132,10 +135,10 @@ GroupDone:
Next
'自动选择
Dim ToCheck As MyRadioButton = Nothing
If TargetInstance <> " " Then
Dim TargetFile = Results . FirstOrDefault ( Function ( v ) v . GameVersions . Contains ( TargetInstance ) )
If TargetVersion <> " " Then
Dim TargetFile = Results . FirstOrDefault ( Function ( v ) v . GameVersions . Contains ( TargetVersion ) )
If TargetFile IsNot Nothing Then
Dim TargetGroup = GetGroupedVersionName ( TargetInstance , GroupedDrop , GroupedOld )
Dim TargetGroup = GetGroupedVersionName ( TargetVersion , GroupedDrop , GroupedOld )
For Each Button As MyRadioButton In PanFilter . Children
If Button . Text <> TargetGroup Then Continue For
ToCheck = Button
@@ -153,12 +156,11 @@ GroupDone:
Private Sub UpdateFilterResult ( )
Dim Results = GetResults ( )
Dim TargetCardName As String = If ( TargetInstance <> " " OrElse TargetLoader <> ModLoaderTypes . Any ,
$ " {If(TargetLoader <> ModLoaderTypes.Any , TargetLoader.ToString & " " , "" )}{TargetInstance }(所选版本) " , " " )
Dim TargetCardName As String = If ( TargetVersion <> " " OrElse TargetLoaders <> ModLoaders . None ,
$ " {If(TargetLoaders <> ModLoaders.None , TargetLoaders .ToString & " " , "" )}{TargetVersion }(所选版本) " , " " )
'归类到卡片下
Dim Dict As New SortedDictionary ( Of String , List ( Of ResourceVersion ) ) ( New CardSorter ( TargetCardName ) )
Dict . Add ( " 其他 " , New List ( Of ResourceVersion ) )
Dim SupportedLoaders As New List ( Of Integer ) ( [ Enum ] . GetValues ( GetType ( ModLoaderTypes ) ) )
For Each Version As ResourceVersion In Results
For Each GameVersion In Version . GameVersions
'检查是否符合版本筛选器
@@ -168,12 +170,12 @@ GroupDone:
Dim VerName As String = GetGroupedVersionName ( GameVersion , False , False )
'遍历加入的加载器列表
Dim Loaders As New List ( Of String )
If Project . Loaders . Count > 1 AndAlso '工程至少有两个加载器
If Project . ModLoaders . Flags . Count > 1 AndAlso '工程至少有两个加载器
Version . ResourceType = ResourceTypes . Mod AndAlso '是 Mod
McVersion . IsFormatFit ( VerName ) Then '不是 “快照版本” 之类的
For Each Loader In Version . Loaders
If Loader = ModLoaderTypes . Quilt AndAlso Settings . Get ( " ToolDownloadIgnoreQuilt " ) Then Continue For
If SupportedLoaders . Contains ( Loader ) Then Loaders . Add ( Loader . ToString & " " )
For Each Loader In Version . ModLoaders . Flags
If Loader = ModLoaders . Quilt AndAlso Settings . Get ( Of Boolean ) ( " ToolDownloadIgnoreQuilt " ) Then Continue For
Loaders . Add ( Loader . ToString & " " )
Next
End If
If Not Loaders . Any ( ) Then Loaders . Add ( " " ) '保底加一个空的,确保它在一张卡片里
@@ -186,11 +188,11 @@ GroupDone:
Next
Next
'添加筛选的版本的卡片
If TargetCardName <> " " AndAlso ( VersionFilter Is Nothing OrElse GetGroupedVersionName ( TargetInstance , GroupedDrop , GroupedOld ) . StartsWithF ( VersionFilter ) ) Then
If TargetCardName <> " " AndAlso ( VersionFilter Is Nothing OrElse GetGroupedVersionName ( TargetVersion , GroupedDrop , GroupedOld ) . StartsWithF ( VersionFilter ) ) Then
Dict . Add ( TargetCardName , New List ( Of ResourceVersion ) )
For Each Version As ResourceVersion In Results
If Version . GameVersions . Contains ( TargetInstance ) AndAlso
( TargetLoader = ModLoaderTypes . Any OrElse Version . Loaders . Contains ( TargetLoader ) ) Then
If Version . GameVersions . Contains ( TargetVersion ) AndAlso
( TargetLoaders = ModLoaders . None OrElse TargetLoaders . Flags . Intersect ( Version . ModLoaders . Flags ) . Any ) Then
'检查是否符合版本筛选器
If VersionFilter IsNot Nothing AndAlso
Not Version . GameVersions . Any ( Function ( v ) GetGroupedVersionName ( v , GroupedDrop , GroupedOld ) = VersionFilter ) Then Continue For
@@ -205,16 +207,16 @@ GroupDone:
If Not Pair . Value . Any ( ) Then Continue For
If Pair . Key = TargetCardName . Replace ( " (所选版本) " , " " ) Then Continue For
'增加卡片
Dim NewCard As New MyCard With { . Title = Pair . Key , . Margin = New Thickness ( 0 , 0 , 0 , 15 ) , . SwapType = If ( TargetType = ResourceTypes . ModPack , 9 , 8 ) } '9 是安装,8 是另存为
Dim NewCard As New MyCard With { . Title = Pair . Key , . Margin = New Thickness ( 0 , 0 , 0 , 15 ) , . SwapType = If ( TargetResourceType = ResourceTypes . ModPack , 9 , 8 ) } '9 是安装,8 是另存为
Dim NewStack As New StackPanel With { . Margin = New Thickness ( 20 , MyCard . SwapedHeight , 18 , 0 ) , . VerticalAlignment = VerticalAlignment . Top , . RenderTransform = New TranslateTransform ( 0 , 0 ) , . Tag = Pair . Value }
NewCard . Children . Add ( NewStack )
NewCard . SwapControl = NewStack
PanResults . Children . Add ( NewCard )
'确定卡片是否展开
'确定卡片是否默认 展开
If Pair . Key = TargetCardName OrElse
( FrmMain . PageCurrent . Additional IsNot Nothing AndAlso '#2761
CType ( FrmMain . PageCurrent . Additional ( 1 ) , List ( Of String ) ) . Contains ( NewCard . Title ) ) Then
MyCard . StackInstall ( NewStack , If ( TargetType = ResourceTypes . ModPack , 9 , 8 ) , Pair . Key ) '9 是安装,8 是另存为
MyCard . StackInstall ( NewStack , If ( TargetResourceType = ResourceTypes . ModPack , 9 , 8 ) , Pair . Key ) '9 是安装,8 是另存为
Else
NewCard . IsSwapped = True
End If
@@ -228,15 +230,15 @@ GroupDone:
CType ( PanResults . Children ( 0 ) , MyCard ) . IsSwapped = False
End If
'替代提示
If Project . Types = ResourceTypes . ModOrDataPack AndAlso ( TargetType = ResourceTypes . Mod OrElse TargetType = ResourceTypes . DataPack ) Then
If Project . Types = ResourceTypes . ModOrDataPack AndAlso ( TargetResourceType = ResourceTypes . Mod OrElse TargetResourceType = ResourceTypes . DataPack ) Then
HintAlternative . Visibility = Visibility . Visible
HintAlternative . Text = If ( TargetType = ResourceTypes . Mod ,
HintAlternative . Text = If ( TargetResourceType = ResourceTypes . Mod ,
" 以下是该项目的 Mod 版本。点击这里查看其数据包版本。 " , " 以下是该项目的数据包版本。点击这里查看其 Mod 版本。 " )
Else
HintAlternative . Visibility = Visibility . Collapsed
End If
Catch ex As Exception
Log ( ex , " 可视化工程下载列表出错 " , NotifyLevel . MsgBoxAndFeedback )
Logger . Error ( ex , " 可视化工程下载列表出错 " )
End Try
End Sub
Private Function GetGroupedVersionName ( Name As String , GroupedByDrop As Boolean , FoldOld As Boolean ) As String
@@ -303,16 +305,18 @@ GroupDone:
Dim Loaders As New List ( Of LoaderBase )
Dim Target As String = $ " {McFolderSelected}versions\{InstanceName}\原始整合包.{If(Project.Platform = ResourcePlatforms.CurseForge, " zip " , " mrpack " )} "
Dim LogoFileAddress As String = ResourceItem . PathLogo . ActualSource
Loaders . Add ( New LoaderDownload ( " 下载整合包文件 " , New List ( Of NetFile ) From { File . ToNetFile ( Target ) } ) With { . ProgressWeight = 10 , . Block = True } )
Loaders . Add ( New LoaderDownload ( " 下载整合包文件 " , {
File . ToNetFile ( Target , ResourceVersion . DownloadReason . Standalone , File . GameVersions . FirstOrDefault , File . ModLoaders )
} ) With { . ProgressWeight = 10 , . Block = True } )
Loaders . Add ( New LoaderTask ( Of Integer , Integer ) ( " 准备安装整合包 " ,
Sub ( ) ModpackInstall ( Target , InstanceName , If ( IO . File . Exists ( LogoFileAddress ) , LogoFileAddress , Nothing ) ) ) With { . ProgressWeight = 0 . 1 } )
Sub ( ) ModpackInstall ( Target , InstanceName , If ( FileUtils . Exists ( LogoFileAddress ) , LogoFileAddress , Nothing ) ) ) With { . ProgressWeight = 0 . 1 } )
'启动
Dim Loader As New LoaderCombo ( Of String ) ( LoaderName , Loaders ) With { . OnStateChanged =
Sub ( MyLoader )
Select Case MyLoader . State
Case LoadState . Failed
Hint ( MyLoader . Name & " 失败: " & MyLoader . Error . GetBrief ( ) , HintType . Red )
Hint ( MyLoader . Name & " 失败: " & MyLoader . Error . GetDisplay ( False ) , HintType . Red )
Case LoadState . Interrupted
Hint ( MyLoader . Name & " 已取消! " , HintType . Blue )
Case LoadState . Loading
@@ -326,7 +330,7 @@ GroupDone:
FrmMain . BtnExtraDownload . Ribble ( )
Catch ex As Exception
Log ( ex , " 下载资源整合包失败 " , NotifyLevel . MsgBoxAndFeedback )
Logger . Error ( ex , " 下载资源整合包失败 " )
End Try
End Sub
'资源下载;整合包另存为
@@ -356,13 +360,13 @@ GroupDone:
End Select
Dim IsInstanceSuitable As Func ( Of McInstance , Boolean ) = Nothing
'获取资源所需的加载器
Dim AllowedLoaders As New List ( Of ModLoaderTypes )
If File . Loaders . Any Then
AllowedLoaders = File . Loaders
ElseIf Project . Loaders . Any Then
AllowedLoaders = Project . Loaders
Dim AllowedLoaders As ModLoaders = ModLoaders . None
If File . ModLoaders <> ModLoaders . None Then
AllowedLoaders = File . ModLoaders
ElseIf Project . ModLoaders <> ModLoaders . None Then
AllowedLoaders = Project . ModLoaders
End If
Log ( $ " [Resource] {Desc}要求的加载器种类:" & If ( AllowedLoaders . Any ( ) , AllowedLoaders . Join ( " / " ) , " 无要求 " ) )
Logger . Info ( $ " {Desc}要求的加载器种类:{AllowedLoaders} " )
'判断某个版本是否符合资源要求
IsInstanceSuitable =
Function ( Instance As McInstance )
@@ -403,21 +407,16 @@ GroupDone:
End Function ) Then Return False
End If
'加载器
If Not AllowedLoaders . Any ( ) Then Return True '无要求
If AllowedLoaders . Contains ( ModLoaderTypes . Forge ) AndAlso Instance . Version . HasForge Then Return True
If AllowedLoaders . Contains ( ModLoaderTypes . Fabric ) AndAlso Instance . Version . HasFabric Then Return True
If AllowedLoaders . Contains ( ModLoaderTypes . NeoForge ) AndAlso Instance . Version . HasNeoForge Then Return True
If AllowedLoaders . Contains ( ModLoaderTypes . LiteLoader ) AndAlso Instance . Version . HasLiteLoader Then Return True
Return False
Return AllowedLoaders = ModLoaders . None OrElse AllowedLoaders . Flags . Intersect ( Instance . Version . ModLoaders . Flags ) . Any
End Function
'获取常规资源默认下载位置
If CachedFolder . ContainsKey ( File . ResourceType ) Then
DefaultFolder = CachedFolder ( File . ResourceType )
Log ( $ " [Resource] 使用上次下载时的文件夹作为默认下载位置:{DefaultFolder}" )
Logger . Info ( $ " 使用上次下载时的文件夹作为默认下载位置:{DefaultFolder} " )
ElseIf McInstanceSelected IsNot Nothing AndAlso IsInstanceSuitable ( McInstanceSelected ) Then
DefaultFolder = $ " {McInstanceSelected.PathIndie}{SubFolder} "
DirectoryUtils . Create ( DefaultFolder )
Log ( $ " [Resource] 使用当前版本作为默认下载位置:{DefaultFolder}" )
Logger . Info ( $ " 使用当前版本作为默认下载位置:{DefaultFolder} " )
Else
'查找所有可能的版本
Dim NeedLoad As Boolean = McInstanceListLoader . State <> LoadState . Finished
@@ -426,21 +425,21 @@ GroupDone:
LoaderFolderRun ( McInstanceListLoader , McFolderSelected , LoaderFolderRunType . ForceRun , MaxDepth : = 1 , ExtraPath : = " versions\ " , WaitForExit : = True )
End If
Dim SuitableInstanceList = McInstanceList . Values . SelectMany ( Function ( l ) l ) . Where ( Function ( v ) IsInstanceSuitable ( v ) ) .
Select ( Function ( v ) New DirectoryInfo ( $ " {v.PathIndie}{SubFolder} " ) )
Select ( Function ( v ) DirectoryUtils . GetInfo ( $ " {v.PathIndie}{SubFolder} " ) )
If SuitableInstanceList . Any Then
Dim SelectedInstance = SuitableInstanceList .
OrderByDescending ( Function ( Dir ) If ( Dir . Exists , Dir . LastWriteTimeUtc , Date . MinValue ) ) . '先按文件夹更改时间降序
ThenByDescending ( Function ( Dir ) If ( Dir . Exists , Dir . GetFiles ( ) . Length , - 1 ) ) . '再按文件夹中的文件数量降序
First ( )
DefaultFolder = SelectedInstance . FullName
DefaultFolder = PathUtils . RemoveExtendedPrefix ( SelectedInstance . FullName )
DirectoryUtils . Create ( DefaultFolder )
Log ( $ " [Resource] 使用适合的游戏版本作为默认下载位置:{DefaultFolder}" )
Logger . Info ( $ " 使用适合的游戏版本作为默认下载位置:{DefaultFolder} " )
Else
DefaultFolder = McFolderSelected
If NeedLoad Then
Hint ( $ " 当前 MC 文件夹中没有找到合适的版本! " )
Else
Log ( " [Resource] 由于当前版本不兼容,使用当前的 MC 文件夹作为默认下载位置" )
Logger . Info ( " 由于当前版本不兼容,使用当前的 MC 文件夹作为默认下载位置 " )
End If
End If
End If
@@ -452,7 +451,7 @@ GroupDone:
Else
Dim ChineseName As String = Project . TranslatedName . BeforeFirst ( " ( " ) . BeforeFirst ( " - " ) .
Replace ( " \ " , " \ " ) . Replace ( " / " , " / " ) . Replace ( " | " , " | " ) . Replace ( " : " , " : " ) . Replace ( " < " , " < " ) . Replace ( " > " , " > " ) . Replace ( " * " , " * " ) . Replace ( " ? " , " ? " ) . Replace ( " "" " , " " ) . Replace ( " : " , " : " )
Select Case Settings . Get ( " ToolDownloadTranslateV2 " )
Select Case Settings . Get ( Of Integer ) ( " ToolDownloadTranslateV2 " )
Case 0
FileName = $ " 【{ChineseName}】{File.FileName} "
Case 1
@@ -470,17 +469,18 @@ GroupDone:
Sub ( )
'弹窗要求选择保存位置
Dim Target As String
Target = SelectSaveFile ( " 选择保存位置 " , FileName ,
Desc & " 文件| " &
If ( File . ResourceType = ResourceTypes . Mod ,
If ( File . FileName . EndsWithF ( " .litemod " ) , " *.litemod " , " *.jar " ) ,
If ( File . FileName . EndsWithF ( " .mrpack " ) , " *.mrpack " , " *.zip " ) ) , DefaultFolder )
If Not Target . Contains ( " \ " ) Then Return
Dim Ext As String = If ( File . ResourceType = ResourceTypes . Mod ,
If ( File . FileName . EndsWithF ( " .litemod " ) , " litemod " , " jar " ) ,
If ( File . FileName . EndsWithF ( " .mrpack " ) , " mrpack " , " zip " ) )
Target = Dialogs . SaveFile ( " 选择保存位置 " , FileName , DefaultFolder , { ( Ext , Desc & " 文件 " ) } )
If Target Is Nothing Then Return
'构造步骤加载器
Dim LoaderName As String = Desc & " 下载: " & Path . GetFileNameWithoutExtension ( Target ) & " "
If Target <> DefaultFolder Then CachedFolder ( File . ResourceType ) = GetPathFromFullPath ( Target )
Dim LoaderName As String = Desc & " 下载: " & PathUtils . GetFileNameWithoutExtension ( Target ) & " "
If Target <> DefaultFolder Then CachedFolder ( File . ResourceType ) = PathUtils . RemoveLastPart ( Target )
Dim Loaders As New List ( Of LoaderBase )
Loaders . Add ( New LoaderDownload ( " 下载文件 " , New List ( Of NetFile ) From { File . ToNetFile ( Target ) } ) With { . ProgressWeight = 6 , . Block = True } )
Loaders . Add ( New LoaderDownload ( " 下载文件 " , {
File . ToNetFile ( Target , If ( TargetResourceType = ResourceTypes . Any , ResourceVersion . DownloadReason . Dependency , ResourceVersion . DownloadReason . Standalone ) )
} ) With { . ProgressWeight = 6 , . Block = True } )
'启动
Dim Loader As New LoaderCombo ( Of Integer ) ( LoaderName , Loaders ) With { . OnStateChanged = AddressOf LoaderStateChangedHintOnly }
Loader . Start ( 1 )
@@ -489,7 +489,7 @@ GroupDone:
FrmMain . BtnExtraDownload . Ribble ( )
End Sub )
Catch ex As Exception
Log ( ex , " 保存资源文件失败 " , NotifyLevel . MsgBoxAndFeedback )
Logger . Error ( ex , " 保存资源文件失败 " )
End Try
End Sub , " Download Resource Detail Save " )
End Sub
@@ -506,8 +506,8 @@ GroupDone:
'Mod / 数据包 互相跳转
Private Sub HintAlternative_Click ( ) Handles HintAlternative . Click
TargetType = If ( TargetType = ResourceTypes . Mod , ResourceTypes . DataPack , ResourceTypes . Mod )
FrmMain . PageCurrent . Additional ( 4 ) = TargetType '加载器会从这里重新拿数据
TargetResourceType = If ( TargetResourceType = ResourceTypes . Mod , ResourceTypes . DataPack , ResourceTypes . Mod )
FrmMain . PageCurrent . Additional ( 4 ) = TargetResourceType '加载器会从这里重新拿数据
PageLoaderRestart ( IsForceRestart : = True )
End Sub
@@ -522,7 +522,7 @@ GroupDone:
If Not Deps . Any ( ) Then Return
Deps = Deps . Where (
Function ( dep )
If Not ResourceProject . Cache . ContainsKey ( dep ) Then Log ( $ " [Resource] 未找到 ID {dep} 的前置信息" , NotifyLevel . DebugModeOnly )
If Not ResourceProject . Cache . ContainsKey ( dep ) Then Logger . Warn ( $ " 未找到 ID {dep} 的前置信息 " )
Return ResourceProject . Cache . ContainsKey ( dep )
End Function ) . ToList
'添加开头间隔