public static void Save(Settings settings) { Contract.Requires(settings != null); EnsureSettingsDirectoryAvailable(); var path = Path.Combine(PathUtil.SettingsFolderPath, Constants.SettingsFile); using (var sw = new StreamWriter(path)) { var document = new XDocument( new XComment($"{Constants.ApplicationName} {Constants.ApplicationVersion} by {Constants.Author}"), new XComment($"Website: {Constants.HomepageUrl}"), new XElement( XmlRootElement, new XElement( XmlGeneralElement, XElementSerializer.ToXml(nameof(settings.LastProcess), settings.LastProcess), XElementSerializer.ToXml(nameof(settings.LastCoreProvider), settings.LastCoreProvider), XElementSerializer.ToXml(nameof(settings.StayOnTop), settings.StayOnTop), XElementSerializer.ToXml(nameof(settings.RunAsAdmin), settings.RunAsAdmin), XElementSerializer.ToXml(nameof(settings.RandomizeWindowTitle), settings.RandomizeWindowTitle) ), new XElement( XmlDisplayElement, XElementSerializer.ToXml(nameof(settings.ShowNodeAddress), settings.ShowNodeAddress), XElementSerializer.ToXml(nameof(settings.ShowNodeOffset), settings.ShowNodeOffset), XElementSerializer.ToXml(nameof(settings.ShowNodeText), settings.ShowNodeText), XElementSerializer.ToXml(nameof(settings.HighlightChangedValues), settings.HighlightChangedValues), XElementSerializer.ToXml(nameof(settings.ShowCommentFloat), settings.ShowCommentFloat), XElementSerializer.ToXml(nameof(settings.ShowCommentInteger), settings.ShowCommentInteger), XElementSerializer.ToXml(nameof(settings.ShowCommentPointer), settings.ShowCommentPointer), XElementSerializer.ToXml(nameof(settings.ShowCommentRtti), settings.ShowCommentRtti), XElementSerializer.ToXml(nameof(settings.ShowCommentSymbol), settings.ShowCommentSymbol), XElementSerializer.ToXml(nameof(settings.ShowCommentString), settings.ShowCommentString), XElementSerializer.ToXml(nameof(settings.ShowCommentPluginInfo), settings.ShowCommentPluginInfo) ), new XElement( XmlColorsElement, XElementSerializer.ToXml(nameof(settings.BackgroundColor), settings.BackgroundColor), XElementSerializer.ToXml(nameof(settings.SelectedColor), settings.SelectedColor), XElementSerializer.ToXml(nameof(settings.HiddenColor), settings.HiddenColor), XElementSerializer.ToXml(nameof(settings.OffsetColor), settings.OffsetColor), XElementSerializer.ToXml(nameof(settings.AddressColor), settings.AddressColor), XElementSerializer.ToXml(nameof(settings.HexColor), settings.HexColor), XElementSerializer.ToXml(nameof(settings.TypeColor), settings.TypeColor), XElementSerializer.ToXml(nameof(settings.NameColor), settings.NameColor), XElementSerializer.ToXml(nameof(settings.ValueColor), settings.ValueColor), XElementSerializer.ToXml(nameof(settings.IndexColor), settings.IndexColor), XElementSerializer.ToXml(nameof(settings.CommentColor), settings.CommentColor), XElementSerializer.ToXml(nameof(settings.TextColor), settings.TextColor), XElementSerializer.ToXml(nameof(settings.VTableColor), settings.VTableColor) ), settings.CustomData.Serialize(XmlCustomDataElement) ) ); document.Save(sw); } }
internal void Deserialize(XElement element) { foreach (var kv in XElementSerializer.ToDictionary(element)) { data[kv.Key] = kv.Value; } }
internal XElement Serialize(string name) { return(XElementSerializer.ToXml(name, data)); }
public static Settings Load() { EnsureSettingsDirectoryAvailable(); var settings = new Settings(); try { var path = Path.Combine(PathUtil.SettingsFolderPath, Constants.SettingsFile); using (var sr = new StreamReader(path)) { var document = XDocument.Load(sr); var root = document.Root; var general = root?.Element(XmlGeneralElement); if (general != null) { XElementSerializer.TryRead(general, nameof(settings.LastProcess), e => settings.LastProcess = XElementSerializer.ToString(e)); XElementSerializer.TryRead(general, nameof(settings.StayOnTop), e => settings.StayOnTop = XElementSerializer.ToBool(e)); XElementSerializer.TryRead(general, nameof(settings.RunAsAdmin), e => settings.RunAsAdmin = XElementSerializer.ToBool(e)); XElementSerializer.TryRead(general, nameof(settings.RandomizeWindowTitle), e => settings.RandomizeWindowTitle = XElementSerializer.ToBool(e)); } var display = root?.Element(XmlDisplayElement); if (display != null) { XElementSerializer.TryRead(display, nameof(settings.ShowNodeAddress), e => settings.ShowNodeAddress = XElementSerializer.ToBool(e)); XElementSerializer.TryRead(display, nameof(settings.ShowNodeOffset), e => settings.ShowNodeOffset = XElementSerializer.ToBool(e)); XElementSerializer.TryRead(display, nameof(settings.ShowNodeText), e => settings.ShowNodeText = XElementSerializer.ToBool(e)); XElementSerializer.TryRead(display, nameof(settings.HighlightChangedValues), e => settings.HighlightChangedValues = XElementSerializer.ToBool(e)); XElementSerializer.TryRead(display, nameof(settings.ShowCommentFloat), e => settings.ShowCommentFloat = XElementSerializer.ToBool(e)); XElementSerializer.TryRead(display, nameof(settings.ShowCommentInteger), e => settings.ShowCommentInteger = XElementSerializer.ToBool(e)); XElementSerializer.TryRead(display, nameof(settings.ShowCommentPointer), e => settings.ShowCommentPointer = XElementSerializer.ToBool(e)); XElementSerializer.TryRead(display, nameof(settings.ShowCommentRtti), e => settings.ShowCommentRtti = XElementSerializer.ToBool(e)); XElementSerializer.TryRead(display, nameof(settings.ShowCommentSymbol), e => settings.ShowCommentSymbol = XElementSerializer.ToBool(e)); XElementSerializer.TryRead(display, nameof(settings.ShowCommentString), e => settings.ShowCommentString = XElementSerializer.ToBool(e)); XElementSerializer.TryRead(display, nameof(settings.ShowCommentPluginInfo), e => settings.ShowCommentPluginInfo = XElementSerializer.ToBool(e)); } var colors = root?.Element(XmlColorsElement); if (colors != null) { XElementSerializer.TryRead(colors, nameof(settings.BackgroundColor), e => settings.BackgroundColor = XElementSerializer.ToColor(e)); XElementSerializer.TryRead(colors, nameof(settings.SelectedColor), e => settings.SelectedColor = XElementSerializer.ToColor(e)); XElementSerializer.TryRead(colors, nameof(settings.HiddenColor), e => settings.HiddenColor = XElementSerializer.ToColor(e)); XElementSerializer.TryRead(colors, nameof(settings.OffsetColor), e => settings.OffsetColor = XElementSerializer.ToColor(e)); XElementSerializer.TryRead(colors, nameof(settings.AddressColor), e => settings.AddressColor = XElementSerializer.ToColor(e)); XElementSerializer.TryRead(colors, nameof(settings.HexColor), e => settings.HexColor = XElementSerializer.ToColor(e)); XElementSerializer.TryRead(colors, nameof(settings.TypeColor), e => settings.TypeColor = XElementSerializer.ToColor(e)); XElementSerializer.TryRead(colors, nameof(settings.NameColor), e => settings.NameColor = XElementSerializer.ToColor(e)); XElementSerializer.TryRead(colors, nameof(settings.ValueColor), e => settings.ValueColor = XElementSerializer.ToColor(e)); XElementSerializer.TryRead(colors, nameof(settings.IndexColor), e => settings.IndexColor = XElementSerializer.ToColor(e)); XElementSerializer.TryRead(colors, nameof(settings.CommentColor), e => settings.CommentColor = XElementSerializer.ToColor(e)); XElementSerializer.TryRead(colors, nameof(settings.TextColor), e => settings.TextColor = XElementSerializer.ToColor(e)); XElementSerializer.TryRead(colors, nameof(settings.VTableColor), e => settings.VTableColor = XElementSerializer.ToColor(e)); } var customData = root?.Element(XmlCustomDataElement); if (customData != null) { settings.CustomData.Deserialize(customData); } } } catch { } return(settings); }
public static Settings Load() { EnsureSettingsDirectoryAvailable(); var settings = new Settings(); try { var path = Path.Combine(PathUtil.SettingsFolderPath, Constants.SettingsFile); using (var sr = new StreamReader(path)) { var document = XDocument.Load(sr); var root = document.Root; var general = root?.Element(XmlGeneralElement); if (general != null) { XElementSerializer.TryRead(general, nameof(settings.LastProcess), e => settings.LastProcess = XElementSerializer.ToString(e)); XElementSerializer.TryRead(general, nameof(settings.StayOnTop), e => settings.StayOnTop = XElementSerializer.ToBool(e)); } var display = root?.Element(XmlDisplayElement); if (display != null) { XElementSerializer.TryRead(display, nameof(settings.ShowNodeAddress), e => settings.ShowNodeAddress = XElementSerializer.ToBool(e)); XElementSerializer.TryRead(display, nameof(settings.ShowNodeOffset), e => settings.ShowNodeOffset = XElementSerializer.ToBool(e)); XElementSerializer.TryRead(display, nameof(settings.ShowNodeText), e => settings.ShowNodeText = XElementSerializer.ToBool(e)); XElementSerializer.TryRead(display, nameof(settings.HighlightChangedValues), e => settings.HighlightChangedValues = XElementSerializer.ToBool(e)); XElementSerializer.TryRead(display, nameof(settings.ShowCommentFloat), e => settings.ShowCommentFloat = XElementSerializer.ToBool(e)); XElementSerializer.TryRead(display, nameof(settings.ShowCommentInteger), e => settings.ShowCommentInteger = XElementSerializer.ToBool(e)); XElementSerializer.TryRead(display, nameof(settings.ShowCommentPointer), e => settings.ShowCommentPointer = XElementSerializer.ToBool(e)); XElementSerializer.TryRead(display, nameof(settings.ShowCommentRtti), e => settings.ShowCommentRtti = XElementSerializer.ToBool(e)); XElementSerializer.TryRead(display, nameof(settings.ShowCommentSymbol), e => settings.ShowCommentSymbol = XElementSerializer.ToBool(e)); XElementSerializer.TryRead(display, nameof(settings.ShowCommentString), e => settings.ShowCommentString = XElementSerializer.ToBool(e)); XElementSerializer.TryRead(display, nameof(settings.ShowCommentPluginInfo), e => settings.ShowCommentPluginInfo = XElementSerializer.ToBool(e)); } var colors = root?.Element(XmlColorsElement); if (colors != null) { XElementSerializer.TryRead(colors, nameof(settings.BackgroundColor), e => settings.BackgroundColor = XElementSerializer.ToColor(e)); XElementSerializer.TryRead(colors, nameof(settings.SelectedColor), e => settings.SelectedColor = XElementSerializer.ToColor(e)); XElementSerializer.TryRead(colors, nameof(settings.HiddenColor), e => settings.HiddenColor = XElementSerializer.ToColor(e)); XElementSerializer.TryRead(colors, nameof(settings.OffsetColor), e => settings.OffsetColor = XElementSerializer.ToColor(e)); XElementSerializer.TryRead(colors, nameof(settings.AddressColor), e => settings.AddressColor = XElementSerializer.ToColor(e)); XElementSerializer.TryRead(colors, nameof(settings.HexColor), e => settings.HexColor = XElementSerializer.ToColor(e)); XElementSerializer.TryRead(colors, nameof(settings.TypeColor), e => settings.TypeColor = XElementSerializer.ToColor(e)); XElementSerializer.TryRead(colors, nameof(settings.NameColor), e => settings.NameColor = XElementSerializer.ToColor(e)); XElementSerializer.TryRead(colors, nameof(settings.ValueColor), e => settings.ValueColor = XElementSerializer.ToColor(e)); XElementSerializer.TryRead(colors, nameof(settings.IndexColor), e => settings.IndexColor = XElementSerializer.ToColor(e)); XElementSerializer.TryRead(colors, nameof(settings.CommentColor), e => settings.CommentColor = XElementSerializer.ToColor(e)); XElementSerializer.TryRead(colors, nameof(settings.TextColor), e => settings.TextColor = XElementSerializer.ToColor(e)); XElementSerializer.TryRead(colors, nameof(settings.VTableColor), e => settings.VTableColor = XElementSerializer.ToColor(e)); } var typeDefinitions = root?.Element(XmlTypeDefinitionsElement); if (typeDefinitions != null) { XElementSerializer.TryRead(typeDefinitions, nameof(settings.TypePadding), e => settings.TypePadding = XElementSerializer.ToString(e)); XElementSerializer.TryRead(typeDefinitions, nameof(settings.TypeBool), e => settings.TypeBool = XElementSerializer.ToString(e)); XElementSerializer.TryRead(typeDefinitions, nameof(settings.TypeInt8), e => settings.TypeInt8 = XElementSerializer.ToString(e)); XElementSerializer.TryRead(typeDefinitions, nameof(settings.TypeInt16), e => settings.TypeInt16 = XElementSerializer.ToString(e)); XElementSerializer.TryRead(typeDefinitions, nameof(settings.TypeInt32), e => settings.TypeInt32 = XElementSerializer.ToString(e)); XElementSerializer.TryRead(typeDefinitions, nameof(settings.TypeInt64), e => settings.TypeInt64 = XElementSerializer.ToString(e)); XElementSerializer.TryRead(typeDefinitions, nameof(settings.TypeUInt8), e => settings.TypeUInt8 = XElementSerializer.ToString(e)); XElementSerializer.TryRead(typeDefinitions, nameof(settings.TypeUInt16), e => settings.TypeUInt16 = XElementSerializer.ToString(e)); XElementSerializer.TryRead(typeDefinitions, nameof(settings.TypeUInt32), e => settings.TypeUInt32 = XElementSerializer.ToString(e)); XElementSerializer.TryRead(typeDefinitions, nameof(settings.TypeUInt64), e => settings.TypeUInt64 = XElementSerializer.ToString(e)); XElementSerializer.TryRead(typeDefinitions, nameof(settings.TypeFloat), e => settings.TypeFloat = XElementSerializer.ToString(e)); XElementSerializer.TryRead(typeDefinitions, nameof(settings.TypeDouble), e => settings.TypeDouble = XElementSerializer.ToString(e)); XElementSerializer.TryRead(typeDefinitions, nameof(settings.TypeVector2), e => settings.TypeVector2 = XElementSerializer.ToString(e)); XElementSerializer.TryRead(typeDefinitions, nameof(settings.TypeVector3), e => settings.TypeVector3 = XElementSerializer.ToString(e)); XElementSerializer.TryRead(typeDefinitions, nameof(settings.TypeVector4), e => settings.TypeVector4 = XElementSerializer.ToString(e)); XElementSerializer.TryRead(typeDefinitions, nameof(settings.TypeMatrix3x3), e => settings.TypeMatrix3x3 = XElementSerializer.ToString(e)); XElementSerializer.TryRead(typeDefinitions, nameof(settings.TypeMatrix3x4), e => settings.TypeMatrix3x4 = XElementSerializer.ToString(e)); XElementSerializer.TryRead(typeDefinitions, nameof(settings.TypeMatrix4x4), e => settings.TypeMatrix4x4 = XElementSerializer.ToString(e)); XElementSerializer.TryRead(typeDefinitions, nameof(settings.TypeUTF8Text), e => settings.TypeUTF8Text = XElementSerializer.ToString(e)); XElementSerializer.TryRead(typeDefinitions, nameof(settings.TypeUTF8TextPtr), e => settings.TypeUTF8TextPtr = XElementSerializer.ToString(e)); XElementSerializer.TryRead(typeDefinitions, nameof(settings.TypeUTF16Text), e => settings.TypeUTF16Text = XElementSerializer.ToString(e)); XElementSerializer.TryRead(typeDefinitions, nameof(settings.TypeUTF16TextPtr), e => settings.TypeUTF16TextPtr = XElementSerializer.ToString(e)); XElementSerializer.TryRead(typeDefinitions, nameof(settings.TypeUTF32Text), e => settings.TypeUTF32Text = XElementSerializer.ToString(e)); XElementSerializer.TryRead(typeDefinitions, nameof(settings.TypeUTF32TextPtr), e => settings.TypeUTF32TextPtr = XElementSerializer.ToString(e)); XElementSerializer.TryRead(typeDefinitions, nameof(settings.TypeFunctionPtr), e => settings.TypeFunctionPtr = XElementSerializer.ToString(e)); } var customData = root?.Element(XmlCustomDataElement); if (customData != null) { settings.CustomData.Deserialize(customData); } } } catch { } return(settings); }