Explorar o código

UI error handling, config error handling

randoman %!s(int64=6) %!d(string=hai) anos
pai
achega
c19bc569d0

+ 49 - 21
src/XUnity.AutoTranslator.Plugin.Core/AutoTranslationPlugin.cs

@@ -137,12 +137,16 @@ namespace XUnity.AutoTranslator.Plugin.Core
 
       public void Initialize()
       {
+         // Setup 'singleton'
          Current = this;
+
+         // Setup logger, if it was not already initialized by a plugin-version
          if( XuaLogger.Current == null )
          {
             XuaLogger.Current = new ConsoleLogger();
          }
 
+         // Setup configuration
          try
          {
             Settings.Configure();
@@ -157,8 +161,13 @@ namespace XUnity.AutoTranslator.Plugin.Core
             return;
          }
 
-         if( Settings.EnableConsole ) DebugConsole.Enable();
+         // Setup console, if enabled
+         if( Settings.EnableConsole )
+         {
+            DebugConsole.Enable();
+         }
 
+         // Setup hooks
          HooksSetup.InstallTextHooks();
          HooksSetup.InstallImageHooks();
          HooksSetup.InstallTextGetterCompatHooks();
@@ -253,31 +262,38 @@ namespace XUnity.AutoTranslator.Plugin.Core
          LoadTranslations();
          LoadStaticTranslations();
 
-         _window = new XuaWindow(
-            new List<ToggleViewModel>
-            {
+         try
+         {
+            _window = new XuaWindow(
+               new List<ToggleViewModel>
+               {
                new ToggleViewModel(
                   " Translated",
                   "<b>TRANSLATED</b>\nThe plugin currently displays translated texts. Disabling this does not mean the plugin will no longer perform translations, just that they will not be displayed.",
                   "<b>NOT TRANSLATED</b>\nThe plugin currently displays untranslated texts.",
                   ToggleTranslation, () => _isInTranslatedMode )
-            },
-            _configuredEndpoints.Select( x =>
-               new TranslatorDropdownOptionViewModel( () => x == _endpoint, x, OnEndpointSelected ) ).ToList(),
-            new List<ButtonViewModel>
-            {
+               },
+               _configuredEndpoints.Select( x =>
+                  new TranslatorDropdownOptionViewModel( () => x == _endpoint, x, OnEndpointSelected ) ).ToList(),
+               new List<ButtonViewModel>
+               {
                new ButtonViewModel( "Reboot", "<b>REBOOT PLUGIN</b>\nReboots the plugin if it has been shutdown. This only works if the plugin was shut down due to consequtive errors towards the translation endpoint.", RebootPlugin, () => Settings.IsShutdown && !Settings.IsShutdownFatal ),
                new ButtonViewModel( "Reload", "<b>RELOAD TRANSLATION</b>\nReloads all translation text files and texture files from disk.", ReloadTranslations, null ),
                new ButtonViewModel( "Hook", "<b>MANUAL HOOK</b>\nTraverses the unity object tree for looking for anything that can be translated. Performs a translation if something is found.", ManualHook, null )
-            },
-            new List<LabelViewModel>
-            {
+               },
+               new List<LabelViewModel>
+               {
                new LabelViewModel( "Version: ", () => PluginData.Version ),
                new LabelViewModel( "Status: ", () => Settings.IsShutdown ? "Shutdown" : "Running" ),
                new LabelViewModel( "Served translations: ", () => $"{Settings.TranslationCount} / {Settings.MaxTranslationsBeforeShutdown}" ),
                new LabelViewModel( "Queued translations: ", () => $"{(_unstartedJobs.Count + _ongoingJobs.Count)} / {Settings.MaxUnstartedJobs}"  ),
                new LabelViewModel( "Error'ed translations: ", () => $"{_consecutiveErrors} / {Settings.MaxErrors}"  ),
-            } );
+               } );
+         }
+         catch( Exception e )
+         {
+            XuaLogger.Current.Error( e, "An error occurred while setting up UI." );
+         }
 
          UnityTextParsers.Initialize( text => IsTranslatable( text ) && IsBelowMaxLength( text ) );
 
@@ -2012,7 +2028,10 @@ namespace XUnity.AutoTranslator.Plugin.Core
                }
                else if( isAltPressed && ( Input.GetKeyDown( KeyCode.Alpha0 ) || Input.GetKeyDown( KeyCode.Keypad0 ) ) )
                {
-                  _window.IsShown = !_window.IsShown;
+                  if( _window != null )
+                  {
+                     _window.IsShown = !_window.IsShown;
+                  }
                }
             }
          }
