#region Copyright & License Information /* * Copyright 2007-2011 The OpenRA Developers (see AUTHORS) * This file is part of OpenRA, which is free software. It is made * available to you under the terms of the GNU General Public License * as published by the Free Software Foundation. For more information, * see COPYING. */ #endregion using System; using System.Diagnostics; namespace OpenRA { public class Utilities { readonly string Utility; public Utilities(string utility) { Utility = utility; } public void PromptFilepathAsync(string title, Action withPath) { ExecuteUtility("--display-filepicker \"{0}\"".F(title), withPath); } void ExecuteUtility(string args, Action onComplete) { try { Process p = new Process(); p.StartInfo.FileName = Utility; p.StartInfo.Arguments = args; p.StartInfo.CreateNoWindow = true; p.StartInfo.UseShellExecute = false; p.StartInfo.RedirectStandardOutput = true; p.EnableRaisingEvents = true; p.Exited += (_,e) => { onComplete(p.StandardOutput.ReadToEnd().Trim()); }; p.Start(); } catch(System.ComponentModel.Win32Exception) {} // Don't crash if the process fails } } }