ModDownload.vb 88 KB

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