コード例 #1
0
 private void InstallSteam()
 {
     if (string.IsNullOrEmpty(ISteamDirBox.Text))
     {
         Instance.IMessageDialog.IsOpen   = true;
         Instance.IMessageDialogText.Text = "Please make sure you have set a valid path for SteamCMD.";
     }
     else if (!File.Exists(Properties.Options.Default.steamCMDPath + "\\steamcmd.exe"))
     {
         IMessageDialog.IsOpen = true;
         BlurEffect bme = new BlurEffect();
         MainGrid.Effect         = bme;
         IMessageDialogText.Text = "Steam CMD will now download and start the install process. If prompted please enter your Steam Guard " +
                                   "Code.\n\nYou will receive this by email from steam. When this is all complete type \'quit\' to finish.";
         ISteamOutputBox.Document.Blocks.Clear();
         ISteamOutputBox.AppendText("Installing SteamCMD");
         ISteamOutputBox.AppendText("\nFile Downloading...");
         const string url      = "https://steamcdn-a.akamaihd.net/client/installer/steamcmd.zip";
         string       fileName = Properties.Options.Default.steamCMDPath + "\\steamcmd.zip";
         if (!Directory.Exists(Properties.Options.Default.steamCMDPath))
         {
             Directory.CreateDirectory(Properties.Options.Default.steamCMDPath);
         }
         WebClient client = new WebClient();
         client.DownloadFileCompleted += SteamDownloadCompleted;
         client.DownloadFileAsync(new Uri(url), fileName);
     }
     else
     {
         Instance.IMessageDialog.IsOpen = true;
         BlurEffect bme = new BlurEffect();
         MainGrid.Effect = bme;
         Instance.IMessageDialogText.Text = "SteamCMD already appears to be installed.\n\nPlease delete all files in the selected folder to reinstall.";
     }
 }
コード例 #2
0
        private void SteamDownloadCompleted(object sender, AsyncCompletedEventArgs e)
        {
            ISteamOutputBox.AppendText(Environment.NewLine + "Download Finished");

            var    steamPath = Properties.Options.Default.steamCMDPath;
            string zip       = steamPath + "\\steamcmd.zip";

            ISteamOutputBox.AppendText("\nUnzipping...");
            ZipFile.ExtractToDirectory(zip, steamPath);
            ISteamOutputBox.AppendText("\nInstalling...");
            RunSteamCommand(steamPath + "\\steamcmd.exe", "+login anonymous +quit", "install");

            File.Delete(zip);
        }
