Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 19 additions & 14 deletions Plain Craft Launcher 2/Modules/Base/ModValidate.vb
Original file line number Diff line number Diff line change
Expand Up @@ -220,16 +220,18 @@ Public Class ValidateFolderName
Inherits Validate
Public Property Path As String
Public Property UseMinecraftCharCheck As Boolean = True
Public Property IgnoreCase As Boolean = True
Private ReadOnly PathIgnore As IEnumerable(Of DirectoryInfo)
Private ReadOnly PathDirs As IEnumerable(Of DirectoryInfo) = {}
Public Property OldName As String = Nothing
Public Sub New()
End Sub
Public Sub New(Path As String, Optional UseMinecraftCharCheck As Boolean = True, Optional IgnoreCase As Boolean = True)
Public Sub New(Path As String, Optional UseMinecraftCharCheck As Boolean = True, Optional OldName As String = Nothing)
Me.Path = Path
Me.IgnoreCase = IgnoreCase
Me.UseMinecraftCharCheck = UseMinecraftCharCheck
On Error Resume Next
PathIgnore = New DirectoryInfo(Path).EnumerateDirectories
Try
PathDirs = New DirectoryInfo(Path).EnumerateDirectories
Catch ex As Exception
End Try
Me.OldName = OldName
End Sub
Public Overrides Function Validate(Str As String) As String
Try
Expand All @@ -253,14 +255,17 @@ Public Class ValidateFolderName
'检查 NTFS 8.3 文件名(#4505)
If RegexCheck(Str, ".{2,}~\d") Then Return "文件夹名不能包含这一特殊格式!"
'检查文件夹重名
Dim Arr As New List(Of String)
If PathIgnore IsNot Nothing Then
For Each Folder As DirectoryInfo In PathIgnore
Arr.Add(Folder.Name)
Next
Dim SameNameCheck = New ValidateExceptSame(PathDirs.Select(Function(di As DirectoryInfo) di.Name).ToArray(), "不可与现有文件夹重名!", IgnoreCase:=True).Validate(Str)
If Not SameNameCheck = "" Then
'进行重命名相关的特判
If OldName?.Equals(Str, StringComparison.OrdinalIgnoreCase) Then
If OldName.Equals(Str) Then
Return "请输入一个不同的名称!"
End If
Else
Return SameNameCheck
End If
End If
Dim SameNameCheck = New ValidateExceptSame(Arr, "不可与现有文件夹重名!", IgnoreCase).Validate(Str)
If Not SameNameCheck = "" Then Return SameNameCheck
Return ""
Catch ex As Exception
Log(ex, "检查文件夹名出错")
Expand Down Expand Up @@ -377,4 +382,4 @@ Fin:
Next
Return ""
End Function
End Class
End Class
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
Dim OldName As String = PageVersionLeft.Version.Name
Dim OldPath As String = PageVersionLeft.Version.Path
'修改此部分的同时修改快速安装的版本名检测*
Dim NewName As String = MyMsgBoxInput("重命名版本", "", OldName, New ObjectModel.Collection(Of Validate) From {New ValidateFolderName(PathMcFolder & "versions", IgnoreCase:=False)})
Dim NewName As String = MyMsgBoxInput("重命名版本", "", OldName, New ObjectModel.Collection(Of Validate) From {New ValidateFolderName(PathMcFolder & "versions", OldName:=OldName)})
If String.IsNullOrWhiteSpace(NewName) Then Return
Dim NewPath As String = PathMcFolder & "versions\" & NewName & "\"
'获取临时中间名,以防止仅修改大小写的重命名失败
Expand Down