@@ -2024,15 +2043,24 @@ namespace XUnity.AutoTranslator.Plugin.Core
 
       void OnGUI()
       {
-         try
+         if( _window != null )
          {
-            DisableAutoTranslator();
+            try
+            {
+               DisableAutoTranslator();
 
-            if( _window.IsShown ) _window.OnGUI();
-         }
-         finally
-         {
-            EnableAutoTranslator();
+               if( _window.IsShown ) _window.OnGUI();
+            }
+            catch( Exception e )
+            {
+               XuaLogger.Current.Error( e, "An error occurred in XUnity.AutoTranslator UI. Disabling the UI." );
+
+               _window = null;
+            }
+            finally
+            {
+               EnableAutoTranslator();
+            }
          }
       }
 

+ 48 - 61
src/XUnity.AutoTranslator.Plugin.Core/Configuration/Settings.cs

@@ -87,7 +87,6 @@ namespace XUnity.AutoTranslator.Plugin.Core.Configuration
       public static bool EnableTextureScanOnSceneLoad;
       public static bool EnableSpriteRendererHooking;
       public static bool LoadUnmodifiedTextures;
-      //public static bool DeleteUnmodifiedTextures;
       public static TextureHashGenerationStrategy TextureHashGenerationStrategy;
 
       public static bool CopyToClipboard;
@@ -113,52 +112,52 @@ namespace XUnity.AutoTranslator.Plugin.Core.Configuration
          }
 
 
