Add UserConfig Prefix and Config Migration

This commit is contained in:
Jonathan Jenne
2020-12-17 16:55:17 +01:00
parent 82897a2f12
commit 651c5bc2d6
5 changed files with 40 additions and 8 deletions

View File

@@ -42,15 +42,32 @@ Public Class ClassInit
<STAThread()>
Public Sub InitUserConfig()
Try
Dim AppdataPath = Application.UserAppDataPath
Dim CommonAppDataPath = Application.CommonAppDataPath
Dim StartupPath = Application.StartupPath
If My.Settings.UseAppConfigConString = True Then
AppdataPath = StartupPath
CommonAppDataPath = StartupPath
Dim oUserAppDataPath As String = Application.UserAppDataPath
Dim oLegacyAppDataPath As String = Application.UserAppDataPath
Dim oCommonAppDataPath = Application.CommonAppDataPath
Dim oStartupPath = Application.StartupPath
Dim oConfigPrefix As String = My.Settings.UserConfig_Prefix
' If prefix is configured, use it to create a subfolder in app data and migrate existing data
If oConfigPrefix.Length > 0 Then
oUserAppDataPath = IO.Path.Combine(Application.UserAppDataPath, oConfigPrefix)
Dim oConfigUtils As New ConfigUtils(LOGCONFIG)
If oConfigUtils.TestMigrationNeeded(oUserAppDataPath) Then
LOGCONFIG.Debug = True
oConfigUtils.MigrateConfig(oLegacyAppDataPath, oUserAppDataPath)
LOGCONFIG.Debug = False
End If
End If
CONFIG = New ConfigManager(Of ClassConfig)(LOGCONFIG, AppdataPath, CommonAppDataPath, StartupPath)
' If AppConfig from Startup Path should be forced, rewrite the common app data path
If My.Settings.UseAppConfigConString = True Then
' UserAppDataPath = StartupPath
oCommonAppDataPath = oStartupPath
End If
CONFIG = New ConfigManager(Of ClassConfig)(LOGCONFIG, oUserAppDataPath, oCommonAppDataPath, oStartupPath)
LOGGER.Info("Config loaded")
If CONFIG.Config.ConnectionStringTest <> String.Empty And CONFIG.Config.TestMode = True Then