Version 1.9.9.17 - load global config

This commit is contained in:
Jonathan Jenne 2019-02-13 12:09:15 +01:00
parent 10132da679
commit d23cce4e2c
2 changed files with 87 additions and 49 deletions

View File

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

View File

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