ConfigManager: fix paths
This commit is contained in:
parent
5e488b6526
commit
cd5f982b46
@ -11,8 +11,12 @@ Public Class ConfigManager(Of T)
|
|||||||
Private ReadOnly _LogConfig As LogConfig
|
Private ReadOnly _LogConfig As LogConfig
|
||||||
Private ReadOnly _Logger As Logger
|
Private ReadOnly _Logger As Logger
|
||||||
Private ReadOnly _File As Filesystem.File
|
Private ReadOnly _File As Filesystem.File
|
||||||
|
|
||||||
Private ReadOnly _UserDirectory As String
|
Private ReadOnly _UserDirectory As String
|
||||||
|
Private ReadOnly _UserConfigPath As String
|
||||||
Private ReadOnly _ComputerDirectory As String
|
Private ReadOnly _ComputerDirectory As String
|
||||||
|
Private ReadOnly _ComputerConfigPath As String
|
||||||
|
|
||||||
Private ReadOnly _TestMode As Boolean = False
|
Private ReadOnly _TestMode As Boolean = False
|
||||||
|
|
||||||
Private ReadOnly _Blueprint As T
|
Private ReadOnly _Blueprint As T
|
||||||
@ -38,12 +42,20 @@ Public Class ConfigManager(Of T)
|
|||||||
''' </summary>
|
''' </summary>
|
||||||
''' <returns></returns>
|
''' <returns></returns>
|
||||||
Public ReadOnly Property UserConfigPath As String
|
Public ReadOnly Property UserConfigPath As String
|
||||||
|
Get
|
||||||
|
Return _UserConfigPath
|
||||||
|
End Get
|
||||||
|
End Property
|
||||||
|
|
||||||
''' <summary>
|
''' <summary>
|
||||||
''' Path to the current computer config. Maybe the same as `UserConfigPath`
|
''' Path to the current computer config. Maybe the same as `UserConfigPath`
|
||||||
''' </summary>
|
''' </summary>
|
||||||
''' <returns></returns>
|
''' <returns></returns>
|
||||||
Public ReadOnly Property ComputerConfigPath As String
|
Public ReadOnly Property ComputerConfigPath As String
|
||||||
|
Get
|
||||||
|
Return _ComputerConfigPath
|
||||||
|
End Get
|
||||||
|
End Property
|
||||||
|
|
||||||
''' <summary>
|
''' <summary>
|
||||||
''' Creates a new instance of the ConfigManager
|
''' Creates a new instance of the ConfigManager
|
||||||
@ -66,8 +78,8 @@ Public Class ConfigManager(Of T)
|
|||||||
_ComputerDirectory = _File.CreateDirectory(ComputerConfigPath)
|
_ComputerDirectory = _File.CreateDirectory(ComputerConfigPath)
|
||||||
_ForceUserConfig = ForceUserConfig
|
_ForceUserConfig = ForceUserConfig
|
||||||
|
|
||||||
UserConfigPath = Path.Combine(_UserDirectory, USER_CONFIG_NAME)
|
_UserConfigPath = Path.Combine(_UserDirectory, USER_CONFIG_NAME)
|
||||||
ComputerConfigPath = Path.Combine(_ComputerDirectory, COMPUTER_CONFIG_NAME)
|
_ComputerConfigPath = Path.Combine(_ComputerDirectory, COMPUTER_CONFIG_NAME)
|
||||||
|
|
||||||
Config = LoadConfig()
|
Config = LoadConfig()
|
||||||
End Sub
|
End Sub
|
||||||
@ -88,7 +100,7 @@ Public Class ConfigManager(Of T)
|
|||||||
''' <returns>True if save was successful, False otherwise</returns>
|
''' <returns>True if save was successful, False otherwise</returns>
|
||||||
Public Function Save(Optional ForceAll As Boolean = False) As Boolean
|
Public Function Save(Optional ForceAll As Boolean = False) As Boolean
|
||||||
Try
|
Try
|
||||||
WriteToFile(Config, UserConfigPath, ForceAll)
|
WriteToFile(Config, _UserConfigPath, ForceAll)
|
||||||
Return True
|
Return True
|
||||||
Catch ex As Exception
|
Catch ex As Exception
|
||||||
_Logger.Error(ex)
|
_Logger.Error(ex)
|
||||||
@ -152,9 +164,9 @@ Public Class ConfigManager(Of T)
|
|||||||
|
|
||||||
|
|
||||||
Private Function LoadComputerConfig(ByVal Config As T) As T
|
Private Function LoadComputerConfig(ByVal Config As T) As T
|
||||||
If File.Exists(ComputerConfigPath) Then
|
If File.Exists(_ComputerConfigPath) Then
|
||||||
Try
|
Try
|
||||||
Dim oComputerConfig = ReadFromFile(ComputerConfigPath)
|
Dim oComputerConfig = ReadFromFile(_ComputerConfigPath)
|
||||||
CopyValues(oComputerConfig, Config)
|
CopyValues(oComputerConfig, Config)
|
||||||
Catch ex As Exception
|
Catch ex As Exception
|
||||||
_Logger.Error(ex)
|
_Logger.Error(ex)
|
||||||
@ -169,9 +181,9 @@ Public Class ConfigManager(Of T)
|
|||||||
End Function
|
End Function
|
||||||
|
|
||||||
Private Function LoadUserConfig(ByVal Config As T) As T
|
Private Function LoadUserConfig(ByVal Config As T) As T
|
||||||
If File.Exists(UserConfigPath) Then
|
If File.Exists(_UserConfigPath) Then
|
||||||
Try
|
Try
|
||||||
Dim oUserConfig = ReadFromFile(UserConfigPath)
|
Dim oUserConfig = ReadFromFile(_UserConfigPath)
|
||||||
|
|
||||||
' if user config exists
|
' if user config exists
|
||||||
If Not IsNothing(oUserConfig) Then
|
If Not IsNothing(oUserConfig) Then
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user