Skip to content

Commit 646f0e4

Browse files
authored
fix for runtime error at startup (#5066)
1 parent 6ef60b4 commit 646f0e4

2 files changed

Lines changed: 27 additions & 3 deletions

File tree

‎src/UniGetUI.PackageEngine.Managers.WinGet/WinGet.cs‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -386,10 +386,15 @@ Func<string, bool> fileExists
386386
}
387387

388388
internal IWinGetManagerHelper CreateCliHelperForSelectedCliTool()
389+
{
390+
return CreateCliHelperForSelectedCliTool(Status.ExecutablePath);
391+
}
392+
393+
internal IWinGetManagerHelper CreateCliHelperForSelectedCliTool(string executablePath)
389394
{
390395
return SelectedCliToolKind == WinGetCliToolKind.BundledPinget
391-
? new PingetCliHelper(this, Status.ExecutablePath)
392-
: new WinGetCliHelper(this, Status.ExecutablePath);
396+
? new PingetCliHelper(this, executablePath)
397+
: new WinGetCliHelper(this, executablePath);
393398
}
394399

395400
protected override void _loadManagerExecutableFile(
@@ -449,7 +454,7 @@ ex is WinGetComActivationException activationEx
449454
}
450455

451456
Logger.Warn("WinGet will resort to using WinGetCliHelper()");
452-
WinGetHelper.Instance = CreateCliHelperForSelectedCliTool();
457+
WinGetHelper.Instance = CreateCliHelperForSelectedCliTool(path);
453458
}
454459
}
455460

‎src/UniGetUI.PackageEngine.Tests/WinGetManagerTests.cs‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,25 @@ public void ShouldUseWinGetComApiNeverUsesComForBundledPingetCliTool()
500500
);
501501
}
502502

503+
[Fact]
504+
public void CreateCliHelperForSelectedCliToolUsesExplicitExecutablePath()
505+
{
506+
var manager = new WinGet();
507+
SetCliToolKind(manager, WinGetCliToolKind.SystemWinGet);
508+
509+
IWinGetManagerHelper helper = manager.CreateCliHelperForSelectedCliTool(
510+
@"C:\WindowsApps\winget.exe"
511+
);
512+
513+
var pathField = typeof(WinGetCliHelper).GetField(
514+
"_cliExecutablePath",
515+
System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic
516+
);
517+
518+
Assert.NotNull(pathField);
519+
Assert.Equal(@"C:\WindowsApps\winget.exe", pathField.GetValue(helper));
520+
}
521+
503522
[Fact]
504523
public void NativeWinGetHelperUsesSystemCliFallbackForInstalledPackagesWhenCompositeCatalogFails()
505524
{

0 commit comments

Comments
 (0)