/[RomCheater]/trunk/RomCheater.UserSettingsSupport/SettingSubscriber.cs
ViewVC logotype

Contents of /trunk/RomCheater.UserSettingsSupport/SettingSubscriber.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 146 - (show annotations) (download)
Sun May 27 22:24:30 2012 UTC (8 years, 4 months ago) by william
File size: 2150 byte(s)

1 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 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 {
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 }

  ViewVC Help
Powered by ViewVC 1.1.22