private void OnBuildFinished(bool bBuildSucess)
        {
            if (bBuildSucess)
            {
                if (postBuildSettings.CanSaveToZip())
                {
                    if (FinalBuildPath == null)
                    {
                        FinalBuildPath = Path.GetFullPath(AutomationExePath).Replace(@"\Engine\Binaries\DotNET", @"\LocalBuilds\Engine").Replace(Path.GetFileName(AutomationExePath), "");
                        GameAnalyticsCSharp.LogEvent("Final Build Path was null. Fixed.", GameAnalyticsSDK.Net.EGAErrorSeverity.Info);
                    }
                    AddLogEntry(string.Format("Creating ZIP file. Target Engine Directory is {0}", FinalBuildPath));
                    postBuildSettings.PrepareToSave();
                    postBuildSettings.SaveToZip(this, FinalBuildPath, postBuildSettings.ZipPath.Text);
                    AddLogEntry("Saving zip file to " + postBuildSettings.ZipPath.Text);
                    WriteToLogFile();
                    return;
                }
            }

            WriteToLogFile();
            TryShutdown();
        }
        private void BuildRocketUE_Click(object sender, RoutedEventArgs e)
        {
            bLastBuildSuccess = false;

            if (bIsBuilding)
            {
                GameAnalyticsCSharp.AddDesignEvent("Build:AutomationTool:Killed");
                AutomationToolProcess.Kill();
                return;
            }

            if (FinalBuildPath == null && string.IsNullOrWhiteSpace(AutomationExePath) == false)
            {
                FinalBuildPath = Path.GetFullPath(AutomationExePath).Replace(@"\Engine\Binaries\DotNET", @"\LocalBuilds\Engine").Replace(Path.GetFileName(AutomationExePath), "");
            }

            if (Directory.Exists(FinalBuildPath))
            {
                MessageBoxResult MessageResult = MessageBox.Show($"Looks like an Engine build is already available at {FinalBuildPath}. Would you like to skip compiling the Engine and start zipping the existing build?\n\nPress Yes to Skip Engine build and start zipping (if enabled).\nPress No to continue with Engine Build.\nPress Cancel to do nothing.", "Zip Binary Version", MessageBoxButton.YesNoCancel, MessageBoxImage.Question);
                switch (MessageResult)
                {
                case MessageBoxResult.Yes:
                    GameAnalyticsCSharp.AddDesignEvent("Build:EngineExists:FinishBuild");
                    // We don't want the system to shutdown since user is interacting.
                    bool?bOriginalShutdownState = bShutdownWindows.IsChecked;
                    bShutdownWindows.IsChecked = false;
                    OnBuildFinished(true);
                    bShutdownWindows.IsChecked = bOriginalShutdownState;
                    return;

                case MessageBoxResult.Cancel:
                    GameAnalyticsCSharp.AddDesignEvent("Build:EngineExists:Exit");
                    return;

                default:
                    GameAnalyticsCSharp.AddDesignEvent("Build:EngineExists:IgnoreAndContinue");
                    break;
                }
            }

            if (EngineVersionSelection.SelectedIndex == 0)
            {
                MessageBox.Show("Please select your Engine version to build. If you are unsure about the version number look into the following file:\n\n/Engine/Source/Runtime/Launch/Resources/Version.h\n\nAnd check ENGINE_MAJOR_VERSION and ENGINE_MINOR_VERSION.", "Select Engine Version.", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                return;
            }

            ChangeStatusLabel("Preparing to build...");

            if (postBuildSettings.ShouldSaveToZip() && postBuildSettings.DirectoryIsWritable() == false)
            {
                GameAnalyticsCSharp.AddDesignEvent("Build:ZipEnabled:InvalidSetting");
                MessageBox.Show(string.Format("You chose to save Engine build as a zip file but below directory is either not available or not writable.\n\n{0}", postBuildSettings.ZipPath.Text), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            if (CustomBuildXMLFile.Text != DEFAULT_BUILD_XML_FILE)
            {
                if (CustomBuildXMLFile.Text == string.Empty)
                {
                    GameAnalyticsCSharp.LogEvent("Empty Build XML.", GameAnalyticsSDK.Net.EGAErrorSeverity.Error);
                    ChangeStatusLabel("Error. Empty build xml file.");
                    MessageBox.Show(string.Format("Build XML cannot be empty.\n\nIf you don't have a custom build file, press \"Reset to default\" to use default InstalledEngineBuild.xml", CustomBuildXMLFile.Text), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }

                if (File.Exists(CustomBuildXMLFile.Text) == false)
                {
                    GameAnalyticsCSharp.LogEvent("BuildXML does not exist.", GameAnalyticsSDK.Net.EGAErrorSeverity.Error);
                    ChangeStatusLabel("Error. Build xml does not exist.");
                    MessageBox.Show(string.Format("Build XML {0} does not exist!", CustomBuildXMLFile.Text), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
            }

            if (SupportHTML5() == false && bWithHTML5.IsChecked == true)
            {
                GameAnalyticsCSharp.AddDesignEvent($"Build:HTML5:IncorrectEngine:{GetEngineName()}");
                bWithHTML5.IsChecked = false;
                MessageBox.Show("HTML5 support was removed from Unreal Engine 4.24 and higher. You had it enabled but since it is of no use, I disabled it.");
            }

            if (SupportConsoles() == false && (bWithSwitch.IsChecked == true || bWithPS4.IsChecked == true || bWithXboxOne.IsChecked == true))
            {
                GameAnalyticsCSharp.AddDesignEvent($"Build:Console:IncorrectEngine:{GetEngineName()}");
                bWithSwitch.IsChecked = bWithPS4.IsChecked = bWithXboxOne.IsChecked = false;
                MessageBox.Show("Console support was removed from Unreal Engine 4.25 and higher. You had it enabled but since it is of no use, I disabled it.");
            }

            if (MessageBox.Show("You are going to build a binary version of Unreal Engine 4. This is a long process and might take time to finish. Are you sure you want to continue? ", "Build Binary Version", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
            {
                if (bWithDDC.IsChecked == true)
                {
                    MessageBoxResult MessageResult = MessageBox.Show("Building Derived Data Cache (DDC) is one of the slowest aspect of the build. You can skip this step if you want to. Do you want to continue with DDC enabled?\n\nPress Yes to continue with build\nPress No to continue without DDC\nPress Cancel to stop build", "Warning", MessageBoxButton.YesNoCancel, MessageBoxImage.Warning);

                    switch (MessageResult)
                    {
                    case MessageBoxResult.No:
                        bWithDDC.IsChecked = false;
                        GameAnalyticsCSharp.AddDesignEvent("Build:DDC:AutoDisabled");
                        break;

                    case MessageBoxResult.Cancel:
                        GameAnalyticsCSharp.AddDesignEvent("Build:DDC:Exit");
                        return;

                    default:
                        GameAnalyticsCSharp.AddDesignEvent("Build:DDC:IgnoreAndContinue");
                        break;
                    }
                }

                CompiledFiles = CompiledFilesTotal = 0;
                ProcessedFilesLabel.Content = "[Compiled: 0. Total: 0]";

                LogControl.ClearAllLogs();
                AddLogEntry(string.Format("Welcome to UE4 Binary Builder v{0}", PRODUCT_VERSION));
                BuildRocketUE.Content = "Stop Build";

                string CommandLineArgs = PrepareCommandline();

                ProcessStartInfo AutomationStartInfo = new ProcessStartInfo
                {
                    FileName               = AutomationExePath,
                    Arguments              = CommandLineArgs,
                    UseShellExecute        = false,
                    CreateNoWindow         = true,
                    RedirectStandardError  = true,
                    RedirectStandardOutput = true
                };

                DispatchTimer.Start();
                StopwatchTimer.Start();

                AutomationToolProcess                     = new Process();
                AutomationToolProcess.StartInfo           = AutomationStartInfo;
                AutomationToolProcess.EnableRaisingEvents = true;
                AutomationToolProcess.OutputDataReceived += new DataReceivedEventHandler(AutomationToolProcess_OutputDataReceived);
                AutomationToolProcess.ErrorDataReceived  += new DataReceivedEventHandler(AutomationToolProcess_ErrorDataReceived);
                AutomationToolProcess.Exited             += new EventHandler(AutomationToolProcess_Exited);
                AutomationToolProcess.Start();
                AutomationToolProcess.BeginErrorReadLine();
                AutomationToolProcess.BeginOutputReadLine();

                bIsBuilding = true;
                ChangeStatusLabel("Building...");
                GameAnalyticsCSharp.AddDesignEvent("Build:Started");
            }
        }