Skip to content

Commit 52b4c87

Browse files
committed
2.12.2
1 parent 87f5cc2 commit 52b4c87

24 files changed

+529
-2211
lines changed

Plain Craft Launcher 2/Application.xaml.vb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,8 @@ WaitRetry:
145145
Setup.Load("ToolDownloadCert")
146146
Setup.Load("ToolDownloadSpeed")
147147
'计时
148-
Log("[Start] 第一阶段加载用时:" & GetTimeTick() - ApplicationStartTick & " ms")
149-
ApplicationStartTick = GetTimeTick()
148+
Log("[Start] 第一阶段加载用时:" & GetTimeMs() - ApplicationStartTick & " ms")
149+
ApplicationStartTick = GetTimeMs()
150150
'执行测试
151151
#If DEBUG Then
152152
Test()
@@ -213,7 +213,11 @@ WaitRetry:
213213
'WebP 特判
214214
If Prefix = "Imazen.WebP" Then
215215
SetDllDirectory(PathPure.TrimEnd("\"c))
216-
WriteFile(PathPure & "libwebp.dll", GetResources("libwebp64"))
216+
Try
217+
WriteFile(PathPure & "libwebp.dll", GetResources("libwebp64"))
218+
Catch ex As Exception
219+
Log(ex, "写入 libwebp.dll 失败") '防止同时加载多个图片时,同时写入文件导致文件占用,进而导致崩溃
220+
End Try
217221
End If
218222
End If
219223
Return LoadedAssembly(Prefix)

Plain Craft Launcher 2/FormMain.xaml.vb

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,18 @@ Public Class FormMain
1111
Dim FeatureList As New List(Of KeyValuePair(Of Integer, String))
1212
'统计更新日志条目
1313
#If BETA Then
14+
If LastVersion < 379 Then 'Release 2.12.1
15+
If LastVersion >= 376 Then
16+
FeatureList.Add(New KeyValuePair(Of Integer, String)(5, "删除:暂时隐藏联机入口……不过只是暂时关闭,它还会回来的!"))
17+
End If
18+
FeatureList.Add(New KeyValuePair(Of Integer, String)(3, "新增:适配新的 Minecraft 版本号系统与 Unobfuscated 版本"))
19+
FeatureList.Add(New KeyValuePair(Of Integer, String)(2, "优化:巨幅优化各个下载页面和 Mod 管理页面的性能"))
20+
FeatureList.Add(New KeyValuePair(Of Integer, String)(1, "优化:更换披风时会显示当前使用的披风"))
21+
FeatureCount += 33
22+
BugCount += 29
23+
End If
1424
If LastVersion < 376 Then 'Release 2.11.2
15-
FeatureList.Add(New KeyValuePair(Of Integer, String)(5, "新增:联机功能!"))
25+
'FeatureList.Add(New KeyValuePair(Of Integer, String)(5, "新增:联机功能!"))
1626
FeatureCount += 32
1727
BugCount += 21
1828
End If
@@ -118,6 +128,11 @@ Public Class FormMain
118128
'3:BUG+ IMP* FEAT-
119129
'2:BUG* IMP-
120130
'1:BUG-
131+
If LastVersion < 380 Then 'Snapshot 2.12.2
132+
FeatureList.Add(New KeyValuePair(Of Integer, String)(1, "修复:无法搜索 CurseForge 上的社区资源"))
133+
FeatureCount += 3
134+
BugCount += 13
135+
End If
121136
If LastVersion < 378 Then 'Snapshot 2.12.1
122137
If LastVersion >= 377 Then
123138
FeatureList.Add(New KeyValuePair(Of Integer, String)(1, "修复:在版本列表中存在 OptiFine 时可能无法加载版本列表"))
@@ -323,7 +338,7 @@ Public Class FormMain
323338
'窗口加载
324339
Private IsWindowLoadFinished As Boolean = False
325340
Public Sub New()
326-
ApplicationStartTick = GetTimeTick()
341+
ApplicationStartTick = GetTimeMs()
327342
'窗体参数初始化
328343
FrmMain = Me
329344
FrmLaunchLeft = New PageLaunchLeft
@@ -387,10 +402,10 @@ Public Class FormMain
387402
'尽早执行的加载池
388403
McFolderListLoader.Start(0) '为了让下载已存在文件检测可以正常运行,必须跑一次;为了让启动按钮尽快可用,需要尽早执行;为了与 PageLaunchLeft 联动,需要为 0 而不是 GetUuid
389404

390-
Log("[Start] 第二阶段加载用时:" & GetTimeTick() - ApplicationStartTick & " ms")
405+
Log("[Start] 第二阶段加载用时:" & GetTimeMs() - ApplicationStartTick & " ms")
391406
End Sub
392407
Private Sub FormMain_Loaded(sender As Object, e As RoutedEventArgs) Handles Me.Loaded
393-
ApplicationStartTick = GetTimeTick()
408+
ApplicationStartTick = GetTimeMs()
394409
Handle = New Interop.WindowInteropHelper(Me).Handle
395410
'读取设置
396411
Setup.Load("UiBackgroundOpacity")
@@ -496,7 +511,7 @@ Public Class FormMain
496511
Telemetry("启动")
497512
End Sub, "初始化", ThreadPriority.Lowest)
498513

499-
Log("[Start] 第三阶段加载用时:" & GetTimeTick() - ApplicationStartTick & " ms")
514+
Log("[Start] 第三阶段加载用时:" & GetTimeMs() - ApplicationStartTick & " ms")
500515
End Sub
501516
'根据打开次数触发的事件
502517
Private Sub RunCountSub()

Plain Craft Launcher 2/Modules/Base/ModAnimation.vb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -743,9 +743,9 @@ Public Module ModAnimation
743743
''' <param name="AniGroup">由 Aa 开头的函数初始化的 AniData 对象集合。</param>
744744
''' <param name="Name">动画组的名称。如果重复会直接停止同名动画组。</param>
745745
Public Sub AniStart(AniGroup As IList, Optional Name As String = "", Optional RefreshTime As Boolean = False)
746-
If RefreshTime Then AniLastTick = GetTimeTick() '避免处理动画时已经造成了极大的延迟,导致动画突然结束
746+
If RefreshTime Then AniLastTick = GetTimeMs() '避免处理动画时已经造成了极大的延迟,导致动画突然结束
747747
'添加到正在执行的动画组
748-
Dim NewEntry As New AniGroupEntry With {.Data = GetFullList(Of AniData)(AniGroup), .StartTick = GetTimeTick()}
748+
Dim NewEntry As New AniGroupEntry With {.Data = GetFullList(Of AniData)(AniGroup), .StartTick = GetTimeMs()}
749749
If Name = "" Then
750750
Name = NewEntry.Uuid
751751
Else
@@ -788,7 +788,7 @@ Public Module ModAnimation
788788
''' </summary>
789789
Public Sub AniStart()
790790
'初始化计时器
791-
AniLastTick = GetTimeTick()
791+
AniLastTick = GetTimeMs()
792792
AniFPSTimer = AniLastTick
793793
AniRunning = True '标记动画执行开始
794794

@@ -798,9 +798,9 @@ Public Module ModAnimation
798798
Log("[Animation] 动画线程开始")
799799
Do While True
800800
'两帧之间的间隔时间
801-
Dim DeltaTime As Long = MathClamp(GetTimeTick() - AniLastTick, 0, 100000)
801+
Dim DeltaTime As Long = MathClamp(GetTimeMs() - AniLastTick, 0, 100000)
802802
If DeltaTime < 3 Then GoTo Sleeper
803-
AniLastTick = GetTimeTick()
803+
AniLastTick = GetTimeMs()
804804
'记录 FPS
805805
If ModeDebug Then
806806
If MathClamp(AniLastTick - AniFPSTimer, 0, 100000) >= 500 Then

Plain Craft Launcher 2/Modules/Base/ModBase.vb

Lines changed: 42 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ Public Module ModBase
1414
#Region "声明"
1515

1616
'下列版本信息由更新器自动修改
17-
Public Const VersionBaseName As String = "2.12.1" '不含分支前缀的显示用版本名
18-
Public Const VersionStandardCode As String = "2.12.1." & VersionBranchCode '标准格式的四段式版本号
17+
Public Const VersionBaseName As String = "2.12.2" '不含分支前缀的显示用版本名
18+
Public Const VersionStandardCode As String = "2.12.2." & VersionBranchCode '标准格式的四段式版本号
1919
Public Const CommitHash As String = "" 'Commit Hash,由 GitHub Workflow 自动替换
2020
#If BETA Then
21-
Public Const VersionCode As Integer = 372 'Release
21+
Public Const VersionCode As Integer = 379 'Release
2222
#Else
23-
Public Const VersionCode As Integer = 378 'Snapshot
23+
Public Const VersionCode As Integer = 380 'Snapshot
2424
#End If
2525
'自动生成的版本信息
2626
Public Const VersionDisplayName As String = VersionBranchName & " " & VersionBaseName
@@ -62,7 +62,7 @@ Public Module ModBase
6262
''' <summary>
6363
''' 程序的打开计时。
6464
''' </summary>
65-
Public ApplicationStartTick As Long = GetTimeTick()
65+
Public ApplicationStartTick As Long = GetTimeMs()
6666
''' <summary>
6767
''' 程序打开时的时间。
6868
''' </summary>
@@ -1284,27 +1284,31 @@ Re:
12841284
''' <summary>
12851285
''' 尝试根据后缀名判断文件种类并解压文件,支持 gz 与 zip,会尝试将 jar 以 zip 方式解压。
12861286
''' 会尝试创建,但不会清空目标文件夹。
1287+
''' 会先使用 UTF-8 解压,失败后换用 GB18030 解压。
12871288
''' </summary>
1288-
Public Sub ExtractFile(CompressFilePath As String, DestDirectory As String, Optional Encode As Encoding = Nothing,
1289-
Optional ProgressIncrementHandler As Action(Of Double) = Nothing)
1289+
Public Sub ExtractCompressedFile(CompressFilePath As String, DestDirectory As String, Optional ProgressIncrementHandler As Action(Of Double) = Nothing)
12901290
Directory.CreateDirectory(DestDirectory)
1291+
'解压 gz(gz 不需要考虑编码)
12911292
If CompressFilePath.EndsWithF(".gz", True) Then
1292-
'以 gz 方式解压
1293-
Dim stream As New GZipStream(New FileStream(CompressFilePath, FileMode.Open, FileAccess.ReadWrite), CompressionMode.Decompress)
1294-
Dim decompressedFile As New FileStream(DestDirectory & GetFileNameFromPath(CompressFilePath).ToLower.Replace(".tar", "").Replace(".gz", ""), FileMode.OpenOrCreate, FileAccess.Write)
1295-
Dim data As Integer = stream.ReadByte()
1296-
While data <> -1
1297-
decompressedFile.WriteByte(data)
1298-
data = stream.ReadByte()
1299-
End While
1300-
decompressedFile.Close()
1301-
stream.Close()
1302-
Else
1303-
'以 zip 方式解压
1304-
Using Archive = ZipFile.Open(CompressFilePath, ZipArchiveMode.Read, If(Encode, Encoding.GetEncoding("GB18030")))
1305-
Dim TotalCount As Long = Archive.Entries.Count
1306-
For Each Entry As ZipArchiveEntry In Archive.Entries
1307-
If ProgressIncrementHandler IsNot Nothing AndAlso TotalCount > 0 Then ProgressIncrementHandler(1 / TotalCount)
1293+
Using stream As New GZipStream(New FileStream(CompressFilePath, FileMode.Open, FileAccess.Read, FileShare.Read), CompressionMode.Decompress)
1294+
Using decompressedFile As New FileStream(DestDirectory & GetFileNameFromPath(CompressFilePath).ToLower.Replace(".tar", "").Replace(".gz", ""),
1295+
FileMode.OpenOrCreate, FileAccess.Write)
1296+
Dim data As Integer = stream.ReadByte()
1297+
While data <> -1
1298+
decompressedFile.WriteByte(data)
1299+
data = stream.ReadByte()
1300+
End While
1301+
End Using
1302+
End Using
1303+
Return
1304+
End If
1305+
'解压 zip
1306+
Dim TryExtractZip =
1307+
Sub(Encoding As Encoding)
1308+
Using Archive = ZipFile.Open(CompressFilePath, ZipArchiveMode.Read, Encoding)
1309+
Dim EntryCount = Archive.Entries.Count
1310+
For Each Entry In Archive.Entries
1311+
If ProgressIncrementHandler IsNot Nothing AndAlso EntryCount > 0 Then ProgressIncrementHandler(1 / EntryCount)
13081312
Dim DestinationFullPath As String = IO.Path.Combine(DestDirectory, Entry.FullName)
13091313
If Not IO.Path.GetFullPath(DestinationFullPath).StartsWithF(IO.Path.GetFullPath(DestDirectory), True) Then Continue For 'ZipSlip 漏洞修复
13101314
If DestinationFullPath.EndsWithF("\") OrElse DestinationFullPath.EndsWithF("/") Then Continue For '不创建空文件夹
@@ -1313,7 +1317,17 @@ Re:
13131317
Entry.ExtractToFile(DestinationFullPath.Replace(DestinationDirectory, ShortenPath(DestinationDirectory)), True) '#7329
13141318
Next
13151319
End Using
1316-
End If
1320+
End Sub
1321+
Try
1322+
TryExtractZip(Encoding.UTF8)
1323+
Catch ex As Exception
1324+
Log(ex, $"首次解压尝试失败,将更换编码并重试({CompressFilePath} → {DestDirectory})")
1325+
Try
1326+
TryExtractZip(Encoding.GetEncoding("GB18030"))
1327+
Catch
1328+
Throw
1329+
End Try
1330+
End Try
13171331
End Sub
13181332

13191333
''' <summary>
@@ -1609,6 +1623,7 @@ RetryDir:
16091623
End Function
16101624
''' <summary>
16111625
''' 分割字符串。
1626+
''' 若原始字符串为空,则返回 {""}。
16121627
''' </summary>
16131628
<Extension> Public Function Split(FullStr As String, SplitStr As String) As String()
16141629
If SplitStr.Length = 1 Then
@@ -2297,10 +2312,10 @@ NextElement:
22972312
Return Date.Now.ToString("HH':'mm':'ss'.'fff")
22982313
End Function
22992314
''' <summary>
2300-
''' 获取系统运行时间(毫秒),保证为正 Long 且大于 1,但可能突变减小
2315+
''' 获取一个单调递增时间值(毫秒)。
23012316
''' </summary>
2302-
Public Function GetTimeTick() As Long
2303-
Return My.Computer.Clock.TickCount + 2147483651L
2317+
Public Function GetTimeMs() As Long
2318+
Return Stopwatch.GetTimestamp() \ (Stopwatch.Frequency \ 1000L)
23042319
End Function
23052320
''' <summary>
23062321
''' 将时间间隔转换为类似“5 分 10 秒前”的易于阅读的形式。

Plain Craft Launcher 2/Modules/Base/ModLoader.vb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@
295295

296296
If (State = LoadState.Loading OrElse State = LoadState.Finished) AndAlso '正在加载或已结束…
297297
(IgnoreReloadTimeout OrElse ReloadTimeout = -1 OrElse
298-
LastFinishedTime = 0 OrElse GetTimeTick() - LastFinishedTime < ReloadTimeout) Then '…且没有超时…
298+
LastFinishedTime = 0 OrElse GetTimeMs() - LastFinishedTime < ReloadTimeout) Then '…且没有超时…
299299
Return False '…则不重试
300300
Else
301301
Return True '否则需要重启
@@ -328,7 +328,7 @@
328328
If ModeDebug AndAlso Not LogBlackList.Contains(Name) Then Log($"[Loader] 加载线程 {Name} ({Thread.CurrentThread.ManagedThreadId}) 已完成")
329329
RaisePreviewFinish()
330330
State = LoadState.Finished
331-
LastFinishedTime = GetTimeTick() '未中断,本次输出有效
331+
LastFinishedTime = GetTimeMs() '未中断,本次输出有效
332332
Catch ex As CancelledException
333333
If ModeDebug Then Log(ex, $"加载线程 {Name} ({Thread.CurrentThread.ManagedThreadId}) 已触发取消中断,已完成 {Math.Round(Progress * 100)}%")
334334
If Not IsAborted Then State = LoadState.Aborted

0 commit comments

Comments
 (0)