ModDownload.vb 94 KB

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