private bool UpdateBinaries(ICementUpdater updater, string oldHash, string newHash) { ConsoleWriter.Shared.WriteProgressWithoutSave("Updating cement binaries"); try { var zipContent = updater.GetNewCementZip(); if (zipContent is null) { ConsoleWriter.Shared.WriteWarning("Failed to receive cement binary"); return(false); } using (var tempDir = new TempDirectory()) { File.WriteAllBytes(Path.Combine(tempDir.Path, "cement.zip"), zipContent); ZipFile.ExtractToDirectory(Path.Combine(tempDir.Path, "cement.zip"), Path.Combine(tempDir.Path, "cement")); CopyNewCmExe(tempDir.Path); } var okMessage = $"Update succeeded: {oldHash} -> {newHash} ({updater.Name})"; ConsoleWriter.Shared.WriteOk(okMessage); Log.LogDebug(okMessage); return(true); } catch (WebException webException) { Log.LogError(webException, "Fail self-update, exception: '{ErrorMessage}'", webException.Message); if (webException.Status == WebExceptionStatus.ProtocolError && webException.Response != null) { var resp = (HttpWebResponse)webException.Response; if (resp.StatusCode == HttpStatusCode.NotFound) // HTTP 404 { ConsoleWriter.Shared.WriteWarning($"Failed to look for updates on branch {branch}. Server replied 404 ({updater.Name})"); return(false); } } ConsoleWriter.Shared.WriteWarning($"Failed to look for updates on branch {branch}. {webException.Message} ({updater.Name})"); return(false); } }
private bool UpdateBinaries(ICementUpdater updater, string oldHash, string newHash) { ConsoleWriter.WriteProgressWithoutSave("Updating cement binaries"); try { var zipContent = updater.GetNewCementZip(); using (var tempDir = new TempDirectory()) { File.WriteAllBytes(Path.Combine(tempDir.Path, "cement.zip"), zipContent); ZipFile.ExtractToDirectory(Path.Combine(tempDir.Path, "cement.zip"), Path.Combine(tempDir.Path, "cement")); CopyNewCmExe(tempDir.Path); } var okMessage = $"Successfully updated cement binaries. {oldHash} -> {newHash} ({updater.GetName()})"; ConsoleWriter.WriteOk(okMessage); Log.Debug(okMessage); return(true); } catch (WebException ex) { Log.Error("Fail self-update", ex); if (ex.Status == WebExceptionStatus.ProtocolError && ex.Response != null) { var resp = (HttpWebResponse)ex.Response; if (resp.StatusCode == HttpStatusCode.NotFound) // HTTP 404 { ConsoleWriter.WriteError($"Failed to look for updates on branch {branch}. Server responsed 404 ({updater.GetName()})"); return(false); } } ConsoleWriter.WriteError($"Failed to look for updates on branch {branch}. {ex.Message} ({updater.GetName()})"); return(false); } }