示例#1
0
        static void Main()
        {
            var       cmdline = new CommandLine();
            bool      singleInstance;
            Semaphore s = null;

            if (!cmdline.IsDefined("forcenewinstance"))
            {
                s = new Semaphore(0, 1, "gitter-updater", out singleInstance);
            }
            else
            {
                singleInstance = true;
            }
            try
            {
                if (singleInstance)
                {
                    var driverName = cmdline["driver"];
                    if (!string.IsNullOrEmpty(driverName))
                    {
                        var driver = UpdateDrivers.FirstOrDefault(d => d.Name == driverName);
                        if (driver != null)
                        {
                            var process = driver.CreateProcess(cmdline);
                            if (process != null)
                            {
                                if (cmdline.IsDefined("hidden"))
                                {
                                    var monitor = new UpdateProcessMonitor();
                                    process.Update(monitor);
                                }
                                else
                                {
                                    Application.EnableVisualStyles();
                                    Application.SetCompatibleTextRenderingDefault(false);
                                    Application.Run(new MainForm(process));
                                }
                            }
                        }
                    }
                }
            }
            finally
            {
                if (s != null)
                {
                    s.Dispose();
                }
            }
        }
示例#2
0
        public void BeginUpdate(UpdateProcessMonitor monitor)
        {
            if (_currentProcess != null)
            {
                throw new InvalidOperationException();
            }

            monitor.Stage           = Resources.StrInitializing + "...";
            monitor.MaximumProgress = 10;
            Action proc = UpdateProc;

            _monitor        = monitor;
            _currentProcess = proc.BeginInvoke(UpdateProcCallback, proc);
        }
示例#3
0
文件: Program.cs 项目: Kuzq/gitter
 static void Main()
 {
     var cmdline = new CommandLine();
     bool singleInstance;
     Semaphore s = null;
     if(!cmdline.IsDefined("forcenewinstance"))
     {
         s = new Semaphore(0, 1, "gitter-updater", out singleInstance);
     }
     else
     {
         singleInstance = true;
     }
     try
     {
         if(singleInstance)
         {
             var driverName = cmdline["driver"];
             if(!string.IsNullOrEmpty(driverName))
             {
                 var driver = UpdateDrivers.FirstOrDefault(d => d.Name == driverName);
                 if(driver != null)
                 {
                     var process = driver.CreateProcess(cmdline);
                     if(process != null)
                     {
                         if(cmdline.IsDefined("hidden"))
                         {
                             var monitor = new UpdateProcessMonitor();
                             process.Update(monitor);
                         }
                         else
                         {
                             Application.EnableVisualStyles();
                             Application.SetCompatibleTextRenderingDefault(false);
                             Application.Run(new MainForm(process));
                         }
                     }
                 }
             }
         }
     }
     finally
     {
         if(s != null)
         {
             s.Dispose();
         }
     }
 }
示例#4
0
        private void UpdateProcCallback(IAsyncResult ar)
        {
            var proc = (Action)ar.AsyncState;

            try
            {
                proc.EndInvoke(ar);
            }
            catch (Exception exc)
            {
                _monitor.ReportFailure("Unexpected error:\n" + exc.Message);
            }
            _monitor        = null;
            _currentProcess = null;
        }
示例#5
0
文件: MainForm.cs 项目: oqewok/gitter
        public MainForm(IUpdateProcess process)
        {
            Verify.Argument.IsNotNull(process, "process");

            InitializeComponent();

            Font = SystemFonts.MessageBoxFont;

            _process = process;
            _monitor = new UpdateProcessMonitor();

            _monitor.MaximumProgressChanged += OnMaximumProgressChanged;
            _monitor.CurrentProgressChanged += OnCurrentProgressChanged;
            _monitor.StageChanged           += OnStageChanged;
            _monitor.UpdateSuccessful       += OnUpdateSuccessful;
            _monitor.UpdateFailed           += OnUpdateFailed;
            _monitor.UpdateCancelled        += OnUpdateCancelled;
            _monitor.CanCancelChanged       += OnCanCancelChanged;
        }
示例#6
0
文件: MainForm.cs 项目: Kuzq/gitter
        public MainForm(IUpdateProcess process)
        {
            Verify.Argument.IsNotNull(process, "process");

            InitializeComponent();

            Font = SystemFonts.MessageBoxFont;

            _process = process;
            _monitor = new UpdateProcessMonitor();

            _monitor.MaximumProgressChanged += OnMaximumProgressChanged;
            _monitor.CurrentProgressChanged += OnCurrentProgressChanged;
            _monitor.StageChanged += OnStageChanged;
            _monitor.UpdateSuccessful += OnUpdateSuccessful;
            _monitor.UpdateFailed += OnUpdateFailed;
            _monitor.UpdateCancelled += OnUpdateCancelled;
            _monitor.CanCancelChanged += OnCanCancelChanged;
        }
示例#7
0
 public void Update(UpdateProcessMonitor monitor)
 {
     _monitor = monitor;
     UpdateProc();
     _monitor = null;
 }
示例#8
0
 private void UpdateProcCallback(IAsyncResult ar)
 {
     var proc = (Action)ar.AsyncState;
     try
     {
         proc.EndInvoke(ar);
     }
     catch(Exception exc)
     {
         _monitor.ReportFailure("Unexpected error:\n" + exc.Message);
     }
     _monitor = null;
     _currentProcess = null;
 }
示例#9
0
 public void Update(UpdateProcessMonitor monitor)
 {
     _monitor = monitor;
     UpdateProc();
     _monitor = null;
 }
示例#10
0
        public void BeginUpdate(UpdateProcessMonitor monitor)
        {
            if(_currentProcess != null) throw new InvalidOperationException();

            monitor.Stage = Resources.StrInitializing + "...";
            monitor.MaximumProgress = 10;
            Action proc = UpdateProc;

            _monitor = monitor;
            _currentProcess = proc.BeginInvoke(UpdateProcCallback, proc);
        }