ModDownload.vb 89 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670
  1. Public Module ModDownload
  2. #Region "DlClient* | Minecraft 客户端"
  3. ''' <summary>
  4. ''' 返回某 Minecraft 版本对应的原版主 Jar 文件的下载信息,要求对应依赖版本已存在。
  5. ''' 失败则抛出异常,不需要下载则返回 Nothing。
  6. ''' </summary>
  7. Public Function DlClientJarGet(Version As McVersion, ReturnNothingOnFileUseable As Boolean) As NetFile
  8. '获取底层继承版本
  9. Do While Not String.IsNullOrEmpty(Version.InheritVersion)
  10. Version = New McVersion(Version.InheritVersion)
  11. Loop
  12. '检查 Json 是否标准
  13. If Version.JsonObject("downloads") Is Nothing OrElse Version.JsonObject("downloads")("client") Is Nothing OrElse Version.JsonObject("downloads")("client")("url") Is Nothing Then
  14. Throw New Exception("底层版本 " & Version.Name & " 中无 Jar 文件下载信息")
  15. End If
  16. '检查文件
  17. Dim Checker As New FileChecker(MinSize:=1024, ActualSize:=If(Version.JsonObject("downloads")("client")("size"), -1), Hash:=Version.JsonObject("downloads")("client")("sha1"))
  18. If ReturnNothingOnFileUseable Then
  19. '是否跳过
  20. Dim IsSetupSkip As Boolean = Setup.Get("LaunchAdvanceAssets")
  21. Select Case Setup.Get("VersionAdvanceAssets", Version:=Version)
  22. Case 0 '使用全局设置
  23. Case 1 '开启
  24. IsSetupSkip = False
  25. Case 2 '关闭
  26. IsSetupSkip = True
  27. End Select
  28. If IsSetupSkip AndAlso File.Exists(Version.Path & Version.Name & ".jar") Then Return Nothing '跳过校验
  29. If Checker.Check(Version.Path & Version.Name & ".jar") Is Nothing Then Return Nothing '通过校验
  30. End If
  31. '返回下载信息
  32. Dim JarUrl As String = Version.JsonObject("downloads")("client")("url")
  33. Return New NetFile(DlSourceLauncherOrMetaGet(JarUrl), Version.Path & Version.Name & ".jar", Checker)
  34. End Function
  35. ''' <summary>
  36. ''' 返回某 Minecraft 版本对应的原版主 AssetIndex 文件的下载信息,要求对应依赖版本已存在。
  37. ''' 若未找到,则会返回 Legacy 资源文件或 Nothing。
  38. ''' </summary>
  39. Public Function DlClientAssetIndexGet(Version As McVersion) As NetFile
  40. '获取底层继承版本
  41. Do While Not String.IsNullOrEmpty(Version.InheritVersion)
  42. Version = New McVersion(Version.InheritVersion)
  43. Loop
  44. '获取信息
  45. Dim IndexInfo = McAssetsGetIndex(Version, True, True)
  46. Dim IndexAddress As String = PathMcFolder & "assets\indexes\" & IndexInfo("id").ToString & ".json"
  47. Log("[Download] 版本 " & Version.Name & " 对应的资源文件索引为 " & IndexInfo("id").ToString)
  48. Dim IndexUrl As String = If(IndexInfo("url"), "")
  49. If IndexUrl = "" Then
  50. Return Nothing
  51. Else
  52. Return New NetFile(DlSourceLauncherOrMetaGet(IndexUrl, False), IndexAddress, New FileChecker(CanUseExistsFile:=False, IsJson:=True))
  53. End If
  54. End Function
  55. ''' <summary>
  56. ''' 构造补全某 Minecraft 版本的所有文件的加载器列表。失败会抛出异常。
  57. ''' </summary>
  58. Public Function DlClientFix(Version As McVersion, CheckAssetsHash As Boolean, AssetsIndexBehaviour As AssetsIndexExistsBehaviour, SkipAssetsDownloadWhileSetupRequired As Boolean) As List(Of LoaderBase)
  59. Dim Loaders As New List(Of LoaderBase)
  60. #Region "下载支持库文件"
  61. Dim LoadersLib As New List(Of LoaderBase) From {
  62. New LoaderTask(Of String, List(Of NetFile))("分析缺失支持库文件", Sub(Task As LoaderTask(Of String, List(Of NetFile))) Task.Output = McLibFix(Version)) With {.ProgressWeight = 1},
  63. New LoaderDownload("下载支持库文件", New List(Of NetFile)) With {.ProgressWeight = 15}
  64. }
  65. '构造加载器
  66. Loaders.Add(New LoaderCombo(Of String)("下载支持库文件(主加载器)", LoadersLib) With {.Block = False, .Show = False, .ProgressWeight = 16})
  67. #End Region
  68. #Region "下载资源文件"
  69. Dim IsSetupSkip As Boolean = Setup.Get("LaunchAdvanceAssets")
  70. Select Case Setup.Get("VersionAdvanceAssets", Version:=Version)
  71. Case 0
  72. '使用全局设置
  73. Case 1
  74. '开启
  75. IsSetupSkip = False
  76. Case 2
  77. '关闭
  78. IsSetupSkip = True
  79. End Select
  80. If IsSetupSkip Then Log("[Download] 已跳过 Assets 下载")
  81. If (Not SkipAssetsDownloadWhileSetupRequired) OrElse Not IsSetupSkip Then
  82. Dim LoadersAssets As New List(Of LoaderBase)
  83. '获取资源文件索引地址
  84. LoadersAssets.Add(New LoaderTask(Of String, List(Of NetFile))("分析资源文件索引地址",
  85. Sub(Task As LoaderTask(Of String, List(Of NetFile)))
  86. Try
  87. Dim IndexFile = DlClientAssetIndexGet(Version)
  88. Dim IndexFileInfo As New FileInfo(IndexFile.LocalPath)
  89. If AssetsIndexBehaviour <> AssetsIndexExistsBehaviour.AlwaysDownload AndAlso IndexFile.Check.Check(IndexFile.LocalPath) Is Nothing Then
  90. Task.Output = New List(Of NetFile)
  91. Else
  92. Task.Output = New List(Of NetFile) From {IndexFile}
  93. End If
  94. Catch ex As Exception
  95. Throw New Exception("分析资源文件索引地址失败", ex)
  96. End Try
  97. End Sub) With {.ProgressWeight = 0.5, .Show = False})
  98. '下载资源文件索引
  99. LoadersAssets.Add(New LoaderDownload("下载资源文件索引", New List(Of NetFile)) With {.ProgressWeight = 2})
  100. '要求独立更新索引
  101. If AssetsIndexBehaviour = AssetsIndexExistsBehaviour.DownloadInBackground Then
  102. Dim LoadersAssetsUpdate As New List(Of LoaderBase)
  103. Dim TempAddress As String = Nothing
  104. Dim RealAddress As String = Nothing
  105. LoadersAssetsUpdate.Add(New LoaderTask(Of String, List(Of NetFile))("后台分析资源文件索引地址", Sub(Task As LoaderTask(Of String, List(Of NetFile)))
  106. Dim BackAssetsFile As NetFile = DlClientAssetIndexGet(Version)
  107. RealAddress = BackAssetsFile.LocalPath
  108. TempAddress = PathTemp & "Cache\" & BackAssetsFile.LocalName
  109. BackAssetsFile.LocalPath = TempAddress
  110. Task.Output = New List(Of NetFile) From {BackAssetsFile}
  111. End Sub))
  112. LoadersAssetsUpdate.Add(New LoaderDownload("后台下载资源文件索引", New List(Of NetFile)))
  113. LoadersAssetsUpdate.Add(New LoaderTask(Of List(Of NetFile), String)("后台复制资源文件索引", Sub(Task As LoaderTask(Of List(Of NetFile), String))
  114. Try
  115. File.Copy(TempAddress, RealAddress, True)
  116. McLaunchLog("后台更新资源文件索引成功:" & TempAddress)
  117. Catch ex As Exception
  118. Log(ex, "后台更新资源文件索引失败", LogLevel.Debug)
  119. McLaunchLog("后台更新资源文件索引失败:" & TempAddress)
  120. End Try
  121. End Sub))
  122. Dim Updater As New LoaderCombo(Of String)("后台更新资源文件索引", LoadersAssetsUpdate)
  123. Log("[Download] 开始后台更新资源文件索引")
  124. Updater.Start()
  125. End If
  126. '获取资源文件地址
  127. LoadersAssets.Add(New LoaderTask(Of String, List(Of NetFile))("分析缺失资源文件",
  128. Sub(Task As LoaderTask(Of String, List(Of NetFile)))
  129. Task.Output = McAssetsFixList(McAssetsGetIndexName(Version), CheckAssetsHash, Task)
  130. End Sub) With {.ProgressWeight = 3})
  131. '下载资源文件
  132. LoadersAssets.Add(New LoaderDownload("下载资源文件", New List(Of NetFile)) With {.ProgressWeight = 25})
  133. '构造加载器
  134. Loaders.Add(New LoaderCombo(Of String)("下载资源文件(主加载器)", LoadersAssets) With {.Block = False, .Show = False, .ProgressWeight = 30.5})
  135. End If
  136. #End Region
  137. Return Loaders
  138. End Function
  139. Public Enum AssetsIndexExistsBehaviour
  140. ''' <summary>
  141. ''' 如果文件存在,则不进行下载。
  142. ''' </summary>
  143. DontDownload
  144. ''' <summary>
  145. ''' 如果文件存在,则启动新的下载加载器进行独立的更新。
  146. ''' </summary>
  147. DownloadInBackground
  148. ''' <summary>
  149. ''' 如果文件存在,也同样进行下载。
  150. ''' </summary>
  151. AlwaysDownload
  152. End Enum
  153. #End Region
  154. #Region "DlClientList | Minecraft 客户端 版本列表"
  155. '主加载器
  156. Public Structure DlClientListResult
  157. ''' <summary>
  158. ''' 数据来源名称,如“Mojang”,“BMCLAPI”。
  159. ''' </summary>
  160. Public SourceName As String
  161. ''' <summary>
  162. ''' 是否为官方的实时数据。
  163. ''' </summary>
  164. Public IsOfficial As Boolean
  165. ''' <summary>
  166. ''' 获取到的 Json 数据。
  167. ''' </summary>
  168. Public Value As JObject
  169. '''' <summary>
  170. '''' 官方源的失败原因。若没有则为 Nothing。
  171. '''' </summary>
  172. 'Public OfficialError As Exception
  173. End Structure
  174. ''' <summary>
  175. ''' Minecraft 客户端 版本列表,主加载器。
  176. ''' </summary>
  177. Public DlClientListLoader As New LoaderTask(Of Integer, DlClientListResult)("DlClientList Main", AddressOf DlClientListMain)
  178. Private Sub DlClientListMain(Loader As LoaderTask(Of Integer, DlClientListResult))
  179. Select Case Setup.Get("ToolDownloadVersion")
  180. Case 0
  181. DlSourceLoader(Loader, New List(Of KeyValuePair(Of LoaderTask(Of Integer, DlClientListResult), Integer)) From {
  182. New KeyValuePair(Of LoaderTask(Of Integer, DlClientListResult), Integer)(DlClientListBmclapiLoader, 30),
  183. New KeyValuePair(Of LoaderTask(Of Integer, DlClientListResult), Integer)(DlClientListMojangLoader, 60)
  184. }, Loader.IsForceRestarting)
  185. Case 1
  186. DlSourceLoader(Loader, New List(Of KeyValuePair(Of LoaderTask(Of Integer, DlClientListResult), Integer)) From {
  187. New KeyValuePair(Of LoaderTask(Of Integer, DlClientListResult), Integer)(DlClientListMojangLoader, 5),
  188. New KeyValuePair(Of LoaderTask(Of Integer, DlClientListResult), Integer)(DlClientListBmclapiLoader, 35)
  189. }, Loader.IsForceRestarting)
  190. Case Else
  191. DlSourceLoader(Loader, New List(Of KeyValuePair(Of LoaderTask(Of Integer, DlClientListResult), Integer)) From {
  192. New KeyValuePair(Of LoaderTask(Of Integer, DlClientListResult), Integer)(DlClientListMojangLoader, 60),
  193. New KeyValuePair(Of LoaderTask(Of Integer, DlClientListResult), Integer)(DlClientListBmclapiLoader, 60)
  194. }, Loader.IsForceRestarting)
  195. End Select
  196. End Sub
  197. '各个下载源的分加载器
  198. ''' <summary>
  199. ''' Minecraft 客户端 版本列表,Mojang 官方源加载器。
  200. ''' </summary>
  201. Public DlClientListMojangLoader As New LoaderTask(Of Integer, DlClientListResult)("DlClientList Mojang", AddressOf DlClientListMojangMain)
  202. Private IsNewClientVersionHinted As Boolean = False
  203. Private Sub DlClientListMojangMain(Loader As LoaderTask(Of Integer, DlClientListResult))
  204. Dim Json As JObject = NetGetCodeByRequestRetry("https://launchermeta.mojang.com/mc/game/version_manifest.json", IsJson:=True)
  205. Try
  206. Dim Versions As JArray = Json("versions")
  207. If Versions.Count < 200 Then Throw New Exception("获取到的版本列表长度不足(" & Json.ToString & ")")
  208. '添加 PCL2 特供项
  209. If File.Exists(PathTemp & "Cache\download.json") Then Versions.Merge(GetJson(ReadFile(PathTemp & "Cache\download.json")))
  210. '返回
  211. Loader.Output = New DlClientListResult With {.IsOfficial = True, .SourceName = "Mojang 官方源", .Value = Json}
  212. '解析更新提示(Release)
  213. Dim Version As String = Json("latest")("release")
  214. If Setup.Get("ToolUpdateRelease") AndAlso Not Setup.Get("ToolUpdateReleaseLast") = "" AndAlso Version IsNot Nothing AndAlso Not Setup.Get("ToolUpdateReleaseLast") = Version Then
  215. McDownloadClientUpdateHint(Version, Json)
  216. IsNewClientVersionHinted = True
  217. End If
  218. Setup.Set("ToolUpdateReleaseLast", Version)
  219. '解析更新提示(Snapshot)
  220. Version = Json("latest")("snapshot")
  221. If Setup.Get("ToolUpdateSnapshot") AndAlso Not Setup.Get("ToolUpdateSnapshotLast") = "" AndAlso Version IsNot Nothing AndAlso Not Setup.Get("ToolUpdateSnapshotLast") = Version AndAlso Not IsNewClientVersionHinted Then
  222. McDownloadClientUpdateHint(Version, Json)
  223. End If
  224. Setup.Set("ToolUpdateSnapshotLast", If(Version, "Nothing"))
  225. Catch ex As Exception
  226. Throw New Exception("版本列表解析失败", ex)
  227. End Try
  228. End Sub
  229. ''' <summary>
  230. ''' Minecraft 客户端 版本列表,BMCLAPI 源加载器。
  231. ''' </summary>
  232. Public DlClientListBmclapiLoader As New LoaderTask(Of Integer, DlClientListResult)("DlClientList Bmclapi", AddressOf DlClientListBmclapiMain)
  233. Private Sub DlClientListBmclapiMain(Loader As LoaderTask(Of Integer, DlClientListResult))
  234. Dim Json As JObject = NetGetCodeByRequestRetry("https://bmclapi2.bangbang93.com/mc/game/version_manifest.json", IsJson:=True)
  235. Try
  236. Dim Versions As JArray = Json("versions")
  237. If Versions.Count < 200 Then Throw New Exception("获取到的版本列表长度不足(" & Json.ToString & ")")
  238. '添加 PCL2 特供项
  239. If File.Exists(PathTemp & "Cache\download.json") Then Versions.Merge(GetJson(ReadFile(PathTemp & "Cache\download.json")))
  240. '返回
  241. Loader.Output = New DlClientListResult With {.IsOfficial = False, .SourceName = "BMCLAPI", .Value = Json}
  242. Catch ex As Exception
  243. Throw New Exception("版本列表解析失败(" & Json.ToString & ")", ex)
  244. End Try
  245. End Sub
  246. ''' <summary>
  247. ''' 获取某个版本的 Json 下载地址,若失败则返回 Nothing。必须在工作线程执行。
  248. ''' </summary>
  249. Public Function DlClientListGet(Id As String)
  250. Try
  251. '确认 Minecraft 版本列表已完成获取
  252. Select Case DlClientListLoader.State
  253. Case LoadState.Loading
  254. DlClientListLoader.WaitForExit()
  255. Case LoadState.Failed, LoadState.Aborted, LoadState.Waiting
  256. DlClientListLoader.WaitForExit(IsForceRestart:=True)
  257. End Select
  258. '确认版本格式标准
  259. Id = Id.Replace("_", "-") '1.7.10_pre4 在版本列表中显示为 1.7.10-pre4
  260. If Id <> "1.0" AndAlso Id.EndsWith(".0") Then Id = Left(Id, Id.Length - 2) 'OptiFine 1.8 的下载会触发此问题,显示版本为 1.8.0
  261. '查找版本并开始
  262. For Each Version As JObject In DlClientListLoader.Output.Value("versions")
  263. If Version("id") = Id Then
  264. Return Version("url").ToString
  265. End If
  266. Next
  267. Log("未发现版本 " & Id & " 的 Json 下载地址,版本列表返回为:" & vbCrLf & DlClientListLoader.Output.Value.ToString, LogLevel.Debug)
  268. Return Nothing
  269. Catch ex As Exception
  270. Log(ex, "获取版本 " & Id & " 的 Json 下载地址失败")
  271. Return Nothing
  272. End Try
  273. End Function
  274. #End Region
  275. #Region "DlOptiFineList | OptiFine 版本列表"
  276. Public Structure DlOptiFineListResult
  277. ''' <summary>
  278. ''' 数据来源名称,如“Official”,“BMCLAPI”。
  279. ''' </summary>
  280. Public SourceName As String
  281. ''' <summary>
  282. ''' 是否为官方的实时数据。
  283. ''' </summary>
  284. Public IsOfficial As Boolean
  285. ''' <summary>
  286. ''' 获取到的数据。
  287. ''' </summary>
  288. Public Value As List(Of DlOptiFineListEntry)
  289. End Structure
  290. Public Class DlOptiFineListEntry
  291. ''' <summary>
  292. ''' 显示名称,已去除 HD_U 字样,如“1.12.2 C8”。
  293. ''' </summary>
  294. Public NameDisplay As String
  295. ''' <summary>
  296. ''' 原始文件名称,如“preview_OptiFine_1.11_HD_U_E1_pre.jar”。
  297. ''' </summary>
  298. Public NameFile As String
  299. ''' <summary>
  300. ''' 对应的版本名称,如“1.13.2-OptiFine_HD_U_E6”。
  301. ''' </summary>
  302. Public NameVersion As String
  303. ''' <summary>
  304. ''' 是否为测试版。
  305. ''' </summary>
  306. Public IsPreview As Boolean
  307. ''' <summary>
  308. ''' 对应的 Minecraft 版本,如“1.12.2”。
  309. ''' </summary>
  310. Public Property Inherit As String
  311. Get
  312. Return _inherit
  313. End Get
  314. Set(value As String)
  315. If value.EndsWith(".0") Then value = Left(value, value.Length - 2)
  316. _inherit = value
  317. End Set
  318. End Property
  319. Private _inherit As String
  320. ''' <summary>
  321. ''' 发布时间,格式为“yyyy/mm/dd”。OptiFine 源无此数据。
  322. ''' </summary>
  323. Public ReleaseTime As String
  324. End Class
  325. ''' <summary>
  326. ''' OptiFine 版本列表,主加载器。
  327. ''' </summary>
  328. Public DlOptiFineListLoader As New LoaderTask(Of Integer, DlOptiFineListResult)("DlOptiFineList Main", AddressOf DlOptiFineListMain)
  329. Private Sub DlOptiFineListMain(Loader As LoaderTask(Of Integer, DlOptiFineListResult))
  330. Select Case Setup.Get("ToolDownloadVersion")
  331. Case 0
  332. DlSourceLoader(Loader, New List(Of KeyValuePair(Of LoaderTask(Of Integer, DlOptiFineListResult), Integer)) From {
  333. New KeyValuePair(Of LoaderTask(Of Integer, DlOptiFineListResult), Integer)(DlOptiFineListBmclapiLoader, 30),
  334. New KeyValuePair(Of LoaderTask(Of Integer, DlOptiFineListResult), Integer)(DlOptiFineListOfficialLoader, 60)
  335. }, Loader.IsForceRestarting)
  336. Case 1
  337. DlSourceLoader(Loader, New List(Of KeyValuePair(Of LoaderTask(Of Integer, DlOptiFineListResult), Integer)) From {
  338. New KeyValuePair(Of LoaderTask(Of Integer, DlOptiFineListResult), Integer)(DlOptiFineListOfficialLoader, 5),
  339. New KeyValuePair(Of LoaderTask(Of Integer, DlOptiFineListResult), Integer)(DlOptiFineListBmclapiLoader, 35)
  340. }, Loader.IsForceRestarting)
  341. Case Else
  342. DlSourceLoader(Loader, New List(Of KeyValuePair(Of LoaderTask(Of Integer, DlOptiFineListResult), Integer)) From {
  343. New KeyValuePair(Of LoaderTask(Of Integer, DlOptiFineListResult), Integer)(DlOptiFineListOfficialLoader, 60),
  344. New KeyValuePair(Of LoaderTask(Of Integer, DlOptiFineListResult), Integer)(DlOptiFineListBmclapiLoader, 60)
  345. }, Loader.IsForceRestarting)
  346. End Select
  347. End Sub
  348. ''' <summary>
  349. ''' OptiFine 版本列表,官方源。
  350. ''' </summary>
  351. Public DlOptiFineListOfficialLoader As New LoaderTask(Of Integer, DlOptiFineListResult)("DlOptiFineList Official", AddressOf DlOptiFineListOfficialMain)
  352. Private Sub DlOptiFineListOfficialMain(Loader As LoaderTask(Of Integer, DlOptiFineListResult))
  353. Dim Result As String = NetGetCodeByClient("https://optifine.net/downloads", Encoding.Default)
  354. If Result.Length < 200 Then Throw New Exception("获取到的版本列表长度不足(" & Result & ")")
  355. '获取所有版本信息
  356. Dim ReleaseTime As List(Of String) = RegexSearch(Result, "(?<=Date'>)[^<]+")
  357. Dim Name As List(Of String) = RegexSearch(Result, "(?<=OptiFine_)[0-9A-Za-z_.]+(?=.jar"")")
  358. If Not ReleaseTime.Count = Name.Count Then Throw New Exception("版本与发布时间数据无法对应")
  359. If ReleaseTime.Count < 10 Then Throw New Exception("获取到的版本数量不足(" & Result & ")")
  360. '转化为列表输出
  361. Dim Versions As New List(Of DlOptiFineListEntry)
  362. For i = 0 To ReleaseTime.Count - 1
  363. Name(i) = Name(i).Replace("_", " ")
  364. Dim Entry As New DlOptiFineListEntry With {
  365. .NameDisplay = Name(i).ToString.Replace("HD U ", "").Replace(".0 ", " "),
  366. .ReleaseTime = Join({ReleaseTime(i).Split(".")(2), ReleaseTime(i).Split(".")(1), ReleaseTime(i).Split(".")(0)}, "/"),
  367. .IsPreview = Name(i).ToString.ToLower.Contains("pre"),
  368. .Inherit = Name(i).ToString.Split(" ")(0),
  369. .NameFile = If(Name(i).ToString.ToLower.Contains("pre"), "preview_", "") &
  370. "OptiFine_" & Name(i).ToString.Replace(" ", "_") & ".jar"}
  371. Entry.NameVersion = Entry.Inherit & "-OptiFine_" & Name(i).ToString.Replace(" ", "_").Replace(Entry.Inherit & "_", "")
  372. Versions.Add(Entry)
  373. Next
  374. Loader.Output = New DlOptiFineListResult With {.IsOfficial = True, .SourceName = "OptiFine 官方源", .Value = Versions}
  375. End Sub
  376. ''' <summary>
  377. ''' OptiFine 版本列表,BMCLAPI。
  378. ''' </summary>
  379. Public DlOptiFineListBmclapiLoader As New LoaderTask(Of Integer, DlOptiFineListResult)("DlOptiFineList Bmclapi", AddressOf DlOptiFineListBmclapiMain)
  380. Private Sub DlOptiFineListBmclapiMain(Loader As LoaderTask(Of Integer, DlOptiFineListResult))
  381. Dim Json As JArray = NetGetCodeByRequestRetry("https://bmclapi2.bangbang93.com/optifine/versionList", IsJson:=True)
  382. Try
  383. Dim Versions As New List(Of DlOptiFineListEntry)
  384. For Each Token As JObject In Json
  385. Dim Entry As New DlOptiFineListEntry With {
  386. .NameDisplay = (Token("mcversion").ToString & Token("type").ToString.Replace("HD_U", "").Replace("_", " ") & " " & Token("patch").ToString).Replace(".0 ", " "),
  387. .ReleaseTime = "",
  388. .IsPreview = Token("patch").ToString.ToLower.Contains("pre"),
  389. .Inherit = Token("mcversion").ToString,
  390. .NameFile = Token("filename").ToString
  391. }
  392. Entry.NameVersion = Entry.Inherit & "-OptiFine_" & (Token("type").ToString & " " & Token("patch").ToString).Replace(".0 ", " ").Replace(" ", "_").Replace(Entry.Inherit & "_", "")
  393. Versions.Add(Entry)
  394. Next
  395. Loader.Output = New DlOptiFineListResult With {.IsOfficial = False, .SourceName = "BMCLAPI", .Value = Versions}
  396. Catch ex As Exception
  397. Throw New Exception("版本列表解析失败(" & Json.ToString & ")", ex)
  398. End Try
  399. End Sub
  400. #End Region
  401. #Region "DlForgeList | Forge Minecraft 版本列表"
  402. Public Structure DlForgeListResult
  403. ''' <summary>
  404. ''' 数据来源名称,如“Official”,“BMCLAPI”。
  405. ''' </summary>
  406. Public SourceName As String
  407. ''' <summary>
  408. ''' 是否为官方的实时数据。
  409. ''' </summary>
  410. Public IsOfficial As Boolean
  411. ''' <summary>
  412. ''' 获取到的数据。
  413. ''' </summary>
  414. Public Value As List(Of String)
  415. End Structure
  416. ''' <summary>
  417. ''' Forge 版本列表,主加载器。
  418. ''' </summary>
  419. Public DlForgeListLoader As New LoaderTask(Of Integer, DlForgeListResult)("DlForgeList Main", AddressOf DlForgeListMain)
  420. Private Sub DlForgeListMain(Loader As LoaderTask(Of Integer, DlForgeListResult))
  421. Select Case Setup.Get("ToolDownloadVersion")
  422. Case 0
  423. DlSourceLoader(Loader, New List(Of KeyValuePair(Of LoaderTask(Of Integer, DlForgeListResult), Integer)) From {
  424. New KeyValuePair(Of LoaderTask(Of Integer, DlForgeListResult), Integer)(DlForgeListBmclapiLoader, 30),
  425. New KeyValuePair(Of LoaderTask(Of Integer, DlForgeListResult), Integer)(DlForgeListOfficialLoader, 60)
  426. }, Loader.IsForceRestarting)
  427. Case 1
  428. DlSourceLoader(Loader, New List(Of KeyValuePair(Of LoaderTask(Of Integer, DlForgeListResult), Integer)) From {
  429. New KeyValuePair(Of LoaderTask(Of Integer, DlForgeListResult), Integer)(DlForgeListOfficialLoader, 5),
  430. New KeyValuePair(Of LoaderTask(Of Integer, DlForgeListResult), Integer)(DlForgeListBmclapiLoader, 35)
  431. }, Loader.IsForceRestarting)
  432. Case Else
  433. DlSourceLoader(Loader, New List(Of KeyValuePair(Of LoaderTask(Of Integer, DlForgeListResult), Integer)) From {
  434. New KeyValuePair(Of LoaderTask(Of Integer, DlForgeListResult), Integer)(DlForgeListOfficialLoader, 60),
  435. New KeyValuePair(Of LoaderTask(Of Integer, DlForgeListResult), Integer)(DlForgeListBmclapiLoader, 60)
  436. }, Loader.IsForceRestarting)
  437. End Select
  438. End Sub
  439. ''' <summary>
  440. ''' Forge 版本列表,官方源。
  441. ''' </summary>
  442. Public DlForgeListOfficialLoader As New LoaderTask(Of Integer, DlForgeListResult)("DlForgeList Official", AddressOf DlForgeListOfficialMain)
  443. Private Sub DlForgeListOfficialMain(Loader As LoaderTask(Of Integer, DlForgeListResult))
  444. Dim Result As String = NetGetCodeByRequestRetry("http://files.minecraftforge.net/maven/net/minecraftforge/forge/index_1.2.4.html", Encoding.Default, "text/html")
  445. If Result.Length < 200 Then Throw New Exception("获取到的版本列表长度不足(" & Result & ")")
  446. '获取所有版本信息
  447. Dim Names As List(Of String) = RegexSearch(Result, "(?<=a href=""index_)[0-9.]+(_pre[0-9]?)?(?=.html)")
  448. Names.Add("1.2.4") '1.2.4 不会被匹配上
  449. If Names.Count < 10 Then Throw New Exception("获取到的版本数量不足(" & Result & ")")
  450. Loader.Output = New DlForgeListResult With {.IsOfficial = True, .SourceName = "Forge 官方源", .Value = Names}
  451. End Sub
  452. ''' <summary>
  453. ''' Forge 版本列表,BMCLAPI。
  454. ''' </summary>
  455. Public DlForgeListBmclapiLoader As New LoaderTask(Of Integer, DlForgeListResult)("DlForgeList Bmclapi", AddressOf DlForgeListBmclapiMain)
  456. Private Sub DlForgeListBmclapiMain(Loader As LoaderTask(Of Integer, DlForgeListResult))
  457. Dim Result As String = NetGetCodeByRequestRetry("https://bmclapi2.bangbang93.com/forge/minecraft", Encoding.Default)
  458. If Result.Length < 200 Then Throw New Exception("获取到的版本列表长度不足(" & Result & ")")
  459. '获取所有版本信息
  460. Dim Names As List(Of String) = RegexSearch(Result, "[0-9.]+(_pre[0-9]?)?")
  461. If Names.Count < 10 Then Throw New Exception("获取到的版本数量不足(" & Result & ")")
  462. Loader.Output = New DlForgeListResult With {.IsOfficial = False, .SourceName = "BMCLAPI", .Value = Names}
  463. End Sub
  464. #End Region
  465. #Region "DlForgeVersion | Forge 版本列表"
  466. Public Class DlForgeVersionEntry
  467. ''' <summary>
  468. ''' 完整的版本名,如 “14.22.1.2478”。
  469. ''' </summary>
  470. Public Version As String
  471. ''' <summary>
  472. ''' 对应的 Minecraft 版本,如“1.12.2”。
  473. ''' </summary>
  474. Public Inherit As String
  475. ''' <summary>
  476. ''' 发布时间,格式为“yyyy/MM/dd HH:mm”。
  477. ''' </summary>
  478. Public ReleaseTime As String
  479. ''' <summary>
  480. ''' 文件的 MD5 或 SHA1(BMCLAPI 的老版本是 MD5,新版本是 SHA1;官方源总是 MD5)。
  481. ''' </summary>
  482. Public Hash As String = Nothing
  483. ''' <summary>
  484. ''' 是否为推荐版本。
  485. ''' </summary>
  486. Public IsRecommended As Boolean
  487. ''' <summary>
  488. ''' 安装类型。有 installer、client、universal 三种。
  489. ''' </summary>
  490. Public Category As String
  491. ''' <summary>
  492. ''' 版本分支。若无分支则为 Nothing。
  493. ''' </summary>
  494. Public Branch As String = Nothing
  495. ''' <summary>
  496. ''' 是否为新版 Forge。(即为 Minecraft 1.13+)
  497. ''' </summary>
  498. Public ReadOnly Property IsNewType As Boolean
  499. Get
  500. Return Version.Split(".")(0) >= 20
  501. End Get
  502. End Property
  503. ''' <summary>
  504. ''' 构建数。
  505. ''' </summary>
  506. Public ReadOnly Property Build As Integer
  507. Get
  508. Dim Version = Me.Version.Split(".")
  509. If Version(0) < 15 Then
  510. Return Version(Version.Count - 1)
  511. Else
  512. Return Version(Version.Count - 1) + 10000
  513. End If
  514. End Get
  515. End Property
  516. ''' <summary>
  517. ''' 用于下载的文件版本名。可能在 Version 的基础上添加了分支。
  518. ''' </summary>
  519. Public ReadOnly Property FileVersion As String
  520. Get
  521. Return Version & If(Branch Is Nothing, "", "-" & Branch)
  522. End Get
  523. End Property
  524. ''' <summary>
  525. ''' 即将下载的文件全名。
  526. ''' </summary>
  527. Public ReadOnly Property FileName As String
  528. Get
  529. Return "forge-" & Inherit & "-" & FileVersion & "-" & Category & "." & FileSuffix
  530. End Get
  531. End Property
  532. ''' <summary>
  533. ''' 文件扩展名。
  534. ''' </summary>
  535. Public ReadOnly Property FileSuffix As String
  536. Get
  537. If Category = "installer" Then
  538. Return "jar"
  539. Else
  540. Return "zip"
  541. End If
  542. End Get
  543. End Property
  544. End Class
  545. ''' <summary>
  546. ''' Forge 版本列表,主加载器。
  547. ''' </summary>
  548. Public Sub DlForgeVersionMain(Loader As LoaderTask(Of String, List(Of DlForgeVersionEntry)))
  549. Dim DlForgeVersionOfficialLoader As New LoaderTask(Of String, List(Of DlForgeVersionEntry))("DlForgeVersion Official", AddressOf DlForgeVersionOfficialMain)
  550. Dim DlForgeVersionBmclapiLoader As New LoaderTask(Of String, List(Of DlForgeVersionEntry))("DlForgeVersion Bmclapi", AddressOf DlForgeVersionBmclapiMain)
  551. Select Case Setup.Get("ToolDownloadVersion")
  552. Case 0
  553. DlSourceLoader(Loader, New List(Of KeyValuePair(Of LoaderTask(Of String, List(Of DlForgeVersionEntry)), Integer)) From {
  554. New KeyValuePair(Of LoaderTask(Of String, List(Of DlForgeVersionEntry)), Integer)(DlForgeVersionBmclapiLoader, 30),
  555. New KeyValuePair(Of LoaderTask(Of String, List(Of DlForgeVersionEntry)), Integer)(DlForgeVersionOfficialLoader, 60)
  556. }, Loader.IsForceRestarting)
  557. Case 1
  558. DlSourceLoader(Loader, New List(Of KeyValuePair(Of LoaderTask(Of String, List(Of DlForgeVersionEntry)), Integer)) From {
  559. New KeyValuePair(Of LoaderTask(Of String, List(Of DlForgeVersionEntry)), Integer)(DlForgeVersionOfficialLoader, 5),
  560. New KeyValuePair(Of LoaderTask(Of String, List(Of DlForgeVersionEntry)), Integer)(DlForgeVersionBmclapiLoader, 35)
  561. }, Loader.IsForceRestarting)
  562. Case Else
  563. DlSourceLoader(Loader, New List(Of KeyValuePair(Of LoaderTask(Of String, List(Of DlForgeVersionEntry)), Integer)) From {
  564. New KeyValuePair(Of LoaderTask(Of String, List(Of DlForgeVersionEntry)), Integer)(DlForgeVersionOfficialLoader, 60),
  565. New KeyValuePair(Of LoaderTask(Of String, List(Of DlForgeVersionEntry)), Integer)(DlForgeVersionBmclapiLoader, 60)
  566. }, Loader.IsForceRestarting)
  567. End Select
  568. End Sub
  569. ''' <summary>
  570. ''' Forge 版本列表,官方源。
  571. ''' </summary>
  572. Public Sub DlForgeVersionOfficialMain(Loader As LoaderTask(Of String, List(Of DlForgeVersionEntry)))
  573. Dim Result As String
  574. Try
  575. Result = NetGetCodeByDownload("http://files.minecraftforge.net/maven/net/minecraftforge/forge/index_" & Loader.Input & ".html")
  576. Catch ex As Exception
  577. If GetString(ex).Contains("(404)") Then
  578. Throw New Exception("没有可用版本")
  579. Else
  580. Throw
  581. End If
  582. End Try
  583. If Result.Length < 1000 Then Throw New Exception("获取到的版本列表长度不足(" & Result & ")")
  584. Dim Versions As New List(Of DlForgeVersionEntry)
  585. Try
  586. '分割版本信息
  587. Dim VersionCodes = Mid(Result, 1, Result.LastIndexOf("</table>")).Replace("<td class=""download-version", "¨").Split("¨")
  588. '获取所有版本信息
  589. For i = 1 To VersionCodes.Count - 1
  590. Dim VersionCode = VersionCodes(i)
  591. Try
  592. '基础信息获取
  593. Dim Name As String = RegexSeek(VersionCode, "(?<=[^(0-9)]+)[0-9\.]+")
  594. Dim IsRecommended As Boolean = VersionCode.Contains("fa promo-recommended")
  595. Dim Inherit As String = Loader.Input
  596. '分支获取
  597. Dim Branch As String = RegexSeek(VersionCode, "(?<=Branch:</strong>[\s]*)[^<]+")
  598. Branch = RegexSeek(If(Branch, ""), "[^\s]+")
  599. If String.IsNullOrWhiteSpace(Branch) Then Branch = Nothing
  600. If Name = "11.15.1.2318" OrElse Name = "11.15.1.1902" OrElse Name = "11.15.1.1890" Then Branch = "1.8.9"
  601. If Branch Is Nothing AndAlso Inherit = "1.7.10" AndAlso Name.Split(".")(3) >= 1300 Then Branch = "1.7.10"
  602. '发布时间获取
  603. Dim ReleaseTimeOriginal = RegexSeek(VersionCode, "(?<=""download-time"" title="")[^""]+")
  604. Dim ReleaseTimeSplit = ReleaseTimeOriginal.Split(" -:".ToCharArray) '原格式:"2021-02-15 03:24:02"
  605. Dim ReleaseDate As New Date(ReleaseTimeSplit(0), ReleaseTimeSplit(1), ReleaseTimeSplit(2), '年月日
  606. ReleaseTimeSplit(3), ReleaseTimeSplit(4), ReleaseTimeSplit(5), '时分秒
  607. 0, DateTimeKind.Utc) '以 UTC 时间作为标准
  608. Dim ReleaseTime As String = ReleaseDate.ToLocalTime.ToString("yyyy/MM/dd HH:mm") '时区与格式转换
  609. '分类与 MD5 获取
  610. Dim MD5 As String, Category As String
  611. If VersionCode.Contains("classifier-installer""") Then
  612. '类型为 installer.jar,支持范围 ~753 (~ 1.6.1 部分), 738~684 (1.5.2 全部)
  613. VersionCode = VersionCode.Substring(VersionCode.IndexOf("installer.jar"))
  614. MD5 = RegexSeek(VersionCode, "(?<=MD5:</strong> )[^<]+")
  615. Category = "installer"
  616. ElseIf VersionCode.Contains("classifier-universal""") Then
  617. '类型为 universal.zip,支持范围 751~449 (1.6.1 部分), 682~183 (1.5.1 ~ 1.3.2 部分)
  618. VersionCode = VersionCode.Substring(VersionCode.IndexOf("universal.zip"))
  619. MD5 = RegexSeek(VersionCode, "(?<=MD5:</strong> )[^<]+")
  620. Category = "universal"
  621. Else
  622. '类型为 client.zip,支持范围 182~ (1.3.2 部分 ~)
  623. VersionCode = VersionCode.Substring(VersionCode.IndexOf("client.zip"))
  624. MD5 = RegexSeek(VersionCode, "(?<=MD5:</strong> )[^<]+")
  625. Category = "client"
  626. End If
  627. '添加进列表
  628. Versions.Add(New DlForgeVersionEntry With {.Category = Category, .Version = Name, .IsRecommended = IsRecommended, .Hash = MD5.Trim(vbCr, vbLf), .Inherit = Inherit, .ReleaseTime = ReleaseTime, .Branch = Branch})
  629. Catch ex As Exception
  630. Throw New Exception("版本信息提取失败(" & VersionCode & ")", ex)
  631. End Try
  632. Next
  633. Catch ex As Exception
  634. Throw New Exception("版本列表解析失败(" & Result & ")", ex)
  635. End Try
  636. If Versions.Count = 0 Then Throw New Exception("没有可用版本")
  637. Loader.Output = Versions
  638. End Sub
  639. ''' <summary>
  640. ''' Forge 版本列表,BMCLAPI。
  641. ''' </summary>
  642. Public Sub DlForgeVersionBmclapiMain(Loader As LoaderTask(Of String, List(Of DlForgeVersionEntry)))
  643. Dim Json As JArray = NetGetCodeByRequestRetry("https://bmclapi2.bangbang93.com/forge/minecraft/" & Loader.Input, IsJson:=True)
  644. Dim Versions As New List(Of DlForgeVersionEntry)
  645. Try
  646. Dim Recommended As String = McDownloadForgeRecommendedGet(Loader.Input)
  647. For Each Token As JObject In Json
  648. '分类与 Hash 获取
  649. Dim Hash As String = Nothing, Category As String = "unknown", Proi As Integer = -1
  650. For Each File As JObject In Token("files")
  651. Select Case File("category").ToString
  652. Case "installer"
  653. If File("format").ToString = "jar" Then
  654. '类型为 installer.jar,支持范围 ~753 (~ 1.6.1 部分), 738~684 (1.5.2 全部)
  655. Hash = File("hash")
  656. Category = "installer"
  657. Proi = 2
  658. End If
  659. Case "universal"
  660. If Proi <= 1 AndAlso File("format").ToString = "zip" Then
  661. '类型为 universal.zip,支持范围 751~449 (1.6.1 部分), 682~183 (1.5.1 ~ 1.3.2 部分)
  662. Hash = File("hash")
  663. Category = "universal"
  664. Proi = 1
  665. End If
  666. Case "client"
  667. If Proi <= 0 AndAlso File("format").ToString = "zip" Then
  668. '类型为 client.zip,支持范围 182~ (1.3.2 部分 ~)
  669. Hash = File("hash")
  670. Category = "client"
  671. Proi = 0
  672. End If
  673. End Select
  674. Next
  675. '获取 Entry
  676. Dim Inherit As String = Loader.Input
  677. Dim Branch As String = Token("branch")
  678. Dim Name As String = Token("version")
  679. If Name = "11.15.1.2318" OrElse Name = "11.15.1.1902" OrElse Name = "11.15.1.1890" Then Branch = "1.8.9"
  680. If Branch Is Nothing AndAlso Inherit = "1.7.10" AndAlso Name.Split(".")(3) >= 1300 Then Branch = "1.7.10"
  681. '基础信息获取
  682. Dim Entry = New DlForgeVersionEntry With {.Hash = Hash, .Category = Category, .Version = Name, .Branch = Branch, .Inherit = Inherit, .IsRecommended = Recommended = Name}
  683. Dim TimeSplit = Token("modified").ToString.Split("-"c, "T"c, ":"c, "."c, " "c, "/"c)
  684. Entry.ReleaseTime = Token("modified").ToObject(Of Date).ToLocalTime.ToString("yyyy/MM/dd HH:mm")
  685. '添加项
  686. Versions.Add(Entry)
  687. Next
  688. Catch ex As Exception
  689. Throw New Exception("版本列表解析失败(" & Json.ToString & ")", ex)
  690. End Try
  691. If Versions.Count = 0 Then Throw New Exception("没有可用版本")
  692. Loader.Output = Versions
  693. End Sub
  694. #End Region
  695. #Region "DlLiteLoaderList | LiteLoader 版本列表"
  696. Public Structure DlLiteLoaderListResult
  697. ''' <summary>
  698. ''' 数据来源名称,如“Official”,“BMCLAPI”。
  699. ''' </summary>
  700. Public SourceName As String
  701. ''' <summary>
  702. ''' 是否为官方的实时数据。
  703. ''' </summary>
  704. Public IsOfficial As Boolean
  705. ''' <summary>
  706. ''' 获取到的数据。
  707. ''' </summary>
  708. Public Value As List(Of DlLiteLoaderListEntry)
  709. ''' <summary>
  710. ''' 官方源的失败原因。若没有则为 Nothing。
  711. ''' </summary>
  712. Public OfficialError As Exception
  713. End Structure
  714. Public Class DlLiteLoaderListEntry
  715. ''' <summary>
  716. ''' 实际的文件名,如“liteloader-installer-1.12-00-SNAPSHOT.jar”。
  717. ''' </summary>
  718. Public FileName As String
  719. ''' <summary>
  720. ''' 是否为测试版。
  721. ''' </summary>
  722. Public IsPreview As Boolean
  723. ''' <summary>
  724. ''' 对应的 Minecraft 版本,如“1.12.2”。
  725. ''' </summary>
  726. Public Inherit As String
  727. ''' <summary>
  728. ''' 是否为 1.7 及更早的远古版。
  729. ''' </summary>
  730. Public IsLegacy As Boolean
  731. ''' <summary>
  732. ''' 发布时间,格式为“yyyy/mm/dd HH:mm:ss”。
  733. ''' </summary>
  734. Public ReleaseTime As String
  735. ''' <summary>
  736. ''' 文件的 MD5。
  737. ''' </summary>
  738. Public MD5 As String
  739. ''' <summary>
  740. ''' 对应的 Json 项。
  741. ''' </summary>
  742. Public JsonToken As JToken
  743. End Class
  744. ''' <summary>
  745. ''' LiteLoader 版本列表,主加载器。
  746. ''' </summary>
  747. Public DlLiteLoaderListLoader As New LoaderTask(Of Integer, DlLiteLoaderListResult)("DlLiteLoaderList Main", AddressOf DlLiteLoaderListMain)
  748. Private Sub DlLiteLoaderListMain(Loader As LoaderTask(Of Integer, DlLiteLoaderListResult))
  749. Select Case Setup.Get("ToolDownloadVersion")
  750. Case 0
  751. DlSourceLoader(Loader, New List(Of KeyValuePair(Of LoaderTask(Of Integer, DlLiteLoaderListResult), Integer)) From {
  752. New KeyValuePair(Of LoaderTask(Of Integer, DlLiteLoaderListResult), Integer)(DlLiteLoaderListBmclapiLoader, 30),
  753. New KeyValuePair(Of LoaderTask(Of Integer, DlLiteLoaderListResult), Integer)(DlLiteLoaderListOfficialLoader, 60)
  754. }, Loader.IsForceRestarting)
  755. Case 1
  756. DlSourceLoader(Loader, New List(Of KeyValuePair(Of LoaderTask(Of Integer, DlLiteLoaderListResult), Integer)) From {
  757. New KeyValuePair(Of LoaderTask(Of Integer, DlLiteLoaderListResult), Integer)(DlLiteLoaderListOfficialLoader, 5),
  758. New KeyValuePair(Of LoaderTask(Of Integer, DlLiteLoaderListResult), Integer)(DlLiteLoaderListBmclapiLoader, 35)
  759. }, Loader.IsForceRestarting)
  760. Case Else
  761. DlSourceLoader(Loader, New List(Of KeyValuePair(Of LoaderTask(Of Integer, DlLiteLoaderListResult), Integer)) From {
  762. New KeyValuePair(Of LoaderTask(Of Integer, DlLiteLoaderListResult), Integer)(DlLiteLoaderListOfficialLoader, 60),
  763. New KeyValuePair(Of LoaderTask(Of Integer, DlLiteLoaderListResult), Integer)(DlLiteLoaderListBmclapiLoader, 60)
  764. }, Loader.IsForceRestarting)
  765. End Select
  766. End Sub
  767. ''' <summary>
  768. ''' LiteLoader 版本列表,官方源。
  769. ''' </summary>
  770. Public DlLiteLoaderListOfficialLoader As New LoaderTask(Of Integer, DlLiteLoaderListResult)("DlLiteLoaderList Official", AddressOf DlLiteLoaderListOfficialMain)
  771. Private Sub DlLiteLoaderListOfficialMain(Loader As LoaderTask(Of Integer, DlLiteLoaderListResult))
  772. Dim Result As JObject = NetGetCodeByRequestRetry("http://dl.liteloader.com/versions/versions.json", IsJson:=True)
  773. Try
  774. Dim Json As JObject = Result("versions")
  775. Dim Versions As New List(Of DlLiteLoaderListEntry)
  776. For Each Pair As KeyValuePair(Of String, JToken) In Json
  777. If Pair.Key.StartsWith("1.6") OrElse Pair.Key.StartsWith("1.5") Then Continue For
  778. Dim RealEntry As JToken = If(Pair.Value("artefacts"), Pair.Value("snapshots"))("com.mumfrey:liteloader")("latest")
  779. Versions.Add(New DlLiteLoaderListEntry With {
  780. .Inherit = Pair.Key,
  781. .IsLegacy = Pair.Key.Split(".")(1) < 8,
  782. .IsPreview = RealEntry("stream").ToString.ToLower = "snapshot",
  783. .FileName = "liteloader-installer-" & Pair.Key & If(Pair.Key = "1.8" OrElse Pair.Key = "1.9", ".0", "") & "-00-SNAPSHOT.jar",
  784. .MD5 = RealEntry("md5"),
  785. .ReleaseTime = GetLocalTime(GetDate(RealEntry("timestamp"))).ToString("yyyy/MM/dd HH:mm:ss"),
  786. .JsonToken = RealEntry
  787. })
  788. Next
  789. Loader.Output = New DlLiteLoaderListResult With {.IsOfficial = True, .SourceName = "LiteLoader 官方源", .Value = Versions}
  790. Catch ex As Exception
  791. Throw New Exception("版本列表解析失败(" & Result.ToString & ")", ex)
  792. End Try
  793. End Sub
  794. ''' <summary>
  795. ''' LiteLoader 版本列表,BMCLAPI。
  796. ''' </summary>
  797. Public DlLiteLoaderListBmclapiLoader As New LoaderTask(Of Integer, DlLiteLoaderListResult)("DlLiteLoaderList Bmclapi", AddressOf DlLiteLoaderListBmclapiMain)
  798. Private Sub DlLiteLoaderListBmclapiMain(Loader As LoaderTask(Of Integer, DlLiteLoaderListResult))
  799. Dim Result As JObject = NetGetCodeByRequestRetry("https://bmclapi2.bangbang93.com/maven/com/mumfrey/liteloader/versions.json", IsJson:=True)
  800. Try
  801. Dim Json As JObject = Result("versions")
  802. Dim Versions As New List(Of DlLiteLoaderListEntry)
  803. For Each Pair As KeyValuePair(Of String, JToken) In Json
  804. If Pair.Key.StartsWith("1.6") OrElse Pair.Key.StartsWith("1.5") Then Continue For
  805. Dim RealEntry As JToken = If(Pair.Value("artefacts"), Pair.Value("snapshots"))("com.mumfrey:liteloader")("latest")
  806. Versions.Add(New DlLiteLoaderListEntry With {
  807. .Inherit = Pair.Key,
  808. .IsLegacy = Pair.Key.Split(".")(1) < 8,
  809. .IsPreview = RealEntry("stream").ToString.ToLower = "snapshot",
  810. .FileName = "liteloader-installer-" & Pair.Key & If(Pair.Key = "1.8" OrElse Pair.Key = "1.9", ".0", "") & "-00-SNAPSHOT.jar",
  811. .MD5 = RealEntry("md5"),
  812. .ReleaseTime = GetLocalTime(GetDate(RealEntry("timestamp"))).ToString("yyyy/MM/dd HH:mm:ss"),
  813. .JsonToken = RealEntry
  814. })
  815. Next
  816. Loader.Output = New DlLiteLoaderListResult With {.IsOfficial = False, .SourceName = "BMCLAPI", .Value = Versions}
  817. Catch ex As Exception
  818. Throw New Exception("版本列表解析失败(" & Result.ToString & ")", ex)
  819. End Try
  820. End Sub
  821. #End Region
  822. #Region "DlFabricList | Fabric 列表"
  823. Public Structure DlFabricListResult
  824. ''' <summary>
  825. ''' 数据来源名称,如“Official”,“BMCLAPI”。
  826. ''' </summary>
  827. Public SourceName As String
  828. ''' <summary>
  829. ''' 是否为官方的实时数据。
  830. ''' </summary>
  831. Public IsOfficial As Boolean
  832. ''' <summary>
  833. ''' 获取到的数据。
  834. ''' </summary>
  835. Public Value As JObject
  836. End Structure
  837. ''' <summary>
  838. ''' Fabric 列表,主加载器。
  839. ''' </summary>
  840. Public DlFabricListLoader As New LoaderTask(Of Integer, DlFabricListResult)("DlFabricList Main", AddressOf DlFabricListMain)
  841. Private Sub DlFabricListMain(Loader As LoaderTask(Of Integer, DlFabricListResult))
  842. Select Case Setup.Get("ToolDownloadVersion")
  843. Case 0
  844. DlSourceLoader(Loader, New List(Of KeyValuePair(Of LoaderTask(Of Integer, DlFabricListResult), Integer)) From {
  845. New KeyValuePair(Of LoaderTask(Of Integer, DlFabricListResult), Integer)(DlFabricListBmclapiLoader, 30),
  846. New KeyValuePair(Of LoaderTask(Of Integer, DlFabricListResult), Integer)(DlFabricListOfficialLoader, 60)
  847. }, Loader.IsForceRestarting)
  848. Case 1
  849. DlSourceLoader(Loader, New List(Of KeyValuePair(Of LoaderTask(Of Integer, DlFabricListResult), Integer)) From {
  850. New KeyValuePair(Of LoaderTask(Of Integer, DlFabricListResult), Integer)(DlFabricListOfficialLoader, 5),
  851. New KeyValuePair(Of LoaderTask(Of Integer, DlFabricListResult), Integer)(DlFabricListBmclapiLoader, 35)
  852. }, Loader.IsForceRestarting)
  853. Case Else
  854. DlSourceLoader(Loader, New List(Of KeyValuePair(Of LoaderTask(Of Integer, DlFabricListResult), Integer)) From {
  855. New KeyValuePair(Of LoaderTask(Of Integer, DlFabricListResult), Integer)(DlFabricListOfficialLoader, 60),
  856. New KeyValuePair(Of LoaderTask(Of Integer, DlFabricListResult), Integer)(DlFabricListBmclapiLoader, 60)
  857. }, Loader.IsForceRestarting)
  858. End Select
  859. End Sub
  860. ''' <summary>
  861. ''' Fabric 列表,官方源。
  862. ''' </summary>
  863. Public DlFabricListOfficialLoader As New LoaderTask(Of Integer, DlFabricListResult)("DlFabricList Official", AddressOf DlFabricListOfficialMain)
  864. Private Sub DlFabricListOfficialMain(Loader As LoaderTask(Of Integer, DlFabricListResult))
  865. Dim Result As JObject = NetGetCodeByRequestRetry("https://meta.fabricmc.net/v2/versions", IsJson:=True)
  866. Try
  867. Dim Output = New DlFabricListResult With {.IsOfficial = True, .SourceName = "Fabric 官方源", .Value = Result}
  868. If Output.Value("game") Is Nothing OrElse Output.Value("loader") Is Nothing OrElse Output.Value("installer") Is Nothing Then Throw New Exception("获取到的列表缺乏必要项")
  869. Loader.Output = Output
  870. Catch ex As Exception
  871. Throw New Exception("列表解析失败(" & Result.ToString & ")", ex)
  872. End Try
  873. End Sub
  874. ''' <summary>
  875. ''' Fabric 列表,BMCLAPI。
  876. ''' </summary>
  877. Public DlFabricListBmclapiLoader As New LoaderTask(Of Integer, DlFabricListResult)("DlFabricList Bmclapi", AddressOf DlFabricListBmclapiMain)
  878. Private Sub DlFabricListBmclapiMain(Loader As LoaderTask(Of Integer, DlFabricListResult))
  879. Dim Result As JObject = NetGetCodeByRequestRetry("https://bmclapi2.bangbang93.com/fabric-meta/v2/versions", IsJson:=True)
  880. Try
  881. Dim Output = New DlFabricListResult With {.IsOfficial = False, .SourceName = "BMCLAPI", .Value = Result}
  882. If Output.Value("game") Is Nothing OrElse Output.Value("loader") Is Nothing OrElse Output.Value("installer") Is Nothing Then Throw New Exception("获取到的列表缺乏必要项")
  883. Loader.Output = Output
  884. Catch ex As Exception
  885. Throw New Exception("列表解析失败(" & Result.ToString & ")", ex)
  886. End Try
  887. End Sub
  888. ''' <summary>
  889. ''' Fabric API 列表,官方源。
  890. ''' </summary>
  891. Public DlFabricApiLoader As New LoaderTask(Of Integer, List(Of DlCfFile))("Fabric API List Loader",
  892. Sub(Task As LoaderTask(Of Integer, List(Of DlCfFile))) Task.Output = DlCfGetFiles(306612, False))
  893. ''' <summary>
  894. ''' OptiFabric 列表,官方源。
  895. ''' </summary>
  896. Public DlOptiFabricLoader As New LoaderTask(Of Integer, List(Of DlCfFile))("OptiFabric List Loader",
  897. Sub(Task As LoaderTask(Of Integer, List(Of DlCfFile))) Task.Output = DlCfGetFiles(322385, False))
  898. #End Region
  899. #Region "DlCfProject | CurseForge 工程"
  900. Private DlCfProjectDb As JObject = Nothing
  901. Private DlCfProjectCache As New Dictionary(Of Integer, DlCfProject)
  902. ''' <summary>
  903. ''' CurseForge 工程列表获取、搜索请求。
  904. ''' </summary>
  905. Public Class DlCfProjectRequest
  906. Public CategoryId As Integer = 0 '421: Mod(?), 4780: Fabric
  907. Public IsModPack As Boolean = False
  908. Public GameVersion As String = Nothing
  909. Public PageSize As String = 50
  910. Public SearchFilter As String = Nothing
  911. Public Index As Integer? = Nothing
  912. Public ModLoader As Integer? = Nothing
  913. Public Function GetAddress() As String
  914. GetAddress = "https://api.curseforge.com/v1/mods/search?gameId=432&sortField=Featured&sortOrder=desc" &
  915. "&pageSize=" & PageSize &
  916. "&categoryId=" & CategoryId &
  917. If(IsModPack, "&classId=4471", "&classId=6") &
  918. If(String.IsNullOrEmpty(GameVersion), "", "&gameVersion=" & GameVersion) &
  919. If(String.IsNullOrEmpty(SearchFilter), "", "&searchFilter=" & Net.WebUtility.UrlEncode(SearchFilter)) &
  920. If(Index IsNot Nothing, "&index=" & Index, "") &
  921. If(ModLoader IsNot Nothing AndAlso ModLoader > 0, "&modLoaderType=" & ModLoader, "")
  922. End Function
  923. #Region "相同判断"
  924. Public Overrides Function Equals(obj As Object) As Boolean
  925. Dim request = TryCast(obj, DlCfProjectRequest)
  926. Return request IsNot Nothing AndAlso request.GetAddress = GetAddress()
  927. End Function
  928. Public Shared Operator =(left As DlCfProjectRequest, right As DlCfProjectRequest) As Boolean
  929. Return EqualityComparer(Of DlCfProjectRequest).Default.Equals(left, right)
  930. End Operator
  931. Public Shared Operator <>(left As DlCfProjectRequest, right As DlCfProjectRequest) As Boolean
  932. Return Not left = right
  933. End Operator
  934. #End Region
  935. End Class
  936. ''' <summary>
  937. ''' CurseForge 工程信息。
  938. ''' </summary>
  939. Public Class DlCfProject
  940. Public Id As Integer
  941. Public Name As String
  942. Public McWikiId As Integer = 0
  943. Public Description As String
  944. Public Website As String
  945. Public DateUpdate As Date
  946. Public DownloadCount As Integer
  947. Public ModLoaders As New List(Of String)
  948. Public GameVersionDesc As String
  949. Private CategoryDesc As List(Of String)
  950. Private Thumb As String
  951. Public IsModPack As Boolean
  952. Public FileIndexes As New List(Of Integer)
  953. Public Files As List(Of DlCfFile)
  954. Private _MCBBS As String
  955. Public Property MCBBS As String
  956. Get
  957. If DlCfProjectDb Is Nothing Then
  958. DlCfProjectDb = GetJson(DecodeBytes(GetResources("ModData")))
  959. End If
  960. If _MCBBS Is Nothing Then
  961. If Website IsNot Nothing Then
  962. Dim Keyword As String = Website.TrimEnd("/").Split("/").Last
  963. If DlCfProjectDb.ContainsKey(Keyword) Then
  964. Dim Result As String() = DlCfProjectDb(Keyword).ToString.Split("|")
  965. If Result.Length = 3 Then _MCBBS = Result.Last
  966. End If
  967. End If
  968. End If
  969. Return _MCBBS
  970. End Get
  971. Set(value As String)
  972. _MCBBS = value
  973. End Set
  974. End Property
  975. Private _ChineseName As String
  976. Public Property ChineseName As String
  977. Get
  978. If DlCfProjectDb Is Nothing Then
  979. DlCfProjectDb = GetJson(DecodeBytes(GetResources("ModData")))
  980. End If
  981. If _ChineseName Is Nothing Then
  982. _ChineseName = Name
  983. If Website IsNot Nothing Then
  984. Dim Keyword As String = Website.TrimEnd("/").Split("/").Last
  985. If DlCfProjectDb.ContainsKey(Keyword) Then
  986. Dim Result As String = DlCfProjectDb(Keyword)
  987. McWikiId = Result.Split("|")(0)
  988. If Not Result.Split("|")(1) = "~" Then '使用原名
  989. _ChineseName = Result.Split("|")(1) '& " (" & Name & ")"
  990. End If
  991. End If
  992. End If
  993. End If
  994. Return _ChineseName
  995. End Get
  996. Set(ByVal value As String)
  997. _ChineseName = value
  998. End Set
  999. End Property
  1000. ''' <summary>
  1001. ''' 从 CurseForge 工程 Json 项中初始化实例。若出错会抛出异常。
  1002. ''' </summary>
  1003. Public Sub New(Data As JObject)
  1004. 'https://api.curseforge.com/v1/mods/search?gameId=432&pageSize=5&categoryID=421
  1005. Id = Data("id")
  1006. Name = Data("name")
  1007. Description = Data("summary")
  1008. Website = Data("links")("websiteUrl")
  1009. DateUpdate = Data("dateModified")
  1010. DownloadCount = Data("downloadCount")
  1011. IsModPack = Not Website.Contains("/mc-mods/")
  1012. '获取常见文件
  1013. For Each File In If(Data("latestFiles"), {})
  1014. Dim NewFile As New DlCfFile(File, IsModPack)
  1015. If Not NewFile.IsAvailable Then Continue For
  1016. Next
  1017. '获取游戏版本、Mod Loader
  1018. Dim GameVersions As New List(Of Integer)
  1019. ModLoaders = New List(Of String)
  1020. For Each File In If(Data("latestFilesIndexes"), {})
  1021. Dim Version As String = File("gameVersion")
  1022. If Not Version.Contains("1.") Then Continue For
  1023. GameVersions.Add(Version.Split(".")(1).Split("-").First)
  1024. Select Case If(File("modLoader"), "0").ToString
  1025. Case 1
  1026. ModLoaders.Add("Forge")
  1027. Case 2
  1028. ModLoaders.Add("Cauldron")
  1029. Case 3
  1030. ModLoaders.Add("LiteLoader")
  1031. Case 4
  1032. ModLoaders.Add("Fabric")
  1033. End Select
  1034. FileIndexes.Add(File("fileId"))
  1035. Next
  1036. GameVersions = Sort(GameVersions.Distinct.ToList, AddressOf VersionSortBoolean)
  1037. ModLoaders = ModLoaders.Distinct.ToList
  1038. ModLoaders.Sort()
  1039. If GameVersions.Count = 0 Then
  1040. GameVersionDesc = ""
  1041. Else
  1042. Dim SpaVersions As New List(Of String)
  1043. For i = 0 To GameVersions.Count - 1
  1044. Dim StartVersion As Integer = GameVersions(i), EndVersion As Integer = GameVersions(i)
  1045. For ii = i + 1 To GameVersions.Count - 1
  1046. If GameVersions(ii) = EndVersion - 1 Then
  1047. EndVersion = GameVersions(ii)
  1048. i = ii
  1049. Else
  1050. Exit For
  1051. End If
  1052. Next
  1053. If StartVersion = EndVersion Then
  1054. SpaVersions.Add("1." & StartVersion)
  1055. Else
  1056. SpaVersions.Add("1." & StartVersion & "-1." & EndVersion)
  1057. End If
  1058. Next
  1059. GameVersionDesc = "[" & Join(SpaVersions, ", ") & "] "
  1060. End If
  1061. '获取分类
  1062. Dim Categories = Data("categories")
  1063. Dim CategoryId As New List(Of Integer)
  1064. For Each CategoryToken In Categories
  1065. CategoryId.Add(CategoryToken("id"))
  1066. Next
  1067. CategoryId = ArrayNoDouble(CategoryId)
  1068. CategoryId.Sort()
  1069. CategoryDesc = New List(Of String)
  1070. For Each Category In CategoryId
  1071. Dim Desc As String
  1072. Select Case Category
  1073. Case 406 : Desc = "世界生成"
  1074. Case 407 : Desc = "生物群系"
  1075. Case 409 : Desc = "天然结构"
  1076. Case 410 : Desc = "维度"
  1077. Case 411 : Desc = "生物"
  1078. Case 412 : Desc = "科技"
  1079. Case 414 : Desc = "交通与移动"
  1080. Case 415 : Desc = "管道与物流"
  1081. Case 417 : Desc = "能源"
  1082. Case 4558 : Desc = "红石"
  1083. Case 420 : Desc = "仓储"
  1084. Case 416 : Desc = "农业"
  1085. Case 436 : Desc = "食物"
  1086. Case 419 : Desc = "魔法"
  1087. Case 434 : Desc = "装备与工具"
  1088. Case 422 : Desc = "冒险与探索"
  1089. Case 424 : Desc = "建筑与装饰"
  1090. Case 423 : Desc = "信息显示"
  1091. Case 425 : Desc = "杂项"
  1092. Case 421 : Desc = "支持库"
  1093. Case 435 : Desc = "服务器"
  1094. Case 4471 : Desc = "科幻"
  1095. Case 4483 : Desc = "战斗"
  1096. Case 4477 : Desc = "小游戏"
  1097. Case 4478 : Desc = "任务"
  1098. Case 4484 : Desc = "多人"
  1099. Case 4476 : Desc = "探索"
  1100. Case 4736 : Desc = "空岛"
  1101. Case 4475 : Desc = "冒险"
  1102. Case 4487 : Desc = "FTB"
  1103. Case 4480 : Desc = "基于地图"
  1104. Case 4479 : Desc = "硬核"
  1105. Case 4472 : Desc = "科技"
  1106. Case 4473 : Desc = "魔法"
  1107. Case 4481 : Desc = "小型整合"
  1108. Case 4482 : Desc = "大型整合"
  1109. Case Else : Continue For
  1110. End Select
  1111. CategoryDesc.Add(Desc)
  1112. Next
  1113. If CategoryDesc.Count = 0 Then CategoryDesc.Add("杂类")
  1114. '获取图片
  1115. If Data("logo").Count > 0 Then
  1116. If GetPixelSize(1) > 1.25 Then
  1117. Thumb = Data("logo")("thumbnailUrl").ToString '使用 256x256 图标
  1118. Else
  1119. Thumb = Data("logo")("thumbnailUrl").ToString.Replace("/256/256/", "/64/64/") '使用 64x64 图标
  1120. End If
  1121. End If
  1122. '保存缓存
  1123. If Not DlCfProjectCache.ContainsKey(Id) OrElse DlCfProjectCache(Id).Files Is Nothing Then DictionaryAdd(DlCfProjectCache, Id, Me)
  1124. End Sub
  1125. Public Function ToCfItem(ShowVersionDesc As Boolean, ShowLoaderDesc As Boolean, Optional OnClick As MyCfItem.ClickEventHandler = Nothing) As MyCfItem
  1126. Dim NewItem As New MyCfItem With {.Tag = Me}
  1127. NewItem.LabTitle.Text = ChineseName
  1128. NewItem.LabInfo.Text = Description.Replace(vbCr, "").Replace(vbLf, "")
  1129. NewItem.LabLeft.Text = If(ModLoaders.Count > 0 AndAlso ShowLoaderDesc, "[" & Join(ModLoaders, " & ") & "] ", "") &
  1130. If(ShowVersionDesc, GameVersionDesc, "") &
  1131. Join(CategoryDesc, ",") & " (" &
  1132. GetTimeSpanString(DateUpdate - Date.Now) & "更新" &
  1133. If(DownloadCount > 0, "," & If(DownloadCount > 100000, Math.Round(DownloadCount / 10000) & " 万次下载)", DownloadCount & " 次下载)"), "")
  1134. If Thumb Is Nothing Then
  1135. NewItem.Logo = "pack://application:,,,/images/Icons/NoIcon.png"
  1136. Else
  1137. NewItem.Logo = Thumb
  1138. End If
  1139. If OnClick IsNot Nothing Then
  1140. AddHandler NewItem.Click, OnClick
  1141. NewItem.HasAnimation = True
  1142. Else
  1143. NewItem.HasAnimation = False
  1144. End If
  1145. '结束
  1146. Return NewItem
  1147. End Function
  1148. Public Overrides Function Equals(obj As Object) As Boolean
  1149. Dim project = TryCast(obj, DlCfProject)
  1150. Return project IsNot Nothing AndAlso Id = project.Id
  1151. End Function
  1152. Public Shared Operator =(left As DlCfProject, right As DlCfProject) As Boolean
  1153. Return EqualityComparer(Of DlCfProject).Default.Equals(left, right)
  1154. End Operator
  1155. Public Shared Operator <>(left As DlCfProject, right As DlCfProject) As Boolean
  1156. Return Not left = right
  1157. End Operator
  1158. End Class
  1159. Public Class DlCfProjectResult
  1160. Public Projects As List(Of DlCfProject)
  1161. Public Index As Integer
  1162. Public RealCount As Long
  1163. End Class
  1164. ''' <summary>
  1165. ''' CurseForge 工程列表获取事件。
  1166. ''' </summary>
  1167. Public Sub DlCfProjectSub(Task As LoaderTask(Of DlCfProjectRequest, DlCfProjectResult))
  1168. Dim RawFilter As String = If(Task.Input.SearchFilter, "")
  1169. Task.Input.SearchFilter = RawFilter
  1170. Log("[Download] CurseForge 工程列表搜索原始文本:" & RawFilter)
  1171. '中文请求关键字处理
  1172. Dim IsChineseSearch As Boolean = RegexCheck(RawFilter, "[\u4e00-\u9fbb]")
  1173. If IsChineseSearch AndAlso Not String.IsNullOrEmpty(RawFilter) Then
  1174. If Task.Input.IsModPack Then Throw New Exception("整合包搜索仅支持英文")
  1175. '释放资料库文件
  1176. If DlCfProjectDb Is Nothing Then
  1177. DlCfProjectDb = GetJson(DecodeBytes(GetResources("ModData")))
  1178. End If
  1179. '构造搜索请求
  1180. Dim SearchEntries As New List(Of SearchEntry(Of String))
  1181. For Each Entry In DlCfProjectDb
  1182. If Entry.Value.ToString.Contains("动态的树") Then Continue For '傻逼 Mod 的附属太多了
  1183. SearchEntries.Add(New SearchEntry(Of String) With {
  1184. .Item = Entry.Value.ToString.Split("|")(1),
  1185. .SearchSource = New List(Of KeyValuePair(Of String, Double)) From {
  1186. New KeyValuePair(Of String, Double)(Entry.Value.ToString.Replace(" (", "|").Split("|")(1), 1)
  1187. }
  1188. })
  1189. Next
  1190. '获取搜索结果
  1191. Dim SearchResults = Search(SearchEntries, Task.Input.SearchFilter, 3)
  1192. If SearchResults.Count = 0 Then Throw New Exception("无搜索结果,请尝试搜索英文名称")
  1193. Dim SearchResult As String = ""
  1194. For i = 0 To SearchResults.Count - 1
  1195. If Not SearchResults(i).AbsoluteRight AndAlso i >= Math.Min(2, SearchResults.Count - 1) Then Exit For '把 3 个结果拼合以提高准确度
  1196. SearchResult += SearchResults(i).Item.Replace(" (", "|").Split("|").Last.TrimEnd(")") & " "
  1197. Next
  1198. Log("[Download] CurseForge 工程列表中文搜索原始关键词:" & SearchResult, LogLevel.Developer)
  1199. '去除常见连接词
  1200. Dim RealFilter As String = ""
  1201. For Each Word In SearchResult.Split(" ")
  1202. If {"the", "of", "a", "mod"}.Contains(Word.ToLower) Then Continue For
  1203. If SearchResult.Split(" ").Count > 3 AndAlso {"ftb"}.Contains(Word.ToLower) Then Continue For
  1204. RealFilter += Word & " "
  1205. Next
  1206. Task.Input.SearchFilter = RealFilter
  1207. Log("[Download] CurseForge 工程列表中文搜索最终关键词:" & RealFilter, LogLevel.Developer)
  1208. End If
  1209. '驼峰英文请求关键字处理
  1210. Dim SpacedKeywords = RegexReplace(Task.Input.SearchFilter, "$& ", "([A-Z]+|[a-z]+?)(?=[A-Z]+[a-z]+[a-z ]*)")
  1211. Dim ConnectedKeywords = Task.Input.SearchFilter.Replace(" ", "")
  1212. Dim AllPossibleKeywords = SpacedKeywords & " " & If(IsChineseSearch, Task.Input.SearchFilter, ConnectedKeywords & " " & RawFilter)
  1213. '最终处理关键字:分割、去重
  1214. Dim RightKeywords As New List(Of String)
  1215. For Each Keyword In AllPossibleKeywords.Split(" ")
  1216. If Keyword.Trim = "" Then Continue For
  1217. RightKeywords.Add(Keyword)
  1218. Next
  1219. Task.Input.SearchFilter = Join(ArrayNoDouble(RightKeywords), " ").ToLower
  1220. Log("[Download] CurseForge 工程列表搜索最终文本:" & Task.Input.SearchFilter, LogLevel.Developer)
  1221. '正式获取
  1222. Dim Url = Task.Input.GetAddress()
  1223. Log("[Download] 开始获取 CurseForge 工程列表:" & Url)
  1224. Dim RequestResult As JObject = NetGetCodeByRequestRetry(Url, IsJson:=True, Encode:=Encoding.UTF8)
  1225. Dim FileList = GetCfProjectListFromJson(RequestResult("data"), Task.Input.IsModPack)
  1226. If FileList.Count = 0 Then Throw New Exception("无搜索结果")
  1227. '重新排序
  1228. If Not String.IsNullOrEmpty(Task.Input.SearchFilter) Then
  1229. '排序分 = 搜索相对相似度 + 默认排序相对活跃度
  1230. Dim Scores As New Dictionary(Of DlCfProject, Double)
  1231. Dim Entry As New List(Of SearchEntry(Of DlCfProject))
  1232. For i = 1 To FileList.Count
  1233. Dim File = FileList(i - 1)
  1234. Scores.Add(File, (1 - (i / FileList.Count)))
  1235. Entry.Add(New SearchEntry(Of DlCfProject) With {.Item = File, .SearchSource = New List(Of KeyValuePair(Of String, Double)) From {
  1236. New KeyValuePair(Of String, Double)(If(IsChineseSearch, File.ChineseName, File.Name), 1),
  1237. New KeyValuePair(Of String, Double)(File.Description, 0.05)}})
  1238. Next
  1239. Dim SearchResult = Search(Entry, RawFilter, 101, -1)
  1240. For Each OneResult In SearchResult
  1241. Scores(OneResult.Item) += OneResult.Similarity / SearchResult(0).Similarity
  1242. Next
  1243. '根据排序分得出结果
  1244. Dim ResultList = Sort(Scores.ToList, Function(Left As KeyValuePair(Of DlCfProject, Double), Right As KeyValuePair(Of DlCfProject, Double))
  1245. Return Left.Value > Right.Value
  1246. End Function)
  1247. FileList = New List(Of DlCfProject)
  1248. For Each Result In ResultList
  1249. FileList.Add(Result.Key)
  1250. Next
  1251. End If
  1252. Task.Output = New DlCfProjectResult With {.Projects = FileList, .Index = RequestResult("pagination")("index"), .RealCount = RequestResult("pagination")("totalCount")}
  1253. End Sub
  1254. ''' <summary>
  1255. ''' 从 API 返回的 Json 数组中获取工程信息数组。
  1256. ''' </summary>
  1257. Private Function GetCfProjectListFromJson(Json As JArray, IsModPack As Boolean) As List(Of DlCfProject)
  1258. Dim FileList As New List(Of DlCfProject)
  1259. For Each JsonEntry As JObject In Json
  1260. Dim Result = GetCfProjectFromJson(JsonEntry, IsModPack)
  1261. If Result IsNot Nothing Then FileList.Add(Result)
  1262. Next
  1263. Return FileList
  1264. End Function
  1265. ''' <summary>
  1266. ''' 从 API 返回的 Json 中获取工程信息。
  1267. ''' </summary>
  1268. Private Function GetCfProjectFromJson(Json As JObject, IsModPack As Boolean) As DlCfProject
  1269. If Json("links")("websiteUrl") Is Nothing Then
  1270. Log("[Download] 发现关键项为 Nothing 的工程:" & If(Json, "").ToString, LogLevel.Debug)
  1271. Return Nothing
  1272. End If
  1273. If IsModPack = Json("links")("websiteUrl").ToString.Contains("curseforge.com/minecraft/mc-mods") Then
  1274. Log("[Download] 返回的工程与要求的类别不一致:" & Json("links")("websiteUrl").ToString, LogLevel.Debug)
  1275. Return Nothing
  1276. End If
  1277. Return New DlCfProject(Json)
  1278. End Function
  1279. #End Region
  1280. #Region "DlCfFile | CurseForge Files"
  1281. Public DlCfFileLoader As New LoaderTask(Of KeyValuePair(Of Integer, Boolean), List(Of DlCfFile))("DlCfFile Main", Sub(Task As LoaderTask(Of KeyValuePair(Of Integer, Boolean), List(Of DlCfFile))) Task.Output = DlCfGetFiles(Task.Input.Key, Task.Input.Value))
  1282. ''' <summary>
  1283. ''' CurseForge 工程下的单一版本文件。
  1284. ''' </summary>
  1285. Public Class DlCfFile
  1286. Public IsModPack As Boolean
  1287. Public FileId As Integer
  1288. Public DisplayName As String
  1289. Public [Date] As Date
  1290. Public GameVersion As String()
  1291. Public ReleaseType As Integer
  1292. Public FileName As String
  1293. Public DownloadCount As Integer
  1294. Public Dependencies As New List(Of Integer)
  1295. Private DownloadAddress As String()
  1296. Public ReadOnly Property ReleaseTypeString As String
  1297. Get
  1298. Select Case ReleaseType
  1299. Case 1
  1300. Return "正式版"
  1301. Case 2
  1302. Return If(ModeDebug, "Beta 测试版", "测试版")
  1303. Case Else
  1304. Return If(ModeDebug, "Alpha 测试版", "测试版")
  1305. End Select
  1306. End Get
  1307. End Property
  1308. Public ReadOnly Property IsAvailable As Boolean
  1309. Get
  1310. Return DisplayName IsNot Nothing AndAlso GameVersion IsNot Nothing AndAlso FileName IsNot Nothing AndAlso DownloadAddress(0).StartsWith("http")
  1311. End Get
  1312. End Property
  1313. ''' <summary>
  1314. ''' 从 CurseForge 文件 Json 项中初始化实例。若出错会抛出异常。
  1315. ''' </summary>
  1316. Public Sub New(Data As JObject, IsModPack As Boolean)
  1317. FileId = Data("id")
  1318. DisplayName = Data("displayName").ToString.Replace(" ", "").Trim(" ")
  1319. [Date] = Data("fileDate")
  1320. ReleaseType = Data("releaseType")
  1321. DownloadCount = Data("downloadCount")
  1322. FileName = Data("fileName")
  1323. Me.IsModPack = IsModPack
  1324. '获取下载地址
  1325. Dim Url = Data("downloadUrl").ToString
  1326. If Url = "" Then Url = "https://media.forgecdn.net/files/" & FileId.ToString.Substring(0, 4) & "/" & FileId.ToString.Substring(4).TrimStart("0") & "/" & FileName
  1327. Url = Url.Replace(FileName, Net.WebUtility.UrlEncode(FileName)) '对文件名进行编码
  1328. DownloadAddress = ArrayNoDouble({Url.Replace("-service.overwolf.wtf", ".forgecdn.net").Replace("://edge", "://media"), Url.Replace("-service.overwolf.wtf", ".forgecdn.net"), Url.Replace("://edge", "://media"), Url})
  1329. '获取前置 Mod 的 Addon ID
  1330. If Not IsModPack Then
  1331. For Each Dep In Data("dependencies")
  1332. If Dep("relationType").ToObject(Of Integer) = 3 AndAlso '是一个依赖
  1333. Dep("modId").ToObject(Of Integer) <> 306612 Then '排除 Fabric API
  1334. Dependencies.Add(Dep("modId"))
  1335. End If
  1336. Next
  1337. End If
  1338. '获取游戏版本
  1339. Dim Versions As New List(Of String)
  1340. For Each Version In Data("gameVersions")
  1341. If Version.ToString.StartsWith("1.") OrElse Version.ToString.Contains("w") Then
  1342. Versions.Add(Version.ToString.Trim.ToLower)
  1343. End If
  1344. Next
  1345. If Versions.Count > 1 Then
  1346. GameVersion = Sort(Versions, AddressOf VersionSortBoolean).ToArray
  1347. If IsModPack Then GameVersion = {GameVersion(0)}
  1348. ElseIf Versions.Count = 1 Then
  1349. GameVersion = Versions.ToArray
  1350. 'ElseIf Data("gameVersion").Count = 1 AndAlso Not Data("gameVersion")(0).ToString.Contains("1.") Then
  1351. ' GameVersion = {"1.16.4"}
  1352. Else
  1353. GameVersion = {"未知版本"}
  1354. End If
  1355. End Sub
  1356. ''' <summary>
  1357. ''' 获取对应的下载文件信息。
  1358. ''' </summary>
  1359. ''' <param name="LocalAddress">本地文件夹或文件地址。</param>
  1360. Public Function GetDownloadFile(LocalAddress As String, IsFullPath As Boolean) As NetFile
  1361. Return New NetFile(DownloadAddress, LocalAddress & If(IsFullPath, "", FileName))
  1362. End Function
  1363. Public Function ToListItem(OnClick As MyListItem.ClickEventHandler, Optional OnSaveClick As MyIconButton.ClickEventHandler = Nothing) As MyListItem
  1364. '获取描述信息
  1365. Dim Info As String = ""
  1366. If Not IsModPack Then
  1367. Info += "适用于 " & Join(GameVersion, "、").Replace("-snapshot", " 快照") &
  1368. If(ModeDebug AndAlso Dependencies.Count > 0, "," & Dependencies.Count & " 个前置,", ",")
  1369. End If
  1370. Info += If(DownloadCount > 0, If(DownloadCount > 100000, Math.Round(DownloadCount / 10000) & " 万次下载,", DownloadCount & " 次下载,"), "")
  1371. Info += GetTimeSpanString([Date] - Date.Now) & "更新"
  1372. Info += If(ReleaseType <> 1, "," & ReleaseTypeString, "")
  1373. '建立控件
  1374. Dim NewItem As New MyListItem With {
  1375. .Title = DisplayName, .SnapsToDevicePixels = True, .Height = 42, .Type = MyListItem.CheckType.Clickable, .Tag = Me,
  1376. .Info = Info
  1377. }
  1378. Select Case ReleaseType
  1379. Case 1 'R
  1380. NewItem.Logo = "pack://application:,,,/images/Icons/R.png"
  1381. Case 2 'B
  1382. NewItem.Logo = "pack://application:,,,/images/Icons/B.png"
  1383. Case Else 'A
  1384. NewItem.Logo = "pack://application:,,,/images/Icons/A.png"
  1385. End Select
  1386. AddHandler NewItem.Click, OnClick
  1387. '建立另存为按钮
  1388. If OnSaveClick IsNot Nothing Then
  1389. Dim BtnSave As New MyIconButton With {.Logo = Logo.IconButtonSave, .ToolTip = "另存为"}
  1390. ToolTipService.SetPlacement(BtnSave, Primitives.PlacementMode.Center)
  1391. ToolTipService.SetVerticalOffset(BtnSave, 30)
  1392. ToolTipService.SetHorizontalOffset(BtnSave, 2)
  1393. AddHandler BtnSave.Click, OnSaveClick
  1394. NewItem.Buttons = {BtnSave}
  1395. NewItem.PaddingRight = 35
  1396. End If
  1397. '结束
  1398. Return NewItem
  1399. End Function
  1400. Public Overrides Function ToString() As String
  1401. Return DisplayName
  1402. End Function
  1403. End Class
  1404. ''' <summary>
  1405. ''' 获取某个 CurseForge 工程下的全部文件列表。
  1406. ''' 必须在工作线程执行,失败会抛出异常。
  1407. ''' </summary>
  1408. Public Function DlCfGetFiles(ProjectId As Integer, IsModPack As Boolean) As List(Of DlCfFile)
  1409. '获取工程对象
  1410. Dim TargetProject As DlCfProject
  1411. If DlCfProjectCache.ContainsKey(ProjectId) Then
  1412. TargetProject = DlCfProjectCache(ProjectId)
  1413. Else
  1414. TargetProject = GetCfProjectFromJson(NetGetCodeByRequestRetry("https://api.curseforge.com/v1/mods/" & ProjectId, IsJson:=True, Encode:=Encoding.UTF8)("data"), IsModPack)
  1415. End If
  1416. '获取工程对象的文件列表
  1417. If TargetProject.Files Is Nothing Then
  1418. Log("[Download] 开始获取 CurseForge 工程 ID 为 " & ProjectId & " 的文件列表")
  1419. Dim Json As JArray
  1420. If TargetProject.IsModPack Then
  1421. '整合包使用全部文件
  1422. Json = NetGetCodeByRequestRetry("https://api.curseforge.com/v1/mods/" & ProjectId & "/files?pageSize=999", Accept:="application/json", IsJson:=True)("data")
  1423. Else
  1424. 'Mod 使用每个版本最新的文件
  1425. 'TODO: 完整 Mod 文件列表支持
  1426. Json = GetJson(NetRequestRetry("https://api.curseforge.com/v1/mods/files", "POST", "{""fileIds"": [" & Join(TargetProject.FileIndexes, ",") & "]}", "application/json"))("data")
  1427. End If
  1428. Dim Files As New Dictionary(Of Integer, DlCfFile)
  1429. For Each JsonEntry As JObject In Json
  1430. Dim NewFile As New DlCfFile(JsonEntry, IsModPack)
  1431. If NewFile.IsAvailable AndAlso Not Files.ContainsKey(NewFile.FileId) Then Files.Add(NewFile.FileId, NewFile)
  1432. Next
  1433. TargetProject.Files = Files.Values.ToList
  1434. End If
  1435. '获取前置 Mod 列表
  1436. If IsModPack Then GoTo ExitSub
  1437. Dim Deps As New List(Of Integer)
  1438. For Each File In TargetProject.Files
  1439. For Each AddonId In File.Dependencies
  1440. If Not Deps.Contains(AddonId) AndAlso Not DlCfProjectCache.ContainsKey(AddonId) Then Deps.Add(AddonId)
  1441. Next
  1442. Next
  1443. If Deps.Count > 0 Then
  1444. '获取前置 Mod 工程信息
  1445. Log("[Download] 文件列表中需要获取的前置 Mod:" & Join(Deps, ","))
  1446. GetCfProjectListFromJson(GetJson(NetRequestRetry("https://api.curseforge.com/v1/mods", "POST", "{""modIds"": [" & Join(Deps, ",") & "]}", "application/json"))("data"), False)
  1447. End If
  1448. '返回
  1449. ExitSub:
  1450. Return TargetProject.Files
  1451. End Function
  1452. Public Sub DlCfFilesPreload(Stack As StackPanel, Entrys As List(Of DlCfFile), OnClick As MyListItem.ClickEventHandler)
  1453. '获取卡片对应的前置 ID
  1454. '如果为整合包就不会有 Dependencies 信息,所以不用管
  1455. Dim Deps As New List(Of Integer)
  1456. For Each File In Entrys
  1457. For Each AddonId In If(File.Dependencies, New List(Of Integer))
  1458. If Not Deps.Contains(AddonId) Then
  1459. If Not DlCfProjectCache.ContainsKey(AddonId) Then
  1460. Log("[Download] 未找到 ID 为 " & AddonId & " 的前置 Mod 信息", LogLevel.Developer)
  1461. Continue For
  1462. End If
  1463. Deps.Add(AddonId)
  1464. End If
  1465. Next
  1466. Next
  1467. Deps.Remove(306612) '移除 Fabric API
  1468. If Deps.Count = 0 Then Exit Sub
  1469. Deps.Sort()
  1470. '添加开头间隔
  1471. Stack.Children.Add(New TextBlock With {.Text = "前置 Mod", .FontSize = 14, .HorizontalAlignment = HorizontalAlignment.Left, .Margin = New Thickness(6, 2, 0, 5)})
  1472. '添加前置 Mod 列表
  1473. For Each Dep In Deps
  1474. Dim Item = DlCfProjectCache(Dep).ToCfItem(False, True, AddressOf FrmDownloadMod.ProjectClick)
  1475. 'Item.Margin = New Thickness(5, 0, 0, 0)
  1476. Stack.Children.Add(Item)
  1477. Next
  1478. '添加结尾间隔
  1479. Stack.Children.Add(New TextBlock With {.Text = "可选版本", .FontSize = 14, .HorizontalAlignment = HorizontalAlignment.Left, .Margin = New Thickness(6, 12, 0, 5)})
  1480. End Sub
  1481. #End Region
  1482. #Region "DlSource | 镜像下载源"
  1483. Public Function DlSourceResourceGet(MojangBase As String) As String()
  1484. Return {MojangBase.Replace("http://resources.download.minecraft.net", "https://download.mcbbs.net/assets"),
  1485. MojangBase,
  1486. MojangBase.Replace("http://resources.download.minecraft.net", "https://bmclapi2.bangbang93.com/assets")
  1487. }
  1488. End Function
  1489. Public Function DlSourceLibraryGet(MojangBase As String) As String()
  1490. Return {MojangBase.Replace("https://libraries.minecraft.net", "https://download.mcbbs.net/maven"),
  1491. MojangBase.Replace("https://libraries.minecraft.net", "https://download.mcbbs.net/libraries"),
  1492. MojangBase,
  1493. MojangBase.Replace("https://libraries.minecraft.net", "https://bmclapi2.bangbang93.com/maven"),
  1494. MojangBase.Replace("https://libraries.minecraft.net", "https://bmclapi2.bangbang93.com/libraries")
  1495. }
  1496. End Function
  1497. Public Function DlSourceLauncherOrMetaGet(MojangBase As String, Optional IsStatic As Boolean = True) As String()
  1498. If MojangBase Is Nothing Then Throw New Exception("无对应的 Json 下载地址")
  1499. If IsStatic Then
  1500. Return {MojangBase.Replace("https://launcher.mojang.com", "https://download.mcbbs.net").Replace("https://launchermeta.mojang.com", "https://download.mcbbs.net"),
  1501. MojangBase,
  1502. MojangBase.Replace("https://launcher.mojang.com", "https://bmclapi2.bangbang93.com").Replace("https://launchermeta.mojang.com", "https://bmclapi2.bangbang93.com")
  1503. }
  1504. Else
  1505. Return {MojangBase.Replace("https://launcher.mojang.com", "https://download.mcbbs.net").Replace("https://launchermeta.mojang.com", "https://download.mcbbs.net"),
  1506. MojangBase,
  1507. MojangBase.Replace("https://launcher.mojang.com", "https://bmclapi2.bangbang93.com").Replace("https://launchermeta.mojang.com", "https://bmclapi2.bangbang93.com")
  1508. }
  1509. End If
  1510. End Function
  1511. Private Sub DlSourceLoader(Of InputType, OutputType)(MainLoader As LoaderTask(Of InputType, OutputType),
  1512. LoaderList As List(Of KeyValuePair(Of LoaderTask(Of InputType, OutputType), Integer)),
  1513. Optional IsForceRestart As Boolean = False)
  1514. Dim WaitCycle As Integer = 0
  1515. Do While True
  1516. '检查加载结束
  1517. Dim IsAllFailed As Boolean = True
  1518. For Each SubLoader In LoaderList
  1519. If WaitCycle = 0 Then
  1520. '如果要强制刷新,就不使用已经加载好的值
  1521. If IsForceRestart Then Exit For
  1522. '如果输入不一样,就不使用已经加载好的值
  1523. If (SubLoader.Key.Input Is Nothing Xor MainLoader.Input Is Nothing) OrElse
  1524. (SubLoader.Key.Input IsNot Nothing AndAlso Not SubLoader.Key.Input.Equals(MainLoader.Input)) Then Continue For
  1525. End If
  1526. If SubLoader.Key.State <> LoadState.Failed Then IsAllFailed = False
  1527. If SubLoader.Key.State = LoadState.Finished Then
  1528. MainLoader.Output = SubLoader.Key.Output
  1529. DlSourceLoaderAbort(LoaderList)
  1530. Exit Sub
  1531. ElseIf IsAllFailed Then
  1532. If WaitCycle < SubLoader.Value * 100 Then WaitCycle = SubLoader.Value * 100
  1533. End If
  1534. '由于 Forge BMCLAPI 没有可用版本导致强制失败
  1535. '在没有可用版本时,官方源会一直卡住,直接使用 BMCLAPI 判定失败即可
  1536. If SubLoader.Key.Error IsNot Nothing AndAlso SubLoader.Key.Error.Message.Contains("没有可用版本") Then
  1537. For Each SubLoader2 In LoaderList
  1538. If WaitCycle < SubLoader2.Value * 100 Then WaitCycle = SubLoader2.Value * 100
  1539. Next
  1540. End If
  1541. Next
  1542. '启动加载源
  1543. If WaitCycle = 0 Then
  1544. '启动第一个源
  1545. LoaderList(0).Key.Start(MainLoader.Input, IsForceRestart)
  1546. End If
  1547. For i = 0 To LoaderList.Count - 1
  1548. If WaitCycle = LoaderList(i).Value * 100 Then
  1549. If i < LoaderList.Count - 1 Then
  1550. '启动下一个源
  1551. LoaderList(i + 1).Key.Start(MainLoader.Input, IsForceRestart)
  1552. Else
  1553. '失败
  1554. Dim ErrorInfo As Exception = Nothing
  1555. For ii = 0 To LoaderList.Count - 1
  1556. LoaderList(ii).Key.Input = Nothing '重置输入,以免以同样的输入“重试加载”时直接失败
  1557. If LoaderList(ii).Key.Error IsNot Nothing Then
  1558. If ErrorInfo Is Nothing OrElse LoaderList(ii).Key.Error.Message.Contains("没有可用版本") Then
  1559. ErrorInfo = LoaderList(ii).Key.Error
  1560. End If
  1561. End If
  1562. Next
  1563. If ErrorInfo Is Nothing Then ErrorInfo = New TimeoutException("下载源连接超时")
  1564. DlSourceLoaderAbort(LoaderList)
  1565. Throw ErrorInfo
  1566. End If
  1567. Exit For
  1568. End If
  1569. Next
  1570. '计时
  1571. If MainLoader.IsAborted Then
  1572. DlSourceLoaderAbort(LoaderList)
  1573. Exit Sub
  1574. End If
  1575. Thread.Sleep(10)
  1576. WaitCycle += 1
  1577. Loop
  1578. End Sub
  1579. Private Sub DlSourceLoaderAbort(Of InputType, OutputType)(LoaderList As List(Of KeyValuePair(Of LoaderTask(Of InputType, OutputType), Integer)))
  1580. For Each Loader In LoaderList
  1581. If Loader.Key.State = LoadState.Loading Then Loader.Key.Abort()
  1582. Next
  1583. End Sub
  1584. #End Region
  1585. End Module