Ejemplo n.º 1
0
		//TODO: is thread safety required?
		/// <summary>
		/// save visual settings and set as current if succeeded
		/// </summary>
		/// <param name="visualSettings">visual settings to save</param>
		public static void UpdateVisualSettings(VisualSettings visualSettings) {
			if (visualSettings == null) {
				visualSettings = defaultVisualSettings;
			}
			var fi = new FileInfo(Path.Combine(ConfigFolderPath, VisualSettings.name));
			if (!fi.Exists) {
				fi.Directory.Create();
			}
			try {
				using (var fs = fi.Open(FileMode.Create, FileAccess.Write, FileShare.None)) {
					using (var xw = new XmlTextWriter(fs, Encoding.UTF8)) {
						xw.Formatting = Formatting.Indented;
						visualSettings.Serialize().WriteTo(xw);
					}
				}
				_visualSettings = visualSettings;
			} catch {
				log.WriteError("failed to update visual settings");
				dbg.Break();
			}
		}