public static Notify ( string html, MessageImg imageType, string title, string subTitle, Action |
||
html | string | |
imageType | MessageImg | |
title | string | |
subTitle | string | |
clickHandler | Action |
|
duration | int | |
width | int | |
return | void |
/// <summary> /// To call when the user click on an update button /// </summary> public static void CheckForUpdate() { if (!Utils.IsSpamming("updates", 1000)) { UserCommunication.Notify("Now checking for updates, you will be notified when it's done", MessageImg.MsgInfo, "Update", "Update check", 5); Task.Factory.StartNew(() => { CheckForUpdate(true); }); } }
/// <summary> /// Shows a Messagebox informing the user that something went wrong with a file, /// renames said file with the suffix "_errors" /// </summary> public static void ShowErrors(Exception e, string message, string fileName) { UserCommunication.Notify("An error has occurred while loading the following file :<br>" + (fileName + "_errors").ToHtmlLink() + "<br><br>The file has been suffixed with '_errors' to avoid further problems.", MessageImg.MsgPoison, "File load error", message, args => { Npp.Goto(args.Link); args.Handled = true; }); Utils.DeleteFile(fileName + "_errors"); Utils.MoveFile(fileName, fileName + "_errors"); ShowErrors(e, message); // show initial error }
/// <summary> /// check if the User Defined Language for "OpenEdgeABL" exists in the /// userDefineLang.xml file, if it does it updates it, if it doesn't exists it creates it and asks the user /// to restart Notepad++ /// Can also only check and not install it by setting onlyCheckInstall to true /// </summary> public static bool InstallUdl(bool onlyCheckInstall = false) { var encoding = TextEncodingDetect.GetFileEncoding(Config.FileNppUdlXml); var fileContent = File.Exists(Config.FileNppUdlXml) ? Utils.ReadAllText(Config.FileNppUdlXml, encoding) : @"<NotepadPlus />"; var regex = new Regex("<UserLang name=\"OpenEdgeABL\".*?</UserLang>", RegexOptions.Singleline | RegexOptions.IgnoreCase); var matches = regex.Match(fileContent); if (matches.Success) { if (onlyCheckInstall) { return(true); } // if it already exists in the file, delete the existing one fileContent = regex.Replace(fileContent, @""); } else { if (onlyCheckInstall) { return(false); } // if it doesn't exist in the file UserCommunication.Notify("It seems to be the first time that you use this plugin.<br>In order to activate the syntax highlighting, you must restart notepad++.<br><br><i>Please note that if a document is opened at the next start, you will have to manually close/reopen it to see the changes.</i><br><br><b>Sorry for the inconvenience</b>!", MessageImg.MsgInfo, "Information", "Installing syntax highlighting"); } if (fileContent.ContainsFast(@"<NotepadPlus />")) { fileContent = fileContent.Replace(@"<NotepadPlus />", "<NotepadPlus>\r\n" + DataResources.UDL + "\r\n</NotepadPlus>"); } else { fileContent = fileContent.Replace(@"<NotepadPlus>", "<NotepadPlus>\r\n" + DataResources.UDL); } // write to userDefinedLang.xml try { Utils.FileWriteAllText(Config.FileNppUdlXml, fileContent, encoding); } catch (Exception e) { if (e is UnauthorizedAccessException) { UserCommunication.Notify("<b>Couldn't access the file :</b><br>" + Config.FileNppUdlXml + "<br><br>This means i couldn't correctly applied the syntax highlighting feature!<br><br><i>Please make sure to allow write access to this file (Right click on file > Security > Check what's needed to allow total control to current user)</i>", MessageImg.MsgError, "Syntax highlighting", "Can't access userDefineLang.xml"); } else { ErrorHandler.ShowErrors(e, "Error while accessing userDefineLang.xml"); } return(false); } return(true); }
/// <summary> /// Shows an error to the user /// </summary> /// <param name="e"></param> /// <param name="message"></param> public static void ShowErrors(Exception e, string message = null) { if (LogError(e, message, false)) { // show it to the user UserCommunication.Notify("The last action you started has triggered an error and has been canceled.<div class='ToolTipcodeSnippet'>" + e.Message + "</div><br>1. If you didn't ask anything from 3P then you can probably ignore this message.<br>2. Otherwise, you might want to check out the error log below for more details :" + (File.Exists(Config.FileErrorLog) ? "<br>" + Config.FileErrorLog.ToHtmlLink("Link to the error log") : "no .log found!") + "<br>Consider opening an issue on GitHub :<br>" + Config.IssueUrl.ToHtmlLink() + "<br><br>If needed, try to restart Notepad++ and see if things are better!</b>", MessageImg.MsgPoison, "An error has occurred", message, args => { if (args.Link.EndsWith(".log")) { Npp.Goto(args.Link); args.Handled = true; } }); } }
/// <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-mentionned 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); // delete update related files/folders Utils.DeleteFile(Config.FileVersionLog); Utils.DeleteDirectory(Config.FolderUpdate, true); // reset the log files Utils.DeleteDirectory(Config.FolderLog, true); // update UDL if (!Config.Instance.GlobalDontUpdateUdlOnUpdate) { Style.InstallUdl(); } } }
/// <summary> /// Shows an error to the user /// </summary> /// <param name="e"></param> /// <param name="message"></param> public static void ShowErrors(Exception e, string message = null) { if (LogError(e, message)) { if (UserCommunication.Ready) { // show it to the user UserCommunication.Notify("The last action you started has triggered an error and has been cancelled.<div class='ToolTipcodeSnippet'>" + e.Message + "</div><br>1. If you didn't ask anything from 3P then you can probably ignore this message.<br>2. Otherwise, you might want to check out the error log below for more details :" + (File.Exists(Config.FileErrorLog) ? "<br>" + Config.FileErrorLog.ToHtmlLink("Link to the error log") : "no .log found!") + "<br>Consider opening an issue on GitHub :<br>" + Config.IssueUrl.ToHtmlLink() + "<br><br>If needed, try to restart Notepad++ and see if things are better!</b>", MessageImg.MsgPoison, "An error has occured", message, args => { if (args.Link.EndsWith(".log")) { Npp.Goto(args.Link); args.Handled = true; } }); } else { // show an old school message MessageBox.Show("An error has occurred and we couldn't display a notification.\n\nThis very likely happened during the plugin loading; hence there is a hugh probability that it will cause the plugin to not operate normally.\n\nCheck the log at the following location to learn more about this error : " + Config.FileErrorLog.ProQuoter() + "\n\nTry to restart Notepad++, consider opening an issue on : " + Config.IssueUrl + " if the problem persists.", AssemblyInfo.AssemblyProduct + " error message", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
/// <summary> /// Shows a Messagebox informing the user that something went wrong with a file, /// renames said file with the suffix "_errors" /// </summary> public static void ShowErrors(Exception e, string message, string fileName) { if (UserCommunication.Ready) { UserCommunication.Notify("An error has occurred while loading the following file :<div>" + (fileName + "_errors").ToHtmlLink() + "</div><br>The file has been suffixed with '_errors' to avoid further problems.", MessageImg.MsgPoison, "File load error", message, args => { if (args.Link.EndsWith(".log")) { Npp.Goto(args.Link); args.Handled = true; } }); } else { MessageBox.Show("An error has occurred while loading the following file :" + "\n\n" + fileName + "\n\n" + "The file has been suffixed with '_errors' to avoid further problems.", AssemblyInfo.AssemblyProduct + " error message", MessageBoxButtons.OK, MessageBoxIcon.Error); } Utils.DeleteFile(fileName + "_errors"); Utils.MoveFile(fileName, fileName + "_errors"); ShowErrors(e, message); }
/// <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); 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"); } }