8 using System.Reflection;
10 namespace DirectOutput
15 public static class DirectOutputHandler
22 public static string GetVersion()
24 return System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
41 public static void DataReceive(
string TableElementTypeChar,
int Number,
int Value)
46 C = TableElementTypeChar[0];
51 throw new Exception(
"Could not extract the first char of the TableElementTypeChar parameter", E);
55 Pinball.ReceiveData(C, Number, Value);
61 throw new Exception(
"You must call Init before passing data to the DirectOutput framework");
65 throw new Exception(
"A exception occured when passing in data (TableElementTypeChar: {0}, Number: {1}, Value: {2})".Build(C, Number, Value), E);
75 public static void Finish()
94 public static void Init(
string HostingApplicationName,
string TableFilename,
string RomName)
100 string HostAppFilename = HostingApplicationName.Replace(
".",
"");
102 foreach (
char C
in Path.GetInvalidFileNameChars())
104 HostAppFilename = HostAppFilename.Replace(C.ToString(),
"");
107 foreach (
char C
in Path.GetInvalidPathChars())
109 HostAppFilename = HostAppFilename.Replace(C.ToString(),
"");
113 HostAppFilename =
"GlobalConfig_{0}".Build(HostAppFilename);
116 FileInfo F =
new FileInfo(Path.Combine(
new FileInfo(Assembly.GetExecutingAssembly().Location).Directory.FullName,
"config",
"GlobalConfig_{0}.xml".Build(HostAppFilename)));
120 FileInfo LnkFile =
new FileInfo(Path.Combine(
new FileInfo(Assembly.GetExecutingAssembly().Location).Directory.FullName,
"config",
"GlobalConfig_{0}.lnk".Build(HostAppFilename)));
123 string ConfigDirPath = ResolveShortcut(LnkFile);
124 if (Directory.Exists(ConfigDirPath))
126 F =
new FileInfo(Path.Combine(ConfigDirPath,
"GlobalConfig_{0}.xml".Build(HostAppFilename)));
133 F =
new FileInfo(
"GlobalConfig_{0}.xml".Build(HostAppFilename));
137 F =
new FileInfo(Path.Combine(
new FileInfo(Assembly.GetExecutingAssembly().Location).Directory.FullName,
"GlobalConfig_{0}.xml".Build(HostAppFilename)));
141 F =
new FileInfo(Path.Combine(
new FileInfo(Assembly.GetExecutingAssembly().Location).Directory.FullName,
"config",
"GlobalConfig_{0}.xml".Build(HostAppFilename)));
142 if (!F.Directory.Exists)
145 F =
new FileInfo(Path.Combine(
new FileInfo(Assembly.GetExecutingAssembly().Location).Directory.FullName,
"GlobalConfig_{0}.xml".Build(HostAppFilename)));
153 Pinball =
new DirectOutput.Pinball();
154 Pinball.Init((F.Exists ? F.FullName :
""), TableFilename, RomName);
158 throw new Exception(
"Object has already been initialized. You must call Finish() before initializing again.");
167 public static void ShowFrontend()
173 DirectOutput.Frontend.MainMenu.Open(Pinball);
177 System.Windows.Forms.MessageBox.Show(
"Could not show DirectOutput frontend.\n The following exception occured:\n{0}".Build(E.Message),
"DirectOutput");
183 throw new Exception(
"Init has to be called before the frontend is opend.");
190 private static string ResolveShortcut(FileInfo ShortcutFile)
192 string TargetPath =
"";
195 Type WScriptShell = Type.GetTypeFromProgID(
"WScript.Shell");
196 object Shell = Activator.CreateInstance(WScriptShell);
197 object Shortcut = WScriptShell.InvokeMember(
"CreateShortcut", BindingFlags.InvokeMethod, null, Shell,
new object[] { ShortcutFile.FullName });
198 TargetPath = (string)Shortcut.GetType().InvokeMember(
"TargetPath", BindingFlags.GetProperty, null, Shortcut, null);
209 if (Directory.Exists(TargetPath))
213 else if (File.Exists(TargetPath))
233 private static Pinball _Pinball;
241 public static Pinball Pinball
243 get {
return _Pinball; }
244 private set { _Pinball = value; }