-         ServiceEndpoint = Config.Current.Preferences[ "Service" ][ "Endpoint" ].GetOrDefault( KnownEndpointNames.GoogleTranslate );
-
-         Language = Config.Current.Preferences[ "General" ][ "Language" ].GetOrDefault( DefaultLanguage );
-         FromLanguage = Config.Current.Preferences[ "General" ][ "FromLanguage" ].GetOrDefault( DefaultFromLanguage );
-
-         TranslationDirectory = Config.Current.Preferences[ "Files" ][ "Directory" ].GetOrDefault( @"Translation" );
-         OutputFile = Config.Current.Preferences[ "Files" ][ "OutputFile" ].GetOrDefault( @"Translation\_AutoGeneratedTranslations.{lang}.txt" );
-
-         EnableIMGUI = Config.Current.Preferences[ "TextFrameworks" ][ "EnableIMGUI" ].GetOrDefault( false );
-         EnableUGUI = Config.Current.Preferences[ "TextFrameworks" ][ "EnableUGUI" ].GetOrDefault( true );
-         EnableNGUI = Config.Current.Preferences[ "TextFrameworks" ][ "EnableNGUI" ].GetOrDefault( true );
-         EnableTextMeshPro = Config.Current.Preferences[ "TextFrameworks" ][ "EnableTextMeshPro" ].GetOrDefault( true );
-         EnableUtage = Config.Current.Preferences[ "TextFrameworks" ][ "EnableUtage" ].GetOrDefault( true );
-         AllowPluginHookOverride = Config.Current.Preferences[ "TextFrameworks" ][ "AllowPluginHookOverride" ].GetOrDefault( true );
-
-         Delay = Config.Current.Preferences[ "Behaviour" ][ "Delay" ].GetOrDefault( 0f );
-         MaxCharactersPerTranslation = Config.Current.Preferences[ "Behaviour" ][ "MaxCharactersPerTranslation" ].GetOrDefault( 200 );
-         IgnoreWhitespaceInDialogue = Config.Current.Preferences[ "Behaviour" ][ "IgnoreWhitespaceInDialogue" ].GetOrDefault( true );
-         IgnoreWhitespaceInNGUI = Config.Current.Preferences[ "Behaviour" ][ "IgnoreWhitespaceInNGUI" ].GetOrDefault( true );
-         MinDialogueChars = Config.Current.Preferences[ "Behaviour" ][ "MinDialogueChars" ].GetOrDefault( 20 );
-         ForceSplitTextAfterCharacters = Config.Current.Preferences[ "Behaviour" ][ "ForceSplitTextAfterCharacters" ].GetOrDefault( 0 );
-         CopyToClipboard = Config.Current.Preferences[ "Behaviour" ][ "CopyToClipboard" ].GetOrDefault( false );
-         MaxClipboardCopyCharacters = Config.Current.Preferences[ "Behaviour" ][ "MaxClipboardCopyCharacters" ].GetOrDefault( 450 );
-         EnableUIResizing = Config.Current.Preferences[ "Behaviour" ][ "EnableUIResizing" ].GetOrDefault( true );
-         EnableBatching = Config.Current.Preferences[ "Behaviour" ][ "EnableBatching" ].GetOrDefault( true );
-         TrimAllText = Config.Current.Preferences[ "Behaviour" ][ "TrimAllText" ].GetOrDefault( ClrTypes.AdvEngine == null );
-         UseStaticTranslations = Config.Current.Preferences[ "Behaviour" ][ "UseStaticTranslations" ].GetOrDefault( true );
-         OverrideFont = Config.Current.Preferences[ "Behaviour" ][ "OverrideFont" ].GetOrDefault( string.Empty );
-         ResizeUILineSpacingScale = Config.Current.Preferences[ "Behaviour" ][ "ResizeUILineSpacingScale" ].GetOrDefault<float?>( null );
-         ForceUIResizing = Config.Current.Preferences[ "Behaviour" ][ "ForceUIResizing" ].GetOrDefault( false );
-         IgnoreTextStartingWith = Config.Current.Preferences[ "Behaviour" ][ "IgnoreTextStartingWith" ].GetOrDefault( "\\u180e;" )
+         ServiceEndpoint = Config.Current.Preferences.GetOrDefault( "Service", "Endpoint", KnownEndpointNames.GoogleTranslate );
+
+         Language = Config.Current.Preferences.GetOrDefault( "General", "Language", DefaultLanguage );
+         FromLanguage = Config.Current.Preferences.GetOrDefault( "General", "FromLanguage", DefaultFromLanguage );
+
+         TranslationDirectory = Config.Current.Preferences.GetOrDefault( "Files", "Directory", "Translation" );
+         OutputFile = Config.Current.Preferences.GetOrDefault( "Files", "OutputFile", @"Translation\_AutoGeneratedTranslations.{lang}.txt" );
+
+         EnableIMGUI = Config.Current.Preferences.GetOrDefault( "TextFrameworks", "EnableIMGUI", false );
+         EnableUGUI = Config.Current.Preferences.GetOrDefault( "TextFrameworks", "EnableUGUI", true );
+         EnableNGUI = Config.Current.Preferences.GetOrDefault( "TextFrameworks", "EnableNGUI", true );
+         EnableTextMeshPro = Config.Current.Preferences.GetOrDefault( "TextFrameworks", "EnableTextMeshPro", true );
+         EnableUtage = Config.Current.Preferences.GetOrDefault( "TextFrameworks", "EnableUtage", true );
+         AllowPluginHookOverride = Config.Current.Preferences.GetOrDefault( "TextFrameworks", "AllowPluginHookOverride", true );
+
+         Delay = Config.Current.Preferences.GetOrDefault( "Behaviour", "Delay", 0f );
+         MaxCharactersPerTranslation = Config.Current.Preferences.GetOrDefault( "Behaviour", "MaxCharactersPerTranslation", 200 );
+         IgnoreWhitespaceInDialogue = Config.Current.Preferences.GetOrDefault( "Behaviour", "IgnoreWhitespaceInDialogue", true );
+         IgnoreWhitespaceInNGUI = Config.Current.Preferences.GetOrDefault( "Behaviour", "IgnoreWhitespaceInNGUI", true );
+         MinDialogueChars = Config.Current.Preferences.GetOrDefault( "Behaviour", "MinDialogueChars", 20 );
+         ForceSplitTextAfterCharacters = Config.Current.Preferences.GetOrDefault( "Behaviour", "ForceSplitTextAfterCharacters", 0 );
+         CopyToClipboard = Config.Current.Preferences.GetOrDefault( "Behaviour", "CopyToClipboard", false );
+         MaxClipboardCopyCharacters = Config.Current.Preferences.GetOrDefault( "Behaviour", "MaxClipboardCopyCharacters", 450 );
+         EnableUIResizing = Config.Current.Preferences.GetOrDefault( "Behaviour", "EnableUIResizing", true );
+         EnableBatching = Config.Current.Preferences.GetOrDefault( "Behaviour", "EnableBatching", true );
+         TrimAllText = Config.Current.Preferences.GetOrDefault( "Behaviour", "TrimAllText", ClrTypes.AdvEngine == null );
+         UseStaticTranslations = Config.Current.Preferences.GetOrDefault( "Behaviour", "UseStaticTranslations", true );
+         OverrideFont = Config.Current.Preferences.GetOrDefault( "Behaviour", "OverrideFont", string.Empty );
+         ResizeUILineSpacingScale = Config.Current.Preferences.GetOrDefault<float?>( "Behaviour", "ResizeUILineSpacingScale", null );
+         ForceUIResizing = Config.Current.Preferences.GetOrDefault( "Behaviour", "ForceUIResizing", false );
+         IgnoreTextStartingWith = Config.Current.Preferences.GetOrDefault( "Behaviour", "IgnoreTextStartingWith", "\\u180e;" )
             ?.Split( new[] { ';' }, StringSplitOptions.RemoveEmptyEntries ).Select( x => x.UnescapeJson() ).ToArray() ?? new string[ 0 ];
