Esempio n. 1
0
        private int UpdateBinary(ICementUpdater updater)
        {
            var currentCommitHash = Helper.GetCurrentBuildCommitHash();

            ConsoleWriter.WriteProgressWithoutSave("Looking for cement updates");
            var newCommitHash = updater.GetNewCommitHash();

            if (newCommitHash == null)
            {
                return(-1);
            }

            if (IsInstallingCement)
            {
                currentCommitHash = "(NOT INSTALLED)" + currentCommitHash;
            }
            if (!HasAllCementFiles() || !currentCommitHash.Equals(newCommitHash))
            {
                if (!UpdateBinaries(updater, currentCommitHash, newCommitHash))
                {
                    return(-1);
                }
            }
            else
            {
                ConsoleWriter.WriteInfo($"No cement binary updates available ({updater.GetName()})");
                Log.DebugFormat("Already has {0} version", currentCommitHash);
            }
            return(0);
        }
Esempio n. 2
0
        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);
            }
        }