/// <summary>Run the SMA update process</summary> /// <returns></returns> public async Task Update() { // TODO: Add option to wait for user confirmation to update if (UpdateEnabled == false) { return; } ReleaseEntry updateVersion = null; try { if (Wininet.HasNetworking() == false) { return; } CancellationTokenSource cts = new CancellationTokenSource(0); cts.Cancel(); using (await Semaphore.LockAsync(cts.Token)) using (var updateMgr = CreateUpdateMgr()) { State = SMAUpdateState.Fetching; var updateInfo = await updateMgr.CheckForUpdate( true, false, progress => ProgressPct = progress, UpdaterIntention.Update, UpdateMinPrerelease); if (updateInfo?.ReleasesToApply == null) { State = SMAUpdateState.Error; return; } if (updateInfo.ReleasesToApply.None()) { State = SMAUpdateState.UpToDate; return; } updateVersion = updateInfo.FutureReleaseEntry; State = SMAUpdateState.Downloading; await updateMgr.DownloadReleases(updateInfo.ReleasesToApply, progress => ProgressPct = progress); State = SMAUpdateState.Applying; await updateMgr.ApplyReleases(updateInfo, progress => ProgressPct = progress); State = SMAUpdateState.CreatingUninstaller; await updateMgr.CreateUninstallerRegistryEntry(); State = SMAUpdateState.Updated; } } catch (TaskCanceledException) { } catch (Exception ex) // TODO: Update Squirrel UpdateManager to send sub-classed Exceptions { LogTo.Warning(ex, "An exception was caught while {V} update", State.Name().ToLower(CultureInfo.InvariantCulture)); State = SMAUpdateState.Error; } finally { Semaphore.Release(); if (updateVersion != null) { NotifyUpdateResult(updateVersion); } } }
public async Task Update() { // TODO: Ensure only one Update is running across all instances of SMA (in case SMA is closed during the update process) // TODO: Offer manual updates // TODO: Add option to wait for user confirmation to update if (UpdateEnabled == false) { return; } try { if (Wininet.HasNetworking() == false) { return; } CancellationTokenSource cts = new CancellationTokenSource(0); cts.Cancel(); using (await _semaphore.LockAsync(cts.Token)) using (var updateMgr = CreateUpdateMgr()) { State = SMAUpdateState.Fetching; var updateInfo = await updateMgr.CheckForUpdate(false, progress => ProgressPct = progress); if (updateInfo?.ReleasesToApply == null) { State = SMAUpdateState.Error; return; } if (updateInfo.ReleasesToApply.None()) { State = SMAUpdateState.UpToDate; return; } State = SMAUpdateState.Downloading; await updateMgr.DownloadReleases(updateInfo.ReleasesToApply, progress => ProgressPct = progress); State = SMAUpdateState.Applying; await updateMgr.ApplyReleases(updateInfo, progress => ProgressPct = progress); State = SMAUpdateState.CreatingUninstaller; await updateMgr.CreateUninstallerRegistryEntry(); State = SMAUpdateState.Updated; } } catch (TaskCanceledException) {} catch (Exception ex) // TODO: Update Squirrel UpdateManager to send sub-classed Exceptions { LogTo.Warning(ex, $"An exception was caught while {State.Name().ToLower()} update"); State = SMAUpdateState.Error; } finally { _semaphore.Release(); } }