-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
278 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ application. | |
* HeidiSQL | ||
* HexChat | ||
* Inkscape | ||
* Inno Setup | ||
* IrfanView | ||
* KeePass 2 | ||
* LibreOffice | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
This file is part of the updater command line interface. | ||
Copyright (C) 2024 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 <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using updater.software; | ||
|
||
namespace updater_test.software | ||
{ | ||
/// <summary> | ||
/// Test cases for the InnoSetup class. | ||
/// </summary> | ||
[TestClass] | ||
public class InnoSetup_Tests : BasicSoftwareTests | ||
{ | ||
/// <summary> | ||
/// Checks whether info() returns some meaningful data. | ||
/// </summary> | ||
[TestMethod] | ||
public void Test_info() | ||
{ | ||
_info(new InnoSetup(false)); | ||
} | ||
|
||
|
||
/// <summary> | ||
/// Checks whether the class implements the searchForNewer() method. | ||
/// </summary> | ||
[TestMethod] | ||
public void Test_implementsSearchForNewer() | ||
{ | ||
var inno = new InnoSetup(false); | ||
Assert.IsTrue(inno.implementsSearchForNewer()); | ||
} | ||
|
||
|
||
/// <summary> | ||
/// Checks whether searchForNewer() returns something. | ||
/// </summary> | ||
[TestMethod] | ||
public void Test_searchForNewer() | ||
{ | ||
_searchForNewer(new InnoSetup(false)); | ||
} | ||
|
||
|
||
/// <summary> | ||
/// Checks whether the class info is up to date. | ||
/// </summary> | ||
[TestMethod] | ||
public void Test_upToDate_info() | ||
{ | ||
_upToDate_info(new InnoSetup(false)); | ||
} | ||
} // class | ||
} // namespace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,205 @@ | ||
/* | ||
This file is part of the updater command line interface. | ||
Copyright (C) 2024 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 <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.Text.RegularExpressions; | ||
using updater.data; | ||
|
||
namespace updater.software | ||
{ | ||
/// <summary> | ||
/// Handles update of Inno Setup (Unicode version). | ||
/// </summary> | ||
public class InnoSetup: AbstractSoftware | ||
{ | ||
/// <summary> | ||
/// NLog.Logger for InnoSetup class | ||
/// </summary> | ||
private static readonly NLog.Logger logger = NLog.LogManager.GetLogger(typeof(InnoSetup).FullName); | ||
|
||
|
||
/// <summary> | ||
/// publisher name for signed installers of Inno Setup | ||
/// </summary> | ||
private const string publisherX509 = "CN=\"Open Source Developer, Martijn Laan\", O=Open Source Developer, L=Aalsmeer, S=Noord-Holland, C=NL"; | ||
|
||
|
||
/// <summary> | ||
/// expiration date of certificate | ||
/// </summary> | ||
private static readonly DateTime certificateExpiration = new(2025, 4, 17, 9, 58, 13, DateTimeKind.Utc); | ||
|
||
|
||
/// <summary> | ||
/// Constructor. | ||
/// </summary> | ||
/// <param name="autoGetNewer">whether to automatically get | ||
/// newer information about the software when calling the info() method</param> | ||
public InnoSetup(bool autoGetNewer) | ||
: base(autoGetNewer) | ||
{ } | ||
|
||
|
||
/// <summary> | ||
/// Gets the currently known information about the software. | ||
/// </summary> | ||
/// <returns>Returns an AvailableSoftware instance with the known | ||
/// details about the software.</returns> | ||
public override AvailableSoftware knownInfo() | ||
{ | ||
var installer = new InstallInfoExe( | ||
"https://files.innosetup.nl/innosetup-6.3.3.exe", | ||
HashAlgorithm.SHA256, | ||
"0bcb2a409dea17e305a27a6b09555cabe600e984f88570ab72575cd7e93c95e6", | ||
new Signature(publisherX509, certificateExpiration), | ||
"/ALLUSERS /VERYSILENT /NORESTART"); | ||
return new AvailableSoftware("Inno Setup", | ||
"6.3.3", | ||
"^Inno Setup Version [0-9]+\\.[0-9]+\\.[0-9]+$", | ||
"^Inno Setup Version [0-9]+\\.[0-9]+\\.[0-9]+$", | ||
installer, | ||
installer); | ||
} | ||
|
||
|
||
/// <summary> | ||
/// Gets a list of IDs to identify the software. | ||
/// </summary> | ||
/// <returns>Returns a non-empty array of IDs, where at least one entry is unique to the software.</returns> | ||
public override string[] id() | ||
{ | ||
return new string[] { "inno-setup", "innosetup" }; | ||
} | ||
|
||
|
||
/// <summary> | ||
/// Determines whether the method searchForNewer() is implemented. | ||
/// </summary> | ||
/// <returns>Returns true, if searchForNewer() is implemented for that | ||
/// class. Returns false, if not. Calling searchForNewer() may throw an | ||
/// exception in the later case.</returns> | ||
public override bool implementsSearchForNewer() | ||
{ | ||
return true; | ||
} | ||
|
||
|
||
/// <summary> | ||
/// Looks for newer versions of the software than the currently known version. | ||
/// </summary> | ||
/// <returns>Returns an AvailableSoftware instance with the information | ||
/// that was retrieved from the net.</returns> | ||
public override AvailableSoftware searchForNewer() | ||
{ | ||
logger.Info("Searching for newer version of Inno Setup..."); | ||
var client = HttpClientProvider.Provide(); | ||
string response; | ||
try | ||
{ | ||
var task = client.GetStringAsync("https://jrsoftware.org/isdl.php"); | ||
task.Wait(); | ||
response = task.Result; | ||
} | ||
catch (Exception ex) | ||
{ | ||
logger.Warn("Error while looking for newer Inno Setup version: " + ex.Message); | ||
return null; | ||
} | ||
|
||
var regEx = new Regex("innosetup\\-([0-9]+\\.[0-9]+\\.[0-9]+)\\.exe"); | ||
var match = regEx.Match(response); | ||
if (!match.Success) | ||
return null; | ||
string version = match.Groups[1].Value; | ||
regEx = new Regex("<b>sha256 hash:</b> ([0-9a-f]{64})"); | ||
match = regEx.Match(response, match.Index); | ||
if (!match.Success) | ||
return null; | ||
var checksum = match.Groups[1].Value; | ||
|
||
var info = knownInfo(); | ||
info.install32Bit.checksum = checksum; | ||
info.install32Bit.downloadUrl = info.install32Bit.downloadUrl.Replace(info.newestVersion, version); | ||
info.install64Bit.checksum = checksum; | ||
info.install64Bit.downloadUrl = info.install64Bit.downloadUrl.Replace(info.newestVersion, version); | ||
info.newestVersion = version; | ||
return info; | ||
} | ||
|
||
|
||
/// <summary> | ||
/// Lists names of processes that might block an update, e.g. because | ||
/// the application cannot be updated while it is running. | ||
/// </summary> | ||
/// <param name="detected">currently installed / detected software version</param> | ||
/// <returns>Returns a list of process names that block the upgrade.</returns> | ||
public override List<string> blockerProcesses(DetectedSoftware detected) | ||
{ | ||
return new List<string>(4) | ||
{ | ||
"Compil32", | ||
"ISCC", | ||
"islzma32", | ||
"islzma64" | ||
}; | ||
} | ||
|
||
|
||
/// <summary> | ||
/// Determines whether a separate process must be run before the update. | ||
/// </summary> | ||
/// <param name="detected">currently installed / detected software version</param> | ||
/// <returns>Returns true, if a separate process returned by | ||
/// preUpdateProcess() needs to run in preparation of the update. | ||
/// Returns false, if not. Calling preUpdateProcess() may throw an | ||
/// exception in the later case.</returns> | ||
public override bool needsPreUpdateProcess(DetectedSoftware detected) | ||
{ | ||
return true; | ||
} | ||
|
||
|
||
/// <summary> | ||
/// Returns a process that must be run before the update. | ||
/// </summary> | ||
/// <param name="detected">currently installed / detected software version</param> | ||
/// <returns>Returns a Process ready to start that should be run before | ||
/// the update. May return null or may throw, if needsPreUpdateProcess() | ||
/// returned false.</returns> | ||
public override List<Process> preUpdateProcess(DetectedSoftware detected) | ||
{ | ||
if (string.IsNullOrWhiteSpace(detected.installPath)) | ||
{ | ||
logger.Error("There is not enough information to uninstall the old Inno Setup version."); | ||
return null; | ||
} | ||
|
||
// Remove enclosing quotes, if any. | ||
if (detected.installPath.StartsWith("\"") && detected.installPath.EndsWith("\"")) | ||
{ | ||
detected.installPath = detected.installPath[1..^1]; | ||
} | ||
var proc = new Process(); | ||
proc.StartInfo.FileName = System.IO.Path.Combine(detected.installPath, "unins000.exe"); | ||
proc.StartInfo.Arguments = "/VERYSILENT /NORESTART"; | ||
return new List<Process>(1) { proc }; | ||
} | ||
} | ||
} |