Skip to content

Commit 2b0ca78

Browse files
committed
✨ modular settings provider
1 parent 7deb7dd commit 2b0ca78

File tree

6 files changed

+265
-3
lines changed

6 files changed

+265
-3
lines changed

Biyori/App.config

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
1-
<?xml version="1.0" encoding="utf-8" ?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<configuration>
33
<startup>
44
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
55
</startup>
6+
<runtime>
7+
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
8+
<dependentAssembly>
9+
<assemblyIdentity name="System.Collections.Immutable" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
10+
<bindingRedirect oldVersion="0.0.0.0-1.2.3.0" newVersion="1.2.3.0" />
11+
</dependentAssembly>
12+
<dependentAssembly>
13+
<assemblyIdentity name="System.ComponentModel.Annotations" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
14+
<bindingRedirect oldVersion="0.0.0.0-4.2.1.0" newVersion="4.2.1.0" />
15+
</dependentAssembly>
16+
</assemblyBinding>
17+
</runtime>
618
</configuration>

Biyori/Biyori.csproj

+129
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,129 @@
3939
<WarningLevel>4</WarningLevel>
4040
</PropertyGroup>
4141
<ItemGroup>
42+
<Reference Include="Abp, Version=4.8.1.0, Culture=neutral, processorArchitecture=MSIL">
43+
<HintPath>..\packages\Abp.4.8.1\lib\netstandard2.0\Abp.dll</HintPath>
44+
</Reference>
45+
<Reference Include="Castle.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
46+
<HintPath>..\packages\Castle.Core.4.4.0\lib\net45\Castle.Core.dll</HintPath>
47+
</Reference>
48+
<Reference Include="Castle.Facilities.Logging, Version=5.0.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
49+
<HintPath>..\packages\Castle.LoggingFacility.5.0.0\lib\net45\Castle.Facilities.Logging.dll</HintPath>
50+
</Reference>
51+
<Reference Include="Castle.Windsor, Version=5.0.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
52+
<HintPath>..\packages\Castle.Windsor.5.0.0\lib\net45\Castle.Windsor.dll</HintPath>
53+
</Reference>
4254
<Reference Include="Costura, Version=4.0.0.0, Culture=neutral, PublicKeyToken=9919ef960d84173d, processorArchitecture=MSIL">
4355
<HintPath>..\packages\Costura.Fody.4.0.0\lib\net40\Costura.dll</HintPath>
4456
</Reference>
4557
<Reference Include="Gu.Wpf.Adorners, Version=1.5.1.0, Culture=neutral, PublicKeyToken=6dfb64f9972bd31d, processorArchitecture=MSIL">
4658
<HintPath>..\packages\Gu.Wpf.Adorners.1.5.1.0\lib\net45\Gu.Wpf.Adorners.dll</HintPath>
4759
</Reference>
60+
<Reference Include="JetBrains.Annotations, Version=2019.1.1.0, Culture=neutral, PublicKeyToken=1010a0d8d6380325, processorArchitecture=MSIL">
61+
<HintPath>..\packages\JetBrains.Annotations.2019.1.1\lib\net20\JetBrains.Annotations.dll</HintPath>
62+
</Reference>
63+
<Reference Include="Microsoft.Extensions.Caching.Abstractions, Version=2.2.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
64+
<HintPath>..\packages\Microsoft.Extensions.Caching.Abstractions.2.2.0\lib\netstandard2.0\Microsoft.Extensions.Caching.Abstractions.dll</HintPath>
65+
</Reference>
66+
<Reference Include="Microsoft.Extensions.Caching.Memory, Version=2.2.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
67+
<HintPath>..\packages\Microsoft.Extensions.Caching.Memory.2.2.0\lib\netstandard2.0\Microsoft.Extensions.Caching.Memory.dll</HintPath>
68+
</Reference>
69+
<Reference Include="Microsoft.Extensions.DependencyInjection.Abstractions, Version=2.2.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
70+
<HintPath>..\packages\Microsoft.Extensions.DependencyInjection.Abstractions.2.2.0\lib\netstandard2.0\Microsoft.Extensions.DependencyInjection.Abstractions.dll</HintPath>
71+
</Reference>
72+
<Reference Include="Microsoft.Extensions.Options, Version=2.2.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
73+
<HintPath>..\packages\Microsoft.Extensions.Options.2.2.0\lib\netstandard2.0\Microsoft.Extensions.Options.dll</HintPath>
74+
</Reference>
75+
<Reference Include="Microsoft.Extensions.Primitives, Version=2.2.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
76+
<HintPath>..\packages\Microsoft.Extensions.Primitives.2.2.0\lib\netstandard2.0\Microsoft.Extensions.Primitives.dll</HintPath>
77+
</Reference>
78+
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
79+
<HintPath>..\packages\Newtonsoft.Json.12.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
80+
</Reference>
81+
<Reference Include="Nito.AsyncEx.Context, Version=5.0.0.0, Culture=neutral, processorArchitecture=MSIL">
82+
<HintPath>..\packages\Nito.AsyncEx.Context.5.0.0\lib\netstandard2.0\Nito.AsyncEx.Context.dll</HintPath>
83+
</Reference>
84+
<Reference Include="Nito.AsyncEx.Coordination, Version=5.0.0.0, Culture=neutral, processorArchitecture=MSIL">
85+
<HintPath>..\packages\Nito.AsyncEx.Coordination.5.0.0\lib\netstandard2.0\Nito.AsyncEx.Coordination.dll</HintPath>
86+
</Reference>
87+
<Reference Include="Nito.AsyncEx.Tasks, Version=5.0.0.0, Culture=neutral, processorArchitecture=MSIL">
88+
<HintPath>..\packages\Nito.AsyncEx.Tasks.5.0.0\lib\netstandard2.0\Nito.AsyncEx.Tasks.dll</HintPath>
89+
</Reference>
90+
<Reference Include="Nito.Collections.Deque, Version=1.0.4.0, Culture=neutral, processorArchitecture=MSIL">
91+
<HintPath>..\packages\Nito.Collections.Deque.1.0.4\lib\netstandard2.0\Nito.Collections.Deque.dll</HintPath>
92+
</Reference>
93+
<Reference Include="Nito.Disposables, Version=2.0.0.0, Culture=neutral, processorArchitecture=MSIL">
94+
<HintPath>..\packages\Nito.Disposables.2.0.0\lib\netstandard2.0\Nito.Disposables.dll</HintPath>
95+
</Reference>
4896
<Reference Include="PropertyChanged, Version=3.0.1.0, Culture=neutral, PublicKeyToken=ee3ee20bcf148ddd, processorArchitecture=MSIL">
4997
<HintPath>..\packages\PropertyChanged.Fody.3.0.1\lib\net452\PropertyChanged.dll</HintPath>
5098
</Reference>
5199
<Reference Include="System" />
100+
<Reference Include="System.Buffers, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
101+
<HintPath>..\packages\System.Buffers.4.4.0\lib\netstandard2.0\System.Buffers.dll</HintPath>
102+
</Reference>
103+
<Reference Include="System.Collections.Immutable, Version=1.2.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
104+
<HintPath>..\packages\System.Collections.Immutable.1.5.0\lib\netstandard2.0\System.Collections.Immutable.dll</HintPath>
105+
</Reference>
106+
<Reference Include="System.ComponentModel.Annotations, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
107+
<HintPath>..\packages\System.ComponentModel.Annotations.4.5.0\lib\net461\System.ComponentModel.Annotations.dll</HintPath>
108+
</Reference>
109+
<Reference Include="System.ComponentModel.DataAnnotations" />
110+
<Reference Include="System.Configuration" />
111+
<Reference Include="System.Configuration.ConfigurationManager, Version=4.0.1.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
112+
<HintPath>..\packages\System.Configuration.ConfigurationManager.4.5.0\lib\net461\System.Configuration.ConfigurationManager.dll</HintPath>
113+
</Reference>
52114
<Reference Include="System.Data" />
115+
<Reference Include="System.Data.Common, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
116+
<HintPath>..\packages\System.Data.Common.4.3.0\lib\net451\System.Data.Common.dll</HintPath>
117+
<Private>True</Private>
118+
<Private>True</Private>
119+
</Reference>
120+
<Reference Include="System.Data.OracleClient" />
121+
<Reference Include="System.Drawing" />
122+
<Reference Include="System.Linq.Dynamic.Core, Version=1.0.16.0, Culture=neutral, PublicKeyToken=0f07ec44de6ac832, processorArchitecture=MSIL">
123+
<HintPath>..\packages\System.Linq.Dynamic.Core.1.0.16\lib\net46\System.Linq.Dynamic.Core.dll</HintPath>
124+
</Reference>
125+
<Reference Include="System.Memory, Version=4.0.1.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
126+
<HintPath>..\packages\System.Memory.4.5.1\lib\netstandard2.0\System.Memory.dll</HintPath>
127+
</Reference>
128+
<Reference Include="System.Net" />
129+
<Reference Include="System.Numerics" />
130+
<Reference Include="System.Numerics.Vectors, Version=4.1.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
131+
<HintPath>..\packages\System.Numerics.Vectors.4.4.0\lib\net46\System.Numerics.Vectors.dll</HintPath>
132+
</Reference>
133+
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=4.0.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
134+
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.4.5.1\lib\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
135+
</Reference>
136+
<Reference Include="System.Runtime.Remoting" />
137+
<Reference Include="System.Runtime.Serialization" />
138+
<Reference Include="System.Runtime.Serialization.Formatters, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
139+
<HintPath>..\packages\System.Runtime.Serialization.Formatters.4.3.0\lib\net46\System.Runtime.Serialization.Formatters.dll</HintPath>
140+
<Private>True</Private>
141+
<Private>True</Private>
142+
</Reference>
143+
<Reference Include="System.Runtime.Serialization.Primitives, Version=4.1.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
144+
<HintPath>..\packages\System.Runtime.Serialization.Primitives.4.3.0\lib\net46\System.Runtime.Serialization.Primitives.dll</HintPath>
145+
<Private>True</Private>
146+
<Private>True</Private>
147+
</Reference>
148+
<Reference Include="System.Security.AccessControl, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
149+
<HintPath>..\packages\System.Security.AccessControl.4.5.0\lib\net461\System.Security.AccessControl.dll</HintPath>
150+
</Reference>
151+
<Reference Include="System.Security.Claims, Version=4.0.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
152+
<HintPath>..\packages\System.Security.Claims.4.3.0\lib\net46\System.Security.Claims.dll</HintPath>
153+
<Private>True</Private>
154+
<Private>True</Private>
155+
</Reference>
156+
<Reference Include="System.Security.Permissions, Version=4.0.1.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
157+
<HintPath>..\packages\System.Security.Permissions.4.5.0\lib\net461\System.Security.Permissions.dll</HintPath>
158+
</Reference>
159+
<Reference Include="System.Security.Principal.Windows, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
160+
<HintPath>..\packages\System.Security.Principal.Windows.4.5.0\lib\net461\System.Security.Principal.Windows.dll</HintPath>
161+
</Reference>
162+
<Reference Include="System.ServiceProcess" />
163+
<Reference Include="System.Transactions" />
164+
<Reference Include="System.Web" />
53165
<Reference Include="System.Xml" />
54166
<Reference Include="Microsoft.CSharp" />
55167
<Reference Include="System.Core" />
@@ -59,6 +171,22 @@
59171
<Reference Include="System.Xaml">
60172
<RequiredTargetFramework>4.0</RequiredTargetFramework>
61173
</Reference>
174+
<Reference Include="System.Xml.XmlDocument, Version=4.0.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
175+
<HintPath>..\packages\System.Xml.XmlDocument.4.3.0\lib\net46\System.Xml.XmlDocument.dll</HintPath>
176+
<Private>True</Private>
177+
<Private>True</Private>
178+
</Reference>
179+
<Reference Include="System.Xml.XPath, Version=4.0.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
180+
<HintPath>..\packages\System.Xml.XPath.4.3.0\lib\net46\System.Xml.XPath.dll</HintPath>
181+
<Private>True</Private>
182+
<Private>True</Private>
183+
</Reference>
184+
<Reference Include="System.Xml.XPath.XmlDocument, Version=4.0.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
185+
<HintPath>..\packages\System.Xml.XPath.XmlDocument.4.3.0\lib\net46\System.Xml.XPath.XmlDocument.dll</HintPath>
186+
</Reference>
187+
<Reference Include="TimeZoneConverter, Version=3.2.0.0, Culture=neutral, PublicKeyToken=e20ab7d0d9479841, processorArchitecture=MSIL">
188+
<HintPath>..\packages\TimeZoneConverter.3.2.0\lib\net471\TimeZoneConverter.dll</HintPath>
189+
</Reference>
62190
<Reference Include="WindowsBase" />
63191
<Reference Include="PresentationCore" />
64192
<Reference Include="PresentationFramework" />
@@ -83,6 +211,7 @@
83211
<Compile Include="Settings\Frames\SettingsPage-General.xaml.cs">
84212
<DependentUpon>SettingsPage-General.xaml</DependentUpon>
85213
</Compile>
214+
<Compile Include="Settings\SettingsProvider.cs" />
86215
<Compile Include="Settings\SettingsWindow.xaml.cs">
87216
<DependentUpon>SettingsWindow.xaml</DependentUpon>
88217
</Compile>

