-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInstalledBuild.cs
More file actions
42 lines (37 loc) · 1.23 KB
/
Copy pathInstalledBuild.cs
File metadata and controls
42 lines (37 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using System.Diagnostics;
using System.IO;
using System.Reflection;
namespace DataGateWin.Installer;
internal static class InstalledBuild
{
/// <summary>
/// True if the on-disk main executable was built with the same version as this installer assembly.
/// </summary>
public static bool IsSameAsInstaller(string installedExePath)
{
if (string.IsNullOrWhiteSpace(installedExePath) || !File.Exists(installedExePath))
return false;
var fvi = FileVersionInfo.GetVersionInfo(installedExePath);
var onDisk = TryParseVersion(fvi.FileVersion) ?? TryParseVersion(fvi.ProductVersion);
var asm = Assembly.GetExecutingAssembly().GetName().Version;
if (onDisk is null || asm is null)
return false;
return onDisk.Major == asm.Major
&& onDisk.Minor == asm.Minor
&& onDisk.Build == asm.Build
&& onDisk.Revision == asm.Revision;
}
static Version? TryParseVersion(string? s)
{
if (string.IsNullOrWhiteSpace(s))
return null;
try
{
return new Version(s.Trim());
}
catch
{
return Version.TryParse(s.Trim(), out var v) ? v : null;
}
}
}