WIP
DirectOutput framework for virtual pinball cabinets WIP
Go to:
Overview 
GlobalConfigEdit.cs
Go to the documentation of this file.
1 using System;
2 using System.Collections.Generic;
4 using System.Data;
5 using System.Drawing;
6 using System.Linq;
7 using System.Text;
8 using System.Windows.Forms;
10 using System.IO;
11 
13 {
14  public partial class GlobalConfigEdit : Form
15  {
16 
17  GlobalConfig Config = new GlobalConfig();
18 
19  string ConfigFilename = "";
20 
22  {
23  InitializeComponent();
24  }
25 
26  private void GlobalConfigEdit_Load(object sender, EventArgs e)
27  {
28  LoadConfig();
29  }
30 
31 
32 
33  private void SaveConfig(string Filename)
34  {
35  Config.IniFilesPath = IniFilesPath.Text;
36  Config.CabinetConfigFilePattern.Pattern = CabinetFilename.Text;
37  Config.LogFilePattern.Pattern = LogFilename.Text;
38  Config.EnableLogging = LoggingEnabled.Checked;
39  Config.ClearLogOnSessionStart = ClearLogOnSessionStart.Checked;
40  Config.LedWizDefaultMinCommandIntervalMs = (int)LedWizDefaultMinCommandIntervalMs.Value;
41  try
42  {
43  Config.SaveGlobalConfig(Filename);
44 
45  this.Text = "Global Configuration Editor - {0}".Build(Filename);
46  }
47  catch (Exception E)
48  {
49  MessageBox.Show("Could not save global configuration to file: {0}.\n{1}".Build(Filename, E.Message), "Save error", MessageBoxButtons.OK, MessageBoxIcon.Error);
50 
51  }
52  }
53 
54 
55  private void LoadConfig(string Filename = "")
56  {
57  ConfigFilename = "";
58  this.Text = "Global Configuration Editor - <New global configuration>".Build(Filename);
59  if (!Filename.IsNullOrWhiteSpace())
60  {
61  try
62  {
64  ConfigFilename = Filename;
65 
66  this.Text = "Global Configuration Editor - {0}".Build(Filename);
67  }
68  catch (Exception E)
69  {
70  MessageBox.Show("A exception occured when loading the global config file {0}.\nWill use empty global config instead.".Build(Filename), "Global config loading error", MessageBoxButtons.OK, MessageBoxIcon.Error);
71  Config = new GlobalConfig();
72  }
73  }
74  else
75  {
76  Config = new GlobalConfig();
77  }
78 
79 
80 
81  IniFilesPath.Text = Config.IniFilesPath;
82 
83  LoggingEnabled.Checked = Config.EnableLogging;
84  ClearLogOnSessionStart.Checked = Config.ClearLogOnSessionStart;
85  LogFilename.Text = Config.LogFilePattern.Pattern;
86 
87  CabinetFilename.Text = Config.CabinetConfigFilePattern.Pattern;
88  LedWizDefaultMinCommandIntervalMs.Value = Config.LedWizDefaultMinCommandIntervalMs;
89 
90  }
91 
92  private void SelectIniFilePathButton_Click(object sender, EventArgs e)
93  {
94  DirectoryInfo DI = null;
95  if (!IniFilesPath.Text.IsNullOrWhiteSpace())
96  {
97  try
98  {
99  DI = new DirectoryInfo(IniFilesPath.Text);
100  if (DI.Exists)
101  {
102  SelectIniFileDirectoryDialog.SelectedPath = DI.FullName;
103  }
104  }
105  catch { }
106  }
107 
108  if (SelectIniFileDirectoryDialog.ShowDialog(Owner) == DialogResult.OK)
109  {
110 
111  IniFilesPath.Text = SelectIniFileDirectoryDialog.SelectedPath;
112 
113 
114  }
115 
116  }
117 
118 
119 
120  private void SelectCabinetConfigFileButton_Click(object sender, EventArgs e)
121  {
122  FileInfo FI = null;
123  if (!CabinetFilename.Text.IsNullOrWhiteSpace())
124  {
125  try
126  {
127  FI = new FileInfo(CabinetFilename.Text);
128  if (FI.Exists)
129  {
130  SelectCabinetConfigFileDialog.FileName = FI.FullName;
131  }
132  }
133  catch { }
134  }
135 
136  if (SelectCabinetConfigFileDialog.ShowDialog(Owner) == DialogResult.OK)
137  {
138 
139  CabinetFilename.Text = SelectCabinetConfigFileDialog.FileName;
140 
141 
142 
143  }
144  }
145 
146 
147 
148 
149 
150  private void SelectLogFileButton_Click(object sender, EventArgs e)
151  {
152  FileInfo FI = null;
153  if (!LogFilename.Text.IsNullOrWhiteSpace())
154  {
155  try
156  {
157  FI = new FileInfo(LogFilename.Text);
158  if (FI.Exists)
159  {
160  SelectLogFileDialog.FileName = FI.FullName;
161  }
162  }
163  catch { }
164  }
165 
166  if (SelectLogFileDialog.ShowDialog(Owner) == DialogResult.OK)
167  {
168 
169  LogFilename.Text = SelectLogFileDialog.FileName;
170 
171 
172 
173  }
174  }
175 
176 
177 
178  private void saveToolStripMenuItem_Click(object sender, EventArgs e)
179  {
180  if (!ConfigFilename.IsNullOrWhiteSpace())
181  {
182  SaveConfig(ConfigFilename);
183  }
184  else
185  {
186  saveAsToolStripMenuItem_Click(sender, e);
187  }
188  }
189 
190  private void saveAsToolStripMenuItem_Click(object sender, EventArgs e)
191  {
192  SaveGlobalConfigDialog.FileName = ConfigFilename;
193 
194  if (SaveGlobalConfigDialog.ShowDialog(Owner) == DialogResult.OK)
195  {
196  SaveConfig(SaveGlobalConfigDialog.FileName);
197 
198  }
199  }
200 
201  private void newToolStripMenuItem_Click(object sender, EventArgs e)
202  {
203  if (ContinueDialog())
204  {
205  LoadConfig("");
206  }
207  }
208 
209  private void loadToolStripMenuItem_Click(object sender, EventArgs e)
210  {
211  if (ContinueDialog())
212  {
213  OpenGlobalConfigDialog.InitialDirectory = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
214 
215  if (OpenGlobalConfigDialog.ShowDialog(Owner) == DialogResult.OK)
216  {
217  LoadConfig(OpenGlobalConfigDialog.FileName);
218  }
219 
220  }
221  }
222 
223  private bool ContinueDialog()
224  {
225  if (ConfigHasChanged)
226  {
227  switch (MessageBox.Show(Owner, "The current configuration has changed. Do you want to save the changes?\nPress Yes to save your changes.\nPress No to discard your changes.\nPress Cancel to abort this operation.", "Save changes", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question))
228  {
229  case System.Windows.Forms.DialogResult.Yes:
230  SaveGlobalConfigDialog.FileName = ConfigFilename;
231 
232  if (SaveGlobalConfigDialog.ShowDialog(Owner) == DialogResult.OK)
233  {
234  SaveConfig(SaveGlobalConfigDialog.FileName);
235 
236  }
237  else
238  {
239  if (MessageBox.Show(Owner, "You config has not been saved.\nDo you want to continue and discard your changes?", "Discard changes", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) != DialogResult.OK)
240  {
241  return false;
242  }
243  }
244  return true;
245 
246  case System.Windows.Forms.DialogResult.No:
247  return true;
248 
249  default:
250  return false;
251 
252  }
253 
254  }
255  else
256  {
257  return true;
258 
259  }
260  }
261 
262  private void quitToolStripMenuItem_Click(object sender, EventArgs e)
263  {
264 
265  this.Close();
266 
267  }
268 
269  private void GlobalConfigEdit_FormClosing(object sender, FormClosingEventArgs e)
270  {
271  e.Cancel = !ContinueDialog();
272  }
273 
274 
275  private bool ConfigHasChanged
276  {
277  get
278  {
279  return (Config.IniFilesPath != IniFilesPath.Text || Config.CabinetConfigFilePattern.Pattern != CabinetFilename.Text || Config.EnableLogging != LoggingEnabled.Checked || Config.ClearLogOnSessionStart != ClearLogOnSessionStart.Checked || Config.LogFilePattern.Pattern != LogFilename.Text);
280 
281 
282 
283 
284 
285  }
286  }
287  }
288 }
bool EnableLogging
Gets or sets a value indicating whether impotant events in the framework are logged to a file...
int LedWizDefaultMinCommandIntervalMs
Gets or sets the mininimal interval between command for LedWiz units in miliseconds (Default: 1ms)...
Definition: GlobalConfig.cs:40
void SaveGlobalConfig(string GlobalConfigFilename="")
Saves the GlobalConfig to the file specified in GlobalConfigFilename. Before saving the current glob...
FilePattern CabinetConfigFilePattern
Gets or sets the path and name of the cabinet config file.
FilePattern LogFilePattern
Gets or sets the log file pattern. The log file pattern supports the following placeholders: ...
string IniFilesPath
Gets or sets the path to the ini files used for table configurations
Definition: GlobalConfig.cs:89
bool ClearLogOnSessionStart
Gets or sets a value indicating whether DOF clears the log file on session start. ...
Global configuration for the DirectOutput framework.
Definition: GlobalConfig.cs:18
static GlobalConfig GetGlobalConfigFromConfigXmlFile(string GlobalConfigFileName)
Instanciates a GlobalConfig object from a global configuration in a XML file. If the global config f...