Пример #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);
                }
            };
        }
Пример #2
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();
                }
            }
        }
Пример #3
0
        /// <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);
        }
Пример #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);
                }
            }
        }
Пример #5
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 void CheckForUpdateDoneAndStartCheckingForUpdates()
        {
            var previousVersion = File.Exists(Config.UpdatePreviousVersion) ? Utils.ReadAllText(Config.UpdatePreviousVersion, Encoding.Default).Trim() : null;

            // compatibility with 3P v1.7.0 and older
            if (string.IsNullOrEmpty(previousVersion))
            {
                var oldVersionLogPath = Path.Combine(Npp.ConfigDirectory, "version.log");
                if (File.Exists(oldVersionLogPath))
                {
                    previousVersion = "1.7.0";
                    Utils.MoveFile(oldVersionLogPath, Config.UpdateVersionLog);
                }
            }

            // an update has been done
            if (!string.IsNullOrEmpty(previousVersion))
            {
                // we didn't update to a newer version, something went wrong
                if (!AssemblyInfo.Version.IsHigherVersionThan(previousVersion))
                {
                    UserCommunication.Notify(@"<h2>I require your attention!</h2><br>
                        The update didn't go as expected, the old plugin files have not been replaced by the new ones!<br>
                        It is very likely because the updater didn't get the rights to write a file in your /plugins/ folder.<br>
                        You will have to manually copy the new files to replace the existing files :<br><br>
                        <b>MOVE (delete the source and replace the target)</b> all the files in this folder : <div>" + Config.UpdateReleaseUnzippedFolder.ToHtmlLink() + @"</div><br>
                        <b>In this folder</b> (replacing the existing files) : <div>" + Path.GetDirectoryName(AssemblyInfo.Location).ToHtmlLink() + @"</div>", MessageImg.MsgUpdate, UpdatedSoftName + " updater", "Problem during the update!");
                    return;
                }

                Utils.DeleteFile(Config.UpdatePreviousVersion);

                // Special actions to take depending on the previous version?
                if (!string.IsNullOrEmpty(previousVersion))
                {
                    UpdateDoneFromVersion(previousVersion);
                }
            }

            // Show the version log
            if (File.Exists(Config.UpdateVersionLog))
            {
                var versionLog = Utils.ReadAllText(Config.UpdateVersionLog, Encoding.Default);
                UserCommunication.NotifyUnique("UpdateVersionLog", "A new version of the software has been installed, congratulations!" + "<br><br><div>" + "log".ToHtmlLink("Click here to show what is new in this version") + "</div><br><div>" + "close".ToHtmlLink("Click here to stop showing this notification") + "</div>", MessageImg.MsgUpdate, UpdatedSoftName + " updater", "What is new in " + AssemblyInfo.Version + "?", args => {
                    args.Handled = true;
                    Utils.DeleteFile(Config.UpdateVersionLog);
                    if (args.Link.Equals("log"))
                    {
                        UserCommunication.Message(versionLog.MdToHtml(),
                                                  MessageImg.MsgUpdate,
                                                  UpdatedSoftName + " updater",
                                                  "Release notes from " + previousVersion + " to " + AssemblyInfo.Version,
                                                  new List <string> {
                            "ok"
                        },
                                                  false);
                    }
                    UserCommunication.CloseUniqueNotif("UpdateVersionLog");
                });
            }

            StartCheckingForUpdate();
        }