-         TextGetterCompatibilityMode = Config.Current.Preferences[ "Behaviour" ][ "TextGetterCompatibilityMode" ].GetOrDefault( false );
-         GameLogTextPaths = Config.Current.Preferences[ "Behaviour" ][ "GameLogTextPaths" ].GetOrDefault( "" )
+         TextGetterCompatibilityMode = Config.Current.Preferences.GetOrDefault( "Behaviour", "TextGetterCompatibilityMode", false );
+         GameLogTextPaths = Config.Current.Preferences.GetOrDefault( "Behaviour", "GameLogTextPaths", string.Empty )
             ?.Split( new[] { ';' }, StringSplitOptions.RemoveEmptyEntries ).ToHashSet() ?? new HashSet<string>();
          GameLogTextPaths.RemoveWhere( x => !x.StartsWith( "/" ) ); // clean up to ensure no 'empty' entries
+         WhitespaceRemovalStrategy = Config.Current.Preferences.GetOrDefault( "Behaviour", "WhitespaceRemovalStrategy", WhitespaceHandlingStrategy.TrimPerNewline );
 
-         TextureDirectory = Config.Current.Preferences[ "Texture" ][ "TextureDirectory" ].GetOrDefault( @"Translation\Texture" );
-         EnableTextureTranslation = Config.Current.Preferences[ "Texture" ][ "EnableTextureTranslation" ].GetOrDefault( false );
-         EnableTextureDumping = Config.Current.Preferences[ "Texture" ][ "EnableTextureDumping" ].GetOrDefault( false );
-         EnableTextureToggling = Config.Current.Preferences[ "Texture" ][ "EnableTextureToggling" ].GetOrDefault( false );
-         EnableTextureScanOnSceneLoad = Config.Current.Preferences[ "Texture" ][ "EnableTextureScanOnSceneLoad" ].GetOrDefault( false );
-         EnableSpriteRendererHooking = Config.Current.Preferences[ "Texture" ][ "EnableSpriteRendererHooking" ].GetOrDefault( false );
-         LoadUnmodifiedTextures = Config.Current.Preferences[ "Texture" ][ "LoadUnmodifiedTextures" ].GetOrDefault( false );
-         //DeleteUnmodifiedTextures = Config.Current.Preferences[ "Texture" ][ "DeleteUnmodifiedTextures" ].GetOrDefault( false );
-         TextureHashGenerationStrategy = Config.Current.Preferences[ "Texture" ][ "TextureHashGenerationStrategy" ].GetOrDefault( TextureHashGenerationStrategy.FromImageName );
+         TextureDirectory = Config.Current.Preferences.GetOrDefault( "Texture", "TextureDirectory", @"Translation\Texture" );
+         EnableTextureTranslation = Config.Current.Preferences.GetOrDefault( "Texture", "EnableTextureTranslation", false );
+         EnableTextureDumping = Config.Current.Preferences.GetOrDefault( "Texture", "EnableTextureDumping", false );
+         EnableTextureToggling = Config.Current.Preferences.GetOrDefault( "Texture", "EnableTextureToggling", false );
+         EnableTextureScanOnSceneLoad = Config.Current.Preferences.GetOrDefault( "Texture", "EnableTextureScanOnSceneLoad", false );
+         EnableSpriteRendererHooking = Config.Current.Preferences.GetOrDefault( "Texture", "EnableSpriteRendererHooking", false );
+         LoadUnmodifiedTextures = Config.Current.Preferences.GetOrDefault( "Texture", "LoadUnmodifiedTextures", false );
+         TextureHashGenerationStrategy = Config.Current.Preferences.GetOrDefault( "Texture", "TextureHashGenerationStrategy", TextureHashGenerationStrategy.FromImageName );
 
          if( MaxCharactersPerTranslation > MaxMaxCharactersPerTranslation )
          {
@@ -166,26 +165,14 @@ namespace XUnity.AutoTranslator.Plugin.Core.Configuration
             MaxCharactersPerTranslation = MaxMaxCharactersPerTranslation;
          }
 
