Skip to content

Commit

Permalink
Added ability to define executable location in XML file if it differs…
Browse files Browse the repository at this point in the history
… from the older version executable. This resolves #128, resolves #243 and resolves #609.
  • Loading branch information
ravibpatel committed Apr 2, 2023
1 parent ee34a96 commit b847605
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 36 deletions.
10 changes: 5 additions & 5 deletions AutoUpdater.NET/AutoUpdater.NET.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@
<Company>RBSoft</Company>
<Product>AutoUpdater.NET</Product>
<Copyright>Copyright © 2012-2023 RBSoft</Copyright>
<Version>1.7.8.0</Version>
<AssemblyVersion>1.7.8.0</AssemblyVersion>
<FileVersion>1.7.8.0</FileVersion>
<Version>1.8.0.0</Version>
<AssemblyVersion>1.8.0.0</AssemblyVersion>
<FileVersion>1.8.0.0</FileVersion>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>AutoUpdater.NET.snk</AssemblyOriginatorKeyFile>
<NeutralLanguage>en</NeutralLanguage>
<PackageId>Autoupdater.NET.Official</PackageId>
<IncludeSymbols>true</IncludeSymbols>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageVersion>1.7.8.0</PackageVersion>
<PackageVersion>1.8.0.0</PackageVersion>
<Title>AutoUpdater.NET</Title>
<Authors>rbsoft</Authors>
<Description>AutoUpdater.NET is a class library that allows .NET developers to easily add auto update functionality to their WinForms or WPF application projects.</Description>
Expand Down Expand Up @@ -51,6 +51,6 @@
<PackageReference Include="Resource.Embedder" Version="1.2.8" PrivateAssets="All" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.1587.40" />
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.1661.34" />
</ItemGroup>
</Project>
7 changes: 4 additions & 3 deletions AutoUpdater.NET/DownloadUpdateDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,9 @@ private void WebClientOnDownloadFileCompleted(object sender, AsyncCompletedEvent

File.WriteAllBytes(installerPath, Resources.ZipExtractor);

string executablePath = Process.GetCurrentProcess().MainModule?.FileName;
string extractionPath = Path.GetDirectoryName(executablePath);
string currentExe = Process.GetCurrentProcess().MainModule?.FileName;
string updatedExe = _args.ExecutablePath;
string extractionPath = Path.GetDirectoryName(currentExe);

if (!string.IsNullOrEmpty(AutoUpdater.InstallationPath) &&
Directory.Exists(AutoUpdater.InstallationPath))
Expand All @@ -168,7 +169,7 @@ private void WebClientOnDownloadFileCompleted(object sender, AsyncCompletedEvent
}

StringBuilder arguments =
new StringBuilder($"--input \"{tempPath}\" --output \"{extractionPath}\" --executable \"{executablePath}\"");
new StringBuilder($"--input \"{tempPath}\" --output \"{extractionPath}\" --current-exe \"{currentExe}\" --updated-exe \"{updatedExe}\"");

if (AutoUpdater.ClearAppDirectory)
{
Expand Down
6 changes: 6 additions & 0 deletions AutoUpdater.NET/UpdateInfoEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ public string ChangelogURL
/// </summary>
[XmlElement("mandatory")]
public Mandatory Mandatory { get; set; }

/// <summary>
/// Executable path of the updated application relative to installation directory.
/// </summary>
[XmlElement("executable")]
public string ExecutablePath { get; set; }

/// <summary>
/// Command line arguments used by Installer.
Expand Down
10 changes: 5 additions & 5 deletions AutoUpdater.NET/build/Autoupdater.NET.Official.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns="http:https://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
<metadata>
<id>Autoupdater.NET.Official</id>
<version>1.7.8.0</version>
<version>1.8.0.0</version>
<title>AutoUpdater.NET</title>
<authors>rbsoft</authors>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
Expand All @@ -15,16 +15,16 @@
<tags>autoupdate updater c# vb wpf winforms</tags>
<dependencies>
<group targetFramework=".NETFramework4.5">
<dependency id="Microsoft.Web.WebView2" version="1.0.1587.40" exclude="Build,Analyzers" />
<dependency id="Microsoft.Web.WebView2" version="1.0.1661.34" exclude="Build,Analyzers" />
</group>
<group targetFramework=".NETCoreApp3.1">
<dependency id="Microsoft.Web.WebView2" version="1.0.1587.40" exclude="Build,Analyzers" />
<dependency id="Microsoft.Web.WebView2" version="1.0.1661.34" exclude="Build,Analyzers" />
</group>
<group targetFramework="net5.0-windows7.0">
<dependency id="Microsoft.Web.WebView2" version="1.0.1587.40" exclude="Build,Analyzers" />
<dependency id="Microsoft.Web.WebView2" version="1.0.1661.34" exclude="Build,Analyzers" />
</group>
<group targetFramework="net6.0-windows7.0">
<dependency id="Microsoft.Web.WebView2" version="1.0.1587.40" exclude="Build,Analyzers" />
<dependency id="Microsoft.Web.WebView2" version="1.0.1661.34" exclude="Build,Analyzers" />
</group>
</dependencies>
<frameworkReferences>
Expand Down
4 changes: 2 additions & 2 deletions AutoUpdaterTest/FormMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public partial class FormMain : Form
public FormMain()
{
InitializeComponent();
labelVersion.Text = string.Format(Resources.CurrentVersion, Assembly.GetEntryAssembly().GetName().Version);
labelVersion.Text = string.Format(Resources.CurrentVersion, Assembly.GetEntryAssembly()?.GetName().Version);
}

private void FormMain_Load(object sender, EventArgs e)
Expand Down Expand Up @@ -246,7 +246,7 @@ private void ButtonCheckForUpdate_Click(object sender, EventArgs e)
//}

AutoUpdater.ClearAppDirectory = false;
AutoUpdater.Start("https:https://rbsoft.org/updates/AutoUpdaterTest.xml");
AutoUpdater.Start("file:https://///rudra-pc/share/test.xml");
}
}
}
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ There are two things you need to provide in XML file as you can see above.
<mandatory minVersion="1.2.0.0">true</mandatory>
````

