Пример #1
0
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            var startTest = 0;

start:
            var existingProcess = Process.GetProcessesByName(Constants.SWYH_PROCESS_NAME);

            if (existingProcess != null && existingProcess.Length > 1)
            {
                if (e.Args != null && e.Args.Contains(Constants.RESTART_ARGUMENT_NAME) && (startTest++) < Constants.NUMBER_OF_RESTART_TEST)
                {
                    Thread.Sleep(100);
                    goto start;
                }
                MessageBox.Show("Stream What You Hear is already running !", "Stream What You Hear", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                directClose = true;   //Skip the statements in Application_Exit function, otherwise it will casue null object exception
                this.Shutdown();
            }
            else
            {
                if (SWYH.Properties.Settings.Default.Debug)
                {
                    AppDomain.CurrentDomain.UnhandledException += (ss, ee) =>
                    {
                        var           ex    = (Exception)ee.ExceptionObject;
                        StringBuilder error = new StringBuilder();
                        error.AppendLine("Date: " + DateTime.Now.ToString());
                        error.AppendLine("Message: " + ex.Message);
                        error.AppendLine("Detail: " + ex.ToString());
                        error.AppendLine("------------------------------");
                        File.AppendAllText(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), Constants.SWYH_CRASHLOG_FILENAME), error.ToString());
                        MessageBox.Show("An unhandled error has occured ! See the '" + Constants.SWYH_CRASHLOG_FILENAME + "' on your desktop for more information", "Stream What You Hear", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                    };
                }
                if (new NAudio.CoreAudioApi.MMDeviceEnumerator().EnumerateAudioEndPoints(NAudio.CoreAudioApi.DataFlow.Render, NAudio.CoreAudioApi.DeviceState.Active).Count == 0)    //Check the available interface.
                {
                    System.Windows.Forms.MessageBox.Show("Unable to find your sound interface, please check your sound interface in control panel.", "Cannot find the sound interface");
                    directClose = true;    //Skip the statements in Application_Exit function, otherwise it will casue null object exception
                    this.Shutdown();
                }
                else
                {
                    this.CheckAutomaticDeviceStreamed(e);
                    this.CheckNewVersion();
                    this.InitializeUI();
                    DoStuff();
                    this.rendererDiscovery = new AVRendererDiscovery((new AVRendererDiscovery.DiscoveryHandler(RendererAddedSink)));
                    this.rendererDiscovery.OnRendererRemoved += new AVRendererDiscovery.DiscoveryHandler(new AVRendererDiscovery.DiscoveryHandler(RendererRemovedSink));
                    this.wasapiProvider = new WasapiProvider();
                    this.swyhDevice     = new SwyhDevice();
                    this.swyhDevice.Start();
                    notifyIcon.ShowBalloonTip(2000, "Stream What You Hear is running", "Right-click on this icon to show the menu !", System.Windows.Forms.ToolTipIcon.Info);
                }
            }
        }
Пример #2
0
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            var startTest = 0;

start:
            var existingProcess = Process.GetProcessesByName(Constants.SWYH_PROCESS_NAME);

            if (existingProcess != null && existingProcess.Length > 1)
            {
                if (e.Args != null && e.Args.Contains(Constants.RESTART_ARGUMENT_NAME) && (startTest++) < Constants.NUMBER_OF_RESTART_TEST)
                {
                    Thread.Sleep(100);
                    goto start;
                }
                MessageBox.Show("Stream What You Hear is already running !", "Stream What You Hear", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                this.Shutdown();
            }
            else
            {
                if (SWYH.Properties.Settings.Default.Debug)
                {
                    AppDomain.CurrentDomain.UnhandledException += (ss, ee) =>
                    {
                        var           ex    = (Exception)ee.ExceptionObject;
                        StringBuilder error = new StringBuilder();
                        error.AppendLine("Date: " + DateTime.Now.ToString());
                        error.AppendLine("Message: " + ex.Message);
                        error.AppendLine("Detail: " + ex.ToString());
                        error.AppendLine("------------------------------");
                        File.AppendAllText(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), Constants.SWYH_CRASHLOG_FILENAME), error.ToString());
                        MessageBox.Show("An unhandled error has occured ! See the '" + Constants.SWYH_CRASHLOG_FILENAME + "' on your desktop for more information", "Stream What You Hear", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                    };
                }
                this.CheckAutomaticDeviceStreamed(e);
                this.CheckNewVersion();
                this.InitializeUI();
                this.rendererDiscovery = new AVRendererDiscovery((new AVRendererDiscovery.DiscoveryHandler(RendererAddedSink)));
                this.rendererDiscovery.OnRendererRemoved += new AVRendererDiscovery.DiscoveryHandler(new AVRendererDiscovery.DiscoveryHandler(RendererRemovedSink));
                this.wasapiProvider = new WasapiProvider();
                this.swyhDevice     = new SwyhDevice();
                this.swyhDevice.Start();
                notifyIcon.ShowBalloonTip(2000, "Stream What You Hear is running", "Right-click on this icon to show the menu !", System.Windows.Forms.ToolTipIcon.Info);
            }
        }