Пример #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
 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
        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
        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);
        }