public async Task CheckForUpdates() { try { await CheckForUpdatesLock.WaitAsync(); if (EnvironmentHelper.IsDebug) { return; } if (PreviousUpdateFailed) { Logger.Write("Skipping update check due to previous failure. Restart the service to try again, or manually install the update."); return; } var connectionInfo = ConfigService.GetConnectionInfo(); var serverUrl = ConfigService.GetConnectionInfo().Host; var platform = Environment.Is64BitOperatingSystem ? "x64" : "x86"; var fileUrl = serverUrl + $"/Downloads/Remotely-Win10-{platform}.zip"; var lastEtag = string.Empty; if (File.Exists("etag.txt")) { lastEtag = await File.ReadAllTextAsync("etag.txt"); } try { var wr = WebRequest.CreateHttp(fileUrl); wr.Method = "Head"; wr.Headers.Add("If-None-Match", lastEtag); using var response = (HttpWebResponse) await wr.GetResponseAsync(); if (response.StatusCode == HttpStatusCode.NotModified) { Logger.Write("Service Updater: Version is current."); return; } } catch (WebException ex) when((ex.Response as HttpWebResponse).StatusCode == HttpStatusCode.NotModified) { Logger.Write("Service Updater: Version is current."); return; } Logger.Write("Service Updater: Update found."); await InstallLatestVersion(); } catch (Exception ex) { Logger.Write(ex); } finally { CheckForUpdatesLock.Release(); } }
public async Task CheckForUpdates() { try { if (EnvironmentHelper.IsDebug) { return; } await CheckForUpdatesLock.WaitAsync(); var connectionInfo = ConfigService.GetConnectionInfo(); var serverUrl = ConfigService.GetConnectionInfo().Host; string fileUrl; if (EnvironmentHelper.IsWindows) { var platform = Environment.Is64BitOperatingSystem ? "x64" : "x86"; fileUrl = serverUrl + $"/Downloads/Remotely-Win10-{platform}.zip"; } else if (EnvironmentHelper.IsLinux) { fileUrl = serverUrl + $"/Downloads/Remotely-Linux.zip"; } else { throw new PlatformNotSupportedException(); } var lastEtag = string.Empty; if (File.Exists("etag.txt")) { lastEtag = await File.ReadAllTextAsync("etag.txt"); } try { var wr = WebRequest.CreateHttp(fileUrl); wr.Method = "Head"; wr.Headers.Add("If-None-Match", lastEtag); using var response = (HttpWebResponse) await wr.GetResponseAsync(); if (response.StatusCode == HttpStatusCode.NotModified) { Logger.Write("Service Updater: Version is current."); return; } } catch (WebException ex) when((ex.Response as HttpWebResponse).StatusCode == HttpStatusCode.NotModified) { Logger.Write("Service Updater: Version is current."); return; } Logger.Write("Service Updater: Update found."); await InstallLatestVersion(); } catch (Exception ex) { Logger.Write(ex); } finally { CheckForUpdatesLock.Release(); } }