Files
EgtDOORCreator/IniFile.vb
2022-12-19 16:16:35 +01:00

489 lines
21 KiB
VB.net

Imports System.Collections.ObjectModel
Imports System.IO
Imports EgtUILib
Imports EgtWPFLib5
Friend Module IniFile
Public Enum ComboListResult As Integer
MISTAKE = -1
NOTFOUND = 0
FOUND = 1
End Enum
' Livello dell'utilizzatore
Friend m_nUserLevel As Integer = 1
' Livello della chiave inserita nel PC
Friend m_nKeyLevel As Integer = 0
' Opzioni attive sulla chiave
Friend m_nKeyOptions As UInteger = 0
Friend m_ProjectSceneContext As Integer = 0
Friend Enum KEY_OPT As UInteger
BASE = 1
DOORS = 2
DOORCREATOR = 8
JAMBS = 32
STEELDOOR = 256
READ_ONLY = 512
End Enum
' Path cartella Data
Friend m_sDataRoot As String = String.Empty
' Path cartella Config
Friend m_sConfigDir As String = String.Empty
' Path IniFile
Friend m_sIniFile As String = String.Empty
' Path Temp directory
Friend m_sTempDir As String = String.Empty
' Path Default.ini file in Compodi Doors
Friend m_DefaultIniFile As String = String.Empty
' Path MyProject directory
Friend m_MyProjectDir As String = String.Empty
' direttorio dei file della macchina
Friend m_MachinProject As String = String.Empty
' Path Template directory
Friend m_TemplateDir As String = String.Empty
' Path Compo directory
Friend m_CompoDir As String = String.Empty
' Path Help directory
Friend m_sHelpDir As String = String.Empty
' Path del file ddf --> nome file della porta corrente
Friend m_DDFFilePath As String = String.Empty
' Path Doors directory
Friend m_sDoorsDirPath As String = String.Empty
' Path del direttorio List&Label corrente
Friend m_sListLabelDir As String = String.Empty
' Path del modello ListLabel
Friend m_sListLabelCurrent As String = String.Empty
' Path dell'eseguibile Cam5
Friend m_sEgtCameEXEPath As String = String.Empty
' Path LuaLibs Dir
Friend m_sLuaLibsDir As String = String.Empty
' EgtDoorCreator.ini
Public Function GetPrivateProfileLanguage(ByVal lpAppName As String, ByVal lpKeyName As String) As Language
Dim sVal As String = String.Empty
GetMainPrivateProfileString(lpAppName, lpKeyName, "", sVal)
Dim sItems() As String = sVal.Split(",".ToCharArray)
If sItems.Count() = 2 Then
Return New Language(sItems(0), sItems(1))
End If
Return Nothing
End Function
' Default.ini in Compo di Doors
Public Function DefaultGetPrivateProfileString(IpAppName As String, IpKeyName As String, IpDefault As String, ByRef IpString As String) As Integer
Return EgtUILib.GetPrivateProfileString(IpAppName, IpKeyName, IpDefault, IpString, m_DefaultIniFile)
End Function
Public Function DefaultGetPrivateProfileList(ByVal lpAppName As String, ByVal lpKeyName As String, ByVal List As List(Of String)) As Boolean
Dim sVal As String = String.Empty
DefaultGetPrivateProfileString(lpAppName, lpKeyName, "", sVal)
Dim sItems() As String = sVal.Split(",".ToCharArray)
' se la lista ha almeno un elemento
If sItems.Count > 0 Then
For Index = 0 To sItems.Count() - 1
List.Add(Trim(sItems(Index)))
Next
End If
Return True
End Function
Public Function DefaultGetPrivateProfileObservableCollection(ByVal lpAppName As String, ByVal lpKeyName As String, ByVal List As ObservableCollection(Of String)) As Boolean
Dim sVal As String = String.Empty
DefaultGetPrivateProfileString(lpAppName, lpKeyName, "", sVal)
Dim sItems() As String = sVal.Split(",".ToCharArray)
' se la lista ha almeno un elemento
If sItems.Count > 0 And Not String.IsNullOrWhiteSpace(sItems(0)) Then
For Index = 0 To sItems.Count() - 1
List.Add(Trim(sItems(Index)))
Next
Else
Return False
End If
Return True
End Function
' legge e genera le liste delle proprietà per i materiali
Public Function DefaultGetPrivateProfileMaterialProperties( ByVal lpAppName As String, ByVal lpKeyName As String, ByVal MList As ObservableCollection(Of MaterialType)) As Boolean
If IsNothing(MList) orelse MList.Count < 1 then Return false
' lpKeyName = nome della variabile del paragrafo (Property_n)
Dim sVal As String = String.Empty
Dim IndexType As Integer = 1
Dim EndOfList As Boolean = False
Dim bSideExists As Boolean = False
While Not EndOfList
Dim CurrlpKeyName = lpKeyName & DoubleToString(IndexType, 0)
DefaultGetPrivateProfileString(lpAppName, CurrlpKeyName, "", sVal)
If String.IsNullOrEmpty(sVal) Then
EndOfList = True
Continue While
End If
' separo in funzione della virgola ("/" è il separatore NomeDDF/NomeGrafica)
Dim Item() As String = sVal.Split(","c)
' verifico di avere almeno due elementi (altrimenti vado all'elemento successivo senza aggiungerlo alla lista)
If Item.Count < 2 then
IndexType = IndexType + 1
Continue While
End If
' a partire dal secondo elemento del vettore (insieme dei materiali)
For IndexItem = 1 to Item.Count - 1
For Each MaterialItem In MList
If Trim(MaterialItem.NameDDF) = Trim(Item(IndexItem)) then
Dim ItemProp() As String = Item(0).Split("/"c)
If IsNothing(MaterialItem.PropertiesList) then
MaterialItem.PropertiesList = New ObservableCollection(Of PropertyItem)
End If
If ItemProp.Count < 2 then
MaterialItem.PropertiesList.Add(New PropertyItem( ItemProp(0), ItemProp(0), false))
Else
MaterialItem.PropertiesList.Add(New PropertyItem( ItemProp(0), ItemProp(1), false))
End If
End If
Next
Next
IndexType = IndexType + 1
End While
Return true
End Function
' Edge, EgdgeType_n, ObservableCollection
Public Function DefaultGetPrivateProfileNewVersion(ByVal lpAppName As String, ByVal lpKeyName As String, ByVal List As ObservableCollection(Of String),
ByVal ListLock As ObservableCollection(Of EdgeType),
ByVal ListHinge As ObservableCollection(Of EdgeType),
ByVal ListTop As ObservableCollection(Of EdgeType),
ByVal ListBottm As ObservableCollection(Of EdgeType)) As Boolean
Dim sVal As String = String.Empty
Dim IndexBevelType As Integer = 1
Dim EndOfList As Boolean = False
Dim bSideExists As Boolean = False
While Not EndOfList
Dim CurrlpKeyName = lpKeyName & DoubleToString(IndexBevelType, 0)
DefaultGetPrivateProfileString(lpAppName, CurrlpKeyName, "", sVal)
If String.IsNullOrEmpty(sVal) Then
EndOfList = True
Continue While
End If
Dim Item() As String = sVal.Split("/"c)
' verifico che lo split abbia dato il risultato atteso
If Item.Count <> 2 Then Return False
List.Add(Item(0))
If Item(1).ToLower.Contains(SIDE_LOCK) Then
ListLock.Add(New EdgeType(Trim(Item(0)), Visibility.Visible))
bSideExists = True
End If
If Item(1).ToLower.Contains(SIDE_HINGE) Then
ListHinge.Add(New EdgeType(Trim(Item(0)), Visibility.Visible))
bSideExists = True
End If
If Item(1).ToLower.Contains(SIDE_TOP) Then
ListTop.Add(New EdgeType(Trim(Item(0)), Visibility.Visible))
bSideExists = True
End If
If Item(1).ToLower.Contains(SIDE_BOTTOM) Then
ListBottm.Add(New EdgeType(Trim(Item(0)), Visibility.Visible))
bSideExists = True
End If
' verifico che esista un'associazione
If Not bSideExists Then
Return False
Else
bSideExists = False
End If
IndexBevelType = IndexBevelType + 1
End While
Return True
End Function
Public Function DefaultGetPrivateProfilesMachining(ByVal lpAppName As String, ByVal lpKeyName As String, ByRef IpBoolean As Boolean) As Boolean
Dim sVal As String = String.Empty
DefaultGetPrivateProfileString(lpAppName, lpKeyName, "", sVal)
If String.Equals(Trim(sVal), "1") Then
IpBoolean = True
Else
IpBoolean = False
End If
Return IpBoolean
End Function
' restituisce il l'unità di misura della configurazione
Public Function DefaultGetMmUnits(ByVal lpAppName As String, ByVal lpKeyName As String, ByRef IsMM As Boolean) As Boolean
Dim sVal As String = String.Empty
DefaultGetPrivateProfileString(lpAppName, lpKeyName, "", sVal)
If String.Equals(Trim(sVal), "1") Then
IsMM = True
Else
IsMM = False
End If
Return IsMM
End Function
Public Function DefaultGetPrivateProfilesVisibility(ByVal lpAppName As String, ByVal lpKeyName As String, ByRef IpVisibility As Visibility) As Visibility
Dim sVal As String = String.Empty
DefaultGetPrivateProfileString(lpAppName, lpKeyName, "", sVal)
If String.Equals(Trim(sVal), "1") Then
IpVisibility = Visibility.Visible
Else
IpVisibility = Visibility.Collapsed
End If
Return IpVisibility
End Function
Public Function DefaultGetPrivateProfilesBevel(ByVal lpAppName As String, ByVal lpKeyName As String, ByRef IpBoolean As Visibility) As Visibility
Dim sVal As String = String.Empty
DefaultGetPrivateProfileString(lpAppName, lpKeyName, "", sVal)
If String.Equals(Trim(sVal), "1") Then
IpBoolean = Visibility.Visible
Else
IpBoolean = Visibility.Collapsed
End If
Return IpBoolean
End Function
Public Function DefaultWritePrivateProfileString(IpAppName As String, IpKeyName As String, ByRef IpString As String) As Boolean
Return EgtUILib.WritePrivateProfileString(IpAppName, IpKeyName, IpString, m_DefaultIniFile)
End Function
' StdTemplate.ini
Public Function StdTemplateGetPrivateProfileString(IpAppName As String, IpKeyName As String, IpDefault As String, ByRef IpString As String) As Integer
Return EgtUILib.GetPrivateProfileString(IpAppName, IpKeyName, IpDefault, IpString, Map.refHardwarePageVM.CurrHardware.StdTemplate)
End Function
Public Function StdTemplateGetPrivateProfileInt(IpAppName As String, IpKeyName As String, nDefault As Integer) As Integer
Return EgtUILib.GetPrivateProfileInt(IpAppName, IpKeyName, nDefault, Map.refHardwarePageVM.CurrHardware.StdTemplate)
End Function
Public Function StdTemplateGetPrivateProfileList(ByVal lpAppName As String, ByVal lpKeyName As String, ByVal List As List(Of String)) As Boolean
Dim sVal As String = String.Empty
StdTemplateGetPrivateProfileString(lpAppName, lpKeyName, "", sVal)
If String.IsNullOrEmpty(sVal) Then Return False
Dim sItems() As String = sVal.Split(",".ToCharArray)
' se la lista ha almeno un elemento
If sItems.Count > 0 Then
For Index = 0 To sItems.Count() - 1
List.Add(Trim(sItems(Index)))
Next
End If
Return True
End Function
' restituisce l'elenco dei materiali ed eventualmente il valore is Active associato al capitolo (default nIsActive = 3)
Public Function StdTemplateGetPrivateProfileListMaterial(ByVal lpAppName As String, ByVal lpKeyName As String, ByVal List As List(Of String), ByRef nIsActiveMaterial As Integer) As Boolean
Dim sVal As String = String.Empty
StdTemplateGetPrivateProfileString(lpAppName, lpKeyName, "", sVal)
If String.IsNullOrEmpty(sVal) Then Return False
Dim sItems() As String = sVal.Split(",".ToCharArray)
' se la lista ha almeno due elementi
If sItems.Count > 1 Then
For Index = 0 To sItems.Count() - 2
List.Add(Trim(sItems(Index)))
Next
End If
' se la lista ha un solo elemento, oppure ha un solo elemento
Dim LastItems As String() = sItems.Last.Split(";"c)
List.Add(Trim(LastItems(0)))
If LastItems.Count > 1 AndAlso IsNumeric(LastItems(1)) Then
nIsActiveMaterial = CInt(LastItems(1))
End If
Return True
End Function
' restituisce l'elenco dei materiali ed eventualmente il valore di default da associare al parametro Ghost che viene generato in sostituzione del parametro letto
Public Function StdTemplateGetPrivateProfileListMaterialParam(ByVal lpAppName As String, ByVal lpKeyName As String, ByVal List As List(Of String), ByRef sDefaultParam As String) As Boolean
Dim sVal As String = String.Empty
StdTemplateGetPrivateProfileString(lpAppName, lpKeyName, "", sVal)
If String.IsNullOrEmpty(sVal) Then Return False
Dim sItems() As String = sVal.Split(",".ToCharArray)
' se la lista ha almeno due elementi
If sItems.Count > 1 Then
For Index = 0 To sItems.Count() - 2
List.Add(Trim(sItems(Index)))
Next
End If
' se la lista ha un solo elemento, oppure ha un solo elemento
Dim LastItems As String() = sItems.Last.Split(";"c)
List.Add(Trim(LastItems(0)))
If LastItems.Count > 1 Then
sDefaultParam = Trim(LastItems(1))
End If
Return True
End Function
Public Function StdTemplateGetPrivateProfileChapterName(ByVal lpAppName As String, ByVal lpKeyName As String, ByRef sValueLua As String, ByRef sValue As String) As Boolean
Dim sVal As String = String.Empty
StdTemplateGetPrivateProfileString(lpAppName, lpKeyName, "", sVal)
If String.IsNullOrEmpty(sVal) Then Return False
Dim sItems() As String = sVal.Split("/".ToCharArray)
' se la lista ha almeno un elemento
If sItems.Count = 0 Then Return False
If sItems.Count > 0 Then sValueLua = sItems(0)
If sItems.Count > 1 Then sValue = sItems(1)
Return True
End Function
Public Function StdTemplateGetPrivateProfileGroupChapter(ByVal lpAppName As String, ByVal lpKeyName As String, ByRef sValueLua As String) As Boolean
Dim sVal As String = String.Empty
StdTemplateGetPrivateProfileString(lpAppName, lpKeyName, "", sVal)
If String.IsNullOrEmpty(sVal) Then Return False
sValueLua = sVal
Return True
End Function
Public Function StdTemplateGetPrivateProfileChapterVersioning(ByVal lpAppName As String, ByVal lpKeyName As String, ByRef nValue As Integer) As Boolean
' se non trovo significa che è disattiva la versione
nValue = StdTemplateGetPrivateProfileInt(lpAppName, lpKeyName, 0)
Return True
End Function
Public Function StdTemplateGetPrivateProfileChapterIsOpened(ByVal lpAppName As String, ByVal lpKeyName As String, ByRef bValueLua As Boolean) As Boolean
Dim sVal As String = String.Empty
StdTemplateGetPrivateProfileString(lpAppName, lpKeyName, "", sVal)
If String.IsNullOrEmpty(sVal) Then Return False
If sVal = "0" Then bValueLua = False Else bValueLua = True
Return True
End Function
' Config.ini di ciascun direttorio dei componenti (deve ricevere anche la path completa del file)
Public Function GetPrivateProfileCompoName(IpAppName As String, IpKeyName As String, ByRef DDFName As String, ByRef Name As String, CompoIniPath As String) As Boolean
Dim sVal As String = String.Empty
EgtUILib.GetPrivateProfileString(IpAppName, IpKeyName, "", sVal, CompoIniPath)
Dim sItems() As String = sVal.Split("/"c)
If sItems.Count() >= 2 Then
DDFName = sItems(0)
Dim nMsg As Integer
If Integer.TryParse(sItems(1), nMsg) Then
Name = EgtMsg(nMsg)
Else
Name = DDFName
End If
Return True
End If
Return False
End Function
Public Function GetPrivateProfileCompoImage(IpAppName As String, IpKeyName As String, ByRef Image As String, CompoIniPath As String) As Boolean
Dim sVal As String = String.Empty
EgtUILib.GetPrivateProfileString(IpAppName, IpKeyName, "", sVal, CompoIniPath)
Dim CurrDir As String = Path.GetDirectoryName(CompoIniPath)
sVal = sVal.Trim
If Not String.IsNullOrEmpty(sVal) AndAlso Not String.IsNullOrEmpty(CurrDir) Then
sVal = CurrDir.Trim & "\" & sVal
If File.Exists(sVal) Then
Image = sVal
Return True
Else
Return False
End If
End If
Return False
End Function
Public Function GetPrivateProfileFolderName(IpAppName As String, IpKeyName As String, ByRef Name As String, CompoIniPath As String) As Boolean
Dim sVal As String = String.Empty
EgtUILib.GetPrivateProfileString(IpAppName, IpKeyName, "", sVal, CompoIniPath)
If Not String.IsNullOrEmpty(sVal) Then
Dim nMsg As Integer
If Integer.TryParse(sVal, nMsg) Then
Name = EgtMsg(nMsg)
Else
Name = sVal
End If
Return True
Else
Name = EgtMsg(50053)
Return False
End If
End Function
Public Function GetPrivateProfileTidyLayer(IpAppName As String, IpKeyName As String, ByRef Name As String, CompoIniPath As String) As Boolean
Dim sVal As String = String.Empty
EgtUILib.GetPrivateProfileString(IpAppName, IpKeyName, "", sVal, CompoIniPath)
If Not String.IsNullOrEmpty(sVal) Then
Name = sVal
Return True
Else
Return False
End If
End Function
Public Function GetPrivateProfileRefCompoDoor(IpAppName As String, IpKeyName As String, CompoIniPath As String) As Boolean
Dim sVal As String = String.Empty
EgtUILib.GetPrivateProfileString(IpAppName, IpKeyName, "", sVal, CompoIniPath)
If String.IsNullOrEmpty(sVal) OrElse Trim(sVal) = "0" Then
Return False
Else
Return True
End If
End Function
' lettura del nome layer dal file di configurazioe
Public Function GetPrivateProfileLayerName(IpAppName As String, IpKeyName As String, ByRef Name As String, CompoIniPath As String) As Boolean
Dim sVal As String = String.Empty
EgtUILib.GetPrivateProfileString(IpAppName, IpKeyName, "", sVal, CompoIniPath)
If String.IsNullOrEmpty(sVal) Then Return False Else Name = sVal : Return True
End Function
Public Function GetPrivateProfileJambSide(IpAppName As String, IpKeyName As String, ByRef Side As String, CompoIniPath As String) As Boolean
Dim sVal As String = String.Empty
EgtUILib.GetPrivateProfileString(IpAppName, IpKeyName, "", sVal, CompoIniPath)
Side = sVal
Return True
End Function
' carica la lista delle associazioni lette dal file di configurazione della componente
Public Function GetPrivateProfileMatchHardware(IpAppName As String, IpKeyName As String, ByRef HardwareList As ObservableCollection(Of String), ByRef HardwareListDDF As ObservableCollection(Of String), CompoIniPath As String) As Boolean
Dim sVal As String = String.Empty
EgtUILib.GetPrivateProfileString(IpAppName, IpKeyName, "", sVal, CompoIniPath)
If String.IsNullOrEmpty(sVal) Then Return False
Dim Item() As String = sVal.Split(","c)
For Each Element In Item
' divido il nome dal nomeDDF
Dim sName() As String = Element.Split("/"c)
HardwareList.Add(Trim(sName(0)))
If sName.Count > 1 Then
Dim nInd As Integer
If Integer.TryParse(sName(1), nInd) Then
' verifico che sia associato ad un messaggio
Dim sMsg As String = EgtMsg(nInd)
Dim ErrorMsg As String = "Msg" & Trim(sName(1))
If String.Equals(sMsg, ErrorMsg) Then
HardwareListDDF.Add(Trim(sName(0)))
' altrimenti lo restituisco
Else
HardwareListDDF.Add(sMsg)
End If
Else
' se il valore non è un intero lo aggiungo direttamente
HardwareListDDF.Add(Trim(sName(1)))
End If
Else
HardwareListDDF.Add(Trim(sName(0)))
End If
Next
Return True
End Function
Public Function GetGeometryNameList(IpAppName As String, IpKeyName As String, ByRef GeometryName As String, ByRef WorkList As List(Of String)) As Boolean
Dim sVal As String = String.Empty
EgtUILib.GetPrivateProfileString(IpAppName, IpKeyName, "", sVal, m_sDoorsDirPath & "\MTables\GeometryNameList.ini")
If String.IsNullOrEmpty(sVal) Then Return False
Dim sItems() As String = sVal.Split(";"c)
GeometryName = sItems(0)
If sItems.Count > 0 And Not IsNothing(WorkList) Then
Dim Index As Integer = 1
For Index = 1 To sItems.Count() - 1
WorkList.Add(Trim(sItems(Index)))
Next
End If
Return True
End Function
Public Function SetGeometryNameList(IpAppName As String, IpKeyName As String, IpString As String) As Boolean
Return EgtUILib.WritePrivateProfileString(IpAppName, IpKeyName, IpString, m_sDoorsDirPath & "\MTables\GeometryNameList.ini")
End Function
End Module