|
17 | 17 | // DEALINGS IN THE SOFTWARE. |
18 | 18 |
|
19 | 19 | using System; |
20 | | -using System.ComponentModel; |
21 | 20 | using System.Xml.Linq; |
22 | 21 |
|
23 | | -using ICSharpCode.ILSpyX.Settings; |
| 22 | +using TomsToolbox.Wpf; |
24 | 23 |
|
25 | 24 | namespace ICSharpCode.ILSpy.Updates |
26 | 25 | { |
27 | | - sealed class UpdateSettings : INotifyPropertyChanged |
| 26 | + public sealed class UpdateSettings : ObservableObjectBase, ISettingsSection |
28 | 27 | { |
29 | | - public UpdateSettings(ISettingsProvider spySettings) |
30 | | - { |
31 | | - XElement s = spySettings["UpdateSettings"]; |
32 | | - this.automaticUpdateCheckEnabled = (bool?)s.Element("AutomaticUpdateCheckEnabled") ?? true; |
33 | | - try |
34 | | - { |
35 | | - this.lastSuccessfulUpdateCheck = (DateTime?)s.Element("LastSuccessfulUpdateCheck"); |
36 | | - } |
37 | | - catch (FormatException) |
38 | | - { |
39 | | - // avoid crashing on settings files invalid due to |
40 | | - // https://github.com/icsharpcode/ILSpy/issues/closed/#issue/2 |
41 | | - } |
42 | | - } |
| 28 | + public XName SectionName => "UpdateSettings"; |
43 | 29 |
|
44 | 30 | bool automaticUpdateCheckEnabled; |
45 | 31 |
|
46 | 32 | public bool AutomaticUpdateCheckEnabled { |
47 | | - get { return automaticUpdateCheckEnabled; } |
48 | | - set { |
49 | | - if (automaticUpdateCheckEnabled != value) |
50 | | - { |
51 | | - automaticUpdateCheckEnabled = value; |
52 | | - Save(); |
53 | | - OnPropertyChanged(nameof(AutomaticUpdateCheckEnabled)); |
54 | | - } |
55 | | - } |
| 33 | + get => automaticUpdateCheckEnabled; |
| 34 | + set => SetProperty(ref automaticUpdateCheckEnabled, value); |
56 | 35 | } |
57 | 36 |
|
58 | 37 | DateTime? lastSuccessfulUpdateCheck; |
59 | 38 |
|
60 | 39 | public DateTime? LastSuccessfulUpdateCheck { |
61 | | - get { return lastSuccessfulUpdateCheck; } |
62 | | - set { |
63 | | - if (lastSuccessfulUpdateCheck != value) |
64 | | - { |
65 | | - lastSuccessfulUpdateCheck = value; |
66 | | - Save(); |
67 | | - OnPropertyChanged(nameof(LastSuccessfulUpdateCheck)); |
68 | | - } |
69 | | - } |
| 40 | + get => lastSuccessfulUpdateCheck; |
| 41 | + set => SetProperty(ref lastSuccessfulUpdateCheck, value); |
70 | 42 | } |
71 | 43 |
|
72 | | - public void Save() |
| 44 | + public void LoadFromXml(XElement section) |
73 | 45 | { |
74 | | - XElement updateSettings = new XElement("UpdateSettings"); |
75 | | - updateSettings.Add(new XElement("AutomaticUpdateCheckEnabled", automaticUpdateCheckEnabled)); |
76 | | - if (lastSuccessfulUpdateCheck != null) |
77 | | - updateSettings.Add(new XElement("LastSuccessfulUpdateCheck", lastSuccessfulUpdateCheck)); |
78 | | - SettingsService.Instance.SpySettings.SaveSettings(updateSettings); |
| 46 | + AutomaticUpdateCheckEnabled = (bool?)section.Element("AutomaticUpdateCheckEnabled") ?? true; |
| 47 | + try |
| 48 | + { |
| 49 | + LastSuccessfulUpdateCheck = (DateTime?)section.Element("LastSuccessfulUpdateCheck"); |
| 50 | + } |
| 51 | + catch (FormatException) |
| 52 | + { |
| 53 | + // avoid crashing on settings files invalid due to |
| 54 | + // https://github.com/icsharpcode/ILSpy/issues/closed/#issue/2 |
| 55 | + } |
79 | 56 | } |
80 | 57 |
|
81 | | - public event PropertyChangedEventHandler PropertyChanged; |
82 | | - |
83 | | - void OnPropertyChanged(string propertyName) |
| 58 | + public XElement SaveToXml() |
84 | 59 | { |
85 | | - PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); |
| 60 | + var section = new XElement(SectionName); |
| 61 | + |
| 62 | + section.Add(new XElement("AutomaticUpdateCheckEnabled", AutomaticUpdateCheckEnabled)); |
| 63 | + |
| 64 | + if (LastSuccessfulUpdateCheck != null) |
| 65 | + { |
| 66 | + section.Add(new XElement("LastSuccessfulUpdateCheck", LastSuccessfulUpdateCheck)); |
| 67 | + } |
| 68 | + |
| 69 | + return section; |
86 | 70 | } |
87 | 71 | } |
88 | | - |
89 | 72 | } |
0 commit comments