Esempio n. 1
0
        public DataDiggerUpdaterWrapper()
        {
            UpdatedSoftName      = "DataDigger";
            FolderUnzip          = Config.DataDiggerFolder;
            HowToInstallManually = "<br><br><i>If you wish to manually install " + UpdatedSoftName + ", you have to : <br><ul><li>Download the latest release on " + "https://github.com/patrickTingen/DataDigger/releases".ToHtmlLink("GITHUB") + "</li><li>Extract its content to " + ApplicationFolder.ToHtmlLink() + "</li></ul></i>";

            var localVersion = "v0";
            var releasePath  = Path.Combine(ApplicationFolder, "version.i");

            if (File.Exists(releasePath))
            {
                localVersion = Utils.ReadAllText(releasePath, Encoding.Default).Trim();
            }

            Updater.AssetName        = "datadigger.zip";
            Updater.GitHubReleaseApi = Config.DataDiggerReleasesApi;
            Updater.LocalVersion     = localVersion;
            Updater.GetDownloadUrl   = release => release.zipball_url;

            ExtraActionWhenDownloaded += updater => {
                var subFolders = Directory.GetDirectories(FolderUnzip, "*", SearchOption.TopDirectoryOnly).ToNonNullList();
                if (subFolders.Count == 1)
                {
                    Utils.MoveDirectory(subFolders.First(), FolderUnzip);
                    Utils.DeleteDirectory(subFolders.First(), true);
                }
            };
        }
Esempio n. 2
0
 /// <summary>
 /// Called on an update, allows to do special stuff according to the version updated
 /// </summary>
 private static void UpdateDoneFromVersion(string fromVersion)
 {
     if (!fromVersion.IsHigherVersionThan("1.7.3"))
     {
         Utils.DeleteDirectory(Path.Combine(Npp.ConfigDirectory, "Libraries"), true);
     }
 }
