Пример #1
0
 public static ProcessOutput Run(string executable, string args, string dir, EventHandler onExit, bool runAsAdmin, bool shellExec)
 {
     System.Diagnostics.Process proc = new System.Diagnostics.Process();
     ProcessOutput output = new ProcessOutput { proc = proc };
     if (onExit != null)
         proc.Exited += onExit;
     if (runAsAdmin)
     {
         proc.StartInfo.UseShellExecute = true;
         proc.StartInfo.Verb = "runas";
     }
     else if (shellExec)
     {
         proc.StartInfo.UseShellExecute = true;
     }
     else
     {
         proc.StartInfo.UseShellExecute = false;
         proc.StartInfo.RedirectStandardError = true;
         proc.StartInfo.RedirectStandardOutput = true;
         proc.OutputDataReceived += new DataReceivedEventHandler(output.OnOutput);
         proc.ErrorDataReceived += new DataReceivedEventHandler(output.OnError);
     }
     proc.StartInfo.FileName = executable;
     proc.StartInfo.Arguments = args;
     proc.StartInfo.CreateNoWindow = true;
     proc.StartInfo.WorkingDirectory = dir;
     proc.EnableRaisingEvents = true;
     proc.Start();
     if (!runAsAdmin && !shellExec)
     {
         proc.BeginOutputReadLine();
         proc.BeginErrorReadLine();
     }
     return output;
 }
Пример #2
0
        private void LaunchGame(bool joinServer)
        {
            try
            {
                if (m_isInstallValid == false)
                {
                    MessageBoxResult r = MessageBox.Show("Install is not complete, launch anyway?", "Install not validated", MessageBoxButton.OKCancel);
                    if (r == MessageBoxResult.Cancel)
                        return;
                }
                if (m_game != null)
                    m_game.Kill();
                m_game = null;
                string dir = Path.GetFullPath(m_installPath_Arma2OA);
                string a2path = Path.GetFullPath(m_installPath_Arma2);
                string exe = Path.GetFullPath(Path.Combine(dir, "./Expansion/beta/ARMA2OA.exe"));
                string args = String.Format(
                    "\"-mod={0};EXPANSION;ca\" " +
                    "\"-beta=Expansion\\beta;Expansion\\beta\\Expansion;\" " +
                    "-mod=@DayZRP -nosplash -nopause -skipIntro -world=Chernarus ",
                    a2path);
                EventHandler onExit = (EventHandler)delegate(object a, EventArgs b)
                {
                    Dispatcher.BeginInvoke((Action)delegate
                    {
                        OnGameExit();
                    });
                };

                if (joinServer)
                {
                    int i = 0;
                    foreach (var server in m_servers)
                    {
                        if (i != m_serverListBox.SelectedIndex)
                        {
                            ++i;
                            continue;
                        }
                        args += " -connect=" + server.Value.Settings.Host + " -port=" + server.Value.Settings.RemotePort;
                        break;
                    }
                }

                if (m_steamTickBox.IsChecked == true)
                {
                    string steamExe = ReadRegString("Valve\\Steam", "SteamExe");
                    if (steamExe != null)
                    {
                        exe = steamExe;
                        args = "-applaunch 219540 " + args;
                    }
                    else
                        MessageBox.Show("Could not locate Steam installation");
                }

                if (!String.IsNullOrEmpty(m_launchCommands.Text))
                    args = args + " " + m_launchCommands.Text;

                m_game = ProcessOutput.Run(exe, args, dir, onExit, false, false);
                if (m_game != null && !m_game.Finished)
                {
                    m_taskStatus.Content = "Game is running...";
                    m_btnLaunch1.IsEnabled = false;
                    m_btnLaunch2.IsEnabled = false;
                }
                else
                    m_taskStatus.Content = "Error launching game.";
            }
            catch (System.Exception ex)
            {
                MessageBox.Show("Please report this error: " + ex.ToString());
            }
        }