/// <summary> /// Called when a new release has been downloaded /// </summary> protected virtual void OnNewReleaseDownloaded(GitHubUpdater gitHubUpdater, string downloadedFile) { try { // Extract the .zip file if (Utils.ExtractAll(downloadedFile, FolderUnzip)) { // execute extra actions (for the 3P update for instance) if (ExtraActionWhenDownloaded != null) { ExtraActionWhenDownloaded(gitHubUpdater); } NotifyUpdateAvailable(Updater); if (gitHubUpdater.LatestReleaseInfo != null && !RestartNeeded) { Updater.LocalVersion = gitHubUpdater.LatestReleaseInfo.tag_name; } if (OnUpdateDone != null) { OnUpdateDone(this); } } else { UserCommunication.NotifyUnique("Update" + UpdatedSoftName, "Failed to unzip the following file : <br>" + downloadedFile.ToHtmlLink() + "<br>It contains the update for " + UpdatedSoftName + ", you will have to do a manual update." + HowToInstallManually, MessageImg.MsgError, UpdatedSoftName + " updater", "Unzip failed", null); } } finally { _updating = false; } }
/// <summary> /// Called before the download starts /// </summary> protected virtual void MainUpdaterOnStartingUpdate(GitHubUpdater gitHubUpdater, GitHubUpdater.ReleaseInfo releaseInfo, GitHubUpdater.StartingDownloadEvent e) { Config.Instance.TechnicalLastWebserviceCallOk = true; DelayedAction.StartNew(2000, () => { if (_updating && !UserCommunication.IsUniqueNotifShown("Update" + UpdatedSoftName)) { UserCommunication.NotifyUnique("Update" + UpdatedSoftName, "A newer version of " + UpdatedSoftName + " (" + releaseInfo.tag_name + ") has been found online.<br>It is being downloaded, you will be notified when the update is available.", MessageImg.MsgUpdate, UpdatedSoftName + " updater", "New version found", null, 5); } }); }
/// <summary> /// Called when the release file is downloaded and extracted to updater.FolderUnzip /// </summary> /// <param name="updater"></param> private void On3PUpdate(GitHubUpdater updater) { // list all the files of the zip, they should be copied in the notepad++ /plugins/ folder by the updater foreach (var fullPath in Directory.EnumerateFiles(FolderUnzip, "*", SearchOption.TopDirectoryOnly)) { _3PUpdater.Instance.AddFileToMove(fullPath, Path.Combine(Path.GetDirectoryName(AssemblyInfo.Location) ?? "", Path.GetFileName(fullPath) ?? "")); } // write the version log Utils.FileWriteAllText(Config.UpdateVersionLog, updater.VersionLog.ToString(), Encoding.Default); Utils.FileWriteAllText(Config.UpdatePreviousVersion, AssemblyInfo.Version, Encoding.Default); }
/// <summary> /// Called when an update is available /// </summary> protected virtual void NotifyUpdateAvailable(GitHubUpdater updater) { if (updater.LatestReleaseInfo != null) { UserCommunication.NotifyUnique("Update" + UpdatedSoftName, @"Dear user, <br> <br> A new version of " + UpdatedSoftName + @" has been downloaded!<br>" + (RestartNeeded ? @"It will be automatically installed the next time you restart Notepad++<br>" : "It has already been installed successfully<br>") + @" <br> Your version: <b>" + updater.LocalVersion + @"</b><br> New version: <b>" + updater.LatestReleaseInfo.tag_name + @"</b><br> Release name: <b>" + updater.LatestReleaseInfo.name + @"</b><br> Available since: <b>" + updater.LatestReleaseInfo.published_at + @"</b><br> Release URL: <b>" + updater.LatestReleaseInfo.html_url.ToHtmlLink() + @"</b><br>" + (updater.LatestReleaseInfo.prerelease ? "<i>This new release is a beta version</i><br>" : "") + "<br><div>" + "log".ToHtmlLink("Click here to see what is new in this version", true) + "</div>" + (RestartNeeded ? (_3PUpdater.Instance.IsAdminRightsNeeded ? "<div><span class='SubTextColor'><i><b>3pUpdater.exe</b> will need administrator rights to replace your current version by the new release,<br>please click yes when you are asked to execute it</i></span></div>" : "") + @"<div><b>" + "Restart".ToHtmlLink("Click here to restart now!") + @"</b></div>" : ""), MessageImg.MsgUpdate, UpdatedSoftName + " updater", "New update downloaded", args => { if (args.Link.Equals("Restart")) { args.Handled = true; Npp.Restart(); } else if (args.Link.Equals("log")) { args.Handled = true; UserCommunication.Message(updater.VersionLog.ToString().MdToHtml(), MessageImg.MsgUpdate, UpdatedSoftName + " updater", "Release notes from " + Updater.LocalVersion + " to " + Updater.LatestReleaseInfo.tag_name, new List <string> { "ok" }, false); } }); if (RestartNeeded && CheckRegularlyAction != null) { // stop checking for more updates :) CheckRegularlyAction.Dispose(); } } }
/// <summary> /// Called when the soft is already up to date /// </summary> protected virtual void OnAlreadyUpdated(GitHubUpdater gitHubUpdater, GitHubUpdater.ReleaseInfo releaseInfo) { try { Config.Instance.TechnicalLastWebserviceCallOk = true; if (AlwaysShowNotifications) { UserCommunication.NotifyUnique("Update" + UpdatedSoftName, "Congratulations! You already own the latest <b>" + (!gitHubUpdater.GetPreReleases ? "beta" : "stable") + "</b> version of " + UpdatedSoftName + "." + (!gitHubUpdater.GetPreReleases ? "<br><br><i>If you wish to check for beta versions as well, toggle the corresponding option in the update " + "options".ToHtmlLink("options page") + "</i>" : ""), MessageImg.MsgUpdate, UpdatedSoftName + " updater", "Local version is " + gitHubUpdater.LocalVersion, args => { if (args.Link.Equals("options")) { args.Handled = true; Appli.GoToPage(PageNames.OptionsUpdate); } }); } if (OnUpdateDone != null) { OnUpdateDone(this); } } finally { _updating = false; } }
/// <summary> /// Called when an error occurred during the update /// </summary> /// <param name="gitHubUpdater"></param> /// <param name="e"></param> /// <param name="gitHubUpdaterFailReason"></param> protected virtual void OnErrorOccured(GitHubUpdater gitHubUpdater, Exception e, GitHubUpdater.GitHubUpdaterFailReason gitHubUpdaterFailReason) { try { switch (gitHubUpdaterFailReason) { case GitHubUpdater.GitHubUpdaterFailReason.ReleaseApiUnreachable: if (Config.Instance.TechnicalLastWebserviceCallOk || AlwaysShowNotifications) { // only show this message once in case of repetitive failures UserCommunication.NotifyUnique("Update" + UpdatedSoftName, "For your information, it has not been possible to check for new releases on GITHUB.<br><br>The API requested was :<br>" + gitHubUpdater.GitHubReleaseApi.ToHtmlLink() + "<br>You might want to check your proxy settings on the " + "options".ToHtmlLink("update options page") + HowToInstallManually, MessageImg.MsgHighImportance, UpdatedSoftName + " updater", "Couldn't query GITHUB API", args => { if (args.Link.Equals("options")) { args.Handled = true; Appli.GoToPage(PageNames.OptionsUpdate); } }); } Config.Instance.TechnicalLastWebserviceCallOk = false; // check if there is an update available in the Shared config folder if (!String.IsNullOrEmpty(Config.Instance.SharedConfFolder) && Directory.Exists(Config.Instance.SharedConfFolder)) { var potentialUpdate = Path.Combine(Config.Instance.SharedConfFolder, AssemblyInfo.AssemblyName); // if the .dll exists, is higher version and (the user get beta releases or it's a stable release) if (File.Exists(potentialUpdate) && Utils.GetDllVersion(potentialUpdate).IsHigherVersionThan(AssemblyInfo.Version) && (Config.Instance.UserGetsPreReleases || AssemblyInfo.IsPreRelease || Utils.GetDllVersion(potentialUpdate).EndsWith(".0"))) { // copy to local update folder and warn the user if (Utils.CopyFile(potentialUpdate, Path.Combine(FolderUnzip, AssemblyInfo.AssemblyName))) { gitHubUpdater.LatestReleaseInfo = new GitHubUpdater.ReleaseInfo { tag_name = Utils.GetDllVersion(potentialUpdate), prerelease = Utils.GetDllVersion(potentialUpdate).EndsWith(".1"), published_at = "???", html_url = Config.UrlCheckReleases }; if (ExtraActionWhenDownloaded != null) { ExtraActionWhenDownloaded(gitHubUpdater); } gitHubUpdater.VersionLog.Append("Version found on the shared folder : \n" + Config.Instance.SharedConfFolder.ToHtmlLink() + "\n\nCheck the official website to learn more about this release"); NotifyUpdateAvailable(Updater); } } } break; default: ErrorHandler.ShowErrors(e, "Update error for " + UpdatedSoftName + " : " + gitHubUpdaterFailReason); break; } } finally { _updating = false; } }