diff --git a/Modules.Config/ConfigManager.vb b/Modules.Config/ConfigManager.vb
index ac5151d2..446190e2 100644
--- a/Modules.Config/ConfigManager.vb
+++ b/Modules.Config/ConfigManager.vb
@@ -7,6 +7,7 @@ Imports DigitalData.Modules.Config.ConfigAttributes
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"
Private ReadOnly _LogConfig As LogConfig
Private ReadOnly _Logger As Logger
@@ -17,6 +18,7 @@ Public Class ConfigManager(Of T)
Private ReadOnly _ComputerDirectory As String
Private ReadOnly _ComputerConfigPath As String
Private ReadOnly _AppConfigPath As String
+ Private ReadOnly _AppConfigDirectory As String
Private ReadOnly _TestMode As Boolean = False
@@ -70,6 +72,7 @@ Public Class ConfigManager(Of T)
''' LogConfig instance
''' The path to check for a user config file, eg. AppData (Usually Application.UserAppDataPath or Application.LocalUserAppDataPath)
''' The path to check for a computer config file, eg. ProgramData (Usually Application.CommonAppDataPath)
+ ''' The path to check for a third config file. This is useful when running the Application in an environment where AppData/ProgramData directories are not available
''' Override values from ComputerConfig with UserConfig
Public Sub New(LogConfig As LogConfig, UserConfigPath As String, ComputerConfigPath As String, ApplicationStartupPath As String, Optional ForceUserConfig As Boolean = False)
_LogConfig = LogConfig
@@ -82,11 +85,12 @@ Public Class ConfigManager(Of T)
_UserDirectory = _File.CreateDirectory(UserConfigPath)
_ComputerDirectory = _File.CreateDirectory(ComputerConfigPath)
+ _AppConfigDirectory = _File.CreateDirectory(ApplicationStartupPath)
_ForceUserConfig = ForceUserConfig
_UserConfigPath = Path.Combine(_UserDirectory, USER_CONFIG_NAME)
_ComputerConfigPath = Path.Combine(_ComputerDirectory, COMPUTER_CONFIG_NAME)
- _AppConfigPath = Path.Combine(ApplicationStartupPath, "AppConfig.xml")
+ _AppConfigPath = Path.Combine(_AppConfigDirectory, APP_CONFIG_NAME)
Config = LoadConfig()
End Sub
@@ -163,7 +167,10 @@ Public Class ConfigManager(Of T)
' first create an empty/default config object
Dim oConfig = Activator.CreateInstance(_BlueprintType)
+ ' try to load the special app config
+ ' returns nothing if app was not found or could not be loaded
oConfig = LoadAppConfig(oConfig)
+
If oConfig Is Nothing Then
oConfig = Activator.CreateInstance(_BlueprintType)
' then Try to load computer config
@@ -174,6 +181,7 @@ Public Class ConfigManager(Of T)
oConfig = LoadUserConfig(oConfig)
Return oConfig
End Function
+
Private Function LoadAppConfig(ByVal Config As T) As T
If File.Exists(_AppConfigPath) Then
Try
@@ -182,6 +190,7 @@ Public Class ConfigManager(Of T)
Catch ex As Exception
_Logger.Error(ex)
_Logger.Warn("ApplicationConfig could not be loaded!")
+ Return Nothing
End Try
Else
_Logger.Debug("ApplicationConfig does not exist.")