1212namespace Rubberduck . Config
1313{
1414 [ ComVisible ( false ) ]
15- public static class ConfigurationLoader
15+ public class ConfigurationLoader : IConfigurationService
1616 {
17- private static string configFile = Environment . GetFolderPath ( Environment . SpecialFolder . ApplicationData ) + @"\ Rubberduck\ rubberduck.config";
17+ private static string configFile = Path . Combine ( Environment . GetFolderPath ( Environment . SpecialFolder . ApplicationData ) , " Rubberduck" , " rubberduck.config") ;
1818
1919 /// <summary> Saves a Configuration to Rubberduck.config XML file via Serialization.</summary>
20- public static void SaveConfiguration < T > ( T toSerialize )
20+ public void SaveConfiguration < T > ( T toSerialize )
2121 {
2222 XmlSerializer xmlSerializer = new XmlSerializer ( toSerialize . GetType ( ) ) ;
2323 using ( TextWriter textWriter = new StreamWriter ( configFile ) )
@@ -28,14 +28,30 @@ public static void SaveConfiguration<T>(T toSerialize)
2828
2929 /// <summary> Loads the configuration from Rubberduck.config xml file. </summary>
3030 /// <remarks> If an IOException occurs returns a default configuration.</remarks>
31- public static Configuration LoadConfiguration ( )
31+ public Configuration LoadConfiguration ( )
3232 {
3333 try
3434 {
3535 using ( StreamReader reader = new StreamReader ( configFile ) )
3636 {
3737 var deserializer = new XmlSerializer ( typeof ( Configuration ) ) ;
38- return ( Configuration ) deserializer . Deserialize ( reader ) ;
38+ var config = ( Configuration ) deserializer . Deserialize ( reader ) ;
39+
40+ //deserialization can silently fail for just parts of the config,
41+ // so we null check and return defaults if necessary.
42+ if ( config . UserSettings . ToDoListSettings == null )
43+ {
44+ config . UserSettings . ToDoListSettings = new ToDoListSettings ( GetDefaultTodoMarkers ( ) ) ;
45+ }
46+
47+ if ( config . UserSettings . CodeInspectionSettings == null )
48+ {
49+ config . UserSettings . CodeInspectionSettings = new CodeInspectionSettings ( GetDefaultCodeInspections ( ) ) ;
50+ }
51+
52+ //todo: check for implemented inspections that aren't in config file
53+
54+ return config ;
3955 }
4056 }
4157 catch ( IOException )
@@ -64,7 +80,7 @@ public static Configuration LoadConfiguration()
6480 }
6581 }
6682
67- public static Configuration GetDefaultConfiguration ( )
83+ public Configuration GetDefaultConfiguration ( )
6884 {
6985 var userSettings = new UserSettings (
7086 new ToDoListSettings ( GetDefaultTodoMarkers ( ) ) ,
@@ -74,7 +90,7 @@ public static Configuration GetDefaultConfiguration()
7490 return new Configuration ( userSettings ) ;
7591 }
7692
77- public static ToDoMarker [ ] GetDefaultTodoMarkers ( )
93+ public ToDoMarker [ ] GetDefaultTodoMarkers ( )
7894 {
7995 var note = new ToDoMarker ( "NOTE:" , TodoPriority . Low ) ;
8096 var todo = new ToDoMarker ( "TODO:" , TodoPriority . Normal ) ;
@@ -85,7 +101,7 @@ public static ToDoMarker[] GetDefaultTodoMarkers()
85101
86102 /// <summary> Converts implemented code inspections into array of Config.CodeInspection objects. </summary>
87103 /// <returns> An array of Config.CodeInspection. </returns>
88- public static CodeInspection [ ] GetDefaultCodeInspections ( )
104+ public CodeInspection [ ] GetDefaultCodeInspections ( )
89105 {
90106 var configInspections = new List < CodeInspection > ( ) ;
91107 foreach ( var inspection in GetImplementedCodeInspections ( ) )
@@ -97,7 +113,7 @@ public static CodeInspection[] GetDefaultCodeInspections()
97113 }
98114
99115 /// <summary> Gets all implemented code inspections via reflection </summary>
100- public static IList < IInspection > GetImplementedCodeInspections ( )
116+ public IList < IInspection > GetImplementedCodeInspections ( )
101117 {
102118 var inspections = Assembly . GetExecutingAssembly ( )
103119 . GetTypes ( )
@@ -115,7 +131,7 @@ public static IList<IInspection> GetImplementedCodeInspections()
115131 }
116132
117133 /// <summary> Gets all implemented syntax via reflection. </summary>
118- public static List < ISyntax > GetImplementedSyntax ( )
134+ public List < ISyntax > GetImplementedSyntax ( )
119135 {
120136 var grammar = Assembly . GetExecutingAssembly ( )
121137 . GetTypes ( )
0 commit comments