Skip to content

Commit 24fec7c

Browse files
committed
Added persistence for scalar settings.
Refactored Alerts to exist in Settings instead of WatApplication.
1 parent f3b6a8d commit 24fec7c

File tree

9 files changed

+68
-45
lines changed

9 files changed

+68
-45
lines changed

Source/App.config

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
1-
<?xml version="1.0" encoding="utf-8" ?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<configuration>
33
<configSections>
4+
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
5+
<section name="ScriptFUSION.WarframeAlertTracker.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false"/>
6+
</sectionGroup>
47
</configSections>
5-
<startup>
6-
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1" />
7-
</startup>
8-
</configuration>
8+
<userSettings>
9+
<ScriptFUSION.WarframeAlertTracker.Properties.Settings>
10+
<setting name="LoadHidden" serializeAs="String">
11+
<value>False</value>
12+
</setting>
13+
</ScriptFUSION.WarframeAlertTracker.Properties.Settings>
14+
</userSettings>
15+
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1"/></startup></configuration>

Source/Forms/OptionsForm.Designer.cs

Lines changed: 8 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Source/Forms/OptionsForm.cs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,37 @@
11
using System.Windows.Forms;
22
using ScriptFUSION.WarframeAlertTracker.Controls;
3+
using ScriptFUSION.WarframeAlertTracker.Properties;
34
using ScriptFUSION.WarframeAlertTracker.Resource;
45

