DirectOutputR1
DirectOutput framework R1 for virtual pinball cabinets.
Go to:
Overview 
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Events Macros Pages
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;
5 using DirectPluginInterface;
6 using DirectOutput;
7 using System.Windows.Forms;
8 
12 namespace DirectPlugin
13 {
14 
18  [Export(typeof(IDirectPlugin))]
19  public class DirectOutputPlugin : IDirectPlugin, IDirectPluginFrontend
20  {
21 
22  #region IPlugin Members
23 
31  public string Name
32  {
33  get
34  {
35  Version V = typeof(Pinball).Assembly.GetName().Version;
36  DateTime BuildDate = new DateTime(2000, 1, 1).AddDays(V.Build).AddSeconds(V.Revision * 2);
37  return "DirectOutput (V: {0} as of {1})".Build(V.ToString(), BuildDate.ToString("yyyy.MM.dd HH:mm"));
38  }
39  }
40 
41 
42 
50  public void DataReceive(char TableElementTypeChar, int Number, int Value)
51  {
52 
53  Pinball.ReceiveData(TableElementTypeChar, Number, Value);
54 
55  }
56 
57 
58 
59 
65  public void PluginFinish()
66  {
67 
68  Pinball.Finish();
69 
70  }
71 
79  public void PluginInit(string HostingApplicationName, string TableFilename, string GameName)
80  {
81  string HostAppFilename = HostingApplicationName.Replace(".", "");
82  foreach (char C in Path.GetInvalidFileNameChars() )
83  {
84  HostAppFilename=HostAppFilename.Replace(""+C,"");
85  }
86  foreach (char C in Path.GetInvalidPathChars())
87  {
88  HostAppFilename = HostAppFilename.Replace("" + C, "");
89  }
90  HostAppFilename = "GlobalConfig_{0}".Build(HostAppFilename);
91 
92  //Check config dir for global config file
93  FileInfo F = new FileInfo(Path.Combine(new FileInfo(Assembly.GetExecutingAssembly().Location).Directory.FullName, "config", HostAppFilename+".xml"));
94  if (!F.Exists)
95  {
96  //Check if a shortcut to the config dir exists
97  FileInfo LnkFile = new FileInfo(Path.Combine(new FileInfo(Assembly.GetExecutingAssembly().Location).Directory.FullName, "config", HostAppFilename + ".lnk"));
98  if (LnkFile.Exists)
99  {
100  string ConfigDirPath = ResolveShortcut(LnkFile);
101  if (Directory.Exists(ConfigDirPath))
102  {
103  F = new FileInfo(Path.Combine(ConfigDirPath, HostAppFilename+".xml"));
104  }
105  }
106 
107  }
108 
109  Pinball = new Pinball();
110  Pinball.Init(F.FullName,TableFilename,GameName );
111 
112  }
113 
114 
115  private string ResolveShortcut(FileInfo ShortcutFile)
116  {
117  string TargetPath = "";
118  try
119  {
120  Type WScriptShell = Type.GetTypeFromProgID("WScript.Shell");
121  object Shell = Activator.CreateInstance(WScriptShell);
122  object Shortcut = WScriptShell.InvokeMember("CreateShortcut", BindingFlags.InvokeMethod, null, Shell, new object[] { ShortcutFile.FullName });
123  TargetPath = (string)Shortcut.GetType().InvokeMember("TargetPath", BindingFlags.GetProperty, null, Shortcut, null);
124  Shortcut = null;
125  Shell = null;
126  }
127  catch
128  {
129 
130  }
131 
132  try
133  {
134  if (Directory.Exists(TargetPath))
135  {
136  return TargetPath;
137  }
138  else if (File.Exists(TargetPath))
139  {
140  return TargetPath;
141  }
142  else
143  {
144  return "";
145  }
146 
147  }
148  catch
149  {
150  return "";
151  }
152  }
153 
154  #endregion
155 
156  #region IDirectPluginFrontend Member
157 
158  public void PluginShowFrontend(Form Owner = null)
159  {
160  try
161  {
162  DirectOutput.Frontend.MainMenu.Open(Pinball);
163 
164  }
165  catch (Exception E)
166  {
167 
168  System.Windows.Forms.MessageBox.Show("Could not show DirectOutput frontend.\n The following exception occured:\n{0}".Build(E.Message), "DirectOutput");
169  }
170  }
171 
172  #endregion
173 
174  #region Properties
175 
176 
177 
178  private Pinball _Pinball = new Pinball();
179 
186  public Pinball Pinball
187  {
188  get { return _Pinball; }
189  set { _Pinball = value; }
190  }
191 
192  #endregion
193 
194 
195 
196 
197 
202  {
203 
204 
205  }
206 
207 
208 
209 
210 
211 
212 
213 
214 
215 
216 
217 
218 
219  }
220 }