Config: improve config migration

This commit is contained in:
Jonathan Jenne 2023-10-04 13:21:03 +02:00
parent aa27dd8c1c
commit 441f65915f

View File

@ -23,8 +23,15 @@ Public Class ConfigUtils
End If
End Function
Public Function MigrateAppDataConfig(pUserAppDataPath As String, pProductName As String, pOldProductName As String)
Dim oNewDirPath = pUserAppDataPath
''' <summary>
''' Migrate a config file when the ProductName has changed
''' </summary>
''' <param name="pBasePath">The config base path, can be Application.UserAppDataPath or Application.CommonAppDataPath</param>
''' <param name="pProductName">The current or new product name</param>
''' <param name="pOldProductName">The old product name</param>
''' <returns></returns>
Public Function MigrateAppDataConfig(pBasePath 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)
@ -45,7 +52,7 @@ Public Class ConfigUtils
End If
_Logger.Info("Migrating Config from [{0}] to [{1}]", pOldProductName, pProductName)
File.Copy(oOldFilePath, oNewFilePath)
File.Move(oOldFilePath, oNewFilePath)
Return True
Catch ex As Exception