public async Task RefreshUpdateInfo(UpdateCheckFrequency frequency) { if (!CheckUpdateNeeded(frequency)) { return; } LastCheckError = null; using (HttpClient client = new HttpClient()) { client.DefaultRequestHeaders.Add("Cache-Control", "no-cache"); client.DefaultRequestHeaders.UserAgent.TryParseAdd(UserAgent); UriBuilder uriBuilder = new UriBuilder(settings.UpdateSource + versionFile); try { string versions = await client.GetStringAsync(uriBuilder.Uri).ConfigureAwait(false); File.WriteAllText(VersionFile, versions); channels = ResolveUpdateChannels(); } catch (HttpRequestException httpException) { Trace.WriteLine(httpException); LastCheckError = httpException; } } }
public UpdateManager(UserSettings settings) { this.settings = settings ?? throw new ArgumentNullException(nameof(settings)); channels = ResolveUpdateChannels(); // Check for elevation to update; elevation is needed if the update writes failed and the user is NOT an // Administrator. Weird cases (like no permissions on the directory for anyone) are not handled. if (!CheckUpdateWrites()) { WindowsIdentity identity = WindowsIdentity.GetCurrent(); WindowsPrincipal principal = new WindowsPrincipal(identity); UpdaterNeedsElevation = !principal.IsInRole(WindowsBuiltInRole.Administrator); } }