ModDownload.vb 59 KB

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