0f8a2634bd
- modifiche per convertire meta espressioni in file lua in espressioni di interfaccia utente.
259 lines
12 KiB
VB.net
259 lines
12 KiB
VB.net
Imports System.Text.RegularExpressions
|
|
Imports System.IO
|
|
Imports EgtUILib
|
|
Imports EgtWPFLib5
|
|
|
|
Module RegexFunction
|
|
Friend sCurrVersionDoor As String = "1"
|
|
|
|
' restituisce vero se trova il capitoletto [Graphic parameters]
|
|
Friend Function IsGraphicParametersTitle(sLine As String) As Boolean
|
|
Return Regex.Match(sLine, "\s*--\s*(\[Graphic parameters\])\s*$").Groups(1).Value = "[Graphic parameters]"
|
|
End Function
|
|
|
|
' restituisce vero se trova il capitoletto [Match File]
|
|
Friend Function IsMatchingParameterTitle(sLine As String) As Boolean
|
|
Return Regex.Match(sLine, "\s*--\s*(\[Match File\])\s*$").Groups(1).Value = "[Match File]"
|
|
End Function
|
|
|
|
' restituisce vero se trova il capitoletto [DDF parameters]
|
|
Friend Function IsDDFParameterTitle(sLine As String) As Boolean
|
|
If Not sLine.Contains("--") Then Return False
|
|
Return Regex.Match(sLine, "\s*--\s*(\[DDF parameters\])\s*$").Groups(1).Value = "[DDF parameters]"
|
|
End Function
|
|
|
|
' restituisce la chiave commentata ( -- key =)
|
|
Friend Function KeyParamLine(sLine As String) As String
|
|
If sLine.Contains("--") Then
|
|
Return Regex.Match(sLine, "\s*--\s*(.*?\b)\s*=.*").Groups(1).Value
|
|
Else
|
|
Return String.Empty
|
|
End If
|
|
End Function
|
|
|
|
' restituisce un metadato scritto in una riga
|
|
Friend Function Metadata(sLine As String) As String
|
|
Return Regex.Match(sLine, "\s* ## \s*(.*)\s*$").Groups(1).Value
|
|
End Function
|
|
|
|
' Restituisce il valore scritto tra le parentesi tonde ()
|
|
Friend Function Brackets(sLine As String) As String
|
|
If Not sLine.Contains("("c) AndAlso Not sLine.Contains(")"c) Then Return sLine
|
|
Return Regex.Match(sLine, "\s*\(\s*(.*\b)\s*\).*").Groups(1).Value
|
|
End Function
|
|
|
|
' restituisce quello che segue l'uguale assegnata una parola chiave tra i due trattini e 'uguale
|
|
Friend Function ParamLine(sLine As String, sKey As String) As String
|
|
Return Regex.Match(sLine, "\s*--\s*(" & sKey & ")\s*=\s*(.*)\s*$").Groups(2).Value
|
|
End Function
|
|
|
|
' quando questa variabile è settata a vero allora leggo rimuovo i metacommenti in fase di lettura
|
|
Friend IsCompo As Boolean = False
|
|
' toglie il commento da una riga (conservando i metacomandi)
|
|
Friend Function RemoveComment(sLine As String) As String
|
|
sLine = sLine.Replace(DDF_METADATA, "§")
|
|
If sLine.Contains("#"c) Then
|
|
Dim bIgnoreConfig As Boolean = False
|
|
If Not IsNothing(Map.refAssemblyManagerVM) AndAlso Not IsNothing(Map.refAssemblyManagerVM.CurrProject) AndAlso
|
|
Not IsNothing(Map.refAssemblyManagerVM.CurrProject.SelAssemblyName) AndAlso
|
|
Not OptionModule.m_AskMeAgainConfirm Then
|
|
bIgnoreConfig = Map.refAssemblyManagerVM.CurrProject.SelAssemblyName.Name = Part.LastPartName
|
|
End If
|
|
If Not bIgnoreConfig AndAlso Not Part.bFirstConfigRead Then
|
|
Part.bFirstConfigRead = ReadConfig(sLine)
|
|
End If
|
|
sLine = Regex.Match(sLine, "\s*(.*?)\s*#.*$").Groups(1).Value
|
|
End If
|
|
If Not IsCompo Then
|
|
sLine = sLine.Replace("§", DDF_METADATA)
|
|
Else
|
|
sLine = sLine.Replace("§", "")
|
|
End If
|
|
|
|
Return sLine
|
|
End Function
|
|
|
|
' legge la configurazione scritta nelle linee di commento
|
|
Friend Function ReadConfig(sLine As String) As Boolean
|
|
' annullo l'ultiam selezione fatta
|
|
Part.LastPartName = String.Empty
|
|
' Se non c'è Config esco
|
|
If Not sLine.Contains("Config") Then Return False
|
|
' Processo il tipo di configurazione
|
|
Dim ConfigurationCompo As String = Regex.Match(sLine, "\s*:\s*(.*?)\s*$").Groups(1).Value
|
|
' verifico che il nome della configurazione del file DDF sia uguale a quella presente nel file Config.ini a meno delle "maiscuole"
|
|
If Not String.IsNullOrWhiteSpace(ConfigurationCompo) AndAlso
|
|
ConfigurationCompo.ToLower <> Path.GetFileName(IniFile.m_sDoorsDirPath).ToLower Then
|
|
Dim sConfCompoPath As String = Path.GetDirectoryName(IniFile.m_sDoorsDirPath) & "\" & ConfigurationCompo
|
|
If Not Directory.Exists(sConfCompoPath) Then
|
|
' 50196=Configuration program ({0}) does not exist!
|
|
Dim sErrorMsg As String = String.Format(EgtMsg(50196), ConfigurationCompo)
|
|
MessageBox.Show(sErrorMsg, "Error", MessageBoxButton.OK, MessageBoxImage.Error)
|
|
Else
|
|
' se abilitata la modifica delle configurazioni cambio messaggio e disabilito la chiusura del programma
|
|
If Map.refOptionsVM.EnableConfig Then
|
|
Dim sWarningMsg As String = String.Format("The current ddf configuration ({0}) is different from the current program configuration ({1})", ConfigurationCompo, Path.GetFileName(IniFile.m_sDoorsDirPath), vbCrLf)
|
|
MessageBox.Show(sWarningMsg, "Warning", MessageBoxButton.OK, MessageBoxImage.Warning)
|
|
Part.LastPartName = Map.refAssemblyManagerVM.CurrProject.SelAssemblyName.Name
|
|
Return True
|
|
End If
|
|
|
|
Dim MsgBoxResult As MessageBoxResult = MessageBoxResult.No
|
|
' 50195=The current ddf configuration ({0}) is different from the current program configuration ({1}).
|
|
Dim sWarningMas As String = String.Format(EgtMsg(50195), ConfigurationCompo, Path.GetFileName(IniFile.m_sDoorsDirPath), vbCrLf)
|
|
MsgBoxResult = MessageBox.Show(sWarningMas, "Warning", MessageBoxButton.YesNo, MessageBoxImage.Warning)
|
|
If MsgBoxResult = MessageBoxResult.Yes Then
|
|
' Imposto nuova configurazione
|
|
WriteMainPrivateProfileString(S_DOORS, K_BASEDIR, sConfCompoPath)
|
|
' Imposto progetto corrente
|
|
WriteMainPrivateProfileString(S_LAUNCHERWINDOW, K_LASTPROJECT, Map.refAssemblyManagerVM.CurrProject.SelAssemblyName.Name)
|
|
' Imposto apertura automatica al prossimo avvio
|
|
WriteMainPrivateProfileString(S_LAUNCHERWINDOW, K_LAUNCHER, (OptionModule.m_SelectedOptionLauncher + LoOpenOnce).ToString())
|
|
' esco dall'applicazione
|
|
EgtExit()
|
|
Application.Current.MainWindow.Close()
|
|
End
|
|
Else
|
|
Part.LastPartName = Map.refAssemblyManagerVM.CurrProject.SelAssemblyName.Name
|
|
End If
|
|
End If
|
|
End If
|
|
Return True
|
|
End Function
|
|
|
|
' leggo dal vettore per cercare la stringa OrigTemplate
|
|
Friend Function ReadOrigTemplate(fStream As String()) As String
|
|
Dim sOrigTemplate As String = String.Empty
|
|
For Each Line As String In fStream
|
|
If Line.Contains("#OrigTemplate") Then
|
|
sOrigTemplate = Regex.Match(Line, "\s*:\s*(.*?)\s*$").Groups(1).Value
|
|
Return sOrigTemplate
|
|
Exit For
|
|
End If
|
|
Next
|
|
' Processo il tipo di configurazione
|
|
Return sOrigTemplate
|
|
End Function
|
|
|
|
' restituisce quello che segue l'uguale assegnata la parola chiave Err
|
|
Friend Function ErrDraw(sLine As String) As Integer
|
|
Dim sErrMsg As String = Regex.Match(sLine, "\s*(Err)\s*=\s*(.*?\b)\s*$").Groups(2).Value
|
|
' se il valore è numerico allora lo restituisco
|
|
If IsNumeric(sErrMsg) Then
|
|
Return CInt(sErrMsg)
|
|
Else
|
|
' altrimenti restituisco il valore zero (non errore)
|
|
Return 0
|
|
End If
|
|
End Function
|
|
|
|
' restituisce il nome del modello
|
|
Friend Function ModelTemplate(sLine As String) As String
|
|
Dim Model As String = Regex.Match(sLine, "\s* (Compo)\s*\/\s*(.*?\b)\s*$").Groups(2).Value
|
|
If Not String.IsNullOrEmpty(Model) Then
|
|
Return Model
|
|
Else
|
|
Model = Regex.Match(sLine, "\s*(Compo)\s*\\\s*(.*?\b)\s*$").Groups(2).Value
|
|
End If
|
|
If Not String.IsNullOrEmpty(Model) Then
|
|
Return Model
|
|
Else
|
|
Return sLine
|
|
End If
|
|
End Function
|
|
|
|
' dato il direttorio restituisce il nome del file
|
|
Friend Function SubStractDirFromPath(sLine As String, sLastDir As String) As String
|
|
Dim Model As String = Regex.Match(sLine, "\s*(" & sLastDir & ")\s*\/\s*(.*?\b)\s*$").Groups(2).Value
|
|
If Not String.IsNullOrEmpty(Model) Then
|
|
Return Model
|
|
Else
|
|
Model = Regex.Match(sLine, "\s*(" & sLastDir & ")\s*\\\s*(.*?\b)\s*$").Groups(2).Value
|
|
End If
|
|
If Not String.IsNullOrEmpty(Model) Then
|
|
Return Model
|
|
Else
|
|
Return sLine
|
|
End If
|
|
End Function
|
|
|
|
Friend Function ParamExpression(sLine As String) As String
|
|
Return Regex.Match(sLine, "\s*\(*\s*(.*?\b)\s*\).*$").Groups(1).Value
|
|
End Function
|
|
|
|
' Cerca la stringa con 3 trattini
|
|
Friend Function Search3Hyphens(sLine As String) As Boolean
|
|
Dim sTmp As String = RemoveComment(sLine)
|
|
If String.IsNullOrWhiteSpace(sTmp) Then Return False
|
|
Return Regex.Match(sTmp, "\s*(---).*$").Groups(1).Value = "---"
|
|
End Function
|
|
|
|
' Cerca la stringa con 3 puntini
|
|
Friend Function Search3Dots(sLine As String) As Boolean
|
|
Dim sTmp As String = RemoveComment(sLine)
|
|
If String.IsNullOrWhiteSpace(sTmp) Then Return False
|
|
Return Regex.Match(sTmp, "\s*(...).*$").Groups(1).Value = "..."
|
|
End Function
|
|
|
|
' Cerca la chiave che precede i due punti
|
|
Friend Function SearchKey(sLine As String, sKey As String) As Boolean
|
|
Dim sTmp As String = RemoveComment(sLine)
|
|
If String.IsNullOrWhiteSpace(sTmp) Then Return False
|
|
Return Regex.Match(sTmp, "\s*(" & sKey & ")\s*:.*$").Groups(1).Value = sKey
|
|
End Function
|
|
|
|
' Restituisce la chiave che precede i due punti (elimina gli spazi prima della chiave)
|
|
Friend Function GetKey(sLine As String) As String
|
|
Dim sTmp As String = RemoveComment(sLine)
|
|
If String.IsNullOrWhiteSpace(sTmp) Then Return ""
|
|
Return Regex.Match(RemoveComment(sLine), "\s*(.*?\b)\s*:.*").Groups(1).Value
|
|
End Function
|
|
|
|
' Restituisce il valore associato alla chiave ( key: value)
|
|
Friend Function GetValueWithKey(sLine As String, sKey As String) As String
|
|
Dim sTmp As String = RemoveComment(sLine)
|
|
If String.IsNullOrWhiteSpace(sTmp) Then Return ""
|
|
Return Regex.Match(sTmp, "\s*-*\s*" & sKey & "\s*:\s*(.*?)\s*$").Groups(1).Value
|
|
End Function
|
|
|
|
' Restituisce il valore associato ad una chiave non specificata ( unknown_key: value)
|
|
Friend Function GetValueWithoutKey(sLine As String) As String
|
|
Dim sTmp As String = RemoveComment(sLine)
|
|
If String.IsNullOrWhiteSpace(sTmp) Then Return ""
|
|
Return Regex.Match(sTmp, "\s*:\s*(.*?)\s*$").Groups(1).Value
|
|
End Function
|
|
|
|
' Cerca il nome che precede i due punti (tutti i caratteri dall'inizio della stringa)
|
|
Friend Function SearchName(sLine As String, sName As String) As Boolean
|
|
Dim sTmp As String = RemoveComment(sLine)
|
|
If String.IsNullOrWhiteSpace(sTmp) OrElse Char.IsWhiteSpace(sTmp, 0) Then Return False
|
|
Return Regex.Match(sTmp, "\s*(" & sName & ")\s*:.*$").Groups(1).Value = sName
|
|
End Function
|
|
|
|
' Restituisce il nome che precede i due punti (tutti i caratteri dall'inizio della stringa)
|
|
Friend Function GetName(sLine As String) As String
|
|
' La versione deve essere impostata in fase di lettura della porta
|
|
Dim sTmp As String = RemoveComment(sLine)
|
|
If sCurrVersionDoor = "2" Then
|
|
If String.IsNullOrWhiteSpace(sTmp) OrElse sTmp.StartsWith(OptionModule.m_sSpaceHype) OrElse sTmp.StartsWith(OptionModule.m_sSpace3Tab) Then Return ""
|
|
Else
|
|
If String.IsNullOrWhiteSpace(sTmp) OrElse Char.IsWhiteSpace(sTmp, 0) Then Return ""
|
|
End If
|
|
Dim sString As String = Regex.Match(RemoveComment(sLine), "\s*(.*?\b)\s*:.*").Groups(1).Value
|
|
Return Regex.Match(RemoveComment(sLine), "\s*(.*?\b)\s*:.*").Groups(1).Value
|
|
End Function
|
|
|
|
' estrae da una riga lua il contenuto scommentato
|
|
Friend Function RemoveCommentLUA(sLine As String) As String
|
|
If sLine.Contains("--") Then sLine = Regex.Match(sLine, "\s*(.*?)\s*--.*$").Groups(1).Value
|
|
Return sLine
|
|
End Function
|
|
|
|
Friend Function GetNameParamInFileTempl(sLine As String) As String
|
|
If sLine.Contains("%") Then sLine = Regex.Match(sLine, "\s*\%*\s*(.*?)\s*\%.*$").Groups(1).Value : Return sLine
|
|
Return String.Empty
|
|
End Function
|
|
|
|
|
|
End Module
|