From d23cce4e2c995ed21ba0b42ff71c23fb51e04efe Mon Sep 17 00:00:00 2001 From: Jonathan Jenne Date: Wed, 13 Feb 2019 12:09:15 +0100 Subject: [PATCH] Version 1.9.9.17 - load global config --- Global_Indexer/ModuleMySettings.vb | 134 ++++++++++++++-------- Global_Indexer/My Project/AssemblyInfo.vb | 2 +- 2 files changed, 87 insertions(+), 49 deletions(-) diff --git a/Global_Indexer/ModuleMySettings.vb b/Global_Indexer/ModuleMySettings.vb index 16c6f70..ff8fae2 100644 --- a/Global_Indexer/ModuleMySettings.vb +++ b/Global_Indexer/ModuleMySettings.vb @@ -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 + + ''' + ''' Save settings to user config, NOT to common config + ''' 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 diff --git a/Global_Indexer/My Project/AssemblyInfo.vb b/Global_Indexer/My Project/AssemblyInfo.vb index c01e0ad..f88c791 100644 --- a/Global_Indexer/My Project/AssemblyInfo.vb +++ b/Global_Indexer/My Project/AssemblyInfo.vb @@ -33,7 +33,7 @@ Imports System.Runtime.InteropServices ' übernehmen, indem Sie "*" eingeben: ' - + \ No newline at end of file