-         // special handling because of enum parsing
-         try
-         {
-            WhitespaceRemovalStrategy = Config.Current.Preferences[ "Behaviour" ][ "WhitespaceRemovalStrategy" ].GetOrDefault( WhitespaceHandlingStrategy.TrimPerNewline );
-         }
-         catch( Exception e )
-         {
-            WhitespaceRemovalStrategy = WhitespaceHandlingStrategy.TrimPerNewline;
-
-            XuaLogger.Current.Warn( e, "An error occurred while configuring 'WhitespaceRemovalStrategy'. Using default." );
-         }
-
-         UserAgent = Config.Current.Preferences[ "Http" ][ "UserAgent" ].GetOrDefault( string.Empty );
+         UserAgent = Config.Current.Preferences.GetOrDefault( "Http", "UserAgent", string.Empty );
 
-         EnablePrintHierarchy = Config.Current.Preferences[ "Debug" ][ "EnablePrintHierarchy" ].GetOrDefault( false );
-         EnableConsole = Config.Current.Preferences[ "Debug" ][ "EnableConsole" ].GetOrDefault( false );
-         EnableDebugLogs = Config.Current.Preferences[ "Debug" ][ "EnableLog" ].GetOrDefault( false );
+         EnablePrintHierarchy = Config.Current.Preferences.GetOrDefault( "Debug", "EnablePrintHierarchy", false );
+         EnableConsole = Config.Current.Preferences.GetOrDefault( "Debug", "EnableConsole", false );
+         EnableDebugLogs = Config.Current.Preferences.GetOrDefault( "Debug", "EnableLog", false );
 
