예제 #1
0
        static void Main(string[] args)
        {
            string mutexName = "EVRPlay";
            bool grantedOwnership = false;
            Mutex singleInstanceMutex = null;

            // Enable XP style controls
            Application.EnableVisualStyles();
            Application.DoEvents();            
                        
            try
            {
                theForm = new MainForm();
                //using (MainForm form = new MainForm())
                //{
                    if (theForm.ps.SingleInstance)
                    {
                        FileLogger.Log("Single Instance Mode");
                        
                        try
                        {
                            singleInstanceMutex = new Mutex(true, mutexName, out grantedOwnership);
                            FileLogger.Log("grantedOwnership: {0}", grantedOwnership);
                        }
                        catch (Exception ex)
                        {
                            FileLogger.Log("Error getting mutex: {0}", ex.ToString());
                        }
                        
                        if (!(grantedOwnership))
                        {
                            using (EpClient epc = new EpClient())
                            {
                                if (args.Length > 0)
                                    epc.PlayFile(args[0]);
                                else
                                    epc.Focus();
                            }
                            return;
                        }
                        else
                        {
                            theForm.eps = new EpServer();
                        }
                    }

                    if (theForm.ps.PriorityClass > 0)
                    {
                        using (Process cp = Process.GetCurrentProcess())
                            cp.PriorityClass = (ProcessPriorityClass)theForm.ps.PriorityClass;
                    }

                    if (args.Length > 0)
                    {
                        List<string> lArgs = new List<string>();
                        lArgs.AddRange(args);
                        bool hasMedia = true;

                        if (lArgs.Contains("-d"))
                        {
                            FileLogger.Log("In Debug Mode");
                            DebugMode = true;
                            if (args.Length == 1)
                                hasMedia = false;
                        }

                        if (hasMedia)
                        {
                            FileLogger.Log("arg[0] = {0}", args[0]);
                            string mediaPath = args[0];

                            if (Path.GetExtension(mediaPath).ToLower() == ".pls")
                                ParsePls(theForm, mediaPath);
                            else
                                theForm.filename.Add(mediaPath);
                        }
                    }

                    theForm.Show();
                    ThreadPool.QueueUserWorkItem(new WaitCallback(theForm.OpenFile), OpenClipMode.None);

                    Application.Run(theForm);
                //}
            }
            catch (Exception ex)
            {
                FileLogger.Log("Main Error: {0}", ex.ToString());
            }
            finally
            {
                if (singleInstanceMutex != null)
                {
                    FileLogger.Log("Release mutex");
                    singleInstanceMutex.Close();
                }
                if (theForm != null)
                    theForm.Dispose();
            }
        }