コード例 #3
0
        //private void ProcessOutputCharacters(StreamReader streamReader)
        //{
        //    int    outputCharInt;
        //    char   outputChar;
        //    string line = String.Empty;

        //    while (!streamReader.EndOfStream)
        //    {
        //        outputCharInt = streamReader.Read();
        //        if ((outputCharInt != -1))
        //        {
        //            outputChar = ((char)(outputCharInt));
        //            if (((outputCharInt == 10)
        //              || (outputCharInt == 13)))
        //            {
        //                if (!string.IsNullOrEmpty(line))
        //                {
        //                    if (!line.Contains("\\src\\common\\contentmanifest.cpp (650) : Assertion Failed: !m_bIsFinalized*"))
        //                    { UpdateTextBox(line); }
        //                }
        //                line = String.Empty;
        //            }
        //            else if ((line.Length > 7))
        //            {
        //                if ((line.Substring((line.Length - 3)) == " .."))
        //                {
        //                    line = (Environment.NewLine + line);
        //                    UpdateTextBox(line);
        //                    line = String.Empty;
        //                }
        //                else if ((line.Substring((line.Length - 6)) == "bytes)"))
        //                {
        //                    line = (Environment.NewLine + line);
        //                    UpdateTextBox(line);
        //                    line = String.Empty;
        //                }
        //                else
        //                {
        //                    line = (line + outputChar);
        //                }
        //            }
        //            else
        //            {
        //                line = (line + outputChar);
        //            }
        //        }
        //    }
        //}

        public async void RunSteamCommand(string steamCmd, string steamCommand, string type, List <string> modIds = null)
        {
            if (ReadyToUpdate())
            {
                _oProcess = new Process();
                ISteamProgressBar.Value      = 0;
                ISteamCancelButton.IsEnabled = true;
                ISteamUpdateButton.IsEnabled = false;
                IMainMenuItems.SelectedItem  = null;

                var controls   = FindVisualChildren <Control>(ISteamModsTab);
                var enumerable = controls.ToList();
                foreach (Control control in enumerable)
                {
                    control.IsEnabled = false;
                }

                IMainContent.SelectedItem = ISteamUpdaterTab;
                var tasks = new List <Task>();

                ISteamProgressBar.IsIndeterminate = true;

                switch (type)
                {
                case "addon":
                    ISteamOutputBox.Document.Blocks.Clear();
                    ISteamOutputBox.AppendText("Starting SteamCMD to update Addon" + Environment.NewLine + Environment.NewLine);
                    break;

                case "server:":
                    ISteamOutputBox.Document.Blocks.Clear();
                    ISteamOutputBox.AppendText("Starting SteamCMD to update Server" + Environment.NewLine);
                    break;

                case "install":
                    ISteamOutputBox.AppendText("Proceeding with install" + Environment.NewLine);
                    break;
                }

                tasks.Add(Task.Run(() =>
                {
                    _oProcess.StartInfo.FileName               = steamCmd;
                    _oProcess.StartInfo.Arguments              = steamCommand;
                    _oProcess.StartInfo.UseShellExecute        = false;
                    _oProcess.StartInfo.WindowStyle            = ProcessWindowStyle.Hidden;
                    _oProcess.StartInfo.CreateNoWindow         = true;
                    _oProcess.StartInfo.RedirectStandardOutput = true;
                    _oProcess.StartInfo.RedirectStandardError  = true;
                    _oProcess.StartInfo.RedirectStandardInput  = true;
                    _oProcess.EnableRaisingEvents              = true;

                    //Not realtime for some reason
                    //_oProcess.OutputDataReceived += ProcessOutputEvent;
                    //_oProcess.ErrorDataReceived += ProcessOutputEvent;

                    _oProcess.Start();

                    //NOTES
                    // SteamCMD's behaviour is quite odd. It seems like it does not keep on writing new lines but is almost constantly editing lines
                    // Editing lines does not trigger the OutputDataReceived event and nor does the Input header
                    // (When asking for user input, the programmer can add a header specifying what to enter and it is not picked by the event until the user entered its text)

                    ProcessOutputCharacters(_oProcess.StandardError);
                    ProcessOutputCharacters(_oProcess.StandardOutput);

                    //TO USE WITH _oProcess.DataReceived ONLY
                    //_oProcess.BeginErrorReadLine();
                    //_oProcess.BeginOutputReadLine();

                    _oProcess.WaitForExit();
                }));

                await Task.WhenAll(tasks);

                if (_cancelled)
                {
                    _cancelled = false;
                    ISteamProgressBar.IsIndeterminate = false;
                    ISteamProgressBar.Value           = 0;

                    ISteamOutputBox.Document.Blocks.Clear();
                    ISteamOutputBox.AppendText("Process Canceled");

                    _oProcess.Close();
                    _oProcess = null;
                    CheckModUpdatesComplete(modIds);
                }
                else
                {
                    ISteamOutputBox.AppendText("SteamCMD Exited" + Environment.NewLine);
                    ISteamOutputBox.ScrollToEnd();
                    ISteamProgressBar.IsIndeterminate = false;
                    ISteamProgressBar.Value           = 100;
                    BlurEffect bme = new BlurEffect();
                    switch (type)
                    {
                    case "addon":
                        CheckModUpdatesComplete(modIds);
                        break;

                    case "server:":
                        Instance.IMessageDialog.IsOpen = true;
                        MainGrid.Effect = bme;
                        Instance.IMessageDialogText.Text = "Server Installed/ Updated.";
                        break;

                    case "install":
                        Instance.IMessageDialog.IsOpen = true;
                        MainGrid.Effect = bme;
                        Instance.IMessageDialogText.Text = "SteamCMD Installed.";
                        break;
                    }
                }
                ISteamCancelButton.IsEnabled = false;
                ISteamUpdateButton.IsEnabled = true;

                foreach (Control control in enumerable)
                {
                    control.IsEnabled = true;
                }
            }
            else
            {
                IMessageDialog.IsOpen = true;
                BlurEffect bme = new BlurEffect();
                MainGrid.Effect         = bme;
                IMessageDialogText.Text = "Please check that SteamCMD is installed and that all fields are correct: \n\n\n"
                                          + "   -  Steam Dir\n\n"
                                          + "   -  User Name & Pass\n\n"
                                          + "   -  Server Dir";
            }
        }
