diff --git a/src/lib-csharp/Locators/LinuxVelopackLocator.cs b/src/lib-csharp/Locators/LinuxVelopackLocator.cs index 6fddf4d0..7eb921b8 100644 --- a/src/lib-csharp/Locators/LinuxVelopackLocator.cs +++ b/src/lib-csharp/Locators/LinuxVelopackLocator.cs @@ -47,6 +47,12 @@ namespace Velopack.Locators /// File path of the .AppImage which mounted and ran this application. public string? AppImagePath => Environment.GetEnvironmentVariable("APPIMAGE"); + + /// + public override uint ProcessId { get; } + + /// + public override string ProcessExePath { get; } /// /// Creates a new and auto-detects the @@ -59,18 +65,18 @@ namespace Velopack.Locators throw new NotSupportedException("Cannot instantiate LinuxVelopackLocator on a non-linux system."); ProcessId = currentProcessId; - ProcessExePath = currentProcessPath; + var ourPath = ProcessExePath = currentProcessPath; Log.Info($"Initialising {nameof(LinuxVelopackLocator)}"); // are we inside a mounted .AppImage? - var ix = ProcessExePath.IndexOf("/usr/bin/", StringComparison.InvariantCultureIgnoreCase); + var ix = ourPath.IndexOf("/usr/bin/", StringComparison.InvariantCultureIgnoreCase); if (ix <= 0) { - Log.Warn($"Unable to locate .AppImage root from '{ProcessExePath}'. This warning indicates that the application is not running from a mounted .AppImage, for example during development."); + Log.Warn($"Unable to locate .AppImage root from '{ourPath}'. This warning indicates that the application is not running from a mounted .AppImage, for example during development."); return; } - var rootDir = ProcessExePath.Substring(0, ix); + var rootDir = ourPath.Substring(0, ix); var contentsDir = Path.Combine(rootDir, "usr", "bin"); var updateExe = Path.Combine(contentsDir, "UpdateNix"); var metadataPath = Path.Combine(contentsDir, CoreUtil.SpecVersionFileName); diff --git a/src/lib-csharp/Locators/OsxVelopackLocator.cs b/src/lib-csharp/Locators/OsxVelopackLocator.cs index e15db6bb..78b44263 100644 --- a/src/lib-csharp/Locators/OsxVelopackLocator.cs +++ b/src/lib-csharp/Locators/OsxVelopackLocator.cs @@ -44,6 +44,12 @@ namespace Velopack.Locators /// public override string? Channel { get; } + + /// + public override uint ProcessId { get; } + + /// + public override string ProcessExePath { get; } /// /// Creates a new and auto-detects the @@ -56,18 +62,18 @@ namespace Velopack.Locators throw new NotSupportedException("Cannot instantiate OsxLocator on a non-osx system."); ProcessId = currentProcessId; - ProcessExePath = currentProcessPath; + var ourPath = ProcessExePath = currentProcessPath; Log.Info($"Initialising {nameof(OsxVelopackLocator)}"); // are we inside a .app? - var ix = ProcessExePath.IndexOf(".app/", StringComparison.InvariantCultureIgnoreCase); + var ix = ourPath.IndexOf(".app/", StringComparison.InvariantCultureIgnoreCase); if (ix <= 0) { - Log.Warn($"Unable to locate .app root from '{ProcessExePath}'"); + Log.Warn($"Unable to locate .app root from '{ourPath}'"); return; } - var appPath = ProcessExePath.Substring(0, ix + 4); + var appPath = ourPath.Substring(0, ix + 4); var contentsDir = Path.Combine(appPath, "Contents"); var macosDir = Path.Combine(contentsDir, "MacOS"); var updateExe = Path.Combine(macosDir, "UpdateMac"); diff --git a/src/lib-csharp/Locators/TestVelopackLocator.cs b/src/lib-csharp/Locators/TestVelopackLocator.cs index a08bf13c..a2c2aaa5 100644 --- a/src/lib-csharp/Locators/TestVelopackLocator.cs +++ b/src/lib-csharp/Locators/TestVelopackLocator.cs @@ -2,6 +2,7 @@ using System.Diagnostics.CodeAnalysis; using Microsoft.Extensions.Logging; using NuGet.Versioning; +#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member namespace Velopack.Locators { @@ -13,7 +14,6 @@ namespace Velopack.Locators [ExcludeFromCodeCoverage] public class TestVelopackLocator : VelopackLocator { - /// public override string? AppId { get { if (_id == null) { @@ -23,7 +23,6 @@ namespace Velopack.Locators } } - /// public override string? RootAppDir { get { if (_root == null) { @@ -33,7 +32,6 @@ namespace Velopack.Locators } } - /// public override string? PackagesDir { get { if (_packages == null) { @@ -43,7 +41,6 @@ namespace Velopack.Locators } } - /// public override string? UpdateExePath { get { if (_updatePath == null) { @@ -53,7 +50,6 @@ namespace Velopack.Locators } } - /// public override SemanticVersion? CurrentlyInstalledVersion { get { if (_version == null) { @@ -63,7 +59,6 @@ namespace Velopack.Locators } } - /// public override string? AppContentDir { get { if (_appContent == null) { @@ -73,14 +68,12 @@ namespace Velopack.Locators } } - /// public override string? Channel { get { return _channel; } } - /// public override VelopackAsset? GetLatestLocalFullPackage() { if (_asset != null) { @@ -89,6 +82,10 @@ namespace Velopack.Locators return base.GetLatestLocalFullPackage(); } + public override uint ProcessId => 0; + + public override string ProcessExePath { get; } + private readonly string? _updatePath; private readonly SemanticVersion? _version; private readonly string? _packages; @@ -106,7 +103,7 @@ namespace Velopack.Locators /// public TestVelopackLocator(string appId, string version, string packagesDir, string? appDir, - string? rootDir, string? updateExe, string? channel = null, ILogger? logger = null, VelopackAsset? localPackage = null) + string? rootDir, string? updateExe, string? channel = null, ILogger? logger = null, VelopackAsset? localPackage = null, string processPath = null!) : base(logger) { _id = appId; @@ -117,6 +114,7 @@ namespace Velopack.Locators _appContent = appDir; _channel = channel; _asset = localPackage; + ProcessExePath = processPath; } } } diff --git a/src/lib-csharp/Locators/VelopackLocator.cs b/src/lib-csharp/Locators/VelopackLocator.cs index 17cd3b67..14d7bb2a 100644 --- a/src/lib-csharp/Locators/VelopackLocator.cs +++ b/src/lib-csharp/Locators/VelopackLocator.cs @@ -66,13 +66,13 @@ namespace Velopack.Locators public abstract string? Channel { get; } /// - public virtual bool IsPortable => false; - - /// - public uint ProcessId { get; protected set; } + public abstract uint ProcessId { get; } /// - public string ProcessExePath { get; protected set; } + public abstract string ProcessExePath { get; } + + /// + public virtual bool IsPortable => false; /// public virtual string? ThisExeRelativePath { diff --git a/src/lib-csharp/Locators/WindowsVelopackLocator.cs b/src/lib-csharp/Locators/WindowsVelopackLocator.cs index 3b4c9b52..72939e07 100644 --- a/src/lib-csharp/Locators/WindowsVelopackLocator.cs +++ b/src/lib-csharp/Locators/WindowsVelopackLocator.cs @@ -38,6 +38,12 @@ namespace Velopack.Locators /// public override string? Channel { get; } + /// + public override uint ProcessId { get; } + + /// + public override string ProcessExePath { get; } + /// public WindowsVelopackLocator(string currentProcessPath, uint currentProcessId, ILogger logger) : base(logger) @@ -46,7 +52,7 @@ namespace Velopack.Locators throw new NotSupportedException("Cannot instantiate WindowsLocator on a non-Windows system."); ProcessId = currentProcessId; - ProcessExePath = currentProcessPath; + var ourPath = ProcessExePath = currentProcessPath; // We try various approaches here. Firstly, if Update.exe is in the parent directory, // we use that. If it's not present, we search for a parent "current" or "app-{ver}" directory, @@ -54,11 +60,11 @@ namespace Velopack.Locators // There is some legacy code here, because it's possible that we're running in an "app-{ver}" // directory which is NOT containing a sq.version, in which case we need to infer a lot of info. - ProcessExePath = Path.GetFullPath(ProcessExePath); - string myDirPath = Path.GetDirectoryName(ProcessExePath)!; + ProcessExePath = Path.GetFullPath(ourPath); + string myDirPath = Path.GetDirectoryName(ourPath)!; var myDirName = Path.GetFileName(myDirPath); var possibleUpdateExe = Path.GetFullPath(Path.Combine(myDirPath, "..", "Update.exe")); - var ixCurrent = ProcessExePath.LastIndexOf("/current/", StringComparison.InvariantCultureIgnoreCase); + var ixCurrent = ourPath.LastIndexOf("/current/", StringComparison.InvariantCultureIgnoreCase); Log.Info($"Initializing {nameof(WindowsVelopackLocator)}"); @@ -86,7 +92,7 @@ namespace Velopack.Locators } } else if (ixCurrent > 0) { // this is an attempt to handle the case where we are running in a nested current directory. - var rootDir = ProcessExePath.Substring(0, ixCurrent); + var rootDir = ourPath.Substring(0, ixCurrent); var currentDir = Path.Combine(rootDir, "current"); var manifestFile = Path.Combine(currentDir, CoreUtil.SpecVersionFileName); possibleUpdateExe = Path.GetFullPath(Path.Combine(rootDir, "Update.exe"));