/// <summary> /// Load the configuration file from disk or from resource if it does not exist /// </summary> public void Load() { Tracer.Verbose("ThemeManager:Load", "START"); try { string file = Path.Combine(PathHelper.ApplicationPath, "ThemeManagerConfig.xml"); // if found in current directory if (File.Exists(file)) { using (Stream s = File.OpenRead(file)) { if (s == null) { throw new InvalidOperationException("Could not open themes file"); } ThemeElementCollection elem = (ThemeElementCollection)SerializeHelper.Deserialize(s, typeof(ThemeElementCollection), true); _ThemeElements = elem.ThemeElement; //load selected resources InitializeResource(_ThemeElements.Where(p => p.IsSelected == true).ToList()); } } else { //load the config from resources using (Stream s = Application.ResourceAssembly.GetManifestResourceStream("ReflectionStudio.Resources.Embedded.ThemeManagerConfig.xml")) { if (s == null) { throw new InvalidOperationException("Could not find embedded resource"); } ThemeElementCollection elem = (ThemeElementCollection)SerializeHelper.Deserialize(s, typeof(ThemeElementCollection), true); _ThemeElements = elem.ThemeElement; //load default resources InitializeResource(_ThemeElements.Where(p => p.IsDefault == true).ToList()); } } } catch (Exception all) { Tracer.Error("ThemeManager.Load", all); } Tracer.Verbose("ThemeManager:Load", "END"); }
/// <summary> /// Save the configuration to the disk with the current selected resource /// </summary> /// <returns></returns> public bool Save() { Tracer.Verbose("ThemeManager:Save", "START"); bool result = false; try { ThemeElementCollection col = new ThemeElementCollection(); col.ThemeElement = _ThemeElements; result = SerializeHelper.Serialize(Path.Combine(PathHelper.ApplicationPath, "ThemeManagerConfig.xml"), col, true); } catch (Exception all) { Tracer.Error("ThemeManager.Save", all); } Tracer.Verbose("ThemeManager:Save", "END"); return(result); }