-         EnableMigrations = Config.Current.Preferences[ "Migrations" ][ "Enable" ].GetOrDefault( true );
-         MigrationsTag = Config.Current.Preferences[ "Migrations" ][ "Tag" ].GetOrDefault( string.Empty );
+         EnableMigrations = Config.Current.Preferences.GetOrDefault( "Migrations", "Enable", true );
+         MigrationsTag = Config.Current.Preferences.GetOrDefault( "Migrations", "Tag", string.Empty );
 
          AutoTranslationsFilePath = Path.Combine( Config.Current.DataPath, OutputFile.Replace( "{lang}", Language ) ).Replace( "/", "\\" ).Parameterize();
          UsesWhitespaceBetweenWords = LanguageHelper.RequiresWhitespaceUponLineMerging( FromLanguage );

+ 2 - 2
src/XUnity.AutoTranslator.Plugin.Core/Endpoints/InitializationContext.cs

@@ -42,12 +42,12 @@ namespace XUnity.AutoTranslator.Plugin.Core.Endpoints
 
       public T GetOrCreateSetting<T>( string section, string key, T defaultValue )
       {
-         return Config.Current.Preferences[ section ][ key ].GetOrDefault<T>( defaultValue );
+         return Config.Current.Preferences.GetOrDefault( section, key, defaultValue );
       }
 
       public T GetOrCreateSetting<T>( string section, string key )
       {
-         return Config.Current.Preferences[ section ][ key ].GetOrDefault<T>( default( T ) );
+         return Config.Current.Preferences.GetOrDefault( section, key, default( T ) );
       }
    }
 }

+ 80 - 0
src/XUnity.AutoTranslator.Plugin.Core/Extensions/IniFileExtensions.cs

@@ -0,0 +1,80 @@
+using System;
+using System.Globalization;
+using ExIni;
+
+namespace XUnity.AutoTranslator.Plugin.Core.Extensions
+{
+   internal static class IniFileExtensions
+   {
+      public static T GetOrDefault<T>( this IniFile that, string section, string key, T defaultValue )
+      {
+         var typeOfT = typeof( T ).UnwrapNullable();
+         var iniSection = that[ section ];
+         var iniKey = iniSection[ key ];
+
+         try
+         {
+            var value = iniKey.Value;
+
+            if( value == null ) // we want to use the default value, because it is null, the config has just been created
+            {
+               if( defaultValue != null )
+               {
+                  if( typeOfT.IsEnum )
+                  {
+                     iniKey.Value = Enum.GetName( typeOfT, defaultValue );
+                  }
+                  else
+                  {
+                     iniKey.Value = Convert.ToString( defaultValue, CultureInfo.InvariantCulture );
+                  }
+               }
+               else
+               {
+                  iniKey.Value = string.Empty;
+               }
+               return defaultValue;
+            }
+            else
+            {
+               // there exists a value in the config, so we do not want to set anything
+               // we just want to return what we can find, default not included
+               if( !string.IsNullOrEmpty( value ) )
+               {
+                  if( typeOfT.IsEnum )
+                  {
+                     return (T)Enum.Parse( typeOfT, iniKey.Value, true );
+                  }
+                  else
+                  {
+                     return (T)Convert.ChangeType( iniKey.Value, typeOfT, CultureInfo.InvariantCulture );
+                  }
+               }
+               return default( T );
+            }
+         }
+         catch( Exception e )
+         {
+            XuaLogger.Current.Error( e, $"Error occurred while reading config '{key}' in section '{section}'. Updating the config to its default value '{defaultValue}'." );
+
+            if( defaultValue != null )
+            {
+               if( typeOfT.IsEnum )
+               {
+                  iniKey.Value = Enum.GetName( typeOfT, defaultValue );
+               }
+               else
+               {
+                  iniKey.Value = Convert.ToString( defaultValue, CultureInfo.InvariantCulture );
+               }
+            }
+            else
+            {
+               iniKey.Value = string.Empty;
+            }
+
+            return defaultValue;
+         }
+      }
+   }
+}

