Fixed some filename and path validation problems

This commit is contained in:
Michael J. Seiferling
2018-03-17 08:27:01 -06:00
parent e07b2d226f
commit 52f7088ed7
3 changed files with 28 additions and 15 deletions
+2 -2
View File
@@ -38,7 +38,7 @@ Public Class clsGame
Property ID As String Property ID As String
Set(value As String) Set(value As String)
If Not value Is Nothing Then If Not value Is Nothing Then
sGameID = mgrPath.ValidateForFileSystem(value) sGameID = mgrPath.ValidateFileNameForOS(value)
End If End If
End Set End Set
Get Get
@@ -64,7 +64,7 @@ Public Class clsGame
ReadOnly Property FileSafeName As String ReadOnly Property FileSafeName As String
Get Get
Return mgrPath.ValidateForFileSystem(sGameName) Return mgrPath.ValidateFileNameForOS(sGameName)
End Get End Get
End Property End Property
+12 -9
View File
@@ -1204,20 +1204,24 @@ Public Class frmGameManager
If txtID.Text <> String.Empty Then If txtID.Text <> String.Empty Then
oApp.ID = txtID.Text oApp.ID = txtID.Text
End If End If
oApp.Name = txtName.Text oApp.Name = txtName.Text
oApp.IsRegEx = chkRegEx.Checked
If Not oApp.IsRegEx Then
txtProcess.Text = mgrPath.ValidateFileNameForOS(txtProcess.Text)
If Path.HasExtension(txtProcess.Text) Then If Path.HasExtension(txtProcess.Text) Then
If txtProcess.Text.ToLower.EndsWith(".exe") Then If txtProcess.Text.ToLower.EndsWith(".exe") Then
oApp.ProcessName = Path.GetFileNameWithoutExtension(txtProcess.Text) txtProcess.Text = Path.GetFileNameWithoutExtension(txtProcess.Text)
Else
oApp.ProcessName = txtProcess.Text
End If End If
Else
oApp.ProcessName = txtProcess.Text
End If End If
End If
oApp.ProcessName = txtProcess.Text
oApp.Parameter = txtParameter.Text oApp.Parameter = txtParameter.Text
oApp.Path = txtSavePath.Text oApp.Path = mgrPath.ValidatePathForOS(txtSavePath.Text)
'Only do a simple root check here in case the user doesn't really understand creating a proper configuration 'Only do a simple root check here in case the user doesn't really understand creating a proper configuration
oApp.AbsolutePath = Path.IsPathRooted(txtSavePath.Text) oApp.AbsolutePath = Path.IsPathRooted(oApp.Path)
oApp.FileType = txtFileType.Text oApp.FileType = txtFileType.Text
oApp.ExcludeList = txtExclude.Text oApp.ExcludeList = txtExclude.Text
oApp.FolderSave = chkFolderSave.Checked oApp.FolderSave = chkFolderSave.Checked
@@ -1225,10 +1229,9 @@ Public Class frmGameManager
oApp.AppendTimeStamp = chkTimeStamp.Checked oApp.AppendTimeStamp = chkTimeStamp.Checked
oApp.BackupLimit = nudLimit.Value oApp.BackupLimit = nudLimit.Value
oApp.Comments = txtComments.Text oApp.Comments = txtComments.Text
oApp.IsRegEx = chkRegEx.Checked
oApp.Enabled = chkEnabled.Checked oApp.Enabled = chkEnabled.Checked
oApp.MonitorOnly = chkMonitorOnly.Checked oApp.MonitorOnly = chkMonitorOnly.Checked
oApp.ProcessPath = txtAppPath.Text oApp.ProcessPath = mgrPath.ValidatePathForOS(txtAppPath.Text)
oApp.Company = txtCompany.Text oApp.Company = txtCompany.Text
oApp.Version = txtVersion.Text oApp.Version = txtVersion.Text
oApp.Icon = txtIcon.Text oApp.Icon = txtIcon.Text
+12 -2
View File
@@ -99,8 +99,18 @@ Public Class mgrPath
End Set End Set
End Property End Property
Public Shared Function ValidateForFileSystem(ByVal sCheckString As String) As String Public Shared Function ValidatePathForOS(ByVal sCheckString As String) As String
Dim cInvalidCharacters As Char() = {"\", "/", ":", "*", "?", """", "<", ">", "|", "."} Dim cInvalidCharacters As Char() = Path.GetInvalidPathChars
For Each c As Char In cInvalidCharacters
sCheckString = sCheckString.Replace(c, "")
Next
Return sCheckString.Trim
End Function
Public Shared Function ValidateFileNameForOS(ByVal sCheckString As String) As String
Dim cInvalidCharacters As Char() = Path.GetInvalidFileNameChars
For Each c As Char In cInvalidCharacters For Each c As Char In cInvalidCharacters
sCheckString = sCheckString.Replace(c, "") sCheckString = sCheckString.Replace(c, "")