Skip to content

Commit

Permalink
fix: update
Browse files Browse the repository at this point in the history
  • Loading branch information
tangge233 committed Jan 24, 2025
1 parent 9bca4de commit 7dfa823
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions Plain Craft Launcher 2/Modules/ModSecret.vb
Original file line number Diff line number Diff line change
Expand Up @@ -326,33 +326,32 @@ Friend Module ModSecret
End Sub
Public Sub UpdateReplace(ProcessId As Integer, OldFileName As String, NewFileName As String, TriggerRestart As Boolean)
Try
Process.GetProcessById(ProcessId).Kill()
Dim ps = Process.GetProcessById(ProcessId)
If Not ps.HasExited Then
ps.Kill()
End If
Catch ex As Exception
End Try
Dim OriginalPath As String = Strings.Mid(Path, 1, Path.Length - 4) + GetFileNameFromPath(OldFileName)
Dim TempPath As String = Strings.Mid(Path, 1, Path.Length - 4) + GetFileNameFromPath(NewFileName)
Dim ex2 As Exception = Nothing
Dim num As Integer = 0
Do
Try
If File.Exists(OriginalPath) Then
File.Delete(OriginalPath)
End If
If File.Exists(TempPath) Then
File.Delete(TempPath)
If File.Exists(OldFileName) Then
File.Delete(OldFileName)
End If
If Not File.Exists(OriginalPath) AndAlso Not File.Exists(TempPath) Then
If Not File.Exists(OldFileName) Then
Exit Try
End If
Thread.Sleep(2000)
Catch ex3 As Exception
ex2 = ex3
Finally
Thread.Sleep(500)
End Try
num += 1
Loop While num <= 4
If Not File.Exists(OriginalPath) AndAlso Not File.Exists(TempPath) Then
If (Not File.Exists(OldFileName)) AndAlso File.Exists(NewFileName) Then
Try
CopyFile(OriginalPath, TempPath)
CopyFile(NewFileName, OldFileName)
Catch ex4 As UnauthorizedAccessException
MsgBox("PCL 更新失败:权限不足。请手动复制 PCL 文件夹下的新版本程序。" & vbCrLf & "若 PCL 位于桌面或 C 盘,你可以尝试将其挪到其他文件夹,这可能可以解决权限问题。" & vbCrLf + GetExceptionSummary(ex4), MsgBoxStyle.Critical, "更新失败")
Catch ex5 As Exception
Expand All @@ -361,15 +360,21 @@ Friend Module ModSecret
End Try
If TriggerRestart Then
Try
Process.Start(TempPath)
Process.Start(OldFileName)
Catch ex6 As Exception
MsgBox("PCL 更新失败:无法重新启动。" & vbCrLf + GetExceptionSummary(ex6), MsgBoxStyle.Critical, "更新失败")
End Try
End If
Return
End If
If TypeOf ex2 Is UnauthorizedAccessException Then
MsgBox(String.Concat(New String() {"由于权限不足,PCL 无法完成更新。请尝试:" & vbCrLf, If((TempPath.StartsWithF(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), False) OrElse TempPath.StartsWithF(Environment.GetFolderPath(Environment.SpecialFolder.Personal), False)), " - 将 PCL 文件移动到桌面、文档以外的文件夹(这或许可以一劳永逸地解决权限问题)" & vbCrLf, ""), If(TempPath.StartsWithF("C", True), " - 将 PCL 文件移动到 C 盘以外的文件夹(这或许可以一劳永逸地解决权限问题)" & vbCrLf, ""), " - 右键以管理员身份运行 PCL" & vbCrLf & " - 手动复制已下载到 PCL 文件夹下的新版本程序,覆盖原程序" & vbCrLf & vbCrLf, GetExceptionSummary(ex2)}), MsgBoxStyle.Critical, "更新失败")
MsgBox(String.Concat(New String() {"由于权限不足,PCL 无法完成更新。请尝试:" & vbCrLf,
If((Path.StartsWithF(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), False) OrElse Path.StartsWithF(Environment.GetFolderPath(Environment.SpecialFolder.Personal), False)),
" - 将 PCL 文件移动到桌面、文档以外的文件夹(这或许可以一劳永逸地解决权限问题)" & vbCrLf, ""),
If(Path.StartsWithF("C", True),
" - 将 PCL 文件移动到 C 盘以外的文件夹(这或许可以一劳永逸地解决权限问题)" & vbCrLf, ""),
" - 右键以管理员身份运行 PCL" & vbCrLf & " - 手动复制已下载到 PCL 文件夹下的新版本程序,覆盖原程序" & vbCrLf & vbCrLf,
GetExceptionSummary(ex2)}), MsgBoxStyle.Critical, "更新失败")
Return
End If
MsgBox("PCL 更新失败:无法删除原文件。请手动复制已下载到 PCL 文件夹下的新版本程序覆盖原程序。" & vbCrLf + GetExceptionSummary(ex2), MsgBoxStyle.Critical, "更新失败")
Expand Down

0 comments on commit 7dfa823

Please sign in to comment.