This commit is contained in:
龙腾猫跃
2023-11-27 00:49:59 +08:00
parent e2a3dd3281
commit 2c7b532188
50 changed files with 1552 additions and 782 deletions
+20 -10
View File
@@ -11,12 +11,12 @@ Public Module ModBase
#Region "声明"
'下列版本信息由更新器自动修改
Public Const VersionBaseName As String = "2.6.100" '不含分支前缀的显示用版本名
Public Const VersionStandardCode As String = "2.6.100." & VersionBranchCode '标准格式的四段式版本号
Public Const VersionBaseName As String = "2.6.11" '不含分支前缀的显示用版本名
Public Const VersionStandardCode As String = "2.6.11." & VersionBranchCode '标准格式的四段式版本号
#If BETA Then
Public Const VersionCode As Integer = 308 'Release
#Else
Public Const VersionCode As Integer = 307 'Snapshot
Public Const VersionCode As Integer = 309 'Snapshot
#End If
'自动生成的版本信息
Public Const VersionDisplayName As String = VersionBranchName & " " & VersionBaseName
@@ -560,7 +560,7 @@ Public Module ModBase
''' <summary>
''' 重命名一个注册表子键。不可用于包含子键的子键。
''' </summary>
Public Sub RegRename(parentKey As Microsoft.Win32.RegistryKey, subKeyName As String, newSubKeyName As String)
Public Sub RenameReg(parentKey As Microsoft.Win32.RegistryKey, subKeyName As String, newSubKeyName As String)
If parentKey.GetSubKeyNames().Contains(newSubKeyName) Then parentKey.DeleteSubKeyTree(newSubKeyName, False)
Dim SourceKey As Microsoft.Win32.RegistryKey = parentKey.OpenSubKey(subKeyName)
If IsNothing(SourceKey) Then Exit Sub '没有目标项
@@ -1062,7 +1062,7 @@ Public Module ModBase
''' <summary>
''' 获取文件 MD5,若失败则返回空字符串。
''' </summary>
Public Function GetAuthMD5(FilePath As String) As String
Public Function GetFileMD5(FilePath As String) As String
Dim Retry As Boolean = False
Re:
Try
@@ -1091,7 +1091,7 @@ Re:
''' <summary>
''' 获取文件 SHA256,若失败则返回空字符串。
''' </summary>
Public Function GetAuthSHA256(FilePath As String) As String
Public Function GetFileSHA256(FilePath As String) As String
Dim Retry As Boolean = False
Re:
Try
@@ -1122,7 +1122,7 @@ Re:
''' <summary>
''' 获取文件 SHA1,若失败则返回空字符串。
''' </summary>
Public Function GetAuthSHA1(FilePath As String) As String
Public Function GetFileSHA1(FilePath As String) As String
Dim Retry As Boolean = False
Re:
Try
@@ -1210,11 +1210,11 @@ Re:
If MinSize >= 0 AndAlso MinSize > FileSize Then Return "文件大小应大于 " & MinSize & " B,实际为 " & FileSize & " B"
If Not String.IsNullOrEmpty(Hash) Then
If Hash.Length < 35 Then 'MD5
If Hash.ToLowerInvariant <> GetAuthMD5(LocalPath) Then Return "文件 MD5 应为 " & Hash & ",实际为 " & GetAuthMD5(LocalPath)
If Hash.ToLowerInvariant <> GetFileMD5(LocalPath) Then Return "文件 MD5 应为 " & Hash & ",实际为 " & GetFileMD5(LocalPath)
ElseIf Hash.Length = 64 Then 'SHA256
If Hash.ToLowerInvariant <> GetAuthSHA256(LocalPath) Then Return "文件 SHA256 应为 " & Hash & ",实际为 " & GetAuthSHA256(LocalPath)
If Hash.ToLowerInvariant <> GetFileSHA256(LocalPath) Then Return "文件 SHA256 应为 " & Hash & ",实际为 " & GetFileSHA256(LocalPath)
Else 'SHA1 (40)
If Hash.ToLowerInvariant <> GetAuthSHA1(LocalPath) Then Return "文件 SHA1 应为 " & Hash & ",实际为 " & GetAuthSHA1(LocalPath)
If Hash.ToLowerInvariant <> GetFileSHA1(LocalPath) Then Return "文件 SHA1 应为 " & Hash & ",实际为 " & GetFileSHA1(LocalPath)
End If
End If
If IsJson Then
@@ -2321,6 +2321,16 @@ Retry:
Return Thread.CurrentThread.ManagedThreadId = UiThreadId
End Function
''' <summary>
''' 检查某个控件是否位于主窗口可视区域内,且控件本身可见。
''' </summary>
<Extension> Public Function IsVisibleInForm(element As FrameworkElement) As Boolean
If Not element.IsVisible Then Return False
Dim bounds As Rect = element.TransformToAncestor(FrmMain).TransformBounds(New Rect(0, 0, element.ActualWidth, element.ActualHeight))
Dim rect As New Rect(0, 0, FrmMain.ActualWidth, FrmMain.ActualHeight)
Return rect.Contains(bounds.TopLeft) OrElse rect.Contains(bounds.BottomRight)
End Function
#End Region
#Region "Debug"
@@ -153,10 +153,14 @@
End Select
End Get
Set(value As Double)
If _Progress = value Then Exit Property
Dim OldValue = _Progress
_Progress = value
RaiseEvent ProgressChanged(value, OldValue)
End Set
End Property
Private _Progress As Double = -1
Public Event ProgressChanged(NewProgress As Double, OldProgress As Double) Implements ILoadingTrigger.ProgressChanged
''' <summary>
''' 计算总进度时的权重。它应该为预计时间(秒)。
''' </summary>
@@ -236,12 +240,16 @@
''' </summary>
Public ReadOnly Property IsAborted As Boolean
Get
Return LastRunningThread Is Nothing OrElse
Not ReferenceEquals(Thread.CurrentThread, LastRunningThread) OrElse
State = LoadState.Aborted
Return IsAbortedWithThread(Thread.CurrentThread)
End Get
End Property
''' <summary>
''' 当前执行线程是否应当中断。需要手动提供加载器线程,用于需要跨线程检查的情况。
''' </summary>
Public Function IsAbortedWithThread(Thread As Thread) As Boolean
Return LastRunningThread Is Nothing OrElse Not ReferenceEquals(Thread, LastRunningThread) OrElse State = LoadState.Aborted
End Function
''' <summary>
''' 在输入相同时使用原有结果的超时,单位为毫秒。
''' </summary>
Public ReloadTimeout As Integer = -1