NotifyUnique() public static method

Displays a notification on the bottom right of the screen
public static NotifyUnique ( string id, string htmlContent, MessageImg imageType, string title, string subTitle, Action clickHandler, int duration, int width = 450 ) : void
id string
htmlContent string
imageType MessageImg
title string
subTitle string
clickHandler Action
duration int
width int
return void
Exemplo n.º 1
0
 /// <summary>
 /// Try to import the given configuration file
 /// </summary>
 public static bool TryToImportFile(string filePath)
 {
     if (!string.IsNullOrWhiteSpace(filePath) && File.Exists(filePath))
     {
         var item = List.FirstOrDefault(line => line.HandledItem.Equals(filePath));
         if (item != null)
         {
             if (item.OnImport != null)
             {
                 item.OnImport(item);
             }
             UserCommunication.NotifyUnique("Importedconf", "The latest changes to <b>" + item.Label + "</b> have been saved and taken into account!", MessageImg.MsgInfo, "Configuration imported", item.Label, null, 5);
             return(true);
         }
     }
     return(false);
 }
Exemplo n.º 2
0
        private static void NotifyUpdateAvailable()
        {
            if (_latestReleaseInfo != null)
            {
                UserCommunication.NotifyUnique("UpdateAvailable", @"Dear user, <br>
                    <br>
                    A new version of 3P has been downloaded!<br>
                    It will be automatically installed the next time you restart Notepad++<br>
                    <br>
                    Your version: <b>" + AssemblyInfo.Version + @"</b><br>
                    Distant version: <b>" + _latestReleaseInfo.tag_name + @"</b><br>
                    Release name: <b>" + _latestReleaseInfo.name + @"</b><br>
                    Available since: <b>" + _latestReleaseInfo.published_at + @"</b><br>" +
                                               "Release URL: <b>" + _latestReleaseInfo.html_url.ToHtmlLink() + @"</b><br>" +
                                               (_latestReleaseInfo.prerelease ? "<i>This distant release is a beta version</i><br>" : "") +
                                               (_3PUpdater.Instance.IsAdminRightsNeeded ? "<br><span class='SubTextColor'><i><b>3pUpdater.exe</b> will need admin rights to replace your current 3P.dll file by the new release,<br>please click yes when you are asked to execute it</i></span>" : ""), MessageImg.MsgUpdate, "Update check", "An update is available", null);

                _warnedUserAboutUpdateAvail = true;

                // stop checking for more updates :)
                _checkEveryHourAction.Dispose();
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Update the information of the conf list, using the given share directory
        /// </summary>
        public static void UpdateList(string distantShareDirectory)
        {
            try {
                // We get the latest info for each line
                bool sharedDirOk = false;
                if (!string.IsNullOrEmpty(distantShareDirectory) && Directory.Exists(distantShareDirectory))
                {
                    sharedDirOk = true;
                    Config.Instance.SharedConfFolder = distantShareDirectory;
                }

                StringBuilder updateMessage = new StringBuilder();

                // update each line of the list
                foreach (var confLine in List)
                {
                    // read the autoupdate status from the config
                    confLine.AutoUpdate = Config.Instance.AutoUpdateConfList.ContainsFast(confLine.Label);

                    confLine.LocalPath   = confLine.HandledItem;
                    confLine.DistantPath = sharedDirOk ? Path.Combine(distantShareDirectory, (confLine.IsDir ? Path.GetFileName(confLine.HandledItem.TrimEnd('\\')) : Path.GetFileName(confLine.HandledItem)) ?? "") : "";

                    confLine.LocalTime   = DateTime.Now;
                    confLine.DistantTime = DateTime.Now;

                    if (confLine.IsDir)
                    {
                        confLine.LocalExists   = Directory.Exists(confLine.LocalPath);
                        confLine.DistantExists = !string.IsNullOrEmpty(confLine.DistantPath) && Directory.Exists(confLine.DistantPath);

                        if (confLine.LocalExists)
                        {
                            confLine.LocalNbFiles = 0;
                            foreach (var file in Directory.GetFiles(confLine.LocalPath))
                            {
                                if (confLine.LocalNbFiles == 0)
                                {
                                    confLine.LocalTime = File.GetLastWriteTime(file);
                                }
                                else if (File.GetLastWriteTime(file).CompareTo(confLine.LocalTime) > 0)
                                {
                                    confLine.LocalTime = File.GetLastWriteTime(file);
                                }
                                confLine.LocalNbFiles++;
                            }
                        }

                        if (!string.IsNullOrEmpty(confLine.DistantPath) && confLine.DistantExists)
                        {
                            confLine.DistantNbFiles = 0;
                            foreach (var file in Directory.GetFiles(confLine.DistantPath))
                            {
                                if (confLine.DistantNbFiles == 0)
                                {
                                    confLine.DistantTime = File.GetLastWriteTime(file);
                                }
                                else if (File.GetLastWriteTime(file).CompareTo(confLine.DistantTime) > 0)
                                {
                                    confLine.DistantTime = File.GetLastWriteTime(file);
                                }
                                confLine.DistantNbFiles++;
                            }
                        }
                    }
                    else
                    {
                        confLine.LocalExists   = !string.IsNullOrEmpty(confLine.LocalPath) && File.Exists(confLine.LocalPath);
                        confLine.DistantExists = !string.IsNullOrEmpty(confLine.DistantPath) && File.Exists(confLine.DistantPath);

                        if (confLine.LocalExists)
                        {
                            confLine.LocalTime = File.GetLastWriteTime(confLine.LocalPath);
                        }

                        if (!string.IsNullOrEmpty(confLine.DistantPath) && confLine.DistantExists)
                        {
                            confLine.DistantTime = File.GetLastWriteTime(confLine.DistantPath);
                        }
                    }

                    // if the difference between the two dates are small, correct it (it sometimes happen, even when the files are strictly identical)
                    if (Math.Abs(confLine.LocalTime.Subtract(confLine.DistantTime).TotalSeconds) < 2)
                    {
                        confLine.LocalTime = confLine.DistantTime;
                    }

                    confLine.NeedUpdate = confLine.OnFetch != null && ((confLine.DistantExists && !confLine.LocalExists) || (confLine.LocalExists && confLine.DistantExists && confLine.DistantTime.CompareTo(confLine.LocalTime) > 0));

                    // the line needs to be autoupdated
                    if (confLine.AutoUpdate && confLine.NeedUpdate && confLine.OnFetch != null)
                    {
                        _silentUpdate = true;
                        confLine.OnFetch(confLine);
                        confLine.LocalExists  = true;
                        confLine.LocalTime    = confLine.DistantTime;
                        confLine.LocalNbFiles = confLine.DistantNbFiles;
                        confLine.NeedUpdate   = false;
                        _silentUpdate         = false;

                        if (updateMessage.Length == 0)
                        {
                            updateMessage.Append("The following configuration files have been updated from the shared folder:<br><br>");
                        }
                        updateMessage.Append("<div><b>" + confLine.Label + "</b></div>");
                    }
                }

                if (updateMessage.Length > 0)
                {
                    updateMessage.Append("<br><br><i>You can set which config file gets auto-updated in <a href='go'>the option page</a></i>");
                    UserCommunication.NotifyUnique("ExportConfUpdate", updateMessage.ToString(), MessageImg.MsgInfo, "Update notification", "Configuration auto-update", args => {
                        Appli.Appli.GoToPage(PageNames.ExportShareConf);
                        UserCommunication.CloseUniqueNotif("ExportConfUpdate");
                        args.Handled = true;
                    }, 10);
                }
            } catch (Exception e) {
                ErrorHandler.ShowErrors(e, "Error while fetching info on the distant files");
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Called when the gitub api for releases responses
        /// </summary>
        private static void WbOnOnRequestEnded(WebServiceJson webServiceJson, bool alwaysGetFeedBack)
        {
            try {
                if (webServiceJson.StatusCodeResponse == HttpStatusCode.OK && webServiceJson.ResponseException == null)
                {
                    Config.Instance.LastCheckUpdateOk = true;

                    // get the releases
                    var releases = webServiceJson.DeserializeArray <ReleaseInfo>();
                    if (releases != null && releases.Count > 0)
                    {
                        // sort by descring order
                        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 || !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);
                        }
                        else if (alwaysGetFeedBack)
                        {
                            UserCommunication.NotifyUnique("UpdateChecked", "Congratulations! You already possess the latest <b>" + (!Config.Instance.UserGetsPreReleases && !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 (alwaysGetFeedBack || Config.Instance.LastCheckUpdateOk)
                    {
                        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 unsuccessul, 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.LastCheckUpdateOk = 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 || 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
                                };

                                // 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);

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

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

            _checking = false;
        }