Skip to content
This repository has been archived by the owner on Jul 5, 2024. It is now read-only.

Commit

Permalink
Skip "is installed" check if installing!
Browse files Browse the repository at this point in the history
  • Loading branch information
caesay committed Jun 8, 2022
1 parent 637394a commit 878fb99
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/Squirrel/AppDesc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,9 @@ public class AppDescWindows : AppDesc

/// <inheritdoc />
public override bool IsUpdateExe { get; }

/// <summary> True if Update.exe is currently performing first app install. </summary>
public bool IsInstalling { get; }

/// <inheritdoc />
public override SemanticVersion CurrentlyInstalledVersion { get; }
Expand Down Expand Up @@ -290,14 +293,15 @@ public AppDescWindows() : this(SquirrelRuntimeInfo.EntryExePath)
/// Internal use only. Creates a AppDescWindows from the following rootAppDir and
/// does not perform any path auto-detection.
/// </summary>
internal AppDescWindows(string rootAppDir, string appId)
internal AppDescWindows(string rootAppDir, string appId, bool isInstalling = false)
{
AppId = appId;
RootAppDir = rootAppDir;
var updateExe = Path.Combine(rootAppDir, "Update.exe");
UpdateExePath = updateExe;
IsUpdateExe = Utility.FullPathEquals(updateExe, SquirrelRuntimeInfo.EntryExePath);
CurrentlyInstalledVersion = GetLatestVersion()?.Version;
IsInstalling = isInstalling;
}

/// <summary>
Expand Down
9 changes: 7 additions & 2 deletions src/Squirrel/UpdateManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,15 @@ private static IUpdateSource CreateSource(string urlOrPath, IFileDownloader urlD
return new SimpleFileSource(new DirectoryInfo(urlOrPath));
}
}

private Task<IDisposable> acquireUpdateLock()
{
if (!ModeDetector.InUnitTestRunner() && _config.CurrentlyInstalledVersion == null)
bool installing = false;
if (SquirrelRuntimeInfo.IsWindows) {
installing = (_config as AppDescWindows)?.IsInstalling == true;
}

if (!installing && !ModeDetector.InUnitTestRunner() && _config.CurrentlyInstalledVersion == null)
throw new InvalidOperationException("Cannot perform this operation in a portable app (must be installed first).");

lock (_lockobj) {
Expand Down
2 changes: 1 addition & 1 deletion src/Update.Windows/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ static async Task Install(bool silentInstall, ProgressSource progressSource, str
.First().PackageName;

var rootAppDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), ourAppName);
var appDesc = new AppDescWindows(rootAppDir, ourAppName);
var appDesc = new AppDescWindows(rootAppDir, ourAppName, true);
using var mgr = new UpdateManager(new SimpleFileSource(sourceDi), appDesc);

Log.Info("About to install to: " + rootAppDir);
Expand Down

0 comments on commit 878fb99

Please sign in to comment.