Biyori/MainWindow.xaml.cs

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
using Abp.Configuration;
2+
using System;
23
using System.Collections.Generic;
34
using System.Linq;
45
using System.Reflection;
@@ -26,6 +27,11 @@ public MainWindow()
2627
InitializeComponent();
2728
this.Title = Assembly.GetExecutingAssembly()?.GetName()?.Name ?? "Biyori";
2829
}
30+
protected override void OnInitialized(EventArgs e)
31+
{
32+
base.OnInitialized(e);
33+
new Settings.SettingsProvider();
34+
}
2935

3036
private void onSettingsClick(object sender, RoutedEventArgs e)
3137
{

Biyori/Settings/Frames/SettingsPage-Accounts.xaml.cs

+28-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
using Newtonsoft.Json;
2+
using System;
23
using System.Collections.Generic;
34
using System.Linq;
45
using System.Text;
@@ -26,4 +27,30 @@ public SettingsPage_Accounts()
2627
InitializeComponent();
2728
}
2829
}
30+
[SettingsSection("account", true)]
31+
public class AccountSettings
32+
{
33+
[JsonProperty("enable_sync")]
34+
public bool SyncEnabled { get; set; }
35+
[JsonProperty("accounts")]
36+
public List<AccountInfo> Accounts { get; set; }
37+
[JsonProperty("current_account_type")]
38+
public AccountEndpoints CurrentAccountType { get; set; }
39+
[JsonProperty("current_account")]
40+
public AccountInfo CurrentAccount { get; set; }
41+
}
42+
public class AccountInfo
43+
{
44+
[JsonProperty("email")]
45+
public string EmailAddress { get; set; }
46+
[JsonProperty("username")]
47+
public string Username { get; set; }
48+
[JsonProperty("password")]
49+
public string Password { get; set; }
50+
}
51+
public enum AccountEndpoints
52+
{
53+
Kitsu,
54+
Anilist
55+
}
2956
}

