public static Process StartFwApp(string appName, params string[] rgArgs)
{
StringBuilder bldr = new StringBuilder("-" + FwAppArgs.kApp);
bldr.Append(" " + appName);
if (rgArgs.Length == 1 && !rgArgs[0].StartsWith("-"))
{
// Assume that the user wants that argument to be the project name
bldr.Append(" -" + FwAppArgs.kProject);
}
foreach (string arg in rgArgs)
{
bldr.Append(" ");
bool fAddQuotes = (arg.IndexOf(' ') >= 0); // add quotes around parameters with spaces
if (fAddQuotes)
bldr.Append("\"");
bldr.Append(arg);
if (fAddQuotes)
bldr.Append("\"");
}
try
{
string codeBaseUri = Assembly.GetExecutingAssembly().CodeBase;
string path = FileUtils.StripFilePrefix(codeBaseUri);
ProcessStartInfo startInfo = new ProcessStartInfo(path, bldr.ToString());
startInfo.UseShellExecute = false;
startInfo.WorkingDirectory = Path.GetDirectoryName(path) ?? string.Empty;
return Process.Start(startInfo);
}
catch (Exception exception)
{
// I (TomH) would rather know about the exception than silently failing. so show exception on Mono least.
#if DEBUG && __MonoCS__
MessageBox.Show(exception.ToString());
#endif
}
// Something went very wrong :(
return null;
}