Skip to content

Commit 0ea6c63

Browse files
committed
Added load on system startup functionality via Registry.
1 parent 4a2a538 commit 0ea6c63

File tree

8 files changed

+122
-8
lines changed

8 files changed

+122
-8
lines changed

Source/Forms/OptionsForm.cs

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

@@ -9,20 +10,24 @@ public partial class OptionsForm : Form {
910

1011
private Settings Settings { get; }
1112

12-
internal OptionsForm(Settings settings, FissureControl dummyFissureControl) {
13+
private RegistrySettings RegistrySettings { get; }
14+
15+
internal OptionsForm(Settings settings, RegistrySettings registrySettings, FissureControl dummyFissureControl) {
1316
InitializeComponent();
14-
ReadSettings(Settings = settings);
17+
ReadSettings(Settings = settings, RegistrySettings = registrySettings);
1518

1619
imageRepository = dummyFissureControl.ImageRepository;
1720
dummyFissureControl.Size = sample.Size;
1821
sample.Image = dummyFissureControl.Snapshot();
1922
}
2023

21-
private void ReadSettings(Settings settings) {
24+
private void ReadSettings(Settings settings, RegistrySettings registrySettings) {
25+
loadSystem.Checked = registrySettings.LoadAtStartUp.Enabled;
2226
loadHidden.Checked = settings.LoadHidden;
2327
}
2428

2529
private void WriteSettings() {
30+
RegistrySettings.LoadAtStartUp.Enabled = loadSystem.Checked;
2631
Settings.LoadHidden = loadHidden.Checked;
2732
}
2833

Source/Forms/WatForm.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ internal WatForm(WatApplication application) {
4444
trayIcon.Icon = Icon;
4545
}
4646

47-
public void ToggleWindowVisibility() {
47+
private void ToggleWindowVisibility() {
4848
if (Visible = !Visible) {
4949
// Restore previous state.
5050
WindowState = LastWindowState;
@@ -87,9 +87,14 @@ private void alerts_Click(object sender, EventArgs e) {
8787
}
8888

8989
private async void options_Click(object sender, EventArgs e) {
90-
using (var form = new OptionsForm(Application.Settings, await FissureControl.CreateTestControl(Application.ImageRepository))) {
90+
using (var form = new OptionsForm(
91+
Application.Settings,
92+
Application.RegistrySettings,
93+
await FissureControl.CreateTestControl(Application.ImageRepository)
94+
)) {
9195
if (form.ShowDialog(this) == DialogResult.OK) {
9296
Application.Settings.Save();
97+
Application.RegistrySettings.Save();
9398
}
9499
}
95100
}
@@ -105,7 +110,7 @@ private void showMenuItem_Click(object sender, EventArgs e) {
105110
}
106111

107112
private void homePageMenuItem_Click(object sender, EventArgs e) {
108-
System.Diagnostics.Process.Start("https://github.com/ScriptFUSION/WAT");
113+
Process.Start("https://github.com/ScriptFUSION/WAT");
109114
}
110115

111116
private void exitMenuItem_Click(object sender, EventArgs e) {

Source/Properties/Settings.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System;
2+
using System.ComponentModel;
3+
using ScriptFUSION.WarframeAlertTracker.Alerts;
4+
5+
namespace ScriptFUSION.WarframeAlertTracker.Properties {
6+
internal sealed partial class Settings {
7+
public event Action<AlertCollection> AlertsUpdate;
8+
9+
public Settings() {
10+
if (Alerts == null) Alerts = new AlertCollection();
11+
12+
PropertyChanged += Settings_PropertyChanged;
13+
}
14+
15+
private void Settings_PropertyChanged(object sender, PropertyChangedEventArgs e) {
16+
if (e.PropertyName == "Alerts") {
17+
AlertsUpdate?.Invoke(Alerts);
18+
}
19+
}
20+
}
21+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using System.Windows.Forms;
2+
3+
namespace ScriptFUSION.WarframeAlertTracker.Registry {
4+
internal sealed class LoadAtStartupRegistryEntry : RegistryEntry {
5+
private readonly string value = $"\"{Application.ExecutablePath}\"";
6+
7+
private bool dirty;
8+
private bool enabled;
9+
10+
public bool Enabled
11+
{
12+
get => enabled;
13+
set
14+
{
15+
enabled = value;
16+
17+
dirty = true;
18+
}
19+
}
20+
21+
public LoadAtStartupRegistryEntry()
22+
: base(Microsoft.Win32.Registry.CurrentUser, @"Software\Microsoft\Windows\CurrentVersion\Run", Application.ProductName) {
23+
enabled = IsSynchronised();
24+
}
25+
26+
public override bool IsSynchronised() {
27+
using (var key = Hive.OpenSubKey(Key)) {
28+
return key?.GetValue(Name)?.ToString().StartsWith(value) ?? false;
29+
}
30+
}
31+
32+
public override void Synchronise() {
33+
if (!dirty) return;
34+
35+
using (var key = Hive.OpenSubKey(Key, true)) {
36+
if (Enabled) {
37+
key.SetValue(Name, value);
38+
}
39+
else {
40+
key.DeleteValue(Name, false);
41+
}
42+
}
43+
44+
dirty = false;
45+
}
46+
}
47+
}

Source/Registry/RegistryEntry.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using Microsoft.Win32;
2+
3+
namespace ScriptFUSION.WarframeAlertTracker.Registry {
4+
public abstract class RegistryEntry {
5+
protected RegistryKey Hive { get; }
6+
7+
protected string Key { get; }
8+
9+
protected string Name { get; }
10+
11+
protected RegistryEntry(RegistryKey hive, string key, string name) {
12+
Hive = hive;
13+
Key = key;
14+
Name = name;
15+
}
16+
17+
public abstract bool IsSynchronised();
18+
19+
public abstract void Synchronise();
20+
}
21+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace ScriptFUSION.WarframeAlertTracker.Registry {
2+
internal sealed class RegistrySettings {
3+
public LoadAtStartupRegistryEntry LoadAtStartUp { get; set; } = new LoadAtStartupRegistryEntry();
4+
5+
public void Save() {
6+
LoadAtStartUp.Synchronise();
7+
}
8+
}
9+
}

Source/WarframeAlertTracker.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@
7575
<DependentUpon>OptionsForm.cs</DependentUpon>
7676
</Compile>
7777
<Compile Include="Notifier.cs" />
78+
<Compile Include="Registry\LoadAtStartupRegistryEntry.cs" />
79+
<Compile Include="Registry\RegistryEntry.cs" />
80+
<Compile Include="Registry\RegistrySettings.cs" />
7881
<Compile Include="Properties\Settings.cs" />
7982
<Compile Include="Warframe\FissureTierParser.cs" />
8083
<Compile Include="Warframe\MissionType.cs" />

Source/WatApplication.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,19 @@
44
using ScriptFUSION.WarframeAlertTracker.Warframe;
55
using System.Windows.Forms;
66
using Newtonsoft.Json.Linq;
7+
using ScriptFUSION.WarframeAlertTracker.Registry;
78
using ScriptFUSION.WarframeAlertTracker.Properties;
89

910
namespace ScriptFUSION.WarframeAlertTracker {
1011
internal sealed class WatApplication : ApplicationContext {
11-
private Form mainForm;
12+
private WatForm mainForm;
1213

1314
/// <remarks>
1415
/// Hides the base implementation so the base Form is always null. This is needed to stop
1516
/// Application.RunMessageLoopInner forcing the form to be visible, which is undesirable for our purposes since
1617
/// we provide an option to start the application hidden.
1718
/// </remarks>
18-
public new Form MainForm
19+
public new WatForm MainForm
1920
{
2021
get => mainForm;
2122
set
@@ -30,6 +31,8 @@ internal sealed class WatApplication : ApplicationContext {
3031

3132
public Settings Settings { get; } = Settings.Default;
3233

34+
public RegistrySettings RegistrySettings { get; } = new RegistrySettings();
35+
3336
public ImageRepository ImageRepository { get; } = new ImageRepository(new ResourceDownloader(Downloader));
3437

3538
public Task<JObject> SolNodes { get; }

0 commit comments

Comments
 (0)