This commit is contained in:
Digital Data - Marlon Schreiber 2019-04-18 09:48:58 +02:00
commit 3048329cb4
2 changed files with 88 additions and 49 deletions

View File

@ -2,7 +2,10 @@
Imports System.Xml Imports System.Xml
Module ModuleMySettings Module ModuleMySettings
Dim ConfigPath As String = Path.Combine(Application.UserAppDataPath(), "UserConfig.xml") 'Dim ConfigPath As String = Path.Combine(Application.UserAppDataPath(), "UserConfig.xml")
Public Const USER_CONFIG_FILE = "UserConfig.xml"
Public Const COMPUTER_CONFIG_FILE = "ComputerConfig.xml"
Public MyConnectionString As String = "" Public MyConnectionString As String = ""
Public LogErrorsOnly As Boolean = True Public LogErrorsOnly As Boolean = True
Public GI_withWindream As Boolean = False Public GI_withWindream As Boolean = False
@ -11,17 +14,47 @@ Module ModuleMySettings
Public UniversalViewer_Path As String Public UniversalViewer_Path As String
Public FW_started As Boolean = False Public FW_started As Boolean = False
Public FWSCAN_started As Boolean = False Public FWSCAN_started As Boolean = False
Public Function GetUserConfigPath() As String
Return Path.Combine(Application.UserAppDataPath(), USER_CONFIG_FILE)
End Function
Public Function GetAllUsersConfigPath() As String
Return Path.Combine(Application.CommonAppDataPath(), COMPUTER_CONFIG_FILE)
End Function
Public Function GetCurrentConfigPath() As String
If File.Exists(GetUserConfigPath()) Then
Return GetUserConfigPath()
Else
Return GetAllUsersConfigPath()
End If
End Function
Public Function LoadMyConfig() Public Function LoadMyConfig()
Dim rowresult As String = "" Dim rowresult As String = ""
Try Try
Dim DT As DataTable Dim oDatatable As DataTable
'if file doesn't exist, create the file with its default xml table ''if file doesn't exist, create the file with its default xml table
If Not File.Exists(ConfigPath) Then 'If Not File.Exists(ConfigPath) Then
DT = CreateConfigTable() ' DT = CreateConfigTable()
DT.WriteXml(ConfigPath) ' DT.WriteXml(ConfigPath)
'End If
'DT = GetTablefromXML()
' if file in %APPDATA% doesn't exist,
' check for file in %ALLUSERSPROFILE%,
' otherwise create the file with its default xml table
If File.Exists(GetUserConfigPath()) Then
oDatatable = GetTablefromXML(GetUserConfigPath())
ElseIf File.Exists(GetAllUsersConfigPath()) Then
oDatatable = GetTablefromXML(GetAllUsersConfigPath())
Else
oDatatable = CreateConfigTable()
oDatatable.WriteXml(GetUserConfigPath())
End If End If
DT = GetTablefromXML()
For Each Row As DataRow In DT.Rows For Each Row As DataRow In oDatatable.Rows
rowresult &= Row.Item("ConfigName") rowresult &= Row.Item("ConfigName")
Select Case Row.Item("ConfigName") Select Case Row.Item("ConfigName")
Case "MyConnectionString" Case "MyConnectionString"
@ -65,26 +98,26 @@ Module ModuleMySettings
Next Next
'update 1.1 'update 1.1
If rowresult.Contains("FW_started") = False Then If rowresult.Contains("FW_started") = False Then
Dim newRow As DataRow = DT.NewRow() Dim newRow As DataRow = oDatatable.NewRow()
newRow("ConfigName") = "FW_started" newRow("ConfigName") = "FW_started"
newRow("Value") = "False" newRow("Value") = "False"
DT.Rows.Add(newRow) oDatatable.Rows.Add(newRow)
DT.WriteXml(ConfigPath) oDatatable.WriteXml(GetUserConfigPath())
End If End If
'update 1.6 'update 1.6
If rowresult.Contains("Delete_OriginFile") = False Then If rowresult.Contains("Delete_OriginFile") = False Then
Dim newRow As DataRow = DT.NewRow() Dim newRow As DataRow = oDatatable.NewRow()
newRow("ConfigName") = "Delete_OriginFile" newRow("ConfigName") = "Delete_OriginFile"
newRow("Value") = "False" newRow("Value") = "False"
DT.Rows.Add(newRow) oDatatable.Rows.Add(newRow)
DT.WriteXml(ConfigPath) oDatatable.WriteXml(GetUserConfigPath())
End If End If
If rowresult.Contains("FWSCAN_started") = False Then If rowresult.Contains("FWSCAN_started") = False Then
Dim newRow As DataRow = DT.NewRow() Dim newRow As DataRow = oDatatable.NewRow()
newRow("ConfigName") = "FWSCAN_started" newRow("ConfigName") = "FWSCAN_started"
newRow("Value") = "False" newRow("Value") = "False"
DT.Rows.Add(newRow) oDatatable.Rows.Add(newRow)
DT.WriteXml(ConfigPath) oDatatable.WriteXml(GetUserConfigPath())
End If End If
Catch ex As Exception Catch ex As Exception
MsgBox("Error in MySettings-LoadMyConfig" & vbNewLine & ex.Message, MsgBoxStyle.Critical) MsgBox("Error in MySettings-LoadMyConfig" & vbNewLine & ex.Message, MsgBoxStyle.Critical)
@ -93,7 +126,7 @@ Module ModuleMySettings
Return True Return True
End Function End Function
Private Function GetTablefromXML() Private Function GetTablefromXML(ConfigPath As String)
Try Try
Dim DS As New DataSet Dim DS As New DataSet
DS.ReadXml(ConfigPath) DS.ReadXml(ConfigPath)
@ -108,69 +141,75 @@ Module ModuleMySettings
Try Try
' Create sample Customers table, in order ' Create sample Customers table, in order
' to demonstrate the behavior of the DataTableReader. ' to demonstrate the behavior of the DataTableReader.
Dim table As New DataTable Dim oTable As New DataTable
table.TableName = "MyConfig" oTable.TableName = "MyConfig"
' Create two columns, ID and Name. ' Create two columns, ID and Name.
Dim idColumn As DataColumn = table.Columns.Add("ID", _ Dim oIdColumn As DataColumn = oTable.Columns.Add("ID",
GetType(System.Int32)) GetType(System.Int32))
idColumn.AutoIncrement = True oIdColumn.AutoIncrement = True
idColumn.AutoIncrementSeed = 0 oIdColumn.AutoIncrementSeed = 0
idColumn.AutoIncrementStep = 1 oIdColumn.AutoIncrementStep = 1
table.Columns.Add("ConfigName", GetType(System.String)) oTable.Columns.Add("ConfigName", GetType(System.String))
table.Columns.Add("Value", GetType(System.String)) oTable.Columns.Add("Value", GetType(System.String))
'Set the ID column as the primary key column. 'Set the ID column as the primary key column.
table.PrimaryKey = New DataColumn() {idColumn} oTable.PrimaryKey = New DataColumn() {oIdColumn}
Dim newRow As DataRow = table.NewRow() Dim newRow As DataRow = oTable.NewRow()
newRow("ConfigName") = "MyConnectionString" newRow("ConfigName") = "MyConnectionString"
newRow("Value") = "" newRow("Value") = ""
table.Rows.Add(newRow) oTable.Rows.Add(newRow)
Dim newRow1 As DataRow = table.NewRow() Dim newRow1 As DataRow = oTable.NewRow()
newRow1("ConfigName") = "LogErrorsOnly" newRow1("ConfigName") = "LogErrorsOnly"
newRow1("Value") = "True" newRow1("Value") = "True"
table.Rows.Add(newRow1) oTable.Rows.Add(newRow1)
Dim newRow2 As DataRow = table.NewRow() Dim newRow2 As DataRow = oTable.NewRow()
newRow2("ConfigName") = "Preview" newRow2("ConfigName") = "Preview"
newRow2("Value") = "True" newRow2("Value") = "True"
table.Rows.Add(newRow2) oTable.Rows.Add(newRow2)
Dim newRow3 As DataRow = table.NewRow() Dim newRow3 As DataRow = oTable.NewRow()
newRow3("ConfigName") = "UniversalViewer" newRow3("ConfigName") = "UniversalViewer"
newRow3("Value") = "" newRow3("Value") = ""
table.Rows.Add(newRow3) oTable.Rows.Add(newRow3)
Dim newRow4 As DataRow = table.NewRow() Dim newRow4 As DataRow = oTable.NewRow()
newRow4("ConfigName") = "FW_started" newRow4("ConfigName") = "FW_started"
newRow4("Value") = "False" newRow4("Value") = "False"
table.Rows.Add(newRow4) oTable.Rows.Add(newRow4)
Dim newRow5 As DataRow = table.NewRow() Dim newRow5 As DataRow = oTable.NewRow()
newRow5("ConfigName") = "FWSCAN_started" newRow5("ConfigName") = "FWSCAN_started"
newRow5("Value") = "False" newRow5("Value") = "False"
table.Rows.Add(newRow5) oTable.Rows.Add(newRow5)
table.AcceptChanges() oTable.AcceptChanges()
Return table Return oTable
Catch ex As Exception Catch ex As Exception
MsgBox("Error in CreateConfigTable" & vbNewLine & ex.Message, MsgBoxStyle.Critical) MsgBox("Error in CreateConfigTable" & vbNewLine & ex.Message, MsgBoxStyle.Critical)
Return Nothing Return Nothing
End Try End Try
End Function End Function
''' <summary>
''' Save settings to user config, NOT to common config
''' </summary>
Public Function SaveConfigValue(name As String, value As String) Public Function SaveConfigValue(name As String, value As String)
Try Try
Dim DT As DataTable Dim oUserConfigPath = GetUserConfigPath()
DT = GetTablefromXML() Dim oCurrentConfigPath = GetCurrentConfigPath()
For Each Row As DataRow In DT.Rows Dim oDatatable As DataTable = GetTablefromXML(oCurrentConfigPath)
For Each Row As DataRow In oDatatable.Rows
If Row.Item("ConfigName") = name Then If Row.Item("ConfigName") = name Then
Row.Item("Value") = value Row.Item("Value") = value
End If End If
Next Next
DT.AcceptChanges() oDatatable.AcceptChanges()
DT.WriteXml(ConfigPath) oDatatable.WriteXml(oUserConfigPath)
Return True
Catch ex As Exception Catch ex As Exception
MsgBox("Error in SaveConfigValue" & vbNewLine & ex.Message, MsgBoxStyle.Critical) MsgBox("Error in SaveConfigValue" & vbNewLine & ex.Message, MsgBoxStyle.Critical)
Return False Return False
End Try End Try
Return True
End Function End Function
Public Function Load_BasicConfig() Public Function Load_BasicConfig()
Try Try

View File

@ -33,7 +33,7 @@ Imports System.Runtime.InteropServices
' übernehmen, indem Sie "*" eingeben: ' übernehmen, indem Sie "*" eingeben:
' <Assembly: AssemblyVersion("1.0.*")> ' <Assembly: AssemblyVersion("1.0.*")>
<Assembly: AssemblyVersion("1.9.9.16")> <Assembly: AssemblyVersion("1.9.9.18")>
<Assembly: AssemblyFileVersion("1.0.0.0")> <Assembly: AssemblyFileVersion("1.0.0.0")>
<Assembly: NeutralResourcesLanguageAttribute("")> <Assembly: NeutralResourcesLanguageAttribute("")>