public static Task <bool> UpgradeServerAsync(string steamCmdFile, string steamCmdArgs, string serverInstallDirectory, DataReceivedEventHandler outputHandler, CancellationToken cancellationToken, ProcessWindowStyle windowStyle = ProcessWindowStyle.Normal)
        {
            Directory.CreateDirectory(serverInstallDirectory);

            return(ProcessUtils.RunProcessAsync(steamCmdFile, steamCmdArgs, string.Empty, outputHandler, cancellationToken, windowStyle));
        }
        private static ServerProcessStatus GetServerProcessStatus(ServerStatusUpdateRegistration updateContext, out Process serverProcess)
        {
            serverProcess = null;
            if (String.IsNullOrWhiteSpace(updateContext.InstallDirectory))
            {
                return(ServerProcessStatus.NotInstalled);
            }

            var serverExePath = Path.Combine(updateContext.InstallDirectory, Config.Default.ServerBinaryRelativePath, Config.Default.ServerExe);

            if (!File.Exists(serverExePath))
            {
                return(ServerProcessStatus.NotInstalled);
            }

            //
            // The server appears to be installed, now determine if it is running or stopped.
            //
            try
            {
                foreach (var process in Process.GetProcessesByName(Config.Default.ServerProcessName))
                {
                    var commandLine = ProcessUtils.GetCommandLineForProcess(process.Id)?.ToLower();

                    if (commandLine != null && commandLine.Contains(updateContext.InstallDirectory.ToLower()) && commandLine.Contains(Config.Default.ServerExe.ToLower()))
                    {
                        // Does this match our server exe and port?
                        var serverArgMatch = String.Format(Config.Default.ServerCommandLineArgsMatchFormat, updateContext.LocalEndpoint.Port).ToLower();
                        if (commandLine.Contains(serverArgMatch))
                        {
                            // Was an IP set on it?
                            var anyIpArgMatch = String.Format(Config.Default.ServerCommandLineArgsIPMatchFormat, String.Empty).ToLower();
                            if (commandLine.Contains(anyIpArgMatch))
                            {
                                // If we have a specific IP, check for it.
                                var ipArgMatch = String.Format(Config.Default.ServerCommandLineArgsIPMatchFormat, updateContext.LocalEndpoint.Address.ToString()).ToLower();
                                if (!commandLine.Contains(ipArgMatch))
                                {
                                    // Specific IP set didn't match
                                    continue;
                                }

                                // Specific IP matched
                            }

                            // Either specific IP matched or no specific IP was set and we will claim this is ours.

                            process.EnableRaisingEvents = true;
                            if (process.HasExited)
                            {
                                return(ServerProcessStatus.Stopped);
                            }

                            serverProcess = process;
                            return(ServerProcessStatus.Running);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Debug("Exception while checking process status: {0}\n{1}", ex.Message, ex.StackTrace);
            }

            return(ServerProcessStatus.Stopped);
        }
 public static Task <bool> UpgradeModsAsync(string steamCmdFile, string steamCmdArgs, DataReceivedEventHandler outputHandler, CancellationToken cancellationToken, ProcessWindowStyle windowStyle = ProcessWindowStyle.Normal)
 {
     return(ProcessUtils.RunProcessAsync(steamCmdFile, steamCmdArgs, string.Empty, outputHandler, cancellationToken, windowStyle));
 }