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 HyperpinPluginInterface;
6 using DirectOutput;
7 
11 namespace DirectOutputHyperpinPlugin
12 {
13 
17  [Export(typeof(IHyperpinPlugin))]
18  public class DirectOutputPlugin : IHyperpinPlugin
19  {
20 
21 
22 
23 
24 
25 
26  #region IHyperpinPlugin Members
27 
35  public string Name
36  {
37  get
38  {
39  Version V = typeof(Pinball).Assembly.GetName().Version;
40  DateTime BuildDate = new DateTime(2000, 1, 1).AddDays(V.Build).AddSeconds(V.Revision * 2);
41  return "DirectOutput (V: {0} as of {1})".Build(V.ToString(), BuildDate.ToString("yyyy.MM.dd HH:mm"));
42  }
43  }
44 
45 
46 
54  public void DataReceive(int Number, int Value)
55  {
56 
57  Pinball.ReceiveData('E', Number, Value);
58 
59  }
60 
61 
62 
63 
69  public void PluginFinish()
70  {
71 
72  Pinball.Finish();
73 
74  }
75 
84  public void PluginInit()
85  {
86 
87  //Check config dir for global config file
88  FileInfo F = new FileInfo(Path.Combine(new FileInfo(Assembly.GetExecutingAssembly().Location).Directory.FullName, "config", "GlobalConfig_Hyperpin.xml"));
89  if (!F.Exists)
90  {
91  //Check if a shortcut to the config dir exists
92  FileInfo LnkFile = new FileInfo(Path.Combine(new FileInfo(Assembly.GetExecutingAssembly().Location).Directory.FullName, "config", "GlobalConfig_Hyperpin.lnk"));
93  if (LnkFile.Exists)
94  {
95  string ConfigDirPath = ResolveShortcut(LnkFile);
96  if (Directory.Exists(ConfigDirPath))
97  {
98  F = new FileInfo(Path.Combine(ConfigDirPath, "GlobalConfig_Hyperpin.xml"));
99  }
100  }
101 
102  }
103 
104  Pinball.Init(F.FullName, Path.Combine(new FileInfo(Assembly.GetExecutingAssembly().Location).Directory.FullName, "config", "Hyperpin.tmp"), "Hyperpin");
105 
106  }
107 
108 
109  private string ResolveShortcut(FileInfo ShortcutFile)
110  {
111  string TargetPath = "";
112  try
113  {
114  Type WScriptShell = Type.GetTypeFromProgID("WScript.Shell");
115  object Shell = Activator.CreateInstance(WScriptShell);
116  object Shortcut = WScriptShell.InvokeMember("CreateShortcut", BindingFlags.InvokeMethod, null, Shell, new object[] { ShortcutFile.FullName });
117  TargetPath = (string)Shortcut.GetType().InvokeMember("TargetPath", BindingFlags.GetProperty, null, Shortcut, null);
118  Shortcut = null;
119  Shell = null;
120  }
121  catch
122  {
123 
124  }
125 
126  try
127  {
128  if (Directory.Exists(TargetPath))
129  {
130  return TargetPath;
131  }
132  else if (File.Exists(TargetPath))
133  {
134  return TargetPath;
135  }
136  else
137  {
138  return "";
139  }
140 
141  }
142  catch
143  {
144  return "";
145  }
146  }
147 
148  #endregion
149 
150  #region Properties
151 
152 
153 
154  private Pinball _Pinball = new Pinball();
155 
162  public Pinball Pinball
163  {
164  get { return _Pinball; }
165  set { _Pinball = value; }
166  }
167 
168  #endregion
169 
170 
171 
172 
173 
178  {
179 
180 
181  }
182 
183 
184 
185 
186 
187 
188 
189 
190 
191 
192 
193  }
194 }