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(); } } }
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); }
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(); } } }
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; }
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; }
public void Update(UpdateProcessMonitor monitor) { _monitor = monitor; UpdateProc(); _monitor = null; }
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; }
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); }