Skip to content

Commit b847605

Browse files
committed
Added ability to define executable location in XML file if it differs from the older version executable. This resolves #128, resolves #243 and resolves #609.
1 parent ee34a96 commit b847605

File tree

9 files changed

+61
-36
lines changed

9 files changed

+61
-36
lines changed

AutoUpdater.NET/AutoUpdater.NET.csproj

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@
1111
<Company>RBSoft</Company>
1212
<Product>AutoUpdater.NET</Product>
1313
<Copyright>Copyright © 2012-2023 RBSoft</Copyright>
14-
<Version>1.7.8.0</Version>
15-
<AssemblyVersion>1.7.8.0</AssemblyVersion>
16-
<FileVersion>1.7.8.0</FileVersion>
14+
<Version>1.8.0.0</Version>
15+
<AssemblyVersion>1.8.0.0</AssemblyVersion>
16+
<FileVersion>1.8.0.0</FileVersion>
1717
<SignAssembly>true</SignAssembly>
1818
<AssemblyOriginatorKeyFile>AutoUpdater.NET.snk</AssemblyOriginatorKeyFile>
1919
<NeutralLanguage>en</NeutralLanguage>
2020
<PackageId>Autoupdater.NET.Official</PackageId>
2121
<IncludeSymbols>true</IncludeSymbols>
2222
<PackageLicenseExpression>MIT</PackageLicenseExpression>
23-
<PackageVersion>1.7.8.0</PackageVersion>
23+
<PackageVersion>1.8.0.0</PackageVersion>
2424
<Title>AutoUpdater.NET</Title>
2525
<Authors>rbsoft</Authors>
2626
<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>
@@ -51,6 +51,6 @@
5151
<PackageReference Include="Resource.Embedder" Version="1.2.8" PrivateAssets="All" />
5252
</ItemGroup>
5353
<ItemGroup>
54-
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.1587.40" />
54+
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.1661.34" />
5555
</ItemGroup>
5656
</Project>

AutoUpdater.NET/DownloadUpdateDialog.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,9 @@ private void WebClientOnDownloadFileCompleted(object sender, AsyncCompletedEvent
158158

159159
File.WriteAllBytes(installerPath, Resources.ZipExtractor);
160160

161-
string executablePath = Process.GetCurrentProcess().MainModule?.FileName;
162-
string extractionPath = Path.GetDirectoryName(executablePath);
161+
string currentExe = Process.GetCurrentProcess().MainModule?.FileName;
162+
string updatedExe = _args.ExecutablePath;
163+
string extractionPath = Path.GetDirectoryName(currentExe);
163164

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

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

173174
if (AutoUpdater.ClearAppDirectory)
174175
{

AutoUpdater.NET/UpdateInfoEventArgs.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ public string ChangelogURL
6565
/// </summary>
6666
[XmlElement("mandatory")]
6767
public Mandatory Mandatory { get; set; }
68+
69+
/// <summary>
70+
/// Executable path of the updated application relative to installation directory.
71+
/// </summary>
72+
[XmlElement("executable")]
73+
public string ExecutablePath { get; set; }
6874

6975
/// <summary>
7076
/// Command line arguments used by Installer.

AutoUpdater.NET/build/Autoupdater.NET.Official.nuspec

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
33
<metadata>
44
<id>Autoupdater.NET.Official</id>
5-
<version>1.7.8.0</version>
5+
<version>1.8.0.0</version>
66
<title>AutoUpdater.NET</title>
77
<authors>rbsoft</authors>
88
<requireLicenseAcceptance>false</requireLicenseAcceptance>
@@ -15,16 +15,16 @@
1515
<tags>autoupdate updater c# vb wpf winforms</tags>
1616
<dependencies>
1717
<group targetFramework=".NETFramework4.5">
18-
<dependency id="Microsoft.Web.WebView2" version="1.0.1587.40" exclude="Build,Analyzers" />
18+
<dependency id="Microsoft.Web.WebView2" version="1.0.1661.34" exclude="Build,Analyzers" />
1919
</group>
2020
<group targetFramework=".NETCoreApp3.1">
21-
<dependency id="Microsoft.Web.WebView2" version="1.0.1587.40" exclude="Build,Analyzers" />
21+
<dependency id="Microsoft.Web.WebView2" version="1.0.1661.34" exclude="Build,Analyzers" />
2222
</group>
2323
<group targetFramework="net5.0-windows7.0">
24-
<dependency id="Microsoft.Web.WebView2" version="1.0.1587.40" exclude="Build,Analyzers" />
24+
<dependency id="Microsoft.Web.WebView2" version="1.0.1661.34" exclude="Build,Analyzers" />
2525
</group>
2626
<group targetFramework="net6.0-windows7.0">
27-
<dependency id="Microsoft.Web.WebView2" version="1.0.1587.40" exclude="Build,Analyzers" />
27+
<dependency id="Microsoft.Web.WebView2" version="1.0.1661.34" exclude="Build,Analyzers" />
2828
</group>
2929
</dependencies>
3030
<frameworkReferences>

AutoUpdaterTest/FormMain.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public partial class FormMain : Form
1919
public FormMain()
2020
{
2121
InitializeComponent();
22-
labelVersion.Text = string.Format(Resources.CurrentVersion, Assembly.GetEntryAssembly().GetName().Version);
22+
labelVersion.Text = string.Format(Resources.CurrentVersion, Assembly.GetEntryAssembly()?.GetName().Version);
2323
}
2424

2525
private void FormMain_Load(object sender, EventArgs e)
@@ -246,7 +246,7 @@ private void ButtonCheckForUpdate_Click(object sender, EventArgs e)
246246
//}
247247

248248
AutoUpdater.ClearAppDirectory = false;
249-
AutoUpdater.Start("https://rbsoft.org/updates/AutoUpdaterTest.xml");
249+
AutoUpdater.Start("file://///rudra-pc/share/test.xml");
250250
}
251251
}
252252
}

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ There are two things you need to provide in XML file as you can see above.
5656
<mandatory minVersion="1.2.0.0">true</mandatory>
5757
````
5858

