Skip to content

Commit d6ba445

Browse files
authored
Merge pull request #6944 from pynickle/fix/issue-6645
fix(ModDownload): 修复mc同一版本更新日志可能多次出现
2 parents 095bd47 + 9bc39f8 commit d6ba445

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@
203203
''' </summary>
204204
Public DlClientListMojangLoader As New LoaderTask(Of String, DlClientListResult)("DlClientList Mojang", AddressOf DlClientListMojangMain)
205205
Private IsNewClientVersionHinted As Boolean = False
206+
Private ReadOnly HintLock As New Object() ' 线程安全锁
206207
Private Sub DlClientListMojangMain(Loader As LoaderTask(Of String, DlClientListResult))
207208
Dim StartTime As Long = GetTimeTick()
208209
Dim Json As JObject = GetJson(NetRequestByClientRetry("https://launchermeta.mojang.com/mc/game/version_manifest.json", RequireJson:=True))
@@ -222,15 +223,24 @@
222223
'解析更新提示(Release)
223224
Dim Version As String = Json("latest")("release")
224225
If Setup.Get("ToolUpdateRelease") AndAlso Not Setup.Get("ToolUpdateReleaseLast") = "" AndAlso Version IsNot Nothing AndAlso Not Setup.Get("ToolUpdateReleaseLast") = Version Then
225-
McDownloadClientUpdateHint(Version, Json)
226-
IsNewClientVersionHinted = True
226+
SyncLock HintLock
227+
If Not IsNewClientVersionHinted Then ' 在锁内再次检查
228+
McDownloadClientUpdateHint(Version, Json)
229+
IsNewClientVersionHinted = True
230+
End If
231+
End SyncLock
227232
End If
228233
McVersionHighest = Version.Split(".")(1)
229234
Setup.Set("ToolUpdateReleaseLast", Version)
230235
'解析更新提示(Snapshot)
231236
Version = Json("latest")("snapshot")
232-
If Setup.Get("ToolUpdateSnapshot") AndAlso Not Setup.Get("ToolUpdateSnapshotLast") = "" AndAlso Version IsNot Nothing AndAlso Not Setup.Get("ToolUpdateSnapshotLast") = Version AndAlso Not IsNewClientVersionHinted Then
233-
McDownloadClientUpdateHint(Version, Json)
237+
If Setup.Get("ToolUpdateSnapshot") AndAlso Not Setup.Get("ToolUpdateSnapshotLast") = "" AndAlso Version IsNot Nothing AndAlso Not Setup.Get("ToolUpdateSnapshotLast") = Version Then
238+
SyncLock HintLock
239+
If Not IsNewClientVersionHinted Then ' 在锁内再次检查
240+
McDownloadClientUpdateHint(Version, Json)
241+
IsNewClientVersionHinted = True
242+
End If
243+
End SyncLock
234244
End If
235245
Setup.Set("ToolUpdateSnapshotLast", If(Version, "Nothing"))
236246
Catch ex As Exception

0 commit comments

Comments
 (0)