Ejemplo n.º 1
0
        private async void compileTrinityCoreButton_Click(object sender, EventArgs e)
        {
            if (platformComboBox.SelectedIndex == -1)
            {
                MessageBoxEx.Show(this, "A platform must be selected!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

                return;
            }

            if (string.IsNullOrEmpty(Settings.Default.TrunkLocation))
            {
                MessageBoxEx.Show(this, "You must first set the trunk location for TrinityCore!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

                return;
            }

            if (_isCloning)
            {
                MessageBoxEx.Show(this, "Cloning in progress. Please wait until this has finished!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

                return;
            }

            if (_isCompiling)
            {
                if (_compilerCTS != null)
                {
                    _compilerCTS.Cancel();
                }

                compileProgressBar.Visible    = false;
                compileTrinityCoreButton.Text = "Compile && Replace TC";

                return;
            }

            bool x64 = platformComboBox.SelectedIndex == 1;

            _compilerCTS = new CancellationTokenSource();

            var progress = new Progress <string>(prog => Invoke((MethodInvoker) delegate
            {
                outputTextBox.AppendText(prog + Environment.NewLine);
            }));

            outputTextBox.Text = String.Empty;

            compileProgressBar.Visible      = true;
            compileProgressBar.ProgressType = eProgressItemType.Marquee;

            _isCompiling = true;

            compileTrinityCoreButton.Text = "Cancel Compile";
            consoleTabControl.SelectedTab = outputTabItem;

            string temp = FileHelper.GenerateTempDirectory();

            await CMake.Generate(Settings.Default.TrunkLocation, temp, x64, progress, _compilerCTS.Token).ContinueWith(task1 =>
            {
                if (task1.Result)
                {
                    _compilerCTS = new CancellationTokenSource();

                    TCCompiler.Compile(temp, x64, progress, _compilerCTS.Token).ContinueWith(task2 =>
                    {
                        _isCompiling = false;

                        if (task2.Result)
                        {
                            FileHelper.CopyDirectory(Path.Combine(temp, "bin", "Release"), Settings.Default.ServerFolder);
                        }

                        Invoke((MethodInvoker) delegate
                        {
                            compileProgressBar.Visible    = false;
                            compileTrinityCoreButton.Text = "Compile && Replace TC";


                            try
                            {
                                FileHelper.DeleteDirectory(temp);
                            }
                            catch (Exception)
                            {
                                MessageBoxEx.Show(this, "Error while trying to delete the temporary directory!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }

                            if (!task2.Result)
                            {
                                MessageBoxEx.Show(this, "An error has occurred while trying to compile TrinityCore!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                        });
                    });
                }
                else
                {
                    _isCompiling = false;

                    Invoke((MethodInvoker) delegate
                    {
                        compileProgressBar.Visible    = false;
                        compileTrinityCoreButton.Text = "Compile && Replace Trinity Core";

                        MessageBoxEx.Show(this, "Error while executing CMake!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

                        try
                        {
                            FileHelper.DeleteDirectory(temp);
                        }
                        catch (Exception)
                        {
                            MessageBoxEx.Show(this, "Error while trying to delete the temporary directory!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    });
                }
            });
        }
Ejemplo n.º 2
0
        private async void Compile()
        {
            if (String.IsNullOrEmpty(Settings.Default.TrunkLocation))
            {
                if (_messageService.Show("You must first set your trunk location! Want to do this right now?", "Trunk location not set!", MessageButton.YesNo, MessageImage.Question) == MessageResult.Yes)
                {
                    SetTrunkLocation();
                }

                return;
            }

            if (_isCloning)
            {
                _messageService.ShowError("Cloning in progress. Please wait until this has finished!");

                return;
            }

            if (_isCompiling)
            {
                if (_compilerCts != null)
                {
                    _compilerCts.Cancel();
                }

                _messageService.ShowError("Compiling has been aborted!");

                return;
            }

            if (Busy)
            {
                _messageService.ShowError("TrinityCore Manager is currently busy. Please wait.");

                return;
            }

            bool x64 = CompilePlatform.Equals("x64", StringComparison.OrdinalIgnoreCase);

            if (x64 && !Environment.Is64BitOperatingSystem)
            {
                _messageService.ShowError("Your operating system is not 64 bit!");

                return;
            }

            _compilerCts = new CancellationTokenSource();

            OutputText = String.Empty;

            var progress = new Progress <string>(prog => _dispatcherService.BeginInvoke(() =>
            {
                OutputText += prog + Environment.NewLine;
            }));

            Busy = true;
            BusyIndeterminate = true;

            _isCompiling = true;

            string temp = FileHelper.GenerateTempDirectory();

            bool result = await CMake.Generate(Settings.Default.TrunkLocation, temp, x64, progress, _compilerCts.Token);


            if (result)
            {
                _compilerCts = new CancellationTokenSource();

                result = await TCCompiler.Compile(temp, x64, progress, _compilerCts.Token);

                if (result)
                {
                    FileHelper.CopyDirectory(Path.Combine(temp, "bin", "Release"), Settings.Default.ServerFolder);
                }
                else
                {
                    _messageService.ShowError("Compile has failed!");
                }

                FileHelper.DeleteDirectory(temp);
            }
            else
            {
                _messageService.ShowError("Compile has failed!");
            }

            Busy = false;
            BusyIndeterminate = false;

            _isCompiling = false;
        }