コード例 #4
0
        private void UpdateTextBox(string text)
        {
            if (_oProcess != null)
            {
                Dispatcher?.Invoke(() =>
                {
                    ISteamOutputBox.AppendText(text + "\n");
                    ISteamOutputBox.ScrollToEnd();
                });

                if (text.StartsWith("Logging in user") && text.Contains("to Steam"))
                {
                    _runLog = true;
                    Thread t = new Thread(() =>
                    {
                        threadSlept = 0;
                        bool _localRunThread;
                        do
                        {
                            Thread.Sleep(500);
                            threadSlept += 500;
                            lock (_runLogLock)
                            { _localRunThread = _runLog; }
                        }while (_localRunThread && threadSlept < 10000);
                        if (_localRunThread)
                        {
                            Dispatcher?.Invoke(() =>
                            {
                                ISteamGuardDialog.IsOpen = true;
                                BlurEffect bme           = new BlurEffect();
                                MainGrid.Effect          = bme;
                            });
                        }
                    });
                    t.Start();
                }

                if (text.Contains("Logged in OK"))
                {
                    lock (_runLogLock)
                    { _runLog = false; }
                }

                if (text.StartsWith("Retrying..."))
                {
                    threadSlept = 0;
                }

                if (text.EndsWith("..."))
                {
                    Dispatcher?.Invoke(() =>
                    {
                        ISteamOutputBox.AppendText(Environment.NewLine);
                    });
                }

                if (text.Contains("Two-factor code"))
                {
                    Dispatcher?.Invoke(() =>
                    {
                        ISteamGuardDialog.IsOpen = true;
                        BlurEffect bme           = new BlurEffect();
                        MainGrid.Effect          = bme;
                    });
                }

                if (text.Contains("Update state"))
                {
                    int    counter  = text.IndexOf(":", StringComparison.Ordinal);
                    string progress = text.Substring(counter + 2, 2);
                    int    progressValue;
                    if (progress.Contains("."))
                    {
                        int.TryParse(progress.Substring(0, 1), out progressValue);
                    }
                    else
                    {
                        int.TryParse(progress, out progressValue);
                    }

                    Dispatcher?.Invoke(() =>
                    {
                        ISteamProgressBar.IsIndeterminate = false;
                        ISteamProgressBar.Value           = progressValue;
                    });
                }

                if (text.Contains("Success"))
                {
                    Dispatcher?.Invoke(() =>
                    {
                        ISteamProgressBar.Value = 100;
                    });
                }

                if (text.Contains("Timeout"))
                {
                    Dispatcher?.Invoke(() =>
                    {
                        Instance.IMessageDialog.IsOpen = true;
                        BlurEffect bme  = new BlurEffect();
                        MainGrid.Effect = bme;
                        Instance.IMessageDialogText.Text = "A Steam Download timed out. You may have to download again when task is complete.";
                    });
                }
            }
        }