56
namespace ScriptFUSION.WarframeAlertTracker.Forms {
67
public partial class OptionsForm : Form {
78
private readonly ImageRepository imageRepository;
89

9-
public OptionsForm(FissureControl dummyFissureControl) {
10+
private Settings Settings { get; }
11+
12+
internal OptionsForm(Settings settings, FissureControl dummyFissureControl) {
1013
InitializeComponent();
14+
ReadSettings(Settings = settings);
1115

1216
imageRepository = dummyFissureControl.ImageRepository;
13-
1417
dummyFissureControl.Size = sample.Size;
1518
sample.Image = dummyFissureControl.Snapshot();
1619
}
1720

21+
private void ReadSettings(Settings settings) {
22+
loadHidden.Checked = settings.LoadHidden;
23+
}
24+
25+
private void WriteSettings() {
26+
Settings.LoadHidden = loadHidden.Checked;
27+
}
28+
1829
private async void sample_Click(object sender, System.EventArgs e) {
1930
new NotificationForm(await FissureControl.CreateTestControl(imageRepository)).Show(this);
2031
}
32+
33+
private void ok_Click(object sender, System.EventArgs e) {
34+
WriteSettings();
35+
}
2136
}
2237
}

Source/Forms/WatForm.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ internal WatForm(WatApplication application) {
1919
application.CurrentWorldState.Update +=
2020
async worldState => OnWorldStateUpdate(worldState.Fissures, await application.SolNodes);
2121

22-
application.AlertsUpdate += OnAlertsUpdate;
22+
application.Settings.AlertsUpdate += OnAlertsUpdate;
2323

2424
fissures.ImageRepository = application.ImageRepository;
2525

@@ -34,7 +34,7 @@ private void ToggleWindowVisibility() {
3434

3535
private void OnWorldStateUpdate(IReadOnlyCollection<Fissure> fissureList, JObject solNodes) {
3636
fissures.Update(fissureList, solNodes);
37-
OnAlertsUpdate(Application.AlertCollection);
37+
OnAlertsUpdate(Application.Settings.Alerts);
3838
}
3939

4040
private void OnAlertsUpdate(AlertCollection alertsCollection) {
@@ -44,18 +44,21 @@ private void OnAlertsUpdate(AlertCollection alertsCollection) {
4444
}
4545

4646
private void alerts_Click(object sender, EventArgs e) {
47-
var alertCollection = Application.AlertCollection.Clone();
47+
var alertCollection = Application.Settings.Alerts.Clone();
4848

4949
using (var form = new AlertsForm(Application.CurrentWorldState, alertCollection)) {
5050
if (form.ShowDialog(this) == DialogResult.OK) {
51-
Application.AlertCollection = alertCollection;
51+
Application.Settings.Alerts = alertCollection;
52+
Application.Settings.Save();
5253
}
5354
}
5455
}
5556

5657
private async void options_Click(object sender, EventArgs e) {
57-
using (var form = new OptionsForm(await FissureControl.CreateTestControl(Application.ImageRepository))) {
58-
form.ShowDialog(this);
58+
using (var form = new OptionsForm(Application.Settings, await FissureControl.CreateTestControl(Application.ImageRepository))) {
59+
if (form.ShowDialog(this) == DialogResult.OK) {
60+
Application.Settings.Save();
61+
}
5962
}
6063
}
6164

Source/Notifier.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ private void Next() {
4545
}
4646

4747
private async void OnNewWorldStateObject(IWorldStateObject worldStateObject) {
48-
if (!Application.AlertCollection.Matches(worldStateObject)) {
48+
if (!Application.Settings.Alerts.Matches(worldStateObject)) {
4949
return;
5050
}
5151

Source/Properties/Settings.Designer.cs

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Source/Properties/Settings.settings

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,8 @@
55
<Setting Name="Alerts" Type="ScriptFUSION.WarframeAlertTracker.Alerts.AlertCollection" Scope="User">
66
<Value Profile="(Default)" />
77
</Setting>
8+
<Setting Name="LoadHidden" Type="System.Boolean" Scope="User">
9+
<Value Profile="(Default)">False</Value>
10+
</Setting>
811
</Settings>
912
</SettingsFile>

Source/WarframeAlertTracker.csproj

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
1212
<FileAlignment>512</FileAlignment>
1313
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
14+
<TargetFrameworkProfile />
1415
</PropertyGroup>
1516
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
1617
<PlatformTarget>AnyCPU</PlatformTarget>
@@ -74,6 +75,7 @@
7475
<DependentUpon>OptionsForm.cs</DependentUpon>
7576
</Compile>
7677
<Compile Include="Notifier.cs" />
78+
<Compile Include="Properties\Settings.cs" />
7779
<Compile Include="Warframe\FissureTierParser.cs" />
7880
<Compile Include="Warframe\MissionType.cs" />
7981
<Compile Include="Warframe\MissionTypeFormatter.cs" />
@@ -176,19 +178,18 @@
176178
<EmbeddedResource Include="Forms\WatForm.resx">
177179
<DependentUpon>WatForm.cs</DependentUpon>
178180
</EmbeddedResource>
181+
<None Include="App.config" />
179182
<None Include="packages.config" />
180183
<None Include="Properties\Settings.settings">
181184
<Generator>SettingsSingleFileGenerator</Generator>
182185
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
186+
<SubType>Designer</SubType>
183187
</None>
184188
<Compile Include="Properties\Settings.Designer.cs">
185189
<AutoGen>True</AutoGen>
186190
<DependentUpon>Settings.settings</DependentUpon>
187191
<DesignTimeSharedInput>True</DesignTimeSharedInput>
188192
</Compile>
189193
</ItemGroup>
190-
<ItemGroup>
191-
<None Include="App.config" />
192-
</ItemGroup>
193194
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
194195
</Project>

Source/WatApplication.cs

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,16 @@
1-
using System;
2-
using System.Threading.Tasks;
1+
using System.Threading.Tasks;
32
using ScriptFUSION.WarframeAlertTracker.Forms;
43
using ScriptFUSION.WarframeAlertTracker.Resource;
54
using ScriptFUSION.WarframeAlertTracker.Warframe;
6-
using ScriptFUSION.WarframeAlertTracker.Alerts;
75
using System.Windows.Forms;
86
using Newtonsoft.Json.Linq;
97
using ScriptFUSION.WarframeAlertTracker.Properties;
108

119
namespace ScriptFUSION.WarframeAlertTracker {
1210
internal sealed class WatApplication : ApplicationContext {
13-
public event Action<AlertCollection> AlertsUpdate;
14-
1511
public CurrentWorldState CurrentWorldState { get; } = new CurrentWorldState(new WorldStateDownloader(Downloader));
1612

17-
public AlertCollection AlertCollection
18-
{
19-
get => Settings.Default.Alerts ?? new AlertCollection();
20-
set
21-
{
22-
Settings.Default.Alerts = value;
23-
24-
SaveSettings();
25-
26-
AlertsUpdate?.Invoke(value);
27-
}
28-
}
13+
public Settings Settings { get; } = Settings.Default;
2914

3015
public ImageRepository ImageRepository { get; } = new ImageRepository(new ResourceDownloader(Downloader));
3116

@@ -42,9 +27,5 @@ public WatApplication() {
4227
CurrentWorldState.DownloadIndefinitely();
4328
SolNodes = SolNodesDownloader.Download();
4429
}
45-
46-
private static void SaveSettings() {
47-
Settings.Default.Save();
48-
}
4930
}
5031
}

0 commit comments

Comments
 (0)