+ 54 - 54
src/XUnity.AutoTranslator.Plugin.Core/Extensions/IniKeyExtensions.cs

@@ -1,56 +1,56 @@
-using System;
-using System.Collections.Generic;
-using System.Globalization;
-using System.Linq;
-using System.Text;
-using ExIni;
-using XUnity.AutoTranslator.Plugin.Core.Extensions;
+//using System;
+//using System.Collections.Generic;
+//using System.Globalization;
+//using System.Linq;
+//using System.Text;
+//using ExIni;
+//using XUnity.AutoTranslator.Plugin.Core.Extensions;
 
-namespace XUnity.AutoTranslator.Plugin.Core.Extensions
-{
-   internal static class IniKeyExtensions
-   {
-      public static T GetOrDefault<T>( this IniKey that, T defaultValue )
-      {
-         var typeOfT = typeof( T ).UnwrapNullable();
-         var value = that.Value;
+//namespace XUnity.AutoTranslator.Plugin.Core.Extensions
+//{
+//   internal static class IniKeyExtensions
+//   {
+//      public static T GetOrDefault<T>( this IniKey that, T defaultValue )
+//      {
+//         var typeOfT = typeof( T ).UnwrapNullable();
+//         var value = that.Value;
 
-         if( value == null ) // we want to use the default value, because it is null, the config has just been created
-         {
-            if( defaultValue != null )
-            {
-               if( typeOfT.IsEnum )
-               {
-                  that.Value = Enum.GetName( typeOfT, defaultValue );
-               }
-               else
-               {
-                  that.Value = Convert.ToString( defaultValue, CultureInfo.InvariantCulture );
-               }
-            }
-            else
-            {
-               that.Value = string.Empty;
-            }
-            return defaultValue;
-         }
-         else
-         {
-            // there exists a value in the config, so we do not want to set anything
-            // we just want to return what we can find, default not included
-            if( !string.IsNullOrEmpty( value ) )
-            {
-               if( typeOfT.IsEnum )
-               {
-                  return (T)Enum.Parse( typeOfT, that.Value, true );
-               }
-               else
-               {
-                  return (T)Convert.ChangeType( that.Value, typeOfT, CultureInfo.InvariantCulture );
-               }
-            }
-            return default( T );
-         }
-      }
-   }
-}
+//         if( value == null ) // we want to use the default value, because it is null, the config has just been created
+//         {
+//            if( defaultValue != null )
+//            {
+//               if( typeOfT.IsEnum )
+//               {
+//                  that.Value = Enum.GetName( typeOfT, defaultValue );
+//               }
+//               else
+//               {
+//                  that.Value = Convert.ToString( defaultValue, CultureInfo.InvariantCulture );
+//               }
+//            }
+//            else
+//            {
+//               that.Value = string.Empty;
+//            }
+//            return defaultValue;
+//         }
+//         else
+//         {
+//            // there exists a value in the config, so we do not want to set anything
+//            // we just want to return what we can find, default not included
+//            if( !string.IsNullOrEmpty( value ) )
+//            {
+//               if( typeOfT.IsEnum )
+//               {
+//                  return (T)Enum.Parse( typeOfT, that.Value, true );
+//               }
+//               else
+//               {
+//                  return (T)Convert.ChangeType( that.Value, typeOfT, CultureInfo.InvariantCulture );
+//               }
+//            }
+//            return default( T );
+//         }
+//      }
+//   }
+//}