Biyori/Settings/SettingsProvider.cs

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
using Newtonsoft.Json;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.IO;
5+
using System.Linq;
6+
using System.Reflection;
7+
using System.Text;
8+
using System.Threading.Tasks;
9+
10+
namespace Biyori.Settings
11+
{
12+
public class SettingsProvider
13+
{
14+
private string configPath { get => Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "config"); }
15+
private string settingsPath { get => Path.Combine(configPath, "settings.json"); }
16+
public SettingsProvider()
17+
{
18+
if (!Directory.Exists(this.configPath))
19+
{
20+
Directory.CreateDirectory(this.configPath);
21+
initializeConfig();
22+
}
23+
}
24+
private void initializeConfig()
25+
{
26+
var sections = new Dictionary<string, object>();
27+
Assembly.GetEntryAssembly().GetTypes().Where(x => x.GetCustomAttributes<SettingsSectionAttribute>().Count() > 0).ToList().ForEach(x =>
28+
{
29+
var attr = x.GetCustomAttribute<SettingsSectionAttribute>();
30+
var obj = Activator.CreateInstance(x);
31+
if (!sections.ContainsKey(attr.name))
32+
{
33+
sections.Add(attr.name, obj);
34+
}
35+
});
36+
File.WriteAllText(this.settingsPath, JsonConvert.SerializeObject(sections, Formatting.Indented));
37+
}
38+
}
39+
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
40+
public class SettingsSectionAttribute : Attribute
41+
{
42+
public SettingsSectionAttribute(string name, bool isEnabled)
43+
{
44+
this.name = name;
45+
this.isEnabled = isEnabled;
46+
}
47+
48+
public string name { get; set; }
49+
public bool isEnabled { get; set; } = false;
50+
}
51+
}

0 commit comments

Comments
 (0)