From d7fe3edbfa10fdc8ef8eb4d391c0bcd6a75967b2 Mon Sep 17 00:00:00 2001 From: Caelan Sayler Date: Wed, 27 Mar 2024 17:03:59 +0000 Subject: [PATCH] Add IsPortable flag to update manager --- .../Commands/WindowsPackCommandRunner.cs | 3 +++ src/Velopack/Locators/IVelopackLocator.cs | 8 ++++++++ src/Velopack/Locators/VelopackLocator.cs | 3 +++ src/Velopack/Locators/WindowsVelopackLocator.cs | 4 ++++ src/Velopack/UpdateManager.cs | 3 +++ 5 files changed, 21 insertions(+) diff --git a/src/Velopack.Packaging.Windows/Commands/WindowsPackCommandRunner.cs b/src/Velopack.Packaging.Windows/Commands/WindowsPackCommandRunner.cs index f7b3f6d6..fd3fa69c 100644 --- a/src/Velopack.Packaging.Windows/Commands/WindowsPackCommandRunner.cs +++ b/src/Velopack.Packaging.Windows/Commands/WindowsPackCommandRunner.cs @@ -171,6 +171,9 @@ public class WindowsPackCommandRunner : PackageBuilder var stubName = (Options.PackTitle ?? Options.PackId) + ".exe"; File.Move(stubPath, Path.Combine(dir.FullName, stubName)); + // create a .portable file to indicate this is a portable package + File.Create(Path.Combine(dir.FullName, ".portable")).Close(); + await EasyZip.CreateZipFromDirectoryAsync(Log, outputPath, dir.FullName, Utility.CreateProgressDelegate(progress, 40, 100)); progress(100); } diff --git a/src/Velopack/Locators/IVelopackLocator.cs b/src/Velopack/Locators/IVelopackLocator.cs index 9ee2d555..a5df831f 100644 --- a/src/Velopack/Locators/IVelopackLocator.cs +++ b/src/Velopack/Locators/IVelopackLocator.cs @@ -39,6 +39,14 @@ namespace Velopack.Locators /// The release channel this package was built for. public string? Channel { get; } + /// + /// A flag indicating if this is a portable build, and that the settings should be self-contained in the package. + /// On Windows, this is true for portable builds, and false for non-portable builds which were installed by Setup.exe + /// On OSX and Linux, this is always false, because settings and application files should be stored in the user's + /// home directory. + /// + public bool IsPortable { get; } + /// /// Finds .nupkg files in the PackagesDir and returns a list of ReleaseEntryName objects. /// diff --git a/src/Velopack/Locators/VelopackLocator.cs b/src/Velopack/Locators/VelopackLocator.cs index 5a7dce76..a28604ac 100644 --- a/src/Velopack/Locators/VelopackLocator.cs +++ b/src/Velopack/Locators/VelopackLocator.cs @@ -59,6 +59,9 @@ namespace Velopack.Locators /// public abstract string? Channel { get; } + /// + public virtual bool IsPortable => false; + /// public virtual string? ThisExeRelativePath { get { diff --git a/src/Velopack/Locators/WindowsVelopackLocator.cs b/src/Velopack/Locators/WindowsVelopackLocator.cs index c45c651f..f65e6ecf 100644 --- a/src/Velopack/Locators/WindowsVelopackLocator.cs +++ b/src/Velopack/Locators/WindowsVelopackLocator.cs @@ -31,6 +31,10 @@ namespace Velopack.Locators /// public override string? PackagesDir => CreateSubDirIfDoesNotExist(RootAppDir, "packages"); + /// + public override bool IsPortable => + RootAppDir != null ? File.Exists(Path.Combine(RootAppDir, ".portable")) : false; + /// public override string? Channel { get; } diff --git a/src/Velopack/UpdateManager.cs b/src/Velopack/UpdateManager.cs index 448dea29..717225da 100644 --- a/src/Velopack/UpdateManager.cs +++ b/src/Velopack/UpdateManager.cs @@ -24,6 +24,9 @@ namespace Velopack /// True if this application is currently installed, and is able to download/check for updates. public virtual bool IsInstalled => Locator.CurrentlyInstalledVersion != null; + /// + public virtual bool IsPortable => Locator.IsPortable; + /// True if there is a local update prepared that requires a call to to be applied. public virtual bool IsUpdatePendingRestart { get {