From 23fdd6614de714db9b6b4e68e360be791cd6bd6b Mon Sep 17 00:00:00 2001 From: Dirk Stolle Date: Thu, 23 Nov 2023 21:24:03 +0100 Subject: [PATCH] add update support for HexChat --- changelog.md | 4 + supported_applications.md | 1 + updater-test/software/HexChat_Tests.cs | 70 +++++++++++ updater/software/All.cs | 1 + updater/software/HexChat.cs | 161 +++++++++++++++++++++++++ 5 files changed, 237 insertions(+) create mode 100644 updater-test/software/HexChat_Tests.cs create mode 100644 updater/software/HexChat.cs diff --git a/changelog.md b/changelog.md index 14f5c27e..88cb2728 100644 --- a/changelog.md +++ b/changelog.md @@ -6,6 +6,10 @@ improvements may be omitted.)_ ## Next Version +__[new features]__ + +* Update support for HexChat is added. + __[maintenance]__ * NLog library is updated from 5.2.5 to 5.2.6. diff --git a/supported_applications.md b/supported_applications.md index d8240257..0c58a79f 100644 --- a/supported_applications.md +++ b/supported_applications.md @@ -24,6 +24,7 @@ updater application. * GIMP * Git for Windows * HeidiSQL +* HexChat * Inkscape * IrfanView * KeePass 2 diff --git a/updater-test/software/HexChat_Tests.cs b/updater-test/software/HexChat_Tests.cs new file mode 100644 index 00000000..266ca283 --- /dev/null +++ b/updater-test/software/HexChat_Tests.cs @@ -0,0 +1,70 @@ +/* + This file is part of the updater command line interface. + Copyright (C) 2023 Dirk Stolle + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +using Microsoft.VisualStudio.TestTools.UnitTesting; +using updater.software; + +namespace updater_test.software +{ + /// + /// Contains tests for the HexChat class. + /// + [TestClass] + public class HexChat_Tests : BasicSoftwareTests + { + /// + /// Checks whether info() returns some meaningful data. + /// + [TestMethod] + public void Test_info() + { + _info(new HexChat(false)); + } + + + /// + /// Checks whether the class implements the searchForNewer() method. + /// + [TestMethod] + public void Test_implementsSearchForNewer() + { + var hc = new HexChat(false); + Assert.IsTrue(hc.implementsSearchForNewer()); + } + + + /// + /// Checks whether searchForNewer() returns something. + /// + [TestMethod] + public void Test_searchForNewer() + { + _searchForNewer(new HexChat(false)); + } + + + /// + /// Checks whether the class info is up to date. + /// + [TestMethod] + public void Test_upToDate_info() + { + _upToDate_info(new HexChat(false)); + } + } +} diff --git a/updater/software/All.cs b/updater/software/All.cs index 38a82166..c0865ff3 100644 --- a/updater/software/All.cs +++ b/updater/software/All.cs @@ -83,6 +83,7 @@ private static List getUnfiltered(Options opts) result.Add(new FileZilla(autoGetNewer)); result.Add(new GIMP(autoGetNewer)); result.Add(new Git(autoGetNewer)); + result.Add(new HexChat(autoGetNewer)); result.Add(new HeidiSQL(autoGetNewer)); result.Add(new Inkscape(autoGetNewer)); result.Add(new IrfanView(autoGetNewer)); diff --git a/updater/software/HexChat.cs b/updater/software/HexChat.cs new file mode 100644 index 00000000..9c754942 --- /dev/null +++ b/updater/software/HexChat.cs @@ -0,0 +1,161 @@ +/* + This file is part of the updater command line interface. + Copyright (C) 2023 Dirk Stolle + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +using System; +using System.Collections.Generic; +using System.Text.RegularExpressions; +using updater.data; + +namespace updater.software +{ + /// + /// Handles updates of HexChat. + /// + public class HexChat : NoPreUpdateProcessSoftware + { + /// + /// NLog.Logger for HexChat class + /// + private static readonly NLog.Logger logger = NLog.LogManager.GetLogger(typeof(HexChat).FullName); + + + /// + /// Default constructor. + /// + /// whether to automatically get newer + /// information about the software when calling the info() method + public HexChat(bool autoGetNewer) + : base(autoGetNewer) + { } + + + /// + /// Gets the currently known information about the software. + /// + /// Returns an AvailableSoftware instance with the known + /// details about the software. + public override AvailableSoftware knownInfo() + { + return new AvailableSoftware("HexChat", + "2.16.1", + "^HexChat$", + "^HexChat$", + new InstallInfoExe( + "https://dl.hexchat.net/hexchat/HexChat%202.16.1%20x86.exe", + HashAlgorithm.SHA256, + "ab6db5c0cdd0a1ddd80dd7124430a6b56d75905859e4bab68c973837171c6161", + Signature.None, + "/VERYSILENT /NORESTART"), + new InstallInfoExe( + "https://dl.hexchat.net/hexchat/HexChat%202.16.1%20x64.exe", + HashAlgorithm.SHA256, + "4b47930951ebc46e9cb8e8201856b8bddcd7499f5510fe1059f67d65cc80bf07", + Signature.None, + "/VERYSILENT /NORESTART") + ); + } + + + /// + /// Gets a list of IDs to identify the software. + /// + /// Returns a non-empty array of IDs, where at least one entry is unique to the software. + public override string[] id() + { + return new string[] { "hexchat" }; + } + + + /// + /// Determines whether or not the method searchForNewer() is implemented. + /// + /// Returns true, if searchForNewer() is implemented for that + /// class. Returns false, if not. Calling searchForNewer() may throw an + /// exception in the later case. + public override bool implementsSearchForNewer() + { + return true; + } + + + /// + /// Looks for newer versions of the software than the currently known version. + /// + /// Returns an AvailableSoftware instance with the information + /// that was retrieved from the net. + public override AvailableSoftware searchForNewer() + { + logger.Info("Searching for newer version of HexChat..."); + // Just getting the latest release does not work here, because that may also be a release candidate, and we do not want that. + string html; + var client = HttpClientProvider.Provide(); + try + { + var task = client.GetStringAsync("https://hexchat.github.io/downloads.html"); + task.Wait(); + html = task.Result; + } + catch (Exception ex) + { + logger.Warn("Exception occurred while checking for newer version of HexChat: " + ex.Message); + return null; + } + + // HTML text will contain hashes like "4b47930951ebc46e9cb8e8201856b8bddcd7499f5510fe1059f67d65cc80bf07 HexChat 2.16.1 x64.exe". + var reVersion = new Regex("([0-9a-f]{64}) HexChat ([0-9]+\\.[0-9]+\\.[0-9]+) x64\\.exe"); + var matchVersion = reVersion.Match(html); + if (!matchVersion.Success) + return null; + string hash_64_bit = matchVersion.Groups[1].Value; + string current_version = matchVersion.Groups[2].Value; + + reVersion = new Regex("([0-9a-f]{64}) HexChat ([0-9]+\\.[0-9]+\\.[0-9]+) x86\\.exe"); + matchVersion = reVersion.Match(html); + if (!matchVersion.Success) + return null; + string hash_32_bit = matchVersion.Groups[1].Value; + + var new_info = knownInfo(); + string old_version = new_info.newestVersion; + + new_info.newestVersion = current_version; + new_info.install32Bit.checksum = hash_32_bit; + new_info.install32Bit.downloadUrl = new_info.install32Bit.downloadUrl.Replace(old_version, current_version); + new_info.install64Bit.checksum = hash_64_bit; + new_info.install64Bit.downloadUrl = new_info.install64Bit.downloadUrl.Replace(old_version, current_version); + + return new_info; + } + + + /// + /// Lists names of processes that might block an update, e.g. because + /// the application cannot be updated while it is running. + /// + /// currently installed / detected software version + /// Returns a list of process names that block the upgrade. + public override List blockerProcesses(DetectedSoftware detected) + { + return new List(2) + { + "hexchat", // HexChat itself + "thememan" // theme manager + }; + } + } // class +} // namespace