Skip to content

Commit

Permalink
Settings 储存方式变更
Browse files Browse the repository at this point in the history
  • Loading branch information
Yoctillion committed Feb 15, 2016
1 parent f157afc commit 29fcdd8
Show file tree
Hide file tree
Showing 8 changed files with 162 additions and 74 deletions.
17 changes: 7 additions & 10 deletions NotifyEx/Models/HpNotifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.Reactive.Linq;
using Grabacr07.KanColleWrapper.Models;
using NotifyEx.Models.NotifyType;
using NotifyEx.Models.Settings;

namespace NotifyEx.Models
{
Expand All @@ -20,17 +21,14 @@ internal class HpNotifier
{
public static HpNotifier Current = new HpNotifier();

private static readonly Settings Settings = Settings.Default;

public bool Enabled
{
get { return Settings.EnabledLowHpNotifier; }
get { return NotifierSettings.EnabledLowHpNotifier.Value; }
set
{
if (Settings.EnabledLowHpNotifier != value)
if (NotifierSettings.EnabledLowHpNotifier.Value != value)
{
Settings.EnabledLowHpNotifier = value;
Settings.Save();
NotifierSettings.EnabledLowHpNotifier.Value = value;
}
}
}
Expand All @@ -40,13 +38,12 @@ public bool Enabled
/// </summary>
public bool EnabledShowDamageControl
{
get { return Settings.EnabledShowDamageControl; }
get { return NotifierSettings.EnabledShowDamageControl.Value; }
set
{
if (Settings.EnabledShowDamageControl != value)
if (NotifierSettings.EnabledShowDamageControl.Value != value)
{
Settings.EnabledShowDamageControl = value;
Settings.Save();
NotifierSettings.EnabledShowDamageControl.Value = value;
}
}
}
Expand Down
76 changes: 76 additions & 0 deletions NotifyEx/Models/Settings/NotifierSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using MetroTrilithon.Serialization;

namespace NotifyEx.Models.Settings
{
public static class NotifierSettings
{
#region Ship count notifier settings

public static SerializableProperty<bool> EnabledShipNotifier { get; }
= new SerializableProperty<bool>(GetKey(), Provider.Roaming, Properties.Settings.Default.EnabledShipNotifier) { AutoSave = true };

public static SerializableProperty<uint> ShipWarningCount { get; }
= new SerializableProperty<uint>(GetKey(), Provider.Roaming, Properties.Settings.Default.WarningShipCount) { AutoSave = true };

public static SerializableProperty<bool> EnabledEventShipNotifier { get; }
= new SerializableProperty<bool>(GetKey(), Provider.Roaming, Properties.Settings.Default.EnabledEventShipNotifier) { AutoSave = true };

public static SerializableProperty<uint> EventShipWarningCount { get; }
= new SerializableProperty<uint>(GetKey(), Provider.Roaming, Properties.Settings.Default.EventWarningShipCount) { AutoSave = true };

#endregion

#region Slot count notifier settings

public static SerializableProperty<bool> EnabledSlotNotifier { get; }
= new SerializableProperty<bool>(GetKey(), Provider.Roaming, Properties.Settings.Default.EnabledSlotNotifier) { AutoSave = true };

public static SerializableProperty<uint> SlotWarningCount { get; }
= new SerializableProperty<uint>(GetKey(), Provider.Roaming, Properties.Settings.Default.WarningShipCount) { AutoSave = true };

public static SerializableProperty<bool> EnabledEventSlotNotifier { get; }
= new SerializableProperty<bool>(GetKey(), Provider.Roaming, Properties.Settings.Default.EnabledEventSlotNotifier) { AutoSave = true };

public static SerializableProperty<uint> EventSlotWarningCount { get; }
= new SerializableProperty<uint>(GetKey(), Provider.Roaming, Properties.Settings.Default.EventWarningSlotCount) { AutoSave = true };

#endregion

#region Heavily damaged notifier settings

public static SerializableProperty<bool> EnabledLowHpNotifier { get; }
= new SerializableProperty<bool>(GetKey(), Provider.Roaming, Properties.Settings.Default.EnabledLowHpNotifier) { AutoSave = true };

public static SerializableProperty<bool> EnabledShowDamageControl { get; }
= new SerializableProperty<bool>(GetKey(), Provider.Roaming, Properties.Settings.Default.EnabledShowDamageControl) { AutoSave = true };

#endregion

#region Lack of supply notifier

public static SerializableProperty<bool> EnabledSupplyNotifier { get; }
= new SerializableProperty<bool>(GetKey(), Provider.Roaming, Properties.Settings.Default.EnabledSupplyNotifier) { AutoSave = true };

public static SerializableProperty<bool> EnabledSortieSupplyNotifier { get; }
= new SerializableProperty<bool>(GetKey(), Provider.Roaming, Properties.Settings.Default.EnabledSortieSupplyNotifier) { AutoSave = true };

public static SerializableProperty<bool> EnabledExerciseSupplyNotifier { get; }
= new SerializableProperty<bool>(GetKey(), Provider.Roaming, Properties.Settings.Default.EnabledExerciseSupplyNotifier) { AutoSave = true };

public static SerializableProperty<bool> EnabledExpenditionSupplyNotifier { get; }
= new SerializableProperty<bool>(GetKey(), Provider.Roaming, Properties.Settings.Default.EnabledExpenditionSupplyNotifier) { AutoSave = true };

#endregion

private static string GetKey([CallerMemberName] string propertyName = "")
{
return $"{nameof(NotifierSettings)}.{propertyName}";
}
}
}
19 changes: 19 additions & 0 deletions NotifyEx/Models/Settings/Provider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MetroTrilithon.Serialization;

namespace NotifyEx.Models.Settings
{
public static class Provider
{
public static string RoamingPath { get; } = Path.Combine(Environment.GetFolderPath(
Environment.SpecialFolder.ApplicationData),
"grabacr.net", "KanColleViewer", "NotifyEx.xaml");

public static ISerializationProvider Roaming { get; } = new FileSettingsProvider(RoamingPath);
}
}
32 changes: 14 additions & 18 deletions NotifyEx/Models/ShipNotifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using MetroTrilithon.Lifetime;
using MetroTrilithon.Mvvm;
using NotifyEx.Models.NotifyType;
using NotifyEx.Models.Settings;
using NotifyEx.Properties;
using StatefulModel;

Expand All @@ -20,18 +21,16 @@ namespace NotifyEx.Models
internal class ShipNotifier : NotificationObject, IWarningCounter, IDisposableHolder
{
public static ShipNotifier Current { get; } = new ShipNotifier();

private static readonly Settings Settings = Settings.Default;


public bool Enabled
{
get { return Settings.EnabledShipNotifier; }
get { return NotifierSettings.EnabledShipNotifier.Value; }
set
{
if (Settings.EnabledShipNotifier != value)
if (NotifierSettings.EnabledShipNotifier.Value != value)
{
Settings.EnabledShipNotifier = value;
Settings.Save();
NotifierSettings.EnabledShipNotifier.Value = value;
this.RaisePropertyChanged();
}
}
Expand Down Expand Up @@ -59,13 +58,12 @@ private set

public uint NormalWarningCount
{
get { return Settings.WarningShipCount; }
get { return NotifierSettings.ShipWarningCount.Value; }
set
{
if (Settings.WarningShipCount != value)
if (NotifierSettings.ShipWarningCount.Value != value)
{
Settings.WarningShipCount = value;
Settings.Save();
NotifierSettings.ShipWarningCount.Value = value;
this.RaisePropertyChanged();
this.RaisePropertyChanged(nameof(this.WarningCount));
}
Expand All @@ -74,13 +72,12 @@ public uint NormalWarningCount

public bool EnabledEvent
{
get { return Settings.EnabledEventShipNotifier; }
get { return NotifierSettings.EnabledEventShipNotifier.Value; }
set
{
if (Settings.EnabledEventShipNotifier != value)
if (NotifierSettings.EnabledEventShipNotifier.Value != value)
{
Settings.EnabledEventShipNotifier = value;
Settings.Save();
NotifierSettings.EnabledEventShipNotifier.Value = value;
this.RaisePropertyChanged();
this.RaisePropertyChanged(nameof(this.WarningCount));
}
Expand All @@ -89,13 +86,12 @@ public bool EnabledEvent

public uint EventWarningCount
{
get { return Settings.EventWarningShipCount; }
get { return NotifierSettings.EventShipWarningCount.Value; }
set
{
if (Settings.EventWarningShipCount != value)
if (NotifierSettings.EventShipWarningCount.Value != value)
{
Settings.EventWarningShipCount = value;
Settings.Save();
NotifierSettings.EventShipWarningCount.Value = value;
this.RaisePropertyChanged();
this.RaisePropertyChanged(nameof(this.WarningCount));
}
Expand Down
33 changes: 14 additions & 19 deletions NotifyEx/Models/SlotNotifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using MetroTrilithon.Lifetime;
using MetroTrilithon.Mvvm;
using NotifyEx.Models.NotifyType;
using NotifyEx.Models.Settings;
using NotifyEx.Properties;
using StatefulModel;

Expand All @@ -19,17 +20,14 @@ internal class SlotNotifier : NotificationObject, IWarningCounter, IDisposableHo
{
public static SlotNotifier Current { get; } = new SlotNotifier();

private static readonly Settings Settings = Settings.Default;

public bool Enabled
{
get { return Settings.EnabledSlotNotifier; }
get { return NotifierSettings.EnabledSlotNotifier.Value; }
set
{
if (Settings.EnabledSlotNotifier != value)
if (NotifierSettings.EnabledSlotNotifier.Value != value)
{
Settings.EnabledSlotNotifier = value;
Settings.Save();
NotifierSettings.EnabledSlotNotifier.Value = value;
this.RaisePropertyChanged();
}
}
Expand All @@ -38,7 +36,7 @@ public bool Enabled
public uint WarningCount =>
this.EnabledEvent && Util.IsInEvent
? this.EventWarningCount
: Settings.WarningSlotCount;
: this.NormalWarningCount;

private uint _remain = uint.MaxValue;

Expand All @@ -57,13 +55,12 @@ private set

public uint NormalWarningCount
{
get { return Settings.WarningSlotCount; }
get { return NotifierSettings.SlotWarningCount.Value; }
set
{
if (Settings.WarningSlotCount != value)
if (NotifierSettings.SlotWarningCount.Value != value)
{
Settings.WarningSlotCount = value;
Settings.Save();
NotifierSettings.SlotWarningCount.Value = value;
this.RaisePropertyChanged();
this.RaisePropertyChanged(nameof(this.WarningCount));
}
Expand All @@ -72,13 +69,12 @@ public uint NormalWarningCount

public bool EnabledEvent
{
get { return Settings.EnabledEventSlotNotifier; }
get { return NotifierSettings.EnabledEventSlotNotifier.Value; }
set
{
if (Settings.EnabledEventSlotNotifier != value)
if (NotifierSettings.EnabledEventSlotNotifier.Value != value)
{
Settings.EnabledEventSlotNotifier = value;
Settings.Save();
NotifierSettings.EnabledEventSlotNotifier.Value = value;
this.RaisePropertyChanged();
this.RaisePropertyChanged(nameof(this.WarningCount));
}
Expand All @@ -87,13 +83,12 @@ public bool EnabledEvent

public uint EventWarningCount
{
get { return Settings.EventWarningSlotCount; }
get { return NotifierSettings.EventSlotWarningCount.Value; }
set
{
if (Settings.EventWarningSlotCount != value)
if (NotifierSettings.EventSlotWarningCount.Value != value)
{
Settings.EventWarningSlotCount = value;
Settings.Save();
NotifierSettings.EventSlotWarningCount.Value = value;
this.RaisePropertyChanged();
this.RaisePropertyChanged(nameof(this.WarningCount));
}
Expand Down
31 changes: 13 additions & 18 deletions NotifyEx/Models/SupplyNotifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Grabacr07.KanColleWrapper;
using Grabacr07.KanColleWrapper.Models;
using NotifyEx.Models.NotifyType;
using NotifyEx.Models.Settings;
using NotifyEx.Properties;

namespace NotifyEx.Models
Expand All @@ -18,56 +19,50 @@ internal class SupplyNotifier
{
public static SupplyNotifier Current { get; } = new SupplyNotifier();

private static readonly Settings Settings = Settings.Default;

public bool Enabled
{
get { return Settings.EnabledSupplyNotifier; }
get { return NotifierSettings.EnabledSupplyNotifier.Value; }
set
{
if (Settings.EnabledSupplyNotifier != value)
if (NotifierSettings.EnabledSupplyNotifier.Value != value)
{
Settings.EnabledSupplyNotifier = value;
Settings.Save();
NotifierSettings.EnabledSupplyNotifier.Value = value;
}
}
}

public bool EnabledSortie
{
get { return Settings.EnabledSortieSupplyNotifier; }
get { return NotifierSettings.EnabledSortieSupplyNotifier.Value; }
set
{
if (Settings.EnabledSortieSupplyNotifier != value)
if (NotifierSettings.EnabledSortieSupplyNotifier.Value != value)
{
Settings.EnabledSortieSupplyNotifier = value;
Settings.Save();
NotifierSettings.EnabledSortieSupplyNotifier.Value = value;
}
}
}

public bool EnabledExercise
{
get { return Settings.EnabledExerciseSupplyNotifier; }
get { return NotifierSettings.EnabledExerciseSupplyNotifier.Value; }
set
{
if (Settings.EnabledExerciseSupplyNotifier != value)
if (NotifierSettings.EnabledExerciseSupplyNotifier.Value != value)
{
Settings.EnabledExerciseSupplyNotifier = value;
Settings.Save();
NotifierSettings.EnabledExerciseSupplyNotifier.Value = value;
}
}
}

public bool EnabledExpendition
{
get { return Settings.EnabledExpenditionSupplyNotifier; }
get { return NotifierSettings.EnabledExpenditionSupplyNotifier.Value; }
set
{
if (Settings.EnabledExpenditionSupplyNotifier != value)
if (NotifierSettings.EnabledExpenditionSupplyNotifier.Value != value)
{
Settings.EnabledExpenditionSupplyNotifier = value;
Settings.Save();
NotifierSettings.EnabledExpenditionSupplyNotifier.Value = value;
}
}
}
Expand Down
Loading

0 comments on commit 29fcdd8

Please sign in to comment.