Esempio n. 3
0
        /// <summary>
        /// Method to call when the user starts notepad++,
        /// check if an update has been done since the last time notepad was closed
        /// </summary>
        public static void CheckForUpdateDone()
        {
            // an update has been done
            if (File.Exists(Config.FileVersionLog))
            {
                // The dll is still in the update dir, something went wrong
                if (File.Exists(Config.FileDownloadedPlugin))
                {
                    UserCommunication.Notify(@"<h2>I require your attention!</h2><br>
                        <div>
                        The update didn't go as expected, i couldn't replace the old plugin file by the new one!<br>
                        It is very likely because i didn't get the rights to write a file in your /plugins/ folder, don't panic!<br>
                        You will have to manually copy the new file and delete the old file :<br><br>
                        <b>MOVE (delete the source and replace the target)</b> this file : <div>" + Path.GetDirectoryName(Config.FileDownloadedPlugin).ToHtmlLink(Config.FileDownloadedPlugin) + @"</div><br>
                        <b>In this folder</b> (replacing the old file) : <div>" + Path.GetDirectoryName(AssemblyInfo.Location).ToHtmlLink() + @"</div><br><br>
                        Please do it as soon as possible, as i will stop checking for more updates until this problem is fixed.<br>
                        <i>(n.b. : this message will be shown at startup as long as the above-mentioned file exists!)</i><br>
                        Thank you for your patience!</div>", MessageImg.MsgUpdate, "Update", "Problem during the update!");
                    return;
                }

                UserCommunication.Message(("# What's new in this version? #\n\n" + Utils.ReadAllText(Config.FileVersionLog, Encoding.Default)).MdToHtml(),
                                          MessageImg.MsgUpdate,
                                          "A new version has been installed!",
                                          "Updated to version " + AssemblyInfo.Version,
                                          new List <string> {
                    "ok"
                },
                                          false);

                // Special actions to take depending on the previous version?
                if (File.Exists(Config.FilePreviousVersion))
                {
                    UpdateDoneFromVersion(Utils.ReadAllText(Config.FilePreviousVersion, Encoding.Default));
                }

                // delete update related files/folders
                Utils.DeleteDirectory(Config.FolderUpdate, true);
                Utils.DeleteFile(Config.FileVersionLog);

                // reset the log files
                Utils.DeleteDirectory(Config.FolderLog, true);

                // update UDL
                if (!Config.Instance.GlobalDontUpdateUdlOnUpdate)
                {
                    Style.InstallUdl();
                }
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Called on an update, allows to do special stuff according to the version updated
        /// </summary>
        private void UpdateDoneFromVersion(string fromVersion)
        {
            // reset the log files
            Utils.DeleteDirectory(Config.FolderLog, true);

            if (!fromVersion.IsHigherVersionThan("1.7.3"))
            {
                Utils.DeleteDirectory(Path.Combine(Npp.ConfigDirectory, "Libraries"), true);
            }
            if (!fromVersion.IsHigherVersionThan("1.7.6"))
            {
                // delete old UDL
                if (File.Exists(Npp.ConfXml.FileNppUserDefinedLang))
                {
                    var encoding    = TextEncodingDetect.GetFileEncoding(Npp.ConfXml.FileNppUserDefinedLang);
                    var fileContent = Utils.ReadAllText(Npp.ConfXml.FileNppUserDefinedLang, encoding);
                    var regex       = new Regex("<UserLang name=\"OpenEdgeABL\".*?</UserLang>", RegexOptions.Singleline | RegexOptions.IgnoreCase);
                    var matches     = regex.Match(fileContent);
                    if (matches.Success)
                    {
                        fileContent = regex.Replace(fileContent, "");

                        // write to userDefinedLang.xml
                        var copyPath = Path.Combine(Config.FolderUpdate, "userDefineLang.xml");
                        Utils.FileWriteAllText(copyPath, fileContent, encoding);

                        // replace default file by its copy on npp shutdown
                        _3PUpdater.Instance.AddFileToMove(copyPath, Npp.ConfXml.FileNppUserDefinedLang);
                    }
                }
            }
            if (!fromVersion.IsHigherVersionThan("1.7.8"))
            {
                // delete old database dump
                try {
                    if (Directory.Exists(Config.FolderDatabase))
                    {
                        foreach (string file in Directory.EnumerateFiles(Config.FolderDatabase, "*.dump", SearchOption.TopDirectoryOnly))
                        {
                            File.Delete(file);
                        }
                    }
                } catch (Exception e) {
                    ErrorHandler.LogError(e);
                }
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Called when the latest release download is done
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="asyncCompletedEventArgs"></param>
        private static void OnDownloadFileCompleted(object sender, AsyncCompletedEventArgs asyncCompletedEventArgs)
        {
            try {
                // Extract the .zip file
                if (Utils.ExtractAll(Config.FileLatestReleaseZip, Config.FolderUpdate))
                {
                    // check the presence of the plugin file
                    if (File.Exists(Config.FileDownloadedPlugin))
                    {
                        // set up the update so the .dll file downloaded replaces the current .dll
                        _3PUpdater.Instance.AddFileToMove(Config.FileDownloadedPlugin, AssemblyInfo.Location);

                        // if the release was containing a .pdb file, we want to copied it as well
                        if (File.Exists(Config.FileDownloadedPdb))
                        {
                            _3PUpdater.Instance.AddFileToMove(Config.FileDownloadedPdb, Path.Combine(Path.GetDirectoryName(AssemblyInfo.Location) ?? "", Path.GetFileName(Config.FileDownloadedPdb) ?? ""));
                        }

                        // write the version log
                        Utils.FileWriteAllText(Config.FileVersionLog, _latestReleaseInfo.body, Encoding.Default);
                        Utils.FileWriteAllText(Config.FilePreviousVersion, AssemblyInfo.Version, Encoding.Default);

                        NotifyUpdateAvailable();
                    }
                    else
                    {
                        Utils.DeleteDirectory(Config.FolderUpdate, true);
                    }
                }
                else
                {
                    UserCommunication.Notify("I failed to unzip the following file : <br>" + Config.FileLatestReleaseZip + "<br>It contains the update for 3P, you will have to do a manual update.", MessageImg.MsgError, "Unzip", "Failed");
                }
            } catch (Exception e) {
                ErrorHandler.ShowErrors(e, "On Download File Completed");
            }
            _isChecking = false;
        }
Esempio n. 6
0
        /// <summary>
        /// Called when the gitub api for releases responses
        /// </summary>
        private static void WbOnOnRequestEnded(WebServiceJson webServiceJson)
        {
            try {
                if (webServiceJson.StatusCodeResponse == HttpStatusCode.OK && webServiceJson.ResponseException == null)
                {
                    Config.Instance.TechnicalLastCheckUpdateOk = true;

                    // get the releases
                    var releases = webServiceJson.DeserializeArray <ReleaseInfo>();
                    if (releases != null && releases.Count > 0)
                    {
                        // sort
                        releases.Sort((o, o2) => o.tag_name.IsHigherVersionThan(o2.tag_name) ? -1 : 1);

                        var localVersion = AssemblyInfo.Version;
                        var outputBody   = new StringBuilder();
                        foreach (var release in releases)
                        {
                            if (string.IsNullOrEmpty(release.tag_name))
                            {
                                continue;
                            }

                            // For each version higher than the local one, append to the release body
                            // Will be used to display the version log to the user
                            if (release.tag_name.IsHigherVersionThan(localVersion) &&
                                (Config.Instance.UserGetsPreReleases || AssemblyInfo.IsPreRelease || !release.prerelease) &&
                                release.assets != null && release.assets.Count > 0 && release.assets.Exists(asset => asset.name.EqualsCi(Config.FileGitHubAssetName)))
                            {
                                // in case something is undefined (but shouldn't happen)
                                if (string.IsNullOrEmpty(release.tag_name))
                                {
                                    release.tag_name = "vX.X.X.X";
                                }
                                if (string.IsNullOrEmpty(release.name))
                                {
                                    release.name = "unknown";
                                }
                                if (string.IsNullOrEmpty(release.body))
                                {
                                    release.body = "...";
                                }
                                if (string.IsNullOrEmpty(release.published_at))
                                {
                                    release.published_at = DateTime.Now.ToString(CultureInfo.CurrentCulture);
                                }

                                // h1
                                outputBody.AppendLine("## " + release.tag_name + " : " + release.name + " ##\n\n");
                                // body
                                outputBody.AppendLine(release.body + "\n\n");

                                // the first higher release encountered is the latest
                                if (_latestReleaseInfo == null)
                                {
                                    _latestReleaseInfo = release;
                                }
                            }
                        }

                        // There is a distant version higher than the local one
                        if (_latestReleaseInfo != null)
                        {
                            // to display all the release notes
                            _latestReleaseInfo.body = outputBody.ToString();

                            // delete existing dir
                            Utils.DeleteDirectory(Config.FolderUpdate, true);

                            Utils.DownloadFile(_latestReleaseInfo.assets.First(asset => asset.name.EqualsCi(Config.FileGitHubAssetName)).browser_download_url, Config.FileLatestReleaseZip, OnDownloadFileCompleted);
                            return;
                        }

                        if (_displayResultNotif)
                        {
                            UserCommunication.NotifyUnique("UpdateChecked", "Congratulations! You already possess the latest <b>" + (!AssemblyInfo.IsPreRelease ? "stable" : "beta") + "</b> version of 3P!", MessageImg.MsgOk, "Update check", "You own the version " + AssemblyInfo.Version, null);
                        }
                    }
                }
                else
                {
                    // failed to retrieve the list
                    if (_displayResultNotif || Config.Instance.TechnicalLastCheckUpdateOk)
                    {
                        UserCommunication.NotifyUnique("ReleaseListDown", "For your information, I couldn't manage to retrieve the latest published version on GITHUB.<br><br>A request has been sent to :<br>" + Config.ReleasesApi.ToHtmlLink() + "<br>but was unsuccessful, you might have to check for a new version manually if this happens again.", MessageImg.MsgHighImportance, "Couldn't reach GITHUB", "Connection failed", null);
                    }

                    Config.Instance.TechnicalLastCheckUpdateOk = 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, Config.FileDownloadedPlugin))
                            {
                                _latestReleaseInfo = new ReleaseInfo {
                                    name         = "Updated from shared directory",
                                    tag_name     = Utils.GetDllVersion(Config.FileDownloadedPlugin),
                                    prerelease   = Utils.GetDllVersion(Config.FileDownloadedPlugin).EndsWith(".1"),
                                    published_at = "???",
                                    html_url     = Config.UrlCheckReleases
                                };

                                // set up the update so the .dll file downloaded replaces the current .dll
                                _3PUpdater.Instance.AddFileToMove(Config.FileDownloadedPlugin, AssemblyInfo.Location);

                                // write the version log
                                Utils.FileWriteAllText(Config.FileVersionLog, @"This version has been updated from the shared directory" + Environment.NewLine + Environment.NewLine + @"Find more information on this release [here](" + Config.UrlCheckReleases + @")", Encoding.Default);
                                Utils.FileWriteAllText(Config.FilePreviousVersion, AssemblyInfo.Version, Encoding.Default);

                                NotifyUpdateAvailable();
                            }
                        }
                    }
                }
            } catch (Exception e) {
                ErrorHandler.ShowErrors(e, "Error when checking the latest release");
            }
            _isChecking = false;
        }