Browse Source

fix(ModDownload): 修复mc同一版本更新日志可能多次出现

ENC_Euphony 1 year ago
parent
commit
9bc39f8a95
1 changed files with 14 additions and 4 deletions
  1. 14 4
      Plain Craft Launcher 2/Modules/Minecraft/ModDownload.vb

+ 14 - 4
Plain Craft Launcher 2/Modules/Minecraft/ModDownload.vb

@@ -196,6 +196,7 @@
     ''' </summary>
     Public DlClientListMojangLoader As New LoaderTask(Of String, DlClientListResult)("DlClientList Mojang", AddressOf DlClientListMojangMain)
     Private IsNewClientVersionHinted As Boolean = False
+    Private ReadOnly HintLock As New Object() ' 线程安全锁
     Private Sub DlClientListMojangMain(Loader As LoaderTask(Of String, DlClientListResult))
         Dim StartTime As Long = GetTimeTick()
         Dim Json As JObject = GetJson(NetRequestByClientRetry("https://launchermeta.mojang.com/mc/game/version_manifest.json"))
@@ -215,15 +216,24 @@
             '解析更新提示(Release)
             Dim Version As String = Json("latest")("release")
             If Setup.Get("ToolUpdateRelease") AndAlso Not Setup.Get("ToolUpdateReleaseLast") = "" AndAlso Version IsNot Nothing AndAlso Not Setup.Get("ToolUpdateReleaseLast") = Version Then
-                McDownloadClientUpdateHint(Version, Json)
-                IsNewClientVersionHinted = True
+                SyncLock HintLock
+                    If Not IsNewClientVersionHinted Then ' 在锁内再次检查
+                        McDownloadClientUpdateHint(Version, Json)
+                        IsNewClientVersionHinted = True
+                    End If
+                End SyncLock
             End If
             McVersionHighest = Version.Split(".")(1)
             Setup.Set("ToolUpdateReleaseLast", Version)
             '解析更新提示(Snapshot)
             Version = Json("latest")("snapshot")
-            If Setup.Get("ToolUpdateSnapshot") AndAlso Not Setup.Get("ToolUpdateSnapshotLast") = "" AndAlso Version IsNot Nothing AndAlso Not Setup.Get("ToolUpdateSnapshotLast") = Version AndAlso Not IsNewClientVersionHinted Then
-                McDownloadClientUpdateHint(Version, Json)
+            If Setup.Get("ToolUpdateSnapshot") AndAlso Not Setup.Get("ToolUpdateSnapshotLast") = "" AndAlso Version IsNot Nothing AndAlso Not Setup.Get("ToolUpdateSnapshotLast") = Version Then
+                SyncLock HintLock
+                    If Not IsNewClientVersionHinted Then ' 在锁内再次检查
+                        McDownloadClientUpdateHint(Version, Json)
+                        IsNewClientVersionHinted = True
+                    End If
+                End SyncLock
             End If
             Setup.Set("ToolUpdateSnapshotLast", If(Version, "Nothing"))
         Catch ex As Exception