Skip to content

Commit 08ad8e6

Browse files
committed
✨ 👌 允许多个链接
1 parent 1e5d5f0 commit 08ad8e6

1 file changed

Lines changed: 27 additions & 16 deletions

File tree

Plain Craft Launcher 2/Modules/Minecraft/ModModpack.vb

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,7 +1028,7 @@ Retry:
10281028
'从 Modrinth 获取信息
10291029
Dim ModrinthMapping As New Dictionary(Of String, JObject) 'Modrinth 获取到的 Mod
10301030
Dim CurseForgeMapping As New Dictionary(Of String, JObject) 'CurseForge 获取到的 Mod
1031-
Dim ModrinthFailed As New Dictionary(Of String, McMod) 'Modrinth 获取失败的 Mod
1031+
Dim Failed = Mods.ToArray().ToDictionary(Function(a) a.Key, Function(a) a.Value) '获取失败的 Mod
10321032
Dim ModrinthHashes = Mods.Select(Function(m) m.Value.ModrinthHash).ToList()
10331033
If Mods.Count = 0 Then GoTo JumpMod
10341034
Dim ModrinthVersion = CType(GetJson(NetRequestRetry("https://api.modrinth.com/v2/version_files", "POST",
@@ -1038,14 +1038,14 @@ Retry:
10381038
For Each Entry In Mods
10391039
If (Not ModrinthVersion.ContainsKey(Entry.Value.ModrinthHash)) OrElse
10401040
(ModrinthVersion(Entry.Value.ModrinthHash)("files")(0)("hashes")("sha1") <> Entry.Value.ModrinthHash) Then
1041-
ModrinthFailed.Add(Entry.Key, Entry.Value)
10421041
Continue For
10431042
End If
1043+
Failed.Remove(Entry.Key)
10441044
ModrinthMapping.Add(Entry.Key, ModrinthVersion(Entry.Value.ModrinthHash)("files")(0))
10451045
Next
10461046

1047-
'步骤 2:把获取失败的 Mod 从 CurseForge 继续获取
1048-
Dim CurseForgeHashes = ModrinthFailed.Select(Function(m) m.Value.CurseForgeHash).ToList()
1047+
'步骤 2:从 CurseForge 继续获取
1048+
Dim CurseForgeHashes = Mods.Select(Function(m) m.Value.CurseForgeHash).ToList()
10491049
Dim CurseForgeRaw = CType(CType(GetJson(NetRequestRetry("https://api.curseforge.com/v1/fingerprints/432/", "POST",
10501050
$"{{""fingerprints"": [{CurseForgeHashes.Join(",")}]}}", "application/json")), JObject)("data")("exactMatches"), JContainer)
10511051
Log($"[Export] 从 CurseForge 获取到 {CurseForgeRaw.Count} 个本地 Mod 的对应信息")
@@ -1060,40 +1060,51 @@ Retry:
10601060
If String.IsNullOrEmpty(hash) OrElse String.IsNullOrEmpty(m("file")("downloadUrl")) Then Continue For
10611061

10621062
m("file")("ModrinthHash") = hash
1063-
For Each file In ModrinthFailed
1063+
Dim f = Mods.ToArray()
1064+
For Each file In f
10641065
If file.Value.ModrinthHash = hash Then
10651066
CurseForgeMapping.Add(file.Key, m("file"))
1066-
ModrinthFailed.Remove(file.Key)
1067+
Failed.Remove(file.Key)
10671068
Exit For
10681069
End If
10691070
Next
10701071
Next
10711072

10721073
JumpMod:
1073-
'步骤 3:写入 Json 文件
1074+
'步骤 3:合并下载链接,写入 Json 文件
10741075
'获取作为检查目标的加载器和版本
10751076
Dim ModLoaders = GetTargetModLoaders()
10761077
Dim McVersion = Version.Version.McName
10771078
Log($"[Export] 目标加载器:{ModLoaders.Join("/")},版本:{McVersion}")
10781079

1080+
'合并下载链接
1081+
Dim BothUrls As New Dictionary(Of String, String()) '两个下载源都有 URL 的 Mod
1082+
For Each modrinth In ModrinthMapping
1083+
Dim curseforge As New JObject
1084+
If CurseForgeMapping.TryGetValue(modrinth.Key, curseforge) Then
1085+
BothUrls.Add(modrinth.Key, {modrinth.Value("url"), curseforge("downloadUrl")})
1086+
End If
1087+
Next
10791088
Dim files As New JArray
10801089
For Each m In ModrinthMapping
10811090
files.Add(New JObject From {
10821091
{"path", $"mods/{m.Key}"},
10831092
{"hashes", m.Value("hashes")},
10841093
{"env", New JObject From {{"client", "required"}, {"server", "required"}}},
1085-
{"downloads", New JArray From {m.Value("url")}},
1094+
{"downloads", If(BothUrls.ContainsKey(m.Key), JArray.FromObject(BothUrls(m.Key)), New JArray From {m.Value("url")})},
10861095
{"fileSize", m.Value("size")}
10871096
})
10881097
Next
10891098
For Each m In CurseForgeMapping
1090-
files.Add(New JObject From {
1091-
{"path", $"mods/{m.Key}"},
1092-
{"hashes", New JObject From {{"sha1", m.Value("ModrinthHash").ToString}}},
1093-
{"env", New JObject From {{"client", "required"}, {"server", "required"}}},
1094-
{"downloads", New JArray From {m.Value("downloadUrl")}},
1095-
{"fileSize", m.Value("fileLength")}
1096-
})
1099+
If Not BothUrls.ContainsKey(m.Key) Then
1100+
files.Add(New JObject From {
1101+
{"path", $"mods/{m.Key}"},
1102+
{"hashes", New JObject From {{"sha1", m.Value("ModrinthHash").ToString}}},
1103+
{"env", New JObject From {{"client", "required"}, {"server", "required"}}},
1104+
{"downloads", New JArray From {m.Value("downloadUrl")}},
1105+
{"fileSize", m.Value("fileLength")}
1106+
})
1107+
End If
10971108
Next
10981109

10991110
Dim depend As New JObject From {{"minecraft", McVersion}}
@@ -1114,7 +1125,7 @@ JumpMod:
11141125
File.WriteAllText(tempDir & "modrinth.index.json", json.ToString)
11151126

11161127
'步骤 4:将获取不到的保存到 overrides 目录
1117-
For Each m In ModrinthFailed
1128+
For Each m In Failed
11181129
CopyFile(m.Value.Path, tempDir & "overrides\mods\" & m.Value.FileName)
11191130
Next
11201131

0 commit comments

Comments
 (0)