2.12.8.1
This commit is contained in:
@@ -10,12 +10,12 @@ Public Module ModBase
|
||||
#Region "声明"
|
||||
|
||||
'下列版本信息由更新器自动修改
|
||||
Public Const VersionBaseName As String = "2.12.8.0" '显示用版本名
|
||||
Public Const VersionBaseName As String = "2.12.8.1" '显示用版本名
|
||||
Public Const CommitHash As String = "" 'Commit Hash,由 GitHub Workflow 自动替换
|
||||
#If RELEASE Then
|
||||
Public Const VersionCode As Integer = 400 '正式版
|
||||
Public Const VersionCode As Integer = 402 '正式版
|
||||
#Else
|
||||
Public Const VersionCode As Integer = 399 '快照版
|
||||
Public Const VersionCode As Integer = 401 '快照版
|
||||
#End If
|
||||
|
||||
'版本信息
|
||||
@@ -710,13 +710,13 @@ Public Module ModBase
|
||||
End If
|
||||
If Not String.IsNullOrEmpty(Hash) Then
|
||||
If Hash.Length < 35 Then 'MD5
|
||||
Dim md5 As String = HashUtils.ComputeFromFile(LocalPath, HashUtils.HashMethod.Md5)
|
||||
Dim md5 As String = CryptographyUtils.ComputeFileHash(LocalPath, CryptographyUtils.HashMethod.Md5)
|
||||
If Hash.Lower <> md5 Then Return "文件 MD5 应为 " & Hash & ",实际为 " & md5
|
||||
ElseIf Hash.Length = 64 Then 'SHA256
|
||||
Dim sha256 As String = HashUtils.ComputeFromFile(LocalPath, HashUtils.HashMethod.Sha256)
|
||||
Dim sha256 As String = CryptographyUtils.ComputeFileHash(LocalPath, CryptographyUtils.HashMethod.Sha256)
|
||||
If Hash.Lower <> sha256 Then Return "文件 SHA256 应为 " & Hash & ",实际为 " & sha256
|
||||
Else 'SHA1 (40)
|
||||
Dim sha1 As String = HashUtils.ComputeFromFile(LocalPath, HashUtils.HashMethod.Sha1)
|
||||
Dim sha1 As String = CryptographyUtils.ComputeFileHash(LocalPath, CryptographyUtils.HashMethod.Sha1)
|
||||
If Hash.Lower <> sha1 Then Return "文件 SHA1 应为 " & Hash & ",实际为 " & sha1
|
||||
End If
|
||||
End If
|
||||
@@ -793,30 +793,6 @@ Public Module ModBase
|
||||
End Try
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
''' 获取字符串哈希值。
|
||||
''' </summary>
|
||||
Public Function GetHash(Str As String) As ULong
|
||||
Dim Result As ULong = 5381
|
||||
For Each v In Str
|
||||
Result = (Result << 5) Xor Result Xor CType(AscW(v), ULong)
|
||||
Next
|
||||
Return Result Xor &HA98F501BC684032FUL
|
||||
End Function
|
||||
''' <summary>
|
||||
''' 获取字符串 MD5。
|
||||
''' </summary>
|
||||
Public Function GetStringMD5(Str As String) As String
|
||||
Using h = MD5Cng.Create()
|
||||
Dim hashedDataBytes = h.ComputeHash(Encoding.UTF8.GetBytes(Str))
|
||||
Dim tmp As New StringBuilder(hashedDataBytes.Length * 2)
|
||||
For Each i As Byte In hashedDataBytes
|
||||
tmp.Append(i.ToString("x2"))
|
||||
Next
|
||||
Return tmp.ToString()
|
||||
End Using
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
''' 不会报错的 Val。
|
||||
''' 如果输入有误,返回 0。
|
||||
@@ -1399,12 +1375,17 @@ Public Module ModBase
|
||||
''' 将程序中的资源释放到文件。
|
||||
''' </summary>
|
||||
Public Sub ExtractResources(FilePath As String, ResourceName As String)
|
||||
Logger.Info($"将资源写入到文件:{ResourceName} → {FilePath}")
|
||||
Dim Resource = My.Resources.ResourceManager.GetObject(ResourceName)
|
||||
If TypeOf Resource Is Byte() Then
|
||||
FileUtils.Write(FilePath, DirectCast(Resource, Byte()))
|
||||
Dim Bytes = DirectCast(Resource, Byte())
|
||||
If FileUtils.Exists(FilePath) AndAlso CryptographyUtils.ComputeFileHash(FilePath) = CryptographyUtils.ComputeHash(Bytes) Then Return
|
||||
Logger.Info($"将资源写入到文件:{ResourceName} → {FilePath}")
|
||||
FileUtils.Write(FilePath, Bytes)
|
||||
ElseIf TypeOf Resource Is String Then
|
||||
FileUtils.Write(FilePath, DirectCast(Resource, String))
|
||||
Dim Content = DirectCast(Resource, String)
|
||||
If FileUtils.Exists(FilePath) AndAlso FileUtils.ReadAsString(FilePath) = Content Then Return
|
||||
Logger.Info($"将资源写入到文件:{ResourceName} → {FilePath}")
|
||||
FileUtils.Write(FilePath, Content)
|
||||
Else
|
||||
Throw New Exception($"资源 {ResourceName} 的类型不支持:{Resource.GetType.Name}")
|
||||
End If
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
Implements ILoadingTrigger
|
||||
|
||||
Public ReadOnly Property IsLoader As Boolean = True Implements ILoadingTrigger.IsLoader
|
||||
Protected Shared LogBlackList As String() = {"EasyTier CLI"}
|
||||
|
||||
'基础属性
|
||||
''' <summary>
|
||||
@@ -90,7 +89,7 @@
|
||||
Dim OldState = _State
|
||||
If value = LoadState.Finished AndAlso Settings.Get(Of Boolean)("SystemDebugDelay") Then Thread.Sleep(RandomInteger(100, 2000))
|
||||
_State = value
|
||||
If Not LogBlackList.Contains(Name) Then Logger.Info($"加载器 {Name} 状态改变:{value}")
|
||||
Logger.Log($"加载器 {Name} 状态改变:{value}", If(value = LoadState.Failed, LogLevel.Error, LogLevel.Info))
|
||||
'实现 ILoadingTrigger 接口与 OnStateChanged 回调
|
||||
RunInUi(
|
||||
Sub()
|
||||
@@ -319,13 +318,13 @@
|
||||
Sub()
|
||||
Try
|
||||
IsForceRestarting = IsForceRestart
|
||||
If Not LogBlackList.Contains(Name) Then Logger.Trace(Function() $"加载线程 {Name} ({Thread.CurrentThread.ManagedThreadId}) 已{If(IsForceRestarting, "强制", "")}启动")
|
||||
Logger.Trace(Function() $"加载线程 {Name} ({Thread.CurrentThread.ManagedThreadId}) 已{If(IsForceRestarting, "强制", "")}启动")
|
||||
LoadDelegate(Me)
|
||||
If IsInterrupted Then
|
||||
Logger.Warn($"加载线程 {Name} ({Thread.CurrentThread.ManagedThreadId}) 已中断但线程正常运行至结束,输出被弃用(最新线程:{If(LastRunningThread Is Nothing, -1, LastRunningThread.ManagedThreadId)})")
|
||||
Return
|
||||
End If
|
||||
If Not LogBlackList.Contains(Name) Then Logger.Trace(Function() $"加载线程 {Name} ({Thread.CurrentThread.ManagedThreadId}) 已完成")
|
||||
Logger.Trace(Function() $"加载线程 {Name} ({Thread.CurrentThread.ManagedThreadId}) 已完成")
|
||||
RaisePreviewFinish()
|
||||
State = LoadState.Finished
|
||||
LastFinishedTime = GetTimeMs() '未中断,本次输出有效
|
||||
|
||||
@@ -261,8 +261,11 @@ Retry:
|
||||
})
|
||||
End If
|
||||
End SyncLock
|
||||
CancelToken.Dispose() : CancelToken = New CancellationTokenSource(Timeout)
|
||||
Response = RequestClient.SendAsync(Request, HttpCompletionOption.ResponseHeadersRead, CancelToken.Token).GetResultWithTimeout(CancelToken, Timeout)
|
||||
ResilientUtils.RetryOn(Of FileNotFoundException, IOException)( 'CacheCow 读取缓存时若文件被占用,会调用不存在的 System.Net.Http.Formatting.resources,抛出此异常(#8150)
|
||||
Sub()
|
||||
CancelToken.Dispose() : CancelToken = New CancellationTokenSource(Timeout)
|
||||
Response = RequestClient.SendAsync(Request, HttpCompletionOption.ResponseHeadersRead, CancelToken.Token).GetResultWithTimeout(CancelToken, Timeout)
|
||||
End Sub)
|
||||
Dim ResponseBytes As Byte()
|
||||
CancelToken.Dispose() : CancelToken = New CancellationTokenSource(Timeout)
|
||||
Using ResponseStream = Response.Content.ReadAsStreamAsync().GetResultWithTimeout(CancelToken, Timeout)
|
||||
@@ -286,9 +289,6 @@ Retry:
|
||||
Throw
|
||||
Catch ex As HttpRequestException
|
||||
Throw
|
||||
Catch ex As FileNotFoundException
|
||||
'由于 CacheCow 读取缓存失败,然后系统调用不存在的 System.Net.Http.Formatting.resources 抛出(#8150)
|
||||
Throw New Exception($"网络请求时读取缓存失败", ex)
|
||||
Catch ex As Exception
|
||||
RecordIPReliability(HostIp, -1)
|
||||
If TypeOf ex Is OperationCanceledException OrElse TypeOf ex Is TimeoutException Then 'CancellationToken 超时
|
||||
|
||||
Reference in New Issue
Block a user