コード例 #5
0
        public async Task RunSteamCommand(string steamCmd, string steamCommand, string type, List <string> modIds = null, bool localLaunch = false)
        {
            if (ReadyToUpdate())
            {
                _oProcess = new Process();
                ISteamProgressBar.Value      = 0;
                ISteamCancelButton.IsEnabled = true;
                ISteamUpdateButton.IsEnabled = false;

                if (!localLaunch)
                {
                    MainWindow.Instance.NavEnabled = false;
                    MainWindow.Instance?.NavigateToConsole();
                }

                var tasks = new List <Task>();

                ISteamProgressBar.IsIndeterminate = true;

                switch (type)
                {
                case "addon":
                    ISteamOutputBox.Document.Blocks.Clear();
                    ISteamOutputBox.AppendText("Starting SteamCMD to update Addon" + Environment.NewLine + Environment.NewLine);
                    break;

                case "server:":
                    ISteamOutputBox.Document.Blocks.Clear();
                    ISteamOutputBox.AppendText("Starting SteamCMD to update Server" + Environment.NewLine);
                    break;

                case "install":
                    ISteamOutputBox.AppendText("Proceeding with install" + Environment.NewLine);
                    break;
                }

                tasks.Add(Task.Run(() =>
                {
                    _oProcess.StartInfo.FileName               = steamCmd;
                    _oProcess.StartInfo.Arguments              = steamCommand;
                    _oProcess.StartInfo.UseShellExecute        = false;
                    _oProcess.StartInfo.WindowStyle            = ProcessWindowStyle.Hidden;
                    _oProcess.StartInfo.CreateNoWindow         = true;
                    _oProcess.StartInfo.RedirectStandardOutput = true;
                    _oProcess.StartInfo.RedirectStandardError  = true;
                    _oProcess.StartInfo.RedirectStandardInput  = true;
                    _oProcess.EnableRaisingEvents              = true;

                    _oProcess.Start();

                    //NOTES
                    // SteamCMD's behaviour is quite odd. It seems like it does not keep on writing new lines but is almost constantly editing lines
                    // Editing lines does not trigger the OutputDataReceived event and nor does the Input header
                    // (When asking for user input, the programmer can add a header specifying what to enter and it is not picked by the event until the user entered its text)

                    ProcessOutputCharacters(_oProcess.StandardError);
                    ProcessOutputCharacters(_oProcess.StandardOutput);

                    _oProcess.WaitForExit();
                }));

                await Task.WhenAll(tasks);

                if (_cancelled)
                {
                    _cancelled = false;
                    ISteamProgressBar.IsIndeterminate = false;
                    ISteamProgressBar.Value           = 0;

                    ISteamOutputBox.Document.Blocks.Clear();
                    ISteamOutputBox.AppendText("Process Canceled");

                    _oProcess.Close();
                    _oProcess = null;
                    CheckModUpdatesComplete(modIds);
                }
                else
                {
                    ISteamOutputBox.AppendText("SteamCMD Exited" + Environment.NewLine);
                    ISteamOutputBox.ScrollToEnd();
                    ISteamProgressBar.IsIndeterminate = false;
                    ISteamProgressBar.Value           = 100;
                    switch (type)
                    {
                    case "addon":
                        CheckModUpdatesComplete(modIds);
                        break;

                    case "server:":
                        MetroWindow.DisplayMessage("Server Installed/ Updated.");
                        break;

                    case "install":
                        MetroWindow.DisplayMessage("SteamCMD Installed.");
                        break;
                    }
                }
                ISteamCancelButton.IsEnabled = false;
                ISteamUpdateButton.IsEnabled = true;

                if (!localLaunch)
                {
                    MainWindow.Instance.NavEnabled = true;
                }
            }
            else
            {
                MainWindow.Instance?.DisplayMessage("Please check that SteamCMD is installed and that all fields are correct: \n\n\n"
                                                    + "   -  Steam Dir\n\n"
                                                    + "   -  User Name & Pass\n\n"
                                                    + "   -  Server Dir");
            }
        }