Prevent use of reserved variable names for custom variables for #148 and #152

This commit is contained in:
Michael J. Seiferling
2018-09-14 09:50:24 -06:00
parent ace287f42a
commit 333f7ac36a
5 changed files with 33 additions and 1 deletions
+6
View File
@@ -289,6 +289,12 @@ Public Class frmVariableManager
Return False Return False
End If End If
If mgrVariables.GetReservedVariables.Contains(txtName.Text.ToUpper) Then
mgrCommon.ShowMessage(frmVariableManager_ErrorVariableReserved, txtName.Text, MsgBoxStyle.Exclamation)
txtName.Focus()
Return False
End If
Return True Return True
End Function End Function
+3 -1
View File
@@ -501,6 +501,8 @@ Public Class mgrPath
Public Shared Function VerifyCustomVariables(ByVal hshScanlist As Hashtable, ByRef sGames As String) As Boolean Public Shared Function VerifyCustomVariables(ByVal hshScanlist As Hashtable, ByRef sGames As String) As Boolean
Dim hshCustomVariables As Hashtable = mgrVariables.ReadVariables Dim hshCustomVariables As Hashtable = mgrVariables.ReadVariables
'Reserved variables will be resolved on Windows, but not on a Linux. Therefore we an ignore list here, otherwise GBM will bitch about them when using Windows configurations for Wine.
Dim oReservedVariables As List(Of String) = mgrVariables.GetReservedVariables
Dim sVariableCheck As String Dim sVariableCheck As String
Dim sPattern As String = "\%(.*)\%" Dim sPattern As String = "\%(.*)\%"
Dim oGame As clsGame Dim oGame As clsGame
@@ -511,7 +513,7 @@ Public Class mgrPath
oMatch = Regex.Match(oGame.Path, sPattern) oMatch = Regex.Match(oGame.Path, sPattern)
If oMatch.Success Then If oMatch.Success Then
sVariableCheck = oMatch.Value.Replace("%", String.Empty) sVariableCheck = oMatch.Value.Replace("%", String.Empty)
If Not hshCustomVariables.ContainsKey(sVariableCheck) Then If Not hshCustomVariables.ContainsKey(sVariableCheck) And Not oReservedVariables.Contains(sVariableCheck) Then
sGames &= vbCrLf & oGame.Name & " (" & sVariableCheck & ")" sGames &= vbCrLf & oGame.Name & " (" & sVariableCheck & ")"
bClean = False bClean = False
End If End If
+12
View File
@@ -154,4 +154,16 @@
Return hshList Return hshList
End Function End Function
Public Shared Function GetReservedVariables() As List(Of String)
Dim oList As New List(Of String)
oList.Add("APPDATA")
oList.Add("LOCALAPPDATA")
oList.Add("USERDOCUMENTS")
oList.Add("COMMONDOCUMENTS")
oList.Add("USERPROFILE")
Return oList
End Function
End Class End Class
+9
View File
@@ -5442,6 +5442,15 @@ Namespace My.Resources
End Get End Get
End Property End Property
'''<summary>
''' Looks up a localized string similar to [PARAM] is a reserved variable, you must enter a different name..
'''</summary>
Friend ReadOnly Property frmVariableManager_ErrorVariableReserved() As String
Get
Return ResourceManager.GetString("frmVariableManager_ErrorVariableReserved", resourceCulture)
End Get
End Property
'''<summary> '''<summary>
''' Looks up a localized string similar to Custom Variable Manager. ''' Looks up a localized string similar to Custom Variable Manager.
'''</summary> '''</summary>
+3
View File
@@ -2251,4 +2251,7 @@
<data name="frmGameManager_WarningImportBackup" xml:space="preserve"> <data name="frmGameManager_WarningImportBackup" xml:space="preserve">
<value>This feature is intended to import 7-Zip backup archives compatible with the selected game configuration.[BR][BR]GBM does NOT verify these files, you should only use files created by GBM or other compatible archives that were created using the same settings as the current game configuration.[BR][BR]This message will only be shown once.</value> <value>This feature is intended to import 7-Zip backup archives compatible with the selected game configuration.[BR][BR]GBM does NOT verify these files, you should only use files created by GBM or other compatible archives that were created using the same settings as the current game configuration.[BR][BR]This message will only be shown once.</value>
</data> </data>
<data name="frmVariableManager_ErrorVariableReserved" xml:space="preserve">
<value>[PARAM] is a reserved variable, you must enter a different name.</value>
</data>
</root> </root>