ModDownload.vb 61 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049
  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 = ShouldIgnoreFileCheck(Version)
  21. If IsSetupSkip AndAlso File.Exists(Version.Path & Version.Name & ".jar") Then Return Nothing '跳过校验
  22. If Checker.Check(Version.Path & Version.Name & ".jar") Is Nothing Then Return Nothing '通过校验
  23. End If
  24. '返回下载信息
  25. Dim JarUrl As String = Version.JsonObject("downloads")("client")("url")
  26. Return New NetFile(DlSourceLauncherOrMetaGet(JarUrl), Version.Path & Version.Name & ".jar", Checker)
  27. End Function
  28. ''' <summary>
  29. ''' 返回某 Minecraft 版本对应的原版主 AssetIndex 文件的下载信息,要求对应依赖版本已存在。
  30. ''' 若未找到,则会返回 Legacy 资源文件或 Nothing。
  31. ''' </summary>
  32. Public Function DlClientAssetIndexGet(Version As McVersion) As NetFile
  33. '获取底层继承版本
  34. Do While Not String.IsNullOrEmpty(Version.InheritVersion)
  35. Version = New McVersion(Version.InheritVersion)
  36. Loop
  37. '获取信息
  38. Dim IndexInfo = McAssetsGetIndex(Version, True, True)
  39. Dim IndexAddress As String = PathMcFolder & "assets\indexes\" & IndexInfo("id").ToString & ".json"
  40. Log("[Download] 版本 " & Version.Name & " 对应的资源文件索引为 " & IndexInfo("id").ToString)
  41. Dim IndexUrl As String = If(IndexInfo("url"), "")
  42. If IndexUrl = "" Then
  43. Return Nothing
  44. Else
  45. Return New NetFile(DlSourceLauncherOrMetaGet(IndexUrl), IndexAddress, New FileChecker(CanUseExistsFile:=False, IsJson:=True))
  46. End If
  47. End Function
  48. ''' <summary>
  49. ''' 构造补全某 Minecraft 版本的所有文件的加载器列表。失败会抛出异常。
  50. ''' </summary>
  51. Public Function DlClientFix(Version As McVersion, CheckAssetsHash As Boolean, AssetsIndexBehaviour As AssetsIndexExistsBehaviour, SkipAssetsDownloadWhileSetupRequired As Boolean) As List(Of LoaderBase)
  52. Dim Loaders As New List(Of LoaderBase)
  53. #Region "下载支持库文件"
  54. Dim LoadersLib As New List(Of LoaderBase) From {
  55. New LoaderTask(Of String, List(Of NetFile))("分析缺失支持库文件", Sub(Task As LoaderTask(Of String, List(Of NetFile))) Task.Output = McLibFix(Version)) With {.ProgressWeight = 1},
  56. New LoaderDownload("下载支持库文件", New List(Of NetFile)) With {.ProgressWeight = 15}
  57. }
  58. '构造加载器
  59. Loaders.Add(New LoaderCombo(Of String)("下载支持库文件(主加载器)", LoadersLib) With {.Block = False, .Show = False, .ProgressWeight = 16})
  60. #End Region
  61. #Region "下载资源文件"
  62. Dim IsSetupSkip As Boolean = ShouldIgnoreFileCheck(Version)
  63. If IsSetupSkip Then Log("[Download] 已跳过 Assets 下载")
  64. If (Not SkipAssetsDownloadWhileSetupRequired) OrElse Not IsSetupSkip Then
  65. Dim LoadersAssets As New List(Of LoaderBase)
  66. '获取资源文件索引地址
  67. LoadersAssets.Add(New LoaderTask(Of String, List(Of NetFile))("分析资源文件索引地址",
  68. Sub(Task As LoaderTask(Of String, List(Of NetFile)))
  69. Try
  70. Dim IndexFile = DlClientAssetIndexGet(Version)
  71. Dim IndexFileInfo As New FileInfo(IndexFile.LocalPath)
  72. If AssetsIndexBehaviour <> AssetsIndexExistsBehaviour.AlwaysDownload AndAlso IndexFile.Check.Check(IndexFile.LocalPath) Is Nothing Then
  73. Task.Output = New List(Of NetFile)
  74. Else
  75. Task.Output = New List(Of NetFile) From {IndexFile}
  76. End If
  77. Catch ex As Exception
  78. Throw New Exception("分析资源文件索引地址失败", ex)
  79. End Try
  80. End Sub) With {.ProgressWeight = 0.5, .Show = False})
  81. '下载资源文件索引
  82. LoadersAssets.Add(New LoaderDownload("下载资源文件索引", New List(Of NetFile)) With {.ProgressWeight = 2})
  83. '要求独立更新索引
  84. If AssetsIndexBehaviour = AssetsIndexExistsBehaviour.DownloadInBackground Then
  85. Dim LoadersAssetsUpdate As New List(Of LoaderBase)
  86. Dim TempAddress As String = Nothing
  87. Dim RealAddress As String = Nothing
  88. LoadersAssetsUpdate.Add(New LoaderTask(Of String, List(Of NetFile))("后台分析资源文件索引地址", Sub(Task As LoaderTask(Of String, List(Of NetFile)))
  89. Dim BackAssetsFile As NetFile = DlClientAssetIndexGet(Version)
  90. RealAddress = BackAssetsFile.LocalPath
  91. TempAddress = PathTemp & "Cache\" & BackAssetsFile.LocalName
  92. BackAssetsFile.LocalPath = TempAddress
  93. Task.Output = New List(Of NetFile) From {BackAssetsFile}
  94. End Sub))
  95. LoadersAssetsUpdate.Add(New LoaderDownload("后台下载资源文件索引", New List(Of NetFile)))
  96. LoadersAssetsUpdate.Add(New LoaderTask(Of List(Of NetFile), String)("后台复制资源文件索引", Sub(Task As LoaderTask(Of List(Of NetFile), String))
  97. CopyFile(TempAddress, RealAddress)
  98. McLaunchLog("后台更新资源文件索引成功:" & TempAddress)
  99. End Sub))
  100. Dim Updater As New LoaderCombo(Of String)("后台更新资源文件索引", LoadersAssetsUpdate)
  101. Log("[Download] 开始后台更新资源文件索引")
  102. Updater.Start()
  103. End If
  104. '获取资源文件地址
  105. LoadersAssets.Add(New LoaderTask(Of String, List(Of NetFile))("分析缺失资源文件",
  106. Sub(Task As LoaderTask(Of String, List(Of NetFile)))
  107. Task.Output = McAssetsFixList(McAssetsGetIndexName(Version), CheckAssetsHash, Task)
  108. End Sub) With {.ProgressWeight = 3})
  109. '下载资源文件
  110. LoadersAssets.Add(New LoaderDownload("下载资源文件", New List(Of NetFile)) With {.ProgressWeight = 25})
  111. '构造加载器
  112. Loaders.Add(New LoaderCombo(Of String)("下载资源文件(主加载器)", LoadersAssets) With {.Block = False, .Show = False, .ProgressWeight = 30.5})
  113. End If
  114. #End Region
  115. Return Loaders
  116. End Function
  117. Public Enum AssetsIndexExistsBehaviour
  118. ''' <summary>
  119. ''' 如果文件存在,则不进行下载。
  120. ''' </summary>
  121. DontDownload
  122. ''' <summary>
  123. ''' 如果文件存在,则启动新的下载加载器进行独立的更新。
  124. ''' </summary>
  125. DownloadInBackground
  126. ''' <summary>
  127. ''' 如果文件存在,也同样进行下载。
  128. ''' </summary>
  129. AlwaysDownload
  130. End Enum
  131. #End Region
  132. #Region "DlClientList | Minecraft 客户端 版本列表"
  133. '主加载器
  134. Public Structure DlClientListResult
  135. ''' <summary>
  136. ''' 数据来源名称,如“Mojang”,“BMCLAPI”。
  137. ''' </summary>
  138. Public SourceName As String
  139. ''' <summary>
  140. ''' 是否为官方的实时数据。
  141. ''' </summary>
  142. Public IsOfficial As Boolean
  143. ''' <summary>
  144. ''' 获取到的 Json 数据。
  145. ''' </summary>
  146. Public Value As JObject
  147. '''' <summary>
  148. '''' 官方源的失败原因。若没有则为 Nothing。
  149. '''' </summary>
  150. 'Public OfficialError As Exception
  151. End Structure
  152. ''' <summary>
  153. ''' Minecraft 客户端 版本列表,主加载器。
  154. ''' </summary>
  155. Public DlClientListLoader As New LoaderTask(Of Integer, DlClientListResult)("DlClientList Main", AddressOf DlClientListMain)
  156. Private Sub DlClientListMain(Loader As LoaderTask(Of Integer, DlClientListResult))
  157. Select Case Setup.Get("ToolDownloadVersion")
  158. Case 0
  159. DlSourceLoader(Loader, New List(Of KeyValuePair(Of LoaderTask(Of Integer, DlClientListResult), Integer)) From {
  160. New KeyValuePair(Of LoaderTask(Of Integer, DlClientListResult), Integer)(DlClientListBmclapiLoader, 30),
  161. New KeyValuePair(Of LoaderTask(Of Integer, DlClientListResult), Integer)(DlClientListMojangLoader, 60)
  162. }, Loader.IsForceRestarting)
  163. Case 1
  164. DlSourceLoader(Loader, New List(Of KeyValuePair(Of LoaderTask(Of Integer, DlClientListResult), Integer)) From {
  165. New KeyValuePair(Of LoaderTask(Of Integer, DlClientListResult), Integer)(DlClientListMojangLoader, 5),
  166. New KeyValuePair(Of LoaderTask(Of Integer, DlClientListResult), Integer)(DlClientListBmclapiLoader, 35)
  167. }, Loader.IsForceRestarting)
  168. Case Else
  169. DlSourceLoader(Loader, New List(Of KeyValuePair(Of LoaderTask(Of Integer, DlClientListResult), Integer)) From {
  170. New KeyValuePair(Of LoaderTask(Of Integer, DlClientListResult), Integer)(DlClientListMojangLoader, 60),
  171. New KeyValuePair(Of LoaderTask(Of Integer, DlClientListResult), Integer)(DlClientListBmclapiLoader, 60)
  172. }, Loader.IsForceRestarting)
  173. End Select
  174. End Sub
  175. '各个下载源的分加载器
  176. ''' <summary>
  177. ''' Minecraft 客户端 版本列表,Mojang 官方源加载器。
  178. ''' </summary>
  179. Public DlClientListMojangLoader As New LoaderTask(Of Integer, DlClientListResult)("DlClientList Mojang", AddressOf DlClientListMojangMain)
  180. Private IsNewClientVersionHinted As Boolean = False
  181. Private Sub DlClientListMojangMain(Loader As LoaderTask(Of Integer, DlClientListResult))
  182. Dim Json As JObject = NetGetCodeByRequestRetry("https://launchermeta.mojang.com/mc/game/version_manifest.json", IsJson:=True)
  183. Try
  184. Dim Versions As JArray = Json("versions")
  185. If Versions.Count < 200 Then Throw New Exception("获取到的版本列表长度不足(" & Json.ToString & ")")
  186. '添加 PCL 特供项
  187. If File.Exists(PathTemp & "Cache\download.json") Then Versions.Merge(GetJson(ReadFile(PathTemp & "Cache\download.json")))
  188. '返回
  189. Loader.Output = New DlClientListResult With {.IsOfficial = True, .SourceName = "Mojang 官方源", .Value = Json}
  190. '解析更新提示(Release)
  191. Dim Version As String = Json("latest")("release")
  192. If Setup.Get("ToolUpdateRelease") AndAlso Not Setup.Get("ToolUpdateReleaseLast") = "" AndAlso Version IsNot Nothing AndAlso Not Setup.Get("ToolUpdateReleaseLast") = Version Then
  193. McDownloadClientUpdateHint(Version, Json)
  194. IsNewClientVersionHinted = True
  195. End If
  196. McVersionHighest = Version.Split(".")(1)
  197. Setup.Set("ToolUpdateReleaseLast", Version)
  198. '解析更新提示(Snapshot)
  199. Version = Json("latest")("snapshot")
  200. If Setup.Get("ToolUpdateSnapshot") AndAlso Not Setup.Get("ToolUpdateSnapshotLast") = "" AndAlso Version IsNot Nothing AndAlso Not Setup.Get("ToolUpdateSnapshotLast") = Version AndAlso Not IsNewClientVersionHinted Then
  201. McDownloadClientUpdateHint(Version, Json)
  202. End If
  203. Setup.Set("ToolUpdateSnapshotLast", If(Version, "Nothing"))
  204. Catch ex As Exception
  205. Throw New Exception("版本列表解析失败", ex)
  206. End Try
  207. End Sub
  208. ''' <summary>
  209. ''' Minecraft 客户端 版本列表,BMCLAPI 源加载器。
  210. ''' </summary>
  211. Public DlClientListBmclapiLoader As New LoaderTask(Of Integer, DlClientListResult)("DlClientList Bmclapi", AddressOf DlClientListBmclapiMain)
  212. Private Sub DlClientListBmclapiMain(Loader As LoaderTask(Of Integer, DlClientListResult))
  213. Dim Json As JObject = NetGetCodeByRequestRetry("https://bmclapi2.bangbang93.com/mc/game/version_manifest.json",
  214. BackupUrl:="https://download.mcbbs.net/mc/game/version_manifest.json",
  215. IsJson:=True)
  216. Try
  217. Dim Versions As JArray = Json("versions")
  218. If Versions.Count < 200 Then Throw New Exception("获取到的版本列表长度不足(" & Json.ToString & ")")
  219. '添加 PCL 特供项
  220. If File.Exists(PathTemp & "Cache\download.json") Then Versions.Merge(GetJson(ReadFile(PathTemp & "Cache\download.json")))
  221. '返回
  222. Loader.Output = New DlClientListResult With {.IsOfficial = False, .SourceName = "BMCLAPI", .Value = Json}
  223. Catch ex As Exception
  224. Throw New Exception("版本列表解析失败(" & Json.ToString & ")", ex)
  225. End Try
  226. End Sub
  227. ''' <summary>
  228. ''' 获取某个版本的 Json 下载地址,若失败则返回 Nothing。必须在工作线程执行。
  229. ''' </summary>
  230. Public Function DlClientListGet(Id As String)
  231. Try
  232. '确认 Minecraft 版本列表已完成获取
  233. Select Case DlClientListLoader.State
  234. Case LoadState.Loading
  235. DlClientListLoader.WaitForExit()
  236. Case LoadState.Failed, LoadState.Aborted, LoadState.Waiting
  237. DlClientListLoader.WaitForExit(IsForceRestart:=True)
  238. End Select
  239. '确认版本格式标准
  240. Id = Id.Replace("_", "-") '1.7.10_pre4 在版本列表中显示为 1.7.10-pre4
  241. If Id <> "1.0" AndAlso Id.EndsWith(".0") Then Id = Left(Id, Id.Length - 2) 'OptiFine 1.8 的下载会触发此问题,显示版本为 1.8.0
  242. '查找版本并开始
  243. For Each Version As JObject In DlClientListLoader.Output.Value("versions")
  244. If Version("id") = Id Then
  245. Return Version("url").ToString
  246. End If
  247. Next
  248. Log("未发现版本 " & Id & " 的 json 下载地址,版本列表返回为:" & vbCrLf & DlClientListLoader.Output.Value.ToString, LogLevel.Debug)
  249. Return Nothing
  250. Catch ex As Exception
  251. Log(ex, "获取版本 " & Id & " 的 json 下载地址失败")
  252. Return Nothing
  253. End Try
  254. End Function
  255. #End Region
  256. #Region "DlOptiFineList | OptiFine 版本列表"
  257. Public Structure DlOptiFineListResult
  258. ''' <summary>
  259. ''' 数据来源名称,如“Official”,“BMCLAPI”。
  260. ''' </summary>
  261. Public SourceName As String
  262. ''' <summary>
  263. ''' 是否为官方的实时数据。
  264. ''' </summary>
  265. Public IsOfficial As Boolean
  266. ''' <summary>
  267. ''' 获取到的数据。
  268. ''' </summary>
  269. Public Value As List(Of DlOptiFineListEntry)
  270. End Structure
  271. Public Class DlOptiFineListEntry
  272. ''' <summary>
  273. ''' 显示名称,已去除 HD_U 字样,如“1.12.2 C8”。
  274. ''' </summary>
  275. Public NameDisplay As String
  276. ''' <summary>
  277. ''' 原始文件名称,如“preview_OptiFine_1.11_HD_U_E1_pre.jar”。
  278. ''' </summary>
  279. Public NameFile As String
  280. ''' <summary>
  281. ''' 对应的版本名称,如“1.13.2-OptiFine_HD_U_E6”。
  282. ''' </summary>
  283. Public NameVersion As String
  284. ''' <summary>
  285. ''' 是否为测试版。
  286. ''' </summary>
  287. Public IsPreview As Boolean
  288. ''' <summary>
  289. ''' 对应的 Minecraft 版本,如“1.12.2”。
  290. ''' </summary>
  291. Public Property Inherit As String
  292. Get
  293. Return _inherit
  294. End Get
  295. Set(value As String)
  296. If value.EndsWith(".0") Then value = Left(value, value.Length - 2)
  297. _inherit = value
  298. End Set
  299. End Property
  300. Private _inherit As String
  301. ''' <summary>
  302. ''' 发布时间,格式为“yyyy/mm/dd”。OptiFine 源无此数据。
  303. ''' </summary>
  304. Public ReleaseTime As String
  305. ''' <summary>
  306. ''' 需要的最低 Forge 版本。空字符串为无限制,Nothing 为不兼容,“28.1.56” 表示版本号,“1161” 表示版本号的最后一位。
  307. ''' </summary>
  308. Public RequiredForgeVersion As String
  309. End Class
  310. ''' <summary>
  311. ''' OptiFine 版本列表,主加载器。
  312. ''' </summary>
  313. Public DlOptiFineListLoader As New LoaderTask(Of Integer, DlOptiFineListResult)("DlOptiFineList Main", AddressOf DlOptiFineListMain)
  314. Private Sub DlOptiFineListMain(Loader As LoaderTask(Of Integer, DlOptiFineListResult))
  315. Select Case Setup.Get("ToolDownloadVersion")
  316. Case 0
  317. DlSourceLoader(Loader, New List(Of KeyValuePair(Of LoaderTask(Of Integer, DlOptiFineListResult), Integer)) From {
  318. New KeyValuePair(Of LoaderTask(Of Integer, DlOptiFineListResult), Integer)(DlOptiFineListBmclapiLoader, 30),
  319. New KeyValuePair(Of LoaderTask(Of Integer, DlOptiFineListResult), Integer)(DlOptiFineListOfficialLoader, 60)
  320. }, Loader.IsForceRestarting)
  321. Case 1
  322. DlSourceLoader(Loader, New List(Of KeyValuePair(Of LoaderTask(Of Integer, DlOptiFineListResult), Integer)) From {
  323. New KeyValuePair(Of LoaderTask(Of Integer, DlOptiFineListResult), Integer)(DlOptiFineListOfficialLoader, 5),
  324. New KeyValuePair(Of LoaderTask(Of Integer, DlOptiFineListResult), Integer)(DlOptiFineListBmclapiLoader, 35)
  325. }, Loader.IsForceRestarting)
  326. Case Else
  327. DlSourceLoader(Loader, New List(Of KeyValuePair(Of LoaderTask(Of Integer, DlOptiFineListResult), Integer)) From {
  328. New KeyValuePair(Of LoaderTask(Of Integer, DlOptiFineListResult), Integer)(DlOptiFineListOfficialLoader, 60),
  329. New KeyValuePair(Of LoaderTask(Of Integer, DlOptiFineListResult), Integer)(DlOptiFineListBmclapiLoader, 60)
  330. }, Loader.IsForceRestarting)
  331. End Select
  332. End Sub
  333. ''' <summary>
  334. ''' OptiFine 版本列表,官方源。
  335. ''' </summary>
  336. Public DlOptiFineListOfficialLoader As New LoaderTask(Of Integer, DlOptiFineListResult)("DlOptiFineList Official", AddressOf DlOptiFineListOfficialMain)
  337. Private Sub DlOptiFineListOfficialMain(Loader As LoaderTask(Of Integer, DlOptiFineListResult))
  338. Dim Result As String = NetGetCodeByClient("https://optifine.net/downloads", Encoding.Default)
  339. If Result.Length < 200 Then Throw New Exception("获取到的版本列表长度不足(" & Result & ")")
  340. '获取所有版本信息
  341. Dim Forge As List(Of String) = RegexSearch(Result, "(?<=colForge'>)[^<]*")
  342. Dim ReleaseTime As List(Of String) = RegexSearch(Result, "(?<=colDate'>)[^<]+")
  343. Dim Name As List(Of String) = RegexSearch(Result, "(?<=OptiFine_)[0-9A-Za-z_.]+(?=.jar"")")
  344. If Not ReleaseTime.Count = Name.Count Then Throw New Exception("版本与发布时间数据无法对应")
  345. If Not Forge.Count = Name.Count Then Throw New Exception("版本与 Forge 兼容数据无法对应")
  346. If ReleaseTime.Count < 10 Then Throw New Exception("获取到的版本数量不足(" & Result & ")")
  347. '转化为列表输出
  348. Dim Versions As New List(Of DlOptiFineListEntry)
  349. For i = 0 To ReleaseTime.Count - 1
  350. Name(i) = Name(i).Replace("_", " ")
  351. Dim Entry As New DlOptiFineListEntry With {
  352. .NameDisplay = Name(i).Replace("HD U ", "").Replace(".0 ", " "),
  353. .ReleaseTime = Join({ReleaseTime(i).Split(".")(2), ReleaseTime(i).Split(".")(1), ReleaseTime(i).Split(".")(0)}, "/"),
  354. .IsPreview = Name(i).ToLower.Contains("pre"),
  355. .Inherit = Name(i).ToString.Split(" ")(0),
  356. .NameFile = If(Name(i).ToLower.Contains("pre"), "preview_", "") & "OptiFine_" & Name(i).Replace(" ", "_") & ".jar",
  357. .RequiredForgeVersion = Forge(i).Replace("Forge ", "").Replace("#", "")}
  358. If Entry.RequiredForgeVersion.Contains("N/A") Then Entry.RequiredForgeVersion = Nothing
  359. Entry.NameVersion = Entry.Inherit & "-OptiFine_" & Name(i).ToString.Replace(" ", "_").Replace(Entry.Inherit & "_", "")
  360. Versions.Add(Entry)
  361. Next
  362. Loader.Output = New DlOptiFineListResult With {.IsOfficial = True, .SourceName = "OptiFine 官方源", .Value = Versions}
  363. End Sub
  364. ''' <summary>
  365. ''' OptiFine 版本列表,BMCLAPI。
  366. ''' </summary>
  367. Public DlOptiFineListBmclapiLoader As New LoaderTask(Of Integer, DlOptiFineListResult)("DlOptiFineList Bmclapi", AddressOf DlOptiFineListBmclapiMain)
  368. Private Sub DlOptiFineListBmclapiMain(Loader As LoaderTask(Of Integer, DlOptiFineListResult))
  369. Dim Json As JArray = NetGetCodeByRequestRetry("https://bmclapi2.bangbang93.com/optifine/versionList",
  370. BackupUrl:="https://download.mcbbs.net/optifine/versionList", IsJson:=True)
  371. Try
  372. Dim Versions As New List(Of DlOptiFineListEntry)
  373. For Each Token As JObject In Json
  374. Dim Entry As New DlOptiFineListEntry With {
  375. .NameDisplay = (Token("mcversion").ToString & Token("type").ToString.Replace("HD_U", "").Replace("_", " ") & " " & Token("patch").ToString).Replace(".0 ", " "),
  376. .ReleaseTime = "",
  377. .IsPreview = Token("patch").ToString.ToLower.Contains("pre"),
  378. .Inherit = Token("mcversion").ToString,
  379. .NameFile = Token("filename").ToString,
  380. .RequiredForgeVersion = If(Token("forge"), "").ToString.Replace("Forge ", "").Replace("#", "")
  381. }
  382. If Entry.RequiredForgeVersion.Contains("N/A") Then Entry.RequiredForgeVersion = Nothing
  383. Entry.NameVersion = Entry.Inherit & "-OptiFine_" & (Token("type").ToString & " " & Token("patch").ToString).Replace(".0 ", " ").Replace(" ", "_").Replace(Entry.Inherit & "_", "")
  384. Versions.Add(Entry)
  385. Next
  386. Loader.Output = New DlOptiFineListResult With {.IsOfficial = False, .SourceName = "BMCLAPI", .Value = Versions}
  387. Catch ex As Exception
  388. Throw New Exception("版本列表解析失败(" & Json.ToString & ")", ex)
  389. End Try
  390. End Sub
  391. #End Region
  392. #Region "DlForgeList | Forge Minecraft 版本列表"
  393. Public Structure DlForgeListResult
  394. ''' <summary>
  395. ''' 数据来源名称,如“Official”,“BMCLAPI”。
  396. ''' </summary>
  397. Public SourceName As String
  398. ''' <summary>
  399. ''' 是否为官方的实时数据。
  400. ''' </summary>
  401. Public IsOfficial As Boolean
  402. ''' <summary>
  403. ''' 获取到的数据。
  404. ''' </summary>
  405. Public Value As List(Of String)
  406. End Structure
  407. ''' <summary>
  408. ''' Forge 版本列表,主加载器。
  409. ''' </summary>
  410. Public DlForgeListLoader As New LoaderTask(Of Integer, DlForgeListResult)("DlForgeList Main", AddressOf DlForgeListMain)
  411. Private Sub DlForgeListMain(Loader As LoaderTask(Of Integer, DlForgeListResult))
  412. Select Case Setup.Get("ToolDownloadVersion")
  413. Case 0
  414. DlSourceLoader(Loader, New List(Of KeyValuePair(Of LoaderTask(Of Integer, DlForgeListResult), Integer)) From {
  415. New KeyValuePair(Of LoaderTask(Of Integer, DlForgeListResult), Integer)(DlForgeListBmclapiLoader, 30),
  416. New KeyValuePair(Of LoaderTask(Of Integer, DlForgeListResult), Integer)(DlForgeListOfficialLoader, 60)
  417. }, Loader.IsForceRestarting)
  418. Case 1
  419. DlSourceLoader(Loader, New List(Of KeyValuePair(Of LoaderTask(Of Integer, DlForgeListResult), Integer)) From {
  420. New KeyValuePair(Of LoaderTask(Of Integer, DlForgeListResult), Integer)(DlForgeListOfficialLoader, 5),
  421. New KeyValuePair(Of LoaderTask(Of Integer, DlForgeListResult), Integer)(DlForgeListBmclapiLoader, 35)
  422. }, Loader.IsForceRestarting)
  423. Case Else
  424. DlSourceLoader(Loader, New List(Of KeyValuePair(Of LoaderTask(Of Integer, DlForgeListResult), Integer)) From {
  425. New KeyValuePair(Of LoaderTask(Of Integer, DlForgeListResult), Integer)(DlForgeListOfficialLoader, 60),
  426. New KeyValuePair(Of LoaderTask(Of Integer, DlForgeListResult), Integer)(DlForgeListBmclapiLoader, 60)
  427. }, Loader.IsForceRestarting)
  428. End Select
  429. End Sub
  430. ''' <summary>
  431. ''' Forge 版本列表,官方源。
  432. ''' </summary>
  433. Public DlForgeListOfficialLoader As New LoaderTask(Of Integer, DlForgeListResult)("DlForgeList Official", AddressOf DlForgeListOfficialMain)
  434. Private Sub DlForgeListOfficialMain(Loader As LoaderTask(Of Integer, DlForgeListResult))
  435. Dim Result As String = NetGetCodeByRequestRetry("http://files.minecraftforge.net/maven/net/minecraftforge/forge/index_1.2.4.html", Encoding.Default, "text/html")
  436. If Result.Length < 200 Then Throw New Exception("获取到的版本列表长度不足(" & Result & ")")
  437. '获取所有版本信息
  438. Dim Names As List(Of String) = RegexSearch(Result, "(?<=a href=""index_)[0-9.]+(_pre[0-9]?)?(?=.html)")
  439. Names.Add("1.2.4") '1.2.4 不会被匹配上
  440. If Names.Count < 10 Then Throw New Exception("获取到的版本数量不足(" & Result & ")")
  441. Loader.Output = New DlForgeListResult With {.IsOfficial = True, .SourceName = "Forge 官方源", .Value = Names}
  442. End Sub
  443. ''' <summary>
  444. ''' Forge 版本列表,BMCLAPI。
  445. ''' </summary>
  446. Public DlForgeListBmclapiLoader As New LoaderTask(Of Integer, DlForgeListResult)("DlForgeList Bmclapi", AddressOf DlForgeListBmclapiMain)
  447. Private Sub DlForgeListBmclapiMain(Loader As LoaderTask(Of Integer, DlForgeListResult))
  448. Dim Result As String = NetGetCodeByRequestRetry("https://bmclapi2.bangbang93.com/forge/minecraft", Encoding.Default,
  449. BackupUrl:="https://download.mcbbs.net/forge/minecraft")
  450. If Result.Length < 200 Then Throw New Exception("获取到的版本列表长度不足(" & Result & ")")
  451. '获取所有版本信息
  452. Dim Names As List(Of String) = RegexSearch(Result, "[0-9.]+(_pre[0-9]?)?")
  453. If Names.Count < 10 Then Throw New Exception("获取到的版本数量不足(" & Result & ")")
  454. Loader.Output = New DlForgeListResult With {.IsOfficial = False, .SourceName = "BMCLAPI", .Value = Names}
  455. End Sub
  456. #End Region
  457. #Region "DlForgeVersion | Forge 版本列表"
  458. Public Class DlForgeVersionEntry
  459. ''' <summary>
  460. ''' 完整的版本名,如 “14.22.1.2478”。
  461. ''' </summary>
  462. Public Version As String
  463. ''' <summary>
  464. ''' 对应的 Minecraft 版本,如“1.12.2”。
  465. ''' </summary>
  466. Public Inherit As String
  467. ''' <summary>
  468. ''' 发布时间,格式为“yyyy/MM/dd HH:mm”。
  469. ''' </summary>
  470. Public ReleaseTime As String
  471. ''' <summary>
  472. ''' 文件的 MD5 或 SHA1(BMCLAPI 的老版本是 MD5,新版本是 SHA1;官方源总是 MD5)。
  473. ''' </summary>
  474. Public Hash As String = Nothing
  475. ''' <summary>
  476. ''' 是否为推荐版本。
  477. ''' </summary>
  478. Public IsRecommended As Boolean
  479. ''' <summary>
  480. ''' 安装类型。有 installer、client、universal 三种。
  481. ''' </summary>
  482. Public Category As String
  483. ''' <summary>
  484. ''' 版本分支。若无分支则为 Nothing。
  485. ''' </summary>
  486. Public Branch As String = Nothing
  487. ''' <summary>
  488. ''' 是否为新版 Forge。(即为 Minecraft 1.13+)
  489. ''' </summary>
  490. Public ReadOnly Property IsNewType As Boolean
  491. Get
  492. Return Version.Split(".")(0) >= 20
  493. End Get
  494. End Property
  495. ''' <summary>
  496. ''' 构建数。
  497. ''' </summary>
  498. Public ReadOnly Property Build As Integer
  499. Get
  500. Dim Version = Me.Version.Split(".")
  501. If Version(0) < 15 Then
  502. Return Version(Version.Count - 1)
  503. Else
  504. Return Version(Version.Count - 1) + 10000
  505. End If
  506. End Get
  507. End Property
  508. ''' <summary>
  509. ''' 用于下载的文件版本名。可能在 Version 的基础上添加了分支。
  510. ''' </summary>
  511. Public ReadOnly Property FileVersion As String
  512. Get
  513. Return Version & If(Branch Is Nothing, "", "-" & Branch)
  514. End Get
  515. End Property
  516. ''' <summary>
  517. ''' 即将下载的文件全名。
  518. ''' </summary>
  519. Public ReadOnly Property FileName As String
  520. Get
  521. Return "forge-" & Inherit & "-" & FileVersion & "-" & Category & "." & FileSuffix
  522. End Get
  523. End Property
  524. ''' <summary>
  525. ''' 文件扩展名。
  526. ''' </summary>
  527. Public ReadOnly Property FileSuffix As String
  528. Get
  529. If Category = "installer" Then
  530. Return "jar"
  531. Else
  532. Return "zip"
  533. End If
  534. End Get
  535. End Property
  536. End Class
  537. ''' <summary>
  538. ''' Forge 版本列表,主加载器。
  539. ''' </summary>
  540. Public Sub DlForgeVersionMain(Loader As LoaderTask(Of String, List(Of DlForgeVersionEntry)))
  541. Dim DlForgeVersionOfficialLoader As New LoaderTask(Of String, List(Of DlForgeVersionEntry))("DlForgeVersion Official", AddressOf DlForgeVersionOfficialMain)
  542. Dim DlForgeVersionBmclapiLoader As New LoaderTask(Of String, List(Of DlForgeVersionEntry))("DlForgeVersion Bmclapi", AddressOf DlForgeVersionBmclapiMain)
  543. Select Case Setup.Get("ToolDownloadVersion")
  544. Case 0
  545. DlSourceLoader(Loader, New List(Of KeyValuePair(Of LoaderTask(Of String, List(Of DlForgeVersionEntry)), Integer)) From {
  546. New KeyValuePair(Of LoaderTask(Of String, List(Of DlForgeVersionEntry)), Integer)(DlForgeVersionBmclapiLoader, 30),
  547. New KeyValuePair(Of LoaderTask(Of String, List(Of DlForgeVersionEntry)), Integer)(DlForgeVersionOfficialLoader, 60)
  548. }, Loader.IsForceRestarting)
  549. Case 1
  550. DlSourceLoader(Loader, New List(Of KeyValuePair(Of LoaderTask(Of String, List(Of DlForgeVersionEntry)), Integer)) From {
  551. New KeyValuePair(Of LoaderTask(Of String, List(Of DlForgeVersionEntry)), Integer)(DlForgeVersionOfficialLoader, 5),
  552. New KeyValuePair(Of LoaderTask(Of String, List(Of DlForgeVersionEntry)), Integer)(DlForgeVersionBmclapiLoader, 35)
  553. }, Loader.IsForceRestarting)
  554. Case Else
  555. DlSourceLoader(Loader, New List(Of KeyValuePair(Of LoaderTask(Of String, List(Of DlForgeVersionEntry)), Integer)) From {
  556. New KeyValuePair(Of LoaderTask(Of String, List(Of DlForgeVersionEntry)), Integer)(DlForgeVersionOfficialLoader, 60),
  557. New KeyValuePair(Of LoaderTask(Of String, List(Of DlForgeVersionEntry)), Integer)(DlForgeVersionBmclapiLoader, 60)
  558. }, Loader.IsForceRestarting)
  559. End Select
  560. End Sub
  561. ''' <summary>
  562. ''' Forge 版本列表,官方源。
  563. ''' </summary>
  564. Public Sub DlForgeVersionOfficialMain(Loader As LoaderTask(Of String, List(Of DlForgeVersionEntry)))
  565. Dim Result As String
  566. Try
  567. Result = NetGetCodeByDownload("http://files.minecraftforge.net/maven/net/minecraftforge/forge/index_" & Loader.Input & ".html")
  568. Catch ex As Exception
  569. If GetExceptionSummary(ex).Contains("(404)") Then
  570. Throw New Exception("没有可用版本")
  571. Else
  572. Throw
  573. End If
  574. End Try
  575. If Result.Length < 1000 Then Throw New Exception("获取到的版本列表长度不足(" & Result & ")")
  576. Dim Versions As New List(Of DlForgeVersionEntry)
  577. Try
  578. '分割版本信息
  579. Dim VersionCodes = Mid(Result, 1, Result.LastIndexOf("</table>")).Split("<td class=""download-version")
  580. '获取所有版本信息
  581. For i = 1 To VersionCodes.Count - 1
  582. Dim VersionCode = VersionCodes(i)
  583. Try
  584. '基础信息获取
  585. Dim Name As String = RegexSeek(VersionCode, "(?<=[^(0-9)]+)[0-9\.]+")
  586. Dim IsRecommended As Boolean = VersionCode.Contains("fa promo-recommended")
  587. Dim Inherit As String = Loader.Input
  588. '分支获取
  589. Dim Branch As String = RegexSeek(VersionCode, $"(?<=-{Name}-)[^-""]+(?=-[a-z]+.[a-z]{{3}})")
  590. If String.IsNullOrWhiteSpace(Branch) Then Branch = Nothing
  591. If Name = "11.15.1.2318" OrElse Name = "11.15.1.1902" OrElse Name = "11.15.1.1890" Then Branch = "1.8.9"
  592. If Branch Is Nothing AndAlso Inherit = "1.7.10" AndAlso Name.Split(".")(3) >= 1300 Then Branch = "1.7.10"
  593. '发布时间获取
  594. Dim ReleaseTimeOriginal = RegexSeek(VersionCode, "(?<=""download-time"" title="")[^""]+")
  595. Dim ReleaseTimeSplit = ReleaseTimeOriginal.Split(" -:".ToCharArray) '原格式:"2021-02-15 03:24:02"
  596. Dim ReleaseDate As New Date(ReleaseTimeSplit(0), ReleaseTimeSplit(1), ReleaseTimeSplit(2), '年月日
  597. ReleaseTimeSplit(3), ReleaseTimeSplit(4), ReleaseTimeSplit(5), '时分秒
  598. 0, DateTimeKind.Utc) '以 UTC 时间作为标准
  599. Dim ReleaseTime As String = ReleaseDate.ToLocalTime.ToString("yyyy/MM/dd HH:mm") '时区与格式转换
  600. '分类与 MD5 获取
  601. Dim MD5 As String, Category As String
  602. If VersionCode.Contains("classifier-installer""") Then
  603. '类型为 installer.jar,支持范围 ~753 (~ 1.6.1 部分), 738~684 (1.5.2 全部)
  604. VersionCode = VersionCode.Substring(VersionCode.IndexOf("installer.jar"))
  605. MD5 = RegexSeek(VersionCode, "(?<=MD5:</strong> )[^<]+")
  606. Category = "installer"
  607. ElseIf VersionCode.Contains("classifier-universal""") Then
  608. '类型为 universal.zip,支持范围 751~449 (1.6.1 部分), 682~183 (1.5.1 ~ 1.3.2 部分)
  609. VersionCode = VersionCode.Substring(VersionCode.IndexOf("universal.zip"))
  610. MD5 = RegexSeek(VersionCode, "(?<=MD5:</strong> )[^<]+")
  611. Category = "universal"
  612. ElseIf VersionCode.Contains("client.zip") Then
  613. '类型为 client.zip,支持范围 182~ (1.3.2 部分 ~)
  614. VersionCode = VersionCode.Substring(VersionCode.IndexOf("client.zip"))
  615. MD5 = RegexSeek(VersionCode, "(?<=MD5:</strong> )[^<]+")
  616. Category = "client"
  617. Else
  618. '没有任何下载(1.6.4 有一部分这种情况)
  619. Continue For
  620. End If
  621. '添加进列表
  622. Versions.Add(New DlForgeVersionEntry With {.Category = Category, .Version = Name, .IsRecommended = IsRecommended, .Hash = MD5.Trim(vbCr, vbLf), .Inherit = Inherit, .ReleaseTime = ReleaseTime, .Branch = Branch})
  623. Catch ex As Exception
  624. Throw New Exception("版本信息提取失败(" & VersionCode & ")", ex)
  625. End Try
  626. Next
  627. Catch ex As Exception
  628. Throw New Exception("版本列表解析失败(" & Result & ")", ex)
  629. End Try
  630. If Versions.Count = 0 Then Throw New Exception("没有可用版本")
  631. Loader.Output = Versions
  632. End Sub
  633. ''' <summary>
  634. ''' Forge 版本列表,BMCLAPI。
  635. ''' </summary>
  636. Public Sub DlForgeVersionBmclapiMain(Loader As LoaderTask(Of String, List(Of DlForgeVersionEntry)))
  637. Dim Json As JArray = NetGetCodeByRequestRetry("https://bmclapi2.bangbang93.com/forge/minecraft/" & Loader.Input,
  638. BackupUrl:="https://download.mcbbs.net/forge/minecraft/" & Loader.Input, IsJson:=True)
  639. Dim Versions As New List(Of DlForgeVersionEntry)
  640. Try
  641. Dim Recommended As String = McDownloadForgeRecommendedGet(Loader.Input)
  642. For Each Token As JObject In Json
  643. '分类与 Hash 获取
  644. Dim Hash As String = Nothing, Category As String = "unknown", Proi As Integer = -1
  645. For Each File As JObject In Token("files")
  646. Select Case File("category").ToString
  647. Case "installer"
  648. If File("format").ToString = "jar" Then
  649. '类型为 installer.jar,支持范围 ~753 (~ 1.6.1 部分), 738~684 (1.5.2 全部)
  650. Hash = File("hash")
  651. Category = "installer"
  652. Proi = 2
  653. End If
  654. Case "universal"
  655. If Proi <= 1 AndAlso File("format").ToString = "zip" Then
  656. '类型为 universal.zip,支持范围 751~449 (1.6.1 部分), 682~183 (1.5.1 ~ 1.3.2 部分)
  657. Hash = File("hash")
  658. Category = "universal"
  659. Proi = 1
  660. End If
  661. Case "client"
  662. If Proi <= 0 AndAlso File("format").ToString = "zip" Then
  663. '类型为 client.zip,支持范围 182~ (1.3.2 部分 ~)
  664. Hash = File("hash")
  665. Category = "client"
  666. Proi = 0
  667. End If
  668. End Select
  669. Next
  670. '获取 Entry
  671. Dim Inherit As String = Loader.Input
  672. Dim Branch As String = Token("branch")
  673. Dim Name As String = Token("version")
  674. If Name = "11.15.1.2318" OrElse Name = "11.15.1.1902" OrElse Name = "11.15.1.1890" Then Branch = "1.8.9"
  675. If Branch Is Nothing AndAlso Inherit = "1.7.10" AndAlso Name.Split(".")(3) >= 1300 Then Branch = "1.7.10"
  676. '基础信息获取
  677. Dim Entry = New DlForgeVersionEntry With {.Hash = Hash, .Category = Category, .Version = Name, .Branch = Branch, .Inherit = Inherit, .IsRecommended = Recommended = Name}
  678. Dim TimeSplit = Token("modified").ToString.Split("-"c, "T"c, ":"c, "."c, " "c, "/"c)
  679. Entry.ReleaseTime = Token("modified").ToObject(Of Date).ToLocalTime.ToString("yyyy/MM/dd HH:mm")
  680. '添加项
  681. Versions.Add(Entry)
  682. Next
  683. Catch ex As Exception
  684. Throw New Exception("版本列表解析失败(" & Json.ToString & ")", ex)
  685. End Try
  686. If Versions.Count = 0 Then Throw New Exception("没有可用版本")
  687. Loader.Output = Versions
  688. End Sub
  689. #End Region
  690. #Region "DlLiteLoaderList | LiteLoader 版本列表"
  691. Public Structure DlLiteLoaderListResult
  692. ''' <summary>
  693. ''' 数据来源名称,如“Official”,“BMCLAPI”。
  694. ''' </summary>
  695. Public SourceName As String
  696. ''' <summary>
  697. ''' 是否为官方的实时数据。
  698. ''' </summary>
  699. Public IsOfficial As Boolean
  700. ''' <summary>
  701. ''' 获取到的数据。
  702. ''' </summary>
  703. Public Value As List(Of DlLiteLoaderListEntry)
  704. ''' <summary>
  705. ''' 官方源的失败原因。若没有则为 Nothing。
  706. ''' </summary>
  707. Public OfficialError As Exception
  708. End Structure
  709. Public Class DlLiteLoaderListEntry
  710. ''' <summary>
  711. ''' 实际的文件名,如“liteloader-installer-1.12-00-SNAPSHOT.jar”。
  712. ''' </summary>
  713. Public FileName As String
  714. ''' <summary>
  715. ''' 是否为测试版。
  716. ''' </summary>
  717. Public IsPreview As Boolean
  718. ''' <summary>
  719. ''' 对应的 Minecraft 版本,如“1.12.2”。
  720. ''' </summary>
  721. Public Inherit As String
  722. ''' <summary>
  723. ''' 是否为 1.7 及更早的远古版。
  724. ''' </summary>
  725. Public IsLegacy As Boolean
  726. ''' <summary>
  727. ''' 发布时间,格式为“yyyy/mm/dd HH:mm”。
  728. ''' </summary>
  729. Public ReleaseTime As String
  730. ''' <summary>
  731. ''' 文件的 MD5。
  732. ''' </summary>
  733. Public MD5 As String
  734. ''' <summary>
  735. ''' 对应的 Json 项。
  736. ''' </summary>
  737. Public JsonToken As JToken
  738. End Class
  739. ''' <summary>
  740. ''' LiteLoader 版本列表,主加载器。
  741. ''' </summary>
  742. Public DlLiteLoaderListLoader As New LoaderTask(Of Integer, DlLiteLoaderListResult)("DlLiteLoaderList Main", AddressOf DlLiteLoaderListMain)
  743. Private Sub DlLiteLoaderListMain(Loader As LoaderTask(Of Integer, DlLiteLoaderListResult))
  744. Select Case Setup.Get("ToolDownloadVersion")
  745. Case 0
  746. DlSourceLoader(Loader, New List(Of KeyValuePair(Of LoaderTask(Of Integer, DlLiteLoaderListResult), Integer)) From {
  747. New KeyValuePair(Of LoaderTask(Of Integer, DlLiteLoaderListResult), Integer)(DlLiteLoaderListBmclapiLoader, 30),
  748. New KeyValuePair(Of LoaderTask(Of Integer, DlLiteLoaderListResult), Integer)(DlLiteLoaderListOfficialLoader, 60)
  749. }, Loader.IsForceRestarting)
  750. Case 1
  751. DlSourceLoader(Loader, New List(Of KeyValuePair(Of LoaderTask(Of Integer, DlLiteLoaderListResult), Integer)) From {
  752. New KeyValuePair(Of LoaderTask(Of Integer, DlLiteLoaderListResult), Integer)(DlLiteLoaderListOfficialLoader, 5),
  753. New KeyValuePair(Of LoaderTask(Of Integer, DlLiteLoaderListResult), Integer)(DlLiteLoaderListBmclapiLoader, 35)
  754. }, Loader.IsForceRestarting)
  755. Case Else
  756. DlSourceLoader(Loader, New List(Of KeyValuePair(Of LoaderTask(Of Integer, DlLiteLoaderListResult), Integer)) From {
  757. New KeyValuePair(Of LoaderTask(Of Integer, DlLiteLoaderListResult), Integer)(DlLiteLoaderListOfficialLoader, 60),
  758. New KeyValuePair(Of LoaderTask(Of Integer, DlLiteLoaderListResult), Integer)(DlLiteLoaderListBmclapiLoader, 60)
  759. }, Loader.IsForceRestarting)
  760. End Select
  761. End Sub
  762. ''' <summary>
  763. ''' LiteLoader 版本列表,官方源。
  764. ''' </summary>
  765. Public DlLiteLoaderListOfficialLoader As New LoaderTask(Of Integer, DlLiteLoaderListResult)("DlLiteLoaderList Official", AddressOf DlLiteLoaderListOfficialMain)
  766. Private Sub DlLiteLoaderListOfficialMain(Loader As LoaderTask(Of Integer, DlLiteLoaderListResult))
  767. Dim Result As JObject = NetGetCodeByRequestRetry("http://dl.liteloader.com/versions/versions.json", IsJson:=True)
  768. Try
  769. Dim Json As JObject = Result("versions")
  770. Dim Versions As New List(Of DlLiteLoaderListEntry)
  771. For Each Pair As KeyValuePair(Of String, JToken) In Json
  772. If Pair.Key.StartsWith("1.6") OrElse Pair.Key.StartsWith("1.5") Then Continue For
  773. Dim RealEntry As JToken = If(Pair.Value("artefacts"), Pair.Value("snapshots"))("com.mumfrey:liteloader")("latest")
  774. Versions.Add(New DlLiteLoaderListEntry With {
  775. .Inherit = Pair.Key,
  776. .IsLegacy = Pair.Key.Split(".")(1) < 8,
  777. .IsPreview = RealEntry("stream").ToString.ToLower = "snapshot",
  778. .FileName = "liteloader-installer-" & Pair.Key & If(Pair.Key = "1.8" OrElse Pair.Key = "1.9", ".0", "") & "-00-SNAPSHOT.jar",
  779. .MD5 = RealEntry("md5"),
  780. .ReleaseTime = GetLocalTime(GetDate(RealEntry("timestamp"))).ToString("yyyy/MM/dd HH:mm"),
  781. .JsonToken = RealEntry
  782. })
  783. Next
  784. Loader.Output = New DlLiteLoaderListResult With {.IsOfficial = True, .SourceName = "LiteLoader 官方源", .Value = Versions}
  785. Catch ex As Exception
  786. Throw New Exception("版本列表解析失败(" & Result.ToString & ")", ex)
  787. End Try
  788. End Sub
  789. ''' <summary>
  790. ''' LiteLoader 版本列表,BMCLAPI。
  791. ''' </summary>
  792. Public DlLiteLoaderListBmclapiLoader As New LoaderTask(Of Integer, DlLiteLoaderListResult)("DlLiteLoaderList Bmclapi", AddressOf DlLiteLoaderListBmclapiMain)
  793. Private Sub DlLiteLoaderListBmclapiMain(Loader As LoaderTask(Of Integer, DlLiteLoaderListResult))
  794. Dim Result As JObject = NetGetCodeByRequestRetry("https://bmclapi2.bangbang93.com/maven/com/mumfrey/liteloader/versions.json",
  795. BackupUrl:="https://download.mcbbs.net/maven/com/mumfrey/liteloader/versions.json", IsJson:=True)
  796. Try
  797. Dim Json As JObject = Result("versions")
  798. Dim Versions As New List(Of DlLiteLoaderListEntry)
  799. For Each Pair As KeyValuePair(Of String, JToken) In Json
  800. If Pair.Key.StartsWith("1.6") OrElse Pair.Key.StartsWith("1.5") Then Continue For
  801. Dim RealEntry As JToken = If(Pair.Value("artefacts"), Pair.Value("snapshots"))("com.mumfrey:liteloader")("latest")
  802. Versions.Add(New DlLiteLoaderListEntry With {
  803. .Inherit = Pair.Key,
  804. .IsLegacy = Pair.Key.Split(".")(1) < 8,
  805. .IsPreview = RealEntry("stream").ToString.ToLower = "snapshot",
  806. .FileName = "liteloader-installer-" & Pair.Key & If(Pair.Key = "1.8" OrElse Pair.Key = "1.9", ".0", "") & "-00-SNAPSHOT.jar",
  807. .MD5 = RealEntry("md5"),
  808. .ReleaseTime = GetLocalTime(GetDate(RealEntry("timestamp"))).ToString("yyyy/MM/dd HH:mm"),
  809. .JsonToken = RealEntry
  810. })
  811. Next
  812. Loader.Output = New DlLiteLoaderListResult With {.IsOfficial = False, .SourceName = "BMCLAPI", .Value = Versions}
  813. Catch ex As Exception
  814. Throw New Exception("版本列表解析失败(" & Result.ToString & ")", ex)
  815. End Try
  816. End Sub
  817. #End Region
  818. #Region "DlFabricList | Fabric 列表"
  819. Public Structure DlFabricListResult
  820. ''' <summary>
  821. ''' 数据来源名称,如“Official”,“BMCLAPI”。
  822. ''' </summary>
  823. Public SourceName As String
  824. ''' <summary>
  825. ''' 是否为官方的实时数据。
  826. ''' </summary>
  827. Public IsOfficial As Boolean
  828. ''' <summary>
  829. ''' 获取到的数据。
  830. ''' </summary>
  831. Public Value As JObject
  832. End Structure
  833. ''' <summary>
  834. ''' Fabric 列表,主加载器。
  835. ''' </summary>
  836. Public DlFabricListLoader As New LoaderTask(Of Integer, DlFabricListResult)("DlFabricList Main", AddressOf DlFabricListMain)
  837. Private Sub DlFabricListMain(Loader As LoaderTask(Of Integer, DlFabricListResult))
  838. Select Case Setup.Get("ToolDownloadVersion")
  839. Case 0
  840. DlSourceLoader(Loader, New List(Of KeyValuePair(Of LoaderTask(Of Integer, DlFabricListResult), Integer)) From {
  841. New KeyValuePair(Of LoaderTask(Of Integer, DlFabricListResult), Integer)(DlFabricListBmclapiLoader, 30),
  842. New KeyValuePair(Of LoaderTask(Of Integer, DlFabricListResult), Integer)(DlFabricListOfficialLoader, 60)
  843. }, Loader.IsForceRestarting)
  844. Case 1
  845. DlSourceLoader(Loader, New List(Of KeyValuePair(Of LoaderTask(Of Integer, DlFabricListResult), Integer)) From {
  846. New KeyValuePair(Of LoaderTask(Of Integer, DlFabricListResult), Integer)(DlFabricListOfficialLoader, 5),
  847. New KeyValuePair(Of LoaderTask(Of Integer, DlFabricListResult), Integer)(DlFabricListBmclapiLoader, 35)
  848. }, Loader.IsForceRestarting)
  849. Case Else
  850. DlSourceLoader(Loader, New List(Of KeyValuePair(Of LoaderTask(Of Integer, DlFabricListResult), Integer)) From {
  851. New KeyValuePair(Of LoaderTask(Of Integer, DlFabricListResult), Integer)(DlFabricListOfficialLoader, 60),
  852. New KeyValuePair(Of LoaderTask(Of Integer, DlFabricListResult), Integer)(DlFabricListBmclapiLoader, 60)
  853. }, Loader.IsForceRestarting)
  854. End Select
  855. End Sub
  856. ''' <summary>
  857. ''' Fabric 列表,官方源。
  858. ''' </summary>
  859. Public DlFabricListOfficialLoader As New LoaderTask(Of Integer, DlFabricListResult)("DlFabricList Official", AddressOf DlFabricListOfficialMain)
  860. Private Sub DlFabricListOfficialMain(Loader As LoaderTask(Of Integer, DlFabricListResult))
  861. Dim Result As JObject = NetGetCodeByRequestRetry("https://meta.fabricmc.net/v2/versions", IsJson:=True)
  862. Try
  863. Dim Output = New DlFabricListResult With {.IsOfficial = True, .SourceName = "Fabric 官方源", .Value = Result}
  864. If Output.Value("game") Is Nothing OrElse Output.Value("loader") Is Nothing OrElse Output.Value("installer") Is Nothing Then Throw New Exception("获取到的列表缺乏必要项")
  865. Loader.Output = Output
  866. Catch ex As Exception
  867. Throw New Exception("列表解析失败(" & Result.ToString & ")", ex)
  868. End Try
  869. End Sub
  870. ''' <summary>
  871. ''' Fabric 列表,BMCLAPI。
  872. ''' </summary>
  873. Public DlFabricListBmclapiLoader As New LoaderTask(Of Integer, DlFabricListResult)("DlFabricList Bmclapi", AddressOf DlFabricListBmclapiMain)
  874. Private Sub DlFabricListBmclapiMain(Loader As LoaderTask(Of Integer, DlFabricListResult))
  875. Dim Result As JObject = NetGetCodeByRequestRetry("https://bmclapi2.bangbang93.com/fabric-meta/v2/versions",
  876. BackupUrl:="https://download.mcbbs.net/fabric-meta/v2/versions", IsJson:=True)
  877. Try
  878. Dim Output = New DlFabricListResult With {.IsOfficial = False, .SourceName = "BMCLAPI", .Value = Result}
  879. If Output.Value("game") Is Nothing OrElse Output.Value("loader") Is Nothing OrElse Output.Value("installer") Is Nothing Then Throw New Exception("获取到的列表缺乏必要项")
  880. Loader.Output = Output
  881. Catch ex As Exception
  882. Throw New Exception("列表解析失败(" & Result.ToString & ")", ex)
  883. End Try
  884. End Sub
  885. ''' <summary>
  886. ''' Fabric API 列表,官方源。
  887. ''' </summary>
  888. Public DlFabricApiLoader As New LoaderTask(Of Integer, List(Of CompFile))("Fabric API List Loader",
  889. Sub(Task As LoaderTask(Of Integer, List(Of CompFile))) Task.Output = CompFilesGet("fabric-api", False))
  890. ''' <summary>
  891. ''' OptiFabric 列表,官方源。
  892. ''' </summary>
  893. Public DlOptiFabricLoader As New LoaderTask(Of Integer, List(Of CompFile))("OptiFabric List Loader",
  894. Sub(Task As LoaderTask(Of Integer, List(Of CompFile))) Task.Output = CompFilesGet("322385", True))
  895. #End Region
  896. #Region "DlSource | 镜像下载源"
  897. Public Function DlSourceResourceGet(MojangBase As String) As String()
  898. MojangBase = MojangBase.Replace("http://resources.download.minecraft.net", "https://resources.download.minecraft.net")
  899. Return {MojangBase.Replace("https://piston-data.mojang.com", "https://download.mcbbs.net/assets").Replace("https://piston-meta.mojang.com", "https://download.mcbbs.net/assets").Replace("https://resources.download.minecraft.net", "https://download.mcbbs.net/assets"),
  900. MojangBase,
  901. MojangBase.Replace("https://piston-data.mojang.com", "https://bmclapi2.bangbang93.com/assets").Replace("https://piston-meta.mojang.com", "https://bmclapi2.bangbang93.com/assets").Replace("https://resources.download.minecraft.net", "https://bmclapi2.bangbang93.com/assets")
  902. }
  903. End Function
  904. Public Function DlSourceLibraryGet(MojangBase As String) As String()
  905. Return {MojangBase.Replace("https://piston-data.mojang.com", "https://download.mcbbs.net/maven").Replace("https://piston-meta.mojang.com", "https://download.mcbbs.net/maven").Replace("https://libraries.minecraft.net", "https://download.mcbbs.net/maven"),
  906. MojangBase.Replace("https://piston-data.mojang.com", "https://download.mcbbs.net/libraries").Replace("https://piston-meta.mojang.com", "https://download.mcbbs.net/libraries").Replace("https://libraries.minecraft.net", "https://download.mcbbs.net/libraries"),
  907. MojangBase,
  908. MojangBase.Replace("https://piston-data.mojang.com", "https://bmclapi2.bangbang93.com/maven").Replace("https://piston-meta.mojang.com", "https://bmclapi2.bangbang93.com/maven").Replace("https://libraries.minecraft.net", "https://bmclapi2.bangbang93.com/maven"),
  909. MojangBase.Replace("https://piston-data.mojang.com", "https://bmclapi2.bangbang93.com/libraries").Replace("https://piston-meta.mojang.com", "https://bmclapi2.bangbang93.com/libraries").Replace("https://libraries.minecraft.net", "https://bmclapi2.bangbang93.com/libraries")
  910. }
  911. End Function
  912. Public Function DlSourceLauncherOrMetaGet(MojangBase As String) As String()
  913. If MojangBase Is Nothing Then Throw New Exception("无对应的 json 下载地址")
  914. Return {MojangBase.Replace("https://piston-data.mojang.com", "https://download.mcbbs.net").Replace("https://piston-meta.mojang.com", "https://download.mcbbs.net").Replace("https://launcher.mojang.com", "https://download.mcbbs.net").Replace("https://launchermeta.mojang.com", "https://download.mcbbs.net"),
  915. MojangBase,
  916. MojangBase.Replace("https://piston-data.mojang.com", "https://bmclapi2.bangbang93.com").Replace("https://piston-meta.mojang.com", "https://bmclapi2.bangbang93.com").Replace("https://launcher.mojang.com", "https://bmclapi2.bangbang93.com").Replace("https://launchermeta.mojang.com", "https://bmclapi2.bangbang93.com")
  917. }
  918. End Function
  919. Private Sub DlSourceLoader(Of InputType, OutputType)(MainLoader As LoaderTask(Of InputType, OutputType),
  920. LoaderList As List(Of KeyValuePair(Of LoaderTask(Of InputType, OutputType), Integer)),
  921. Optional IsForceRestart As Boolean = False)
  922. Dim WaitCycle As Integer = 0
  923. Do While True
  924. '检查加载结束
  925. Dim IsAllFailed As Boolean = True
  926. For Each SubLoader In LoaderList
  927. If WaitCycle = 0 Then
  928. '如果要强制刷新,就不使用已经加载好的值
  929. If IsForceRestart Then Exit For
  930. '如果输入不一样,就不使用已经加载好的值
  931. If (SubLoader.Key.Input Is Nothing Xor MainLoader.Input Is Nothing) OrElse
  932. (SubLoader.Key.Input IsNot Nothing AndAlso Not SubLoader.Key.Input.Equals(MainLoader.Input)) Then Continue For
  933. End If
  934. If SubLoader.Key.State <> LoadState.Failed Then IsAllFailed = False
  935. If SubLoader.Key.State = LoadState.Finished Then
  936. MainLoader.Output = SubLoader.Key.Output
  937. DlSourceLoaderAbort(LoaderList)
  938. Exit Sub
  939. ElseIf IsAllFailed Then
  940. If WaitCycle < SubLoader.Value * 100 Then WaitCycle = SubLoader.Value * 100
  941. End If
  942. '由于 Forge BMCLAPI 没有可用版本导致强制失败
  943. '在没有可用版本时,官方源会一直卡住,直接使用 BMCLAPI 判定失败即可
  944. If SubLoader.Key.Error IsNot Nothing AndAlso SubLoader.Key.Error.Message.Contains("没有可用版本") Then
  945. For Each SubLoader2 In LoaderList
  946. If WaitCycle < SubLoader2.Value * 100 Then WaitCycle = SubLoader2.Value * 100
  947. Next
  948. End If
  949. Next
  950. '启动加载源
  951. If WaitCycle = 0 Then
  952. '启动第一个源
  953. LoaderList(0).Key.Start(MainLoader.Input, IsForceRestart)
  954. '将其他源标记为未启动,以确保可以切换下载源(#184)
  955. For i = 1 To LoaderList.Count - 1
  956. LoaderList(i).Key.State = LoadState.Waiting
  957. Next
  958. End If
  959. For i = 0 To LoaderList.Count - 1
  960. If WaitCycle = LoaderList(i).Value * 100 Then
  961. If i < LoaderList.Count - 1 Then
  962. '启动下一个源
  963. LoaderList(i + 1).Key.Start(MainLoader.Input, IsForceRestart)
  964. Else
  965. '失败
  966. Dim ErrorInfo As Exception = Nothing
  967. For ii = 0 To LoaderList.Count - 1
  968. LoaderList(ii).Key.Input = Nothing '重置输入,以免以同样的输入“重试加载”时直接失败
  969. If LoaderList(ii).Key.Error IsNot Nothing Then
  970. If ErrorInfo Is Nothing OrElse LoaderList(ii).Key.Error.Message.Contains("没有可用版本") Then
  971. ErrorInfo = LoaderList(ii).Key.Error
  972. End If
  973. End If
  974. Next
  975. If ErrorInfo Is Nothing Then ErrorInfo = New TimeoutException("下载源连接超时")
  976. DlSourceLoaderAbort(LoaderList)
  977. Throw ErrorInfo
  978. End If
  979. Exit For
  980. End If
  981. Next
  982. '计时
  983. If MainLoader.IsAborted Then
  984. DlSourceLoaderAbort(LoaderList)
  985. Exit Sub
  986. End If
  987. Thread.Sleep(10)
  988. WaitCycle += 1
  989. Loop
  990. End Sub
  991. Private Sub DlSourceLoaderAbort(Of InputType, OutputType)(LoaderList As List(Of KeyValuePair(Of LoaderTask(Of InputType, OutputType), Integer)))
  992. For Each Loader In LoaderList
  993. If Loader.Key.State = LoadState.Loading Then Loader.Key.Abort()
  994. Next
  995. End Sub
  996. #End Region
  997. End Module