-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSettings.cs
More file actions
96 lines (88 loc) · 2.43 KB
/
Settings.cs
File metadata and controls
96 lines (88 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
using System;
using System.Collections.Specialized;
using System.Configuration;
using System.IO;
using System.Text;
using System.Xml;
namespace World_Backup
{
class Settings : SettingsProvider
{
public override void Initialize(string name, NameValueCollection config)
{
base.Initialize(this.ApplicationName, config);
}
public override string ApplicationName
{
get => throw new NotImplementedException();
set => throw new NotImplementedException();
}
public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection collection)
{
SettingsPropertyValueCollection values = new SettingsPropertyValueCollection();
foreach (SettingsProperty property in collection)
{
SettingsPropertyValue value = new SettingsPropertyValue(property);
value.IsDirty = false;
values.Add(value);
}
if (!File.Exists(this.GetSavingPath))
return values;
using (XmlTextReader tr = new XmlTextReader(this.GetSavingPath))
{
try
{
tr.ReadStartElement("ID3renamer");
foreach (SettingsPropertyValue value in values)
{
if (IsUserScoped(value.Property))
{
try
{
tr.ReadStartElement(value.Name);
value.SerializedValue = tr.ReadContentAsObject();
tr.ReadEndElement();
}
catch (XmlException)
{ /* ugly */ }
}
}
tr.ReadEndElement();
}
catch (XmlException)
{ /* ugly */ }
}
return values;
}
public override void SetPropertyValues(SettingsContext context, SettingsPropertyValueCollection collection)
{
using (XmlTextWriter tw = new XmlTextWriter(this.GetSavingPath, Encoding.Unicode))
{
tw.WriteStartDocument();
tw.WriteStartElement("ID3renamer");
foreach (SettingsPropertyValue propertyValue in collection)
{
if (IsUserScoped(propertyValue.Property))
{
tw.WriteStartElement(propertyValue.Name);
tw.WriteValue(propertyValue.SerializedValue);
tw.WriteEndElement();
}
}
tw.WriteEndElement();
tw.WriteEndDocument();
}
}
private bool IsUserScoped(SettingsProperty property)
{
return property.Attributes.ContainsKey(typeof(UserScopedSettingAttribute));
}
private string GetSavingPath
{
get
{
return Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + Path.DirectorySeparatorChar + "ID3 renamer" + Path.DirectorySeparatorChar + "user.config";
}
}
}
}