* executable (Optional): You can provide the path of the executable if it was changed in the update. It should be relative to the installation directory of the application. For example, if the new executable is located inside the bin folder of the installation directory, then you should provide it as shown below.

````xml
<executable>bin\AutoUpdaterTest.exe</executable>
````

* args (Optional): You can provide command line arguments for Installer between this tag. You can include %path% with your command line arguments, it will be replaced by path of the directory where currently executing application resides.
* checksum (Optional): You can provide the checksum for the update file between this tag. If you do this AutoUpdater.NET will compare the checksum of the downloaded file before executing the update process to check the integrity of the file. You can provide algorithm attribute in the checksum tag to specify which algorithm should be used to generate the checksum of the downloaded file. Currently, MD5, SHA1, SHA256, SHA384, and SHA512 are supported.

Expand Down
42 changes: 27 additions & 15 deletions ZipExtractor/FormMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ private void FormMain_Shown(object sender, EventArgs e)
{
string zipPath = null;
string extractionPath = null;
string executablePath = null;
string currentExe = null;
string updatedExe = null;
bool clearAppDirectory = false;
string commandLineArgs = null;

Expand All @@ -47,8 +48,11 @@ private void FormMain_Shown(object sender, EventArgs e)
case "--output":
extractionPath = args[index + 1];
break;
case "--executable":
executablePath = args[index + 1];
case "--current-exe":
currentExe = args[index + 1];
break;
case "--updated-exe":
updatedExe = args[index + 1];
break;
case "--clear":
clearAppDirectory = true;
Expand All @@ -62,7 +66,7 @@ private void FormMain_Shown(object sender, EventArgs e)

_logBuilder.AppendLine();

if (string.IsNullOrEmpty(zipPath) || string.IsNullOrEmpty(extractionPath) || string.IsNullOrEmpty(executablePath))
if (string.IsNullOrEmpty(zipPath) || string.IsNullOrEmpty(extractionPath) || string.IsNullOrEmpty(currentExe))
{
return;
}
Expand All @@ -76,11 +80,11 @@ private void FormMain_Shown(object sender, EventArgs e)

_backgroundWorker.DoWork += (_, eventArgs) =>
{
foreach (var process in Process.GetProcessesByName(Path.GetFileNameWithoutExtension(executablePath)))
foreach (var process in Process.GetProcessesByName(Path.GetFileNameWithoutExtension(currentExe)))
{
try
{
if (process.MainModule is { FileName: { } } && process.MainModule.FileName.Equals(executablePath))
if (process.MainModule is { FileName: { } } && process.MainModule.FileName.Equals(currentExe))
{
_logBuilder.AppendLine("Waiting for application process to exit...");
Expand All @@ -96,11 +100,11 @@ private void FormMain_Shown(object sender, EventArgs e)
_logBuilder.AppendLine("BackgroundWorker started successfully.");
// Ensures that the last character on the extraction path
// is the directory separator char.
// Without this, a malicious zip file could try to traverse outside of the expected
// extraction path.
if (!extractionPath.EndsWith(Path.DirectorySeparatorChar.ToString(), StringComparison.Ordinal))
// Ensures that the last character on the extraction path
// is the directory separator char.
// Without this, a malicious zip file could try to traverse outside of the expected
// extraction path.
if (!extractionPath.EndsWith(Path.DirectorySeparatorChar.ToString(), StringComparison.Ordinal))
{
extractionPath += Path.DirectorySeparatorChar;
}
Expand Down Expand Up @@ -156,9 +160,16 @@ private void FormMain_Shown(object sender, EventArgs e)
if (!entry.IsDirectory())
{
var parentDirectory = Path.GetDirectoryName(filePath);
if (!Directory.Exists(parentDirectory))
if (parentDirectory != null)
{
if (!Directory.Exists(parentDirectory))
{
Directory.CreateDirectory(parentDirectory);
}
}
else
{
Directory.CreateDirectory(parentDirectory);
throw new ArgumentNullException($"parentDirectory is null for \"{filePath}\"!");
}
using (Stream destination = File.Open(filePath, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None))
{
Expand Down Expand Up @@ -193,8 +204,8 @@ private void FormMain_Shown(object sender, EventArgs e)
}
catch (Exception)
{
// ignored
}
// ignored
}
}
if (lockingProcesses == null)
Expand Down Expand Up @@ -261,6 +272,7 @@ private void FormMain_Shown(object sender, EventArgs e)
textBoxInformation.Text = @"Finished";
try
{
var executablePath = updatedExe != null ? Path.Combine(extractionPath, updatedExe) : currentExe;
ProcessStartInfo processStartInfo = new ProcessStartInfo(executablePath);
if (!string.IsNullOrEmpty(commandLineArgs))
{
Expand Down
8 changes: 4 additions & 4 deletions ZipExtractor/ZipExtractor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
<Company>RBSoft</Company>
<Product>ZipExtractor</Product>
<Copyright>Copyright © 2012-2023 RBSoft</Copyright>
<Version>1.3.3.0</Version>
<AssemblyVersion>1.3.3.0</AssemblyVersion>
<FileVersion>1.3.3.0</FileVersion>
<ApplicationVersion>1.3.3.0</ApplicationVersion>
<Version>1.4.0.0</Version>
<AssemblyVersion>1.4.0.0</AssemblyVersion>
<FileVersion>1.4.0.0</FileVersion>
<ApplicationVersion>1.4.0.0</ApplicationVersion>
<ApplicationIcon>ZipExtractor.ico</ApplicationIcon>
<ApplicationManifest>app.manifest</ApplicationManifest>
<SignAssembly>true</SignAssembly>
Expand Down
4 changes: 2 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
version: 1.7.8.{build}
version: 1.8.0.{build}
environment:
my_version: 1.7.8
my_version: 1.8.0
my_secret:
secure: vbPRaZLQYpGPr4BrZZ4p6TofpSZMud+FKtlpqjgO8aA=
skip_branch_with_pr: true
Expand Down

0 comments on commit b847605

Please sign in to comment.