WIP
DirectOutput framework for virtual pinball cabinets WIP
Go to:
Overview 
Plugin.cs
Go to the documentation of this file.
1 using System;
2 using System.ComponentModel.Composition;
3 using System.IO;
4 using System.Reflection;
6 using DirectOutput;
7 
11 namespace B2SServerPlugin
12 {
13 
17  [Export(typeof(IDirectPlugin))]
18  public class Plugin : IDirectPlugin, IDirectPluginFrontend
19  {
20 
21  #region IDirectPluginFrontend Member
22 
23 
28  public void PluginShowFrontend(System.Windows.Forms.Form Owner = null)
29  {
30  try
31  {
33 
34  }
35  catch (Exception E)
36  {
37 
38  System.Windows.Forms.MessageBox.Show("Could not show DirectOutput frontend.\n The following exception occured:\n{0}".Build(E.Message), "DirectOutput");
39  }
40  }
41 
42  #endregion
43 
44 
45  #region IDirectPlugin Members
46 
54  public string Name
55  {
56  get
57  {
58  Version V = typeof(Pinball).Assembly.GetName().Version;
59  DateTime BuildDate = new DateTime(2000, 1, 1).AddDays(V.Build).AddSeconds(V.Revision * 2);
60  return "DirectOutput (V: {0} as of {1})".Build(V.ToString(), BuildDate.ToString("yyyy.MM.dd HH:mm"));
61  }
62  }
63 
64 
65 
73  public void DataReceive(char TableElementTypeChar, int Number, int Value)
74  {
75  Pinball.ReceiveData(TableElementTypeChar, Number, Value);
76  }
77 
78 
79 
80 
85  public void PluginFinish()
86  {
87 
88  Pinball.Finish();
89  }
90 
97  public void PluginInit(string TableFilename, string RomName)
98  {
99 
100  //Check config dir for global config file
101  FileInfo F = new FileInfo(Path.Combine(new FileInfo(Assembly.GetExecutingAssembly().Location).Directory.FullName, "config", "GlobalConfig_B2SServer.xml"));
102  if (!F.Exists)
103  {
104  //Check if a shortcut to the config dir exists
105  FileInfo LnkFile = new FileInfo(Path.Combine(new FileInfo(Assembly.GetExecutingAssembly().Location).Directory.FullName, "config", "GlobalConfig_B2SServer.lnk"));
106  if (LnkFile.Exists)
107  {
108  string ConfigDirPath = ResolveShortcut(LnkFile);
109  if (Directory.Exists(ConfigDirPath))
110  {
111  F = new FileInfo(Path.Combine(ConfigDirPath, "GlobalConfig_B2SServer.xml"));
112  }
113  }
114  if (!F.Exists)
115  {
116 
117  //Check table dir for global config file
118  F = new FileInfo("GlobalConfig_B2SServer.xml");
119  if (!F.Exists)
120  {
121  //Check dll dir for global config file
122  F = new FileInfo(Path.Combine(new FileInfo(Assembly.GetExecutingAssembly().Location).Directory.FullName, "GlobalConfig_B2SServer.xml"));
123  if (!F.Exists)
124  {
125  //if global config file does not exist, set filename to config directory.
126  F = new FileInfo(Path.Combine(new FileInfo(Assembly.GetExecutingAssembly().Location).Directory.FullName, "config", "GlobalConfig_B2SServer.xml"));
127  }
128  }
129  }
130  }
131 
132  Pinball.Setup(F.FullName, TableFilename, RomName);
133  Pinball.Init();
134 
135  // PluginShowFrontend();
136 
137 
138  }
139 
140 
141  private string ResolveShortcut(FileInfo ShortcutFile)
142  {
143  string TargetPath = "";
144  try
145  {
146  Type WScriptShell = Type.GetTypeFromProgID("WScript.Shell");
147  object Shell = Activator.CreateInstance(WScriptShell);
148  object Shortcut = WScriptShell.InvokeMember("CreateShortcut", BindingFlags.InvokeMethod, null, Shell, new object[] { ShortcutFile.FullName });
149  TargetPath = (string)Shortcut.GetType().InvokeMember("TargetPath", BindingFlags.GetProperty, null, Shortcut, null);
150  Shortcut = null;
151  Shell = null;
152  }
153  catch
154  {
155 
156  }
157 
158  try
159  {
160  if (Directory.Exists(TargetPath))
161  {
162  return TargetPath;
163  }
164  else if (File.Exists(TargetPath))
165  {
166  return TargetPath;
167  }
168  else
169  {
170  return "";
171  }
172 
173  }
174  catch
175  {
176  return "";
177  }
178  }
179 
180  #endregion
181 
182  #region Properties
183 
184 
185 
186  private Pinball _Pinball = new Pinball();
187 
194  public Pinball Pinball
195  {
196  get { return _Pinball; }
197  set { _Pinball = value; }
198  }
199 
200  #endregion
201 
202 
203 
204 
205 
209  public Plugin()
210  {
211 
212 
213  }
214 
215 
216 
217 
218 
219 
220 
221 
222 
223 
224 
225  }
226 }
void PluginFinish()
Finishes the plugin. This is the last method called, before the plugin is discarded. This method is also called, after a undhandled exception has occured in the plugin.
Definition: Plugin.cs:85
void Setup(string GlobalConfigFilename="", string TableFilename="", string RomName="")
Configures the Pinball object. Loads the global config, table config and cabinet config ...
Definition: Pinball.cs:104
void PluginInit(string TableFilename, string RomName)
Initializes the Plugin. The IDirectPlugin interface requires the implementation of this method...
Definition: Plugin.cs:97
Pinball Pinball
Gets or sets the DirectOutput.Pinball object for the plugin.
Definition: Plugin.cs:195
Pinball is the main object of the DirectOutput framework. It holds all objects required to process P...
Definition: Pinball.cs:23
void Finish()
Finishes the Pinball object.
Definition: Pinball.cs:446
void PluginShowFrontend(System.Windows.Forms.Form Owner=null)
Shows the frontend of the the DirectOutput framework. The IDirectPluginFrontend interface requires t...
Definition: Plugin.cs:28
Plugin()
Initializes a new instance of the Plugin class.
Definition: Plugin.cs:209
DirectOutputPlugin is the namespace of the Dll implementing the actual plugin interface for the B2S S...
Definition: Plugin.cs:11
void Init()
Initializes/starts the Pinball object
Definition: Pinball.cs:402
void ReceiveData(char TableElementTypeChar, int Number, int Value)
Receives the table element data from the calling app (e.g. B2S.Server providing data through the plug...
Definition: Pinball.cs:688
Plugin is the IDirectPlugin interface implementation required by the B2S Server.
Definition: Plugin.cs:18
static void Open(Pinball Pinball, Form Owner=null)
Definition: MainMenu.cs:58
void DataReceive(char TableElementTypeChar, int Number, int Value)
This method is called, when new data from Pinmame becomes available. The IDirectPlugin interface req...
Definition: Plugin.cs:73
string Name
Gets the name of the IDirectPlugin.
Definition: Plugin.cs:55