ModDownload.vb 93 KB

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