Skip to content

Commit

Permalink
Do not lose settings after updating the app
Browse files Browse the repository at this point in the history
  • Loading branch information
dziemborowicz committed Aug 24, 2016
1 parent 294cb36 commit 5eb2cc3
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 4 deletions.
3 changes: 3 additions & 0 deletions Hourglass/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
<setting name="UniqueId" serializeAs="String">
<value>00000000-0000-0000-0000-000000000000</value>
</setting>
<setting name="UpgradeRequired" serializeAs="String">
<value>True</value>
</setting>
</Hourglass.Properties.Settings>
</userSettings>
</configuration>
10 changes: 6 additions & 4 deletions Hourglass/Managers/AppManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

namespace Hourglass.Managers
{
using System.Linq;

/// <summary>
/// Manages the app.
/// </summary>
Expand All @@ -22,6 +24,7 @@ public class AppManager : Manager
private static readonly Manager[] Managers =
{
ErrorManager.Instance,
SettingsManager.Instance,
UpdateManager.Instance,
KeepAwakeManager.Instance,
WakeUpManager.Instance,
Expand All @@ -30,8 +33,7 @@ public class AppManager : Manager
SoundManager.Instance,
TimerStartManager.Instance,
TimerOptionsManager.Instance,
TimerManager.Instance,
SettingsManager.Instance
TimerManager.Instance
};

/// <summary>
Expand All @@ -57,7 +59,7 @@ public override void Initialize()
/// </summary>
public override void Persist()
{
foreach (Manager manager in Managers)
foreach (Manager manager in Managers.Reverse())
{
manager.Persist();
}
Expand All @@ -77,7 +79,7 @@ protected override void Dispose(bool disposing)

if (disposing)
{
foreach (Manager manager in Managers)
foreach (Manager manager in Managers.Reverse())
{
manager.Dispose();
}
Expand Down
13 changes: 13 additions & 0 deletions Hourglass/Managers/SettingsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,19 @@ private SettingsManager()
{
}

/// <summary>
/// Initializes the class.
/// </summary>
public override void Initialize()
{
if (Settings.Default.UpgradeRequired)
{
Settings.Default.Upgrade();
Settings.Default.UpgradeRequired = false;
Settings.Default.Save();
}
}

/// <summary>
/// Persists the state of the class.
/// </summary>
Expand Down
12 changes: 12 additions & 0 deletions Hourglass/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Hourglass/Properties/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,8 @@
<Setting Name="WindowSizeInfo" Type="Hourglass.Serialization.WindowSizeInfo" Scope="User">
<Value Profile="(Default)" />
</Setting>
<Setting Name="UpgradeRequired" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">True</Value>
</Setting>
</Settings>
</SettingsFile>

0 comments on commit 5eb2cc3

Please sign in to comment.