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.Setup((F.Exists ? F.FullName :
""), TableFilename, RomName);
159 throw new Exception(
"Object has already been initialized. You must call Finish() before initializing again.");
168 public static void ShowFrontend()
174 DirectOutput.Frontend.MainMenu.Open(Pinball);
178 System.Windows.Forms.MessageBox.Show(
"Could not show DirectOutput frontend.\n The following exception occured:\n{0}".Build(E.Message),
"DirectOutput");
184 throw new Exception(
"Init has to be called before the frontend is opend.");
191 private static string ResolveShortcut(FileInfo ShortcutFile)
193 string TargetPath =
"";
196 Type WScriptShell = Type.GetTypeFromProgID(
"WScript.Shell");
197 object Shell = Activator.CreateInstance(WScriptShell);
198 object Shortcut = WScriptShell.InvokeMember(
"CreateShortcut", BindingFlags.InvokeMethod, null, Shell,
new object[] { ShortcutFile.FullName });
199 TargetPath = (string)Shortcut.GetType().InvokeMember(
"TargetPath", BindingFlags.GetProperty, null, Shortcut, null);
210 if (Directory.Exists(TargetPath))
214 else if (File.Exists(TargetPath))
234 private static Pinball _Pinball;
242 public static Pinball Pinball
244 get {
return _Pinball; }
245 private set { _Pinball = value; }