예제 #1
0
        static void Main(string[] args)
        {
            startupTime = DateTime.Now;
#if DEBUG
            // In debug builds we'd prefer to have it dump us into the debugger
#else
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
            Application.SetUnhandledExceptionMode(UnhandledExceptionMode.Automatic);
            Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException);
#endif

            culturechanger.ApplyHelp     = culturechanger.ApplyText = culturechanger.ApplyToolTip = true;
            culturechanger.ApplyLocation = culturechanger.ApplySize = false;
            settings     = LocalSettings.TryLoad();
            uploadPrompt = settings.UploadPrompt;
            args         = Array.FindAll <string>(args, delegate(string str) { return(!str.Equals("/m")); });
            Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(settings.Locale, true);
#if DOTNET35
            using (NamedPipeSingleInstance singleInstance = new TCPSingleInstance(TCP_SINGLE_INSTANCE_PORT))
#else
            using (TCPSingleInstance singleInstance = new TCPSingleInstance(TCP_SINGLE_INSTANCE_PORT))
#endif
            {
                if (singleInstance.IsFirstInstance)
                {
                    try
                    {
                        ServicePointManager.ServerCertificateValidationCallback = TransmissionWebClient.ValidateServerCertificate;
                    }
                    catch
                    {
#if MONO
#pragma warning disable 618
                        ServicePointManager.CertificatePolicy = new PromiscuousCertificatePolicy();
#pragma warning restore 618
#endif
                    }
                    ServicePointManager.Expect100Continue = false;

                    /* Store a list of torrents to upload after connect? */
                    if (args.Length > 0)
                    {
                        singleInstance.PassArgumentsToFirstInstance(args);
                    }
                    singleInstance.ArgumentsReceived += singleInstance_ArgumentsReceived;
                    SystemEvents.PowerModeChanged    += new PowerModeChangedEventHandler(SystemEvents_PowerModeChanged);
                    Application.EnableVisualStyles();
                    Application.SetCompatibleTextRenderingDefault(false);
                    form       = new MainWindow();
                    form.Load += new EventHandler(delegate(object sender, EventArgs e)
                    {
                        singleInstance.ListenForArgumentsFromSuccessiveInstances();
                    });
                    Application.Run(form);
                }
                else
                {
                    try
                    {
                        singleInstance.PassArgumentsToFirstInstance(args);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, "Unable to communicate with first instance", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }
        private static void Main(string[] args)
        {
            startupTime = DateTime.Now;
#if DEBUG
            // In debug builds we'd prefer to have it dump us into the debugger
#else
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
            Application.SetUnhandledExceptionMode(UnhandledExceptionMode.Automatic);
            Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException);
#endif

            culturechanger.ApplyHelp = culturechanger.ApplyText = culturechanger.ApplyToolTip = true;
            culturechanger.ApplyLocation = culturechanger.ApplySize = false;
            settings = LocalSettings.TryLoad();
            uploadPrompt = settings.UploadPrompt;
            args = Array.FindAll(args, delegate (string str) { return !str.Equals("/m"); });
            Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(settings.Locale, true);
#if DOTNET35
            using (NamedPipeSingleInstance singleInstance = new TCPSingleInstance(TCP_SINGLE_INSTANCE_PORT))
#else
            using (TCPSingleInstance singleInstance = new TCPSingleInstance(TCP_SINGLE_INSTANCE_PORT))
#endif
            {
                if (singleInstance.IsFirstInstance)
                {
                    try
                    {
                        ServicePointManager.ServerCertificateValidationCallback = TransmissionWebClient.ValidateServerCertificate;
                    }
                    catch
                    {
#if MONO
#pragma warning disable 618
                        ServicePointManager.CertificatePolicy = new PromiscuousCertificatePolicy();
#pragma warning restore 618
#endif
                    }
                    ServicePointManager.Expect100Continue = false;

                    /* Store a list of torrents to upload after connect? */
                    if (args.Length > 0)
                    {
                        singleInstance.PassArgumentsToFirstInstance(args);
                    }
                    singleInstance.ArgumentsReceived += singleInstance_ArgumentsReceived;
                    SystemEvents.PowerModeChanged += new PowerModeChangedEventHandler(SystemEvents_PowerModeChanged);
                    Application.EnableVisualStyles();
                    Application.SetCompatibleTextRenderingDefault(false);
                    form = new MainWindow();
                    form.Load += new EventHandler(delegate (object sender, EventArgs e)
                    {
                        singleInstance.ListenForArgumentsFromSuccessiveInstances();
                    });
                    Application.Run(form);
                }
                else
                {
                    try
                    {
                        singleInstance.PassArgumentsToFirstInstance(args);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, "Unable to communicate with first instance", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }