WIP
DirectOutput framework for virtual pinball cabinets WIP
Go to:
Overview 
Settings.cs
Go to the documentation of this file.
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using System.IO;
6 using System.Xml.Serialization;
7 using System.Reflection;
8 
10 {
11  public class Settings
12  {
13  private string _LastRomName = "";
14 
15  public string LastRomName
16  {
17  get { return _LastRomName; }
18  set { _LastRomName = value; }
19  }
20  private string _LastTableFilename = "";
21 
22  public string LastTableFilename
23  {
24  get { return _LastTableFilename; }
25  set { _LastTableFilename = value; }
26  }
27  private string _LastGlobalConfigFilename = "";
28 
29  public string LastGlobalConfigFilename
30  {
31  get { return _LastGlobalConfigFilename; }
32  set { _LastGlobalConfigFilename = value; }
33  }
34 
35  private List<string> _RomNames = new List<string>();
36 
37  public List<string> RomNames
38  {
39  get { return _RomNames; }
40  set { _RomNames = value; }
41  }
42 
43 
44  private List<string> _TableFilenames = new List<string>();
45 
46  public List<string> TableFilenames
47  {
48  get { return _TableFilenames; }
49  set { _TableFilenames = value; }
50  }
51 
52 
53  private List<string> _GlobalConfigFilenames = new List<string>();
54 
55  public List<string> GlobalConfigFilenames
56  {
57  get { return _GlobalConfigFilenames; }
58  set { _GlobalConfigFilenames = value; }
59  }
60 
61  private int _PulseDurationMs = 100;
62 
63  public int PulseDurationMs
64  {
65  get { return _PulseDurationMs; }
66  set { _PulseDurationMs = value.Limit(10,5000); }
67  }
68 
69 
70  public void SaveSettings()
71  {
72  try
73  {
74  string Xml = "";
75  using (MemoryStream ms = new MemoryStream())
76  {
77  new XmlSerializer(typeof(Settings)).Serialize(ms, this);
78  ms.Position = 0;
79 
80  using (StreamReader sr = new StreamReader(ms, Encoding.Default))
81  {
82  Xml = sr.ReadToEnd();
83 
84  }
85 
86  }
87  new DirectoryInfo(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),"config")).CreateDirectoryPath();
88  Xml.WriteToFile(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),"config","DirectOutputTesterSettings.xml"));
89  }
90  catch
91  {
92 
93  }
94  }
95 
96 
97  public static Settings LoadSettings()
98  {
99  try
100  {
101  string SettingsXML = DirectOutput.General.FileReader.ReadFileToString(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "config", "DirectOutputTesterSettings.xml"));
102 
103  using (MemoryStream ms = new MemoryStream(Encoding.Default.GetBytes(SettingsXML)))
104  {
105  Settings S = (Settings)new XmlSerializer(typeof(Settings)).Deserialize(ms);
106 
107  return S;
108  }
109  }
110  catch
111  {
112  return new Settings();
113  }
114  }
115 
116  }
117 }
Static class to read files.
Definition: FileReader.cs:9
List< string > GlobalConfigFilenames
Definition: Settings.cs:56
static Settings LoadSettings()
Definition: Settings.cs:97
The namespace DirectOutput.General contains classes for general use.