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

Commit

Permalink
SetProcessAppUserModelId should not throw (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
caesay committed Mar 9, 2022
1 parent 7aa7372 commit 86d8efe
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
26 changes: 19 additions & 7 deletions src/Squirrel/UpdateManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,15 +190,27 @@ public SemanticVersion CurrentlyInstalledVersion(string executable = null)
/// <inheritdoc/>
public void SetProcessAppUserModelId()
{
var releases = Utility.LoadLocalReleases(Utility.LocalReleaseFileForAppDir(AppDirectory));
var thisRelease = Utility.FindCurrentVersion(releases);

var zf = new ZipPackage(Path.Combine(
Utility.PackageDirectoryForAppDir(AppDirectory),
thisRelease.Filename));
if (_applicationIdOverride == null && !IsInstalledApp) {
// can't set model id if we don't know the package id.
return;
}

var exeName = Path.GetFileName(AssemblyRuntimeInfo.EntryExePath);
var appUserModelId = Utility.GetAppUserModelId(zf.Id, exeName);

string appUserModelId;
if (_applicationIdOverride != null) {
appUserModelId = Utility.GetAppUserModelId(_applicationIdOverride, exeName);
} else {
var releases = Utility.LoadLocalReleases(Utility.LocalReleaseFileForAppDir(AppDirectory));
var thisRelease = Utility.FindCurrentVersion(releases);

var zf = new ZipPackage(Path.Combine(
Utility.PackageDirectoryForAppDir(AppDirectory),
thisRelease.Filename));

appUserModelId = Utility.GetAppUserModelId(zf.Id, exeName);
}

NativeMethods.SetCurrentProcessExplicitAppUserModelID(appUserModelId);
}

Expand Down
10 changes: 10 additions & 0 deletions test/UpdateManagerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,16 @@ public void CurrentlyInstalledVersionDoesNotThrow()
Assert.False(fixture.IsInstalledApp);
}

[Fact]
public void SetModelIdDoesNotThrow()
{
using (var fixture = new UpdateManager(null))
fixture.SetProcessAppUserModelId();

using (var fixture2 = new UpdateManager(null, "TestASD"))
fixture2.SetProcessAppUserModelId();
}

[Theory]
[InlineData(0, 0, 25, 0)]
[InlineData(12, 0, 25, 3)]
Expand Down

0 comments on commit 86d8efe

Please sign in to comment.