Exemplo n.º 1
0
        public MainForm()
        {
            InitializeComponent();

            settings = Settings.Load();

            ef = new SettingsForm(settings);
            ef.InitializeButtonClick += new InitializeButtonClickEventHandler(EnvironmentForm_InitializeButtonClick);
            crf = null;

            prevChangeTime = DateTime.Now;

            compileProcess = null;
            playProcess    = null;
        }
Exemplo n.º 2
0
        private void compileProcess_OutputDataReceived(object sender, System.Diagnostics.DataReceivedEventArgs e)
        {
            if (compileProcess != null) // Skip when cancelling compilation in MainForm
            {
                if (e.Data != null)
                {
                    compileResultTextList.Add(e.Data);
                }
                else
                {
                    compileProcess.Close();
                    compileProcess = null;

                    BeginInvoke((Action)(() =>
                    {
                        var cr = new CompileResult(compileResultTextList);

                        switch (settings.ResultForm)
                        {
                        case 0:              // Display
                            if (crf == null) // Closed compilation result form
                            {
                                crf = new CompileResultForm();
                                crf.FormClosed += (sender2, e2) => { crf = null; };
                                crf.SetResult(cr);
                                crf.Show();
                            }
                            else
                            {
                                crf.SetResult(cr);
                            }
                            break;

                        case 1:     // Display when compilation failed
                            if (cr.Success)
                            {
                                if (crf != null)
                                {
                                    crf.Close();
                                }
                            }
                            else
                            {
                                if (crf == null)        // Closed compilation result form
                                {
                                    crf = new CompileResultForm();
                                    crf.FormClosed += (sender2, e2) => { crf = null; };
                                    crf.SetResult(cr);
                                    crf.Show();
                                }
                                else
                                {
                                    crf.SetResult(cr);
                                }
                            }
                            break;

                        case 2:     // Hide
                            if (crf != null)
                            {
                                crf.Close();
                            }
                            break;

                        default:
                            break;
                        }

                        if (cr.Success)
                        {
                            toolStripStatusLabel.Text = "Compiled";
                        }
                        else
                        {
                            toolStripStatusLabel.Text = "Compilation failed";
                            if (settings.SoundNotification)
                            {
                                System.Media.SystemSounds.Hand.Play();
                            }
                        }

                        if (cr.Success && settings.AutoPlay)
                        {
                            if (!File.Exists(settings.PlayerPath))
                            {
                                MessageBox.Show("Player was not found.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                toolStripStatusLabel.Text = "Autoplay failed";
                                return;
                            }

                            toolStripStatusLabel.Text = "Sending the song to the player...";
                            statusStrip.Update();
                            try
                            {
                                playProcess?.Close();

                                playProcess = new System.Diagnostics.Process();
                                playProcess.StartInfo.FileName = settings.PlayerPath;
                                playProcess.StartInfo.Arguments = Path.Combine(Path.GetDirectoryName(settings.MMLPath), CompiledFile.GetFileName(settings.MMLPath));
                                playProcess.StartInfo.WorkingDirectory = Path.GetDirectoryName(settings.MMLPath);

                                playProcess.Start();
                            }
                            catch
                            {
                                playProcess.Close();
                                playProcess = null;
                                MessageBox.Show("Failed to play the compiled data.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                toolStripStatusLabel.Text = "Autoplay failed";
                                return;
                            }

                            toolStripStatusLabel.Text = "Success to send the song to the player";
                        }
                    }));
                }
            }
        }