1 |
william |
34 |
using System; |
2 |
|
|
using System.Collections.Generic; |
3 |
|
|
using System.Linq; |
4 |
|
|
using System.Text; |
5 |
|
|
using System.Reflection; |
6 |
|
|
using System.Configuration; |
7 |
|
|
|
8 |
|
|
namespace RomCheater.UserSettingsSupport |
9 |
|
|
{ |
10 |
|
|
public sealed class SettingSubscriber |
11 |
|
|
{ |
12 |
|
|
private class SettingsEventArgs : EventArgs |
13 |
|
|
{ |
14 |
|
|
public SettingsEventArgs() :this(null) { } |
15 |
|
|
public SettingsEventArgs(System.Configuration.ApplicationSettingsBase settings) { this.Settings = settings; } |
16 |
|
|
public System.Configuration.ApplicationSettingsBase Settings { get; private set; } |
17 |
|
|
} |
18 |
|
|
private static EventHandler<SettingsEventArgs> OnSubscribeAddedEvent; |
19 |
|
|
static SettingSubscriber() { OnSubscribeAddedEvent += new EventHandler<SettingsEventArgs>(OnSubscribeAdded); } |
20 |
william |
146 |
public static void AddSubscriber(System.Configuration.ApplicationSettingsBase settings) { AddSubscriber(null, settings); } |
21 |
|
|
public static void AddSubscriber(object Subscriber, System.Configuration.ApplicationSettingsBase settings) { if (OnSubscribeAddedEvent != null) { OnSubscribeAddedEvent(Subscriber, new SettingsEventArgs(settings)); } } |
22 |
|
|
private static void OnSubscribeAdded(object Subscriber, SettingsEventArgs e) |
23 |
william |
34 |
{ |
24 |
|
|
if (e.Settings != null) |
25 |
|
|
{ |
26 |
|
|
foreach (SettingsProperty prop in e.Settings.Properties) |
27 |
|
|
{ |
28 |
|
|
if (prop.Name == "UpgradeRequired") |
29 |
|
|
{ |
30 |
|
|
bool UpgradeRequired = Convert.ToBoolean(e.Settings[prop.Name]); |
31 |
|
|
try |
32 |
|
|
{ |
33 |
|
|
if (UpgradeRequired) |
34 |
|
|
{ |
35 |
|
|
e.Settings.Upgrade(); |
36 |
|
|
e.Settings.Reload(); |
37 |
|
|
e.Settings[prop.Name] = false; |
38 |
|
|
e.Settings.Save(); |
39 |
|
|
} |
40 |
|
|
} |
41 |
|
|
catch { e.Settings.Reset(); } |
42 |
|
|
break; |
43 |
|
|
} |
44 |
|
|
} |
45 |
|
|
} |
46 |
|
|
} |
47 |
|
|
} |
48 |
|
|
} |