From b3b3e80509b85bc08a3d1db8c0789c869a96fe85 Mon Sep 17 00:00:00 2001 From: Jonathan Jenne Date: Wed, 4 Oct 2023 13:39:13 +0200 Subject: [PATCH] fix ConfigUtils --- Config/ConfigManager.vb | 6 +++--- Config/ConfigUtils.vb | 24 +++++++++++------------- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/Config/ConfigManager.vb b/Config/ConfigManager.vb index 8a6b75f4..ef68c64a 100644 --- a/Config/ConfigManager.vb +++ b/Config/ConfigManager.vb @@ -6,9 +6,9 @@ Imports DigitalData.Modules.Config.ConfigAttributes Imports DigitalData.Modules.Base Public Class ConfigManager(Of T) - Private Const USER_CONFIG_NAME As String = "UserConfig.xml" - Private Const COMPUTER_CONFIG_NAME As String = "ComputerConfig.xml" - Private Const APP_CONFIG_NAME As String = "AppConfig.xml" + Public Const USER_CONFIG_NAME As String = "UserConfig.xml" + Public Const COMPUTER_CONFIG_NAME As String = "ComputerConfig.xml" + Public Const APP_CONFIG_NAME As String = "AppConfig.xml" Private ReadOnly _LogConfig As LogConfig Private ReadOnly _Logger As Logger diff --git a/Config/ConfigUtils.vb b/Config/ConfigUtils.vb index 7bf25391..b924c0e3 100644 --- a/Config/ConfigUtils.vb +++ b/Config/ConfigUtils.vb @@ -7,22 +7,12 @@ Public Class ConfigUtils Private _File As FilesystemEx Private Const MIGRATE_DIRECTORY As String = "Migrate" - Private Const USER_CONFIG As String = "UserConfig.xml" - Public Sub New(LogConfig As LogConfig) _Logger = LogConfig.GetLogger() _File = New FilesystemEx(LogConfig) End Sub - Public Function TestMigrationNeeded(TargetDirectory As String) As Boolean - If IO.Directory.Exists(TargetDirectory) Then - Return False - Else - Return True - End If - End Function - ''' ''' Migrate a config file when the ProductName has changed ''' @@ -30,11 +20,11 @@ Public Class ConfigUtils ''' The current or new product name ''' The old product name ''' - Public Function MigrateAppDataConfig(pBasePath As String, pProductName As String, pOldProductName As String) + Private Function MigrateAppDataConfig(pBasePath As String, pConfigName As String, pProductName As String, pOldProductName As String) Dim oNewDirPath = pBasePath Dim oOldDirPath = oNewDirPath.Replace(pProductName, pOldProductName) - Dim oNewFilePath = Path.Combine(oNewDirPath, USER_CONFIG) - Dim oOldFilePath = Path.Combine(oOldDirPath, USER_CONFIG) + Dim oNewFilePath = Path.Combine(oNewDirPath, pConfigName) + Dim oOldFilePath = Path.Combine(oOldDirPath, pConfigName) ' If there is already a new config, exit. If File.Exists(oNewFilePath) Then @@ -63,6 +53,14 @@ Public Class ConfigUtils End Try End Function + Public Function TestMigrationNeeded(TargetDirectory As String) As Boolean + If IO.Directory.Exists(TargetDirectory) Then + Return False + Else + Return True + End If + End Function + Public Sub MigrateConfig(SourceDirectory As String, TargetDirectory As String, Optional FilePattern As String = "*.*") 'If IO.Directory.Exists(TargetDirectory) Then ' _Logger.Warn("Config Migration aborted because new config directory [{0}] already exists!", TargetDirectory)