This commit is contained in:
龙腾猫跃
2023-10-07 05:29:24 +08:00
parent 5ff7aed46e
commit 037e6b19b4
29 changed files with 252 additions and 221 deletions
+16 -10
View File
@@ -1,8 +1,8 @@
Imports System.IO.Compression
Imports System.Management
Imports System.Runtime.CompilerServices
Imports System.Security.Cryptography
Imports System.Security.Principal
Imports System.Text.RegularExpressions
Imports System.Windows.Markup
Imports Newtonsoft.Json
@@ -11,12 +11,12 @@ Public Module ModBase
#Region "声明"
'下列版本信息由更新器自动修改
Public Const VersionBaseName As String = "2.6.8" '不含分支前缀的显示用版本名
Public Const VersionStandardCode As String = "2.6.8." & VersionBranchCode '标准格式的四段式版本号
Public Const VersionBaseName As String = "2.6.9" '不含分支前缀的显示用版本名
Public Const VersionStandardCode As String = "2.6.9." & VersionBranchCode '标准格式的四段式版本号
#If BETA Then
Public Const VersionCode As Integer = 304 'Release
#Else
Public Const VersionCode As Integer = 305 'Snapshot
Public Const VersionCode As Integer = 306 'Snapshot
#End If
'自动生成的版本信息
Public Const VersionDisplayName As String = VersionBranchName & " " & VersionBaseName
@@ -1581,12 +1581,12 @@ Re:
''' <summary>
''' 搜索字符串中的所有正则匹配项。
''' </summary>
Public Function RegexSearch(str As String, regex As String, Optional options As RegularExpressions.RegexOptions = RegularExpressions.RegexOptions.None) As List(Of String)
Public Function RegexSearch(str As String, regex As String, Optional options As RegexOptions = RegularExpressions.RegexOptions.None) As List(Of String)
Try
RegexSearch = New List(Of String)
Dim RegexSearchRes = New RegularExpressions.Regex(regex, options).Matches(str)
Dim RegexSearchRes = New Regex(regex, options).Matches(str)
If RegexSearchRes Is Nothing Then Return RegexSearch
For Each item As RegularExpressions.Match In RegexSearchRes
For Each item As Match In RegexSearchRes
RegexSearch.Add(item.Value)
Next
Catch ex As Exception
@@ -1597,7 +1597,7 @@ Re:
''' <summary>
''' 获取字符串中的第一个正则匹配项,若无匹配则返回 Nothing。
''' </summary>
Public Function RegexSeek(str As String, regex As String, Optional options As RegularExpressions.RegexOptions = RegularExpressions.RegexOptions.None) As String
Public Function RegexSeek(str As String, regex As String, Optional options As RegexOptions = RegularExpressions.RegexOptions.None) As String
Try
Dim Result = RegularExpressions.Regex.Match(str, regex, options).Value
Return If(Result = "", Nothing, Result)
@@ -1609,7 +1609,7 @@ Re:
''' <summary>
''' 检查字符串是否匹配某正则模式。
''' </summary>
Public Function RegexCheck(str As String, regex As String, Optional options As RegularExpressions.RegexOptions = RegularExpressions.RegexOptions.None) As Boolean
Public Function RegexCheck(str As String, regex As String, Optional options As RegexOptions = RegularExpressions.RegexOptions.None) As Boolean
Try
Return RegularExpressions.Regex.IsMatch(str, regex, options)
Catch ex As Exception
@@ -1620,7 +1620,13 @@ Re:
''' <summary>
''' 进行正则替换,会抛出错误。
''' </summary>
Public Function RegexReplace(Input As String, Replacement As String, Regex As String, Optional options As RegularExpressions.RegexOptions = RegularExpressions.RegexOptions.None) As String
Public Function RegexReplace(Input As String, Replacement As String, Regex As String, Optional options As RegexOptions = RegularExpressions.RegexOptions.None) As String
Return RegularExpressions.Regex.Replace(Input, Regex, Replacement, options)
End Function
''' <summary>
''' 对每个正则匹配分别进行替换,会抛出错误。
''' </summary>
Public Function RegexReplaceEach(Input As String, Replacement As MatchEvaluator, Regex As String, Optional options As RegexOptions = RegularExpressions.RegexOptions.None) As String
Return RegularExpressions.Regex.Replace(Input, Regex, Replacement, options)
End Function
+5 -13
View File
@@ -330,7 +330,7 @@ Retry:
''' <summary>
''' 同时发送多个网络请求并要求返回内容。
''' </summary>
Public Function NetRequestMuity(Url As String, Method As String, Data As Object, ContentType As String, Optional RequestCount As Integer = 4, Optional Headers As Dictionary(Of String, String) = Nothing)
Public Function NetRequestMulty(Url As String, Method As String, Data As Object, ContentType As String, Optional RequestCount As Integer = 4, Optional Headers As Dictionary(Of String, String) = Nothing)
Dim Threads As New List(Of Thread)
Dim RequestResult = Nothing
Dim RequestEx As Exception = Nothing
@@ -1278,14 +1278,6 @@ Wrong:
Try
Retry:
SyncLock LockChain
''大小检测
'If DownloadDone <> FileSize AndAlso Not IsUnknownSize Then
' For Each Th As NetThread In Threads
' Log("[Download] " & "File size detail: ")
' Log("[Download] " & Th.Uuid & "#, State " & GetStringFromEnum(CType(Th.State, [Enum])) & ", Range " & Th.DownloadStart & "~" & (Th.DownloadStart + Th.DownloadDone) & ", Left " & Th.DownloadUndone)
' Next
' Throw New Exception("文件大小应为 " & FileSize & " B,实际下载为 " & DownloadDone & " B。")
'End If
If ModeDebug Then Log("[Download] " & LocalName & ":正在合并文件")
'创建文件夹
If File.Exists(LocalPath) Then File.Delete(LocalPath)
@@ -1299,7 +1291,7 @@ Retry:
AddWriter.Write(SmailFileCache.ToArray)
AddWriter.Dispose() : AddWriter = Nothing
MergeFile.Dispose() : MergeFile = Nothing
ElseIf Threads.DownloadDone = DownloadDone Then
ElseIf Threads.DownloadDone = DownloadDone AndAlso Threads.Temp IsNot Nothing Then
'仅有一个文件,直接复制
CopyFile(Threads.Temp, LocalPath)
Else
@@ -1307,7 +1299,7 @@ Retry:
MergeFile = New FileStream(LocalPath, FileMode.Create)
AddWriter = New BinaryWriter(MergeFile)
For Each Thread As NetThread In Threads
If Thread.DownloadDone = 0 Then Continue For
If Thread.DownloadDone = 0 OrElse Thread.Temp Is Nothing Then Continue For
Using fs As New FileStream(Thread.Temp, FileMode.Open, FileAccess.Read, FileShare.Read)
Dim TempReader As New BinaryReader(fs)
AddWriter.Write(TempReader.ReadBytes(fs.Length))
@@ -1328,9 +1320,9 @@ Retry:
'检查文件
Dim CheckResult As String = Check?.Check(LocalPath)
If CheckResult IsNot Nothing Then
Log("[Download] " & "File size detail of " & Uuid & "# :")
Log("[Download] " & Uuid & "# 的下载线程细节:")
For Each Th As NetThread In Threads
Log("[Download] " & Th.Uuid & "#, State " & GetStringFromEnum(CType(Th.State, [Enum])) & ", Range " & Th.DownloadStart & "~" & (Th.DownloadStart + Th.DownloadDone) & ", Left " & Th.DownloadUndone)
Log("[Download] " & Th.Uuid & "#,状态 " & GetStringFromEnum(CType(Th.State, [Enum])) & ",字节范围 " & Th.DownloadStart & "~" & (Th.DownloadStart + Th.DownloadDone) & ",字节剩余 " & Th.DownloadUndone)
Next
Throw New Exception(CheckResult)
End If