59+
* 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.
60+
61+
````xml
62+
<executable>bin\AutoUpdaterTest.exe</executable>
63+
````
64+
5965
* 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.
6066
* 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.
6167

ZipExtractor/FormMain.cs

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ private void FormMain_Shown(object sender, EventArgs e)
2727
{
2828
string zipPath = null;
2929
string extractionPath = null;
30-
string executablePath = null;
30+
string currentExe = null;
31+
string updatedExe = null;
3132
bool clearAppDirectory = false;
3233
string commandLineArgs = null;
3334

@@ -47,8 +48,11 @@ private void FormMain_Shown(object sender, EventArgs e)
4748
case "--output":
4849
extractionPath = args[index + 1];
4950
break;
50-
case "--executable":
51-
executablePath = args[index + 1];
51+
case "--current-exe":
52+
currentExe = args[index + 1];
53+
break;
54+
case "--updated-exe":
55+
updatedExe = args[index + 1];
5256
break;
5357
case "--clear":
5458
clearAppDirectory = true;
@@ -62,7 +66,7 @@ private void FormMain_Shown(object sender, EventArgs e)
6266

6367
_logBuilder.AppendLine();
6468

65-
if (string.IsNullOrEmpty(zipPath) || string.IsNullOrEmpty(extractionPath) || string.IsNullOrEmpty(executablePath))
69+
if (string.IsNullOrEmpty(zipPath) || string.IsNullOrEmpty(extractionPath) || string.IsNullOrEmpty(currentExe))
6670
{
6771
return;
6872
}
@@ -76,11 +80,11 @@ private void FormMain_Shown(object sender, EventArgs e)
7680

7781
_backgroundWorker.DoWork += (_, eventArgs) =>
7882
{
79-
foreach (var process in Process.GetProcessesByName(Path.GetFileNameWithoutExtension(executablePath)))
83+
foreach (var process in Process.GetProcessesByName(Path.GetFileNameWithoutExtension(currentExe)))
8084
{
8185
try
8286
{
83-
if (process.MainModule is { FileName: { } } && process.MainModule.FileName.Equals(executablePath))
87+
if (process.MainModule is { FileName: { } } && process.MainModule.FileName.Equals(currentExe))
8488
{
8589
_logBuilder.AppendLine("Waiting for application process to exit...");
8690

@@ -96,11 +100,11 @@ private void FormMain_Shown(object sender, EventArgs e)
96100

97101
_logBuilder.AppendLine("BackgroundWorker started successfully.");
98102

99-
// Ensures that the last character on the extraction path
100-
// is the directory separator char.
101-
// Without this, a malicious zip file could try to traverse outside of the expected
102-
// extraction path.
103-
if (!extractionPath.EndsWith(Path.DirectorySeparatorChar.ToString(), StringComparison.Ordinal))
103+
// Ensures that the last character on the extraction path
104+
// is the directory separator char.
105+
// Without this, a malicious zip file could try to traverse outside of the expected
106+
// extraction path.
107+
if (!extractionPath.EndsWith(Path.DirectorySeparatorChar.ToString(), StringComparison.Ordinal))
104108
{
105109
extractionPath += Path.DirectorySeparatorChar;
106110
}
@@ -156,9 +160,16 @@ private void FormMain_Shown(object sender, EventArgs e)
156160
if (!entry.IsDirectory())
157161
{
158162
var parentDirectory = Path.GetDirectoryName(filePath);
159-
if (!Directory.Exists(parentDirectory))
163+
if (parentDirectory != null)
164+
{
165+
if (!Directory.Exists(parentDirectory))
166+
{
167+
Directory.CreateDirectory(parentDirectory);
168+
}
169+
}
170+
else
160171
{
161-
Directory.CreateDirectory(parentDirectory);
172+
throw new ArgumentNullException($"parentDirectory is null for \"{filePath}\"!");
162173
}
163174
using (Stream destination = File.Open(filePath, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None))
164175
{
@@ -193,8 +204,8 @@ private void FormMain_Shown(object sender, EventArgs e)
193204
}
194205
catch (Exception)
195206
{
196-
// ignored
197-
}
207+
// ignored
208+
}
198209
}
199210

200211
if (lockingProcesses == null)
@@ -261,6 +272,7 @@ private void FormMain_Shown(object sender, EventArgs e)
261272
textBoxInformation.Text = @"Finished";
262273
try
263274
{
275+
var executablePath = updatedExe != null ? Path.Combine(extractionPath, updatedExe) : currentExe;
264276
ProcessStartInfo processStartInfo = new ProcessStartInfo(executablePath);
265277
if (!string.IsNullOrEmpty(commandLineArgs))
266278
{

ZipExtractor/ZipExtractor.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
<Company>RBSoft</Company>
1010
<Product>ZipExtractor</Product>
1111
<Copyright>Copyright © 2012-2023 RBSoft</Copyright>
12-
<Version>1.3.3.0</Version>
13-
<AssemblyVersion>1.3.3.0</AssemblyVersion>
14-
<FileVersion>1.3.3.0</FileVersion>
15-
<ApplicationVersion>1.3.3.0</ApplicationVersion>
12+
<Version>1.4.0.0</Version>
13+
<AssemblyVersion>1.4.0.0</AssemblyVersion>
14+
<FileVersion>1.4.0.0</FileVersion>
15+
<ApplicationVersion>1.4.0.0</ApplicationVersion>
1616
<ApplicationIcon>ZipExtractor.ico</ApplicationIcon>
1717
<ApplicationManifest>app.manifest</ApplicationManifest>
1818
<SignAssembly>true</SignAssembly>

appveyor.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
version: 1.7.8.{build}
1+
version: 1.8.0.{build}
22
environment:
3-
my_version: 1.7.8
3+
my_version: 1.8.0
44
my_secret:
55
secure: vbPRaZLQYpGPr4BrZZ4p6TofpSZMud+FKtlpqjgO8aA=
66
skip_branch_with_pr: true

0 commit comments

Comments
 (0)