Skip to content
Open
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Devolutions.Now.Policy.Api" Version="2026.7.28" />
<PackageReference Include="Devolutions.Now.Policy.Client" Version="2026.7.28" />
<PackageReference Include="Devolutions.Now.Policy.Api" Version="2026.8.5" />
<PackageReference Include="Devolutions.Now.Policy.Client" Version="2026.8.5" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,18 @@ public OperationVeredict GetResult(
IReadOnlyList<string> processOutput,
int returnCode
);

/// <summary>
/// Applies manager-specific elevation requirements for the given operation, e.g. by
/// setting <c>package.OverridenOptions.RunAsAdministrator</c> when the package's
/// installer is known to require elevation. Called before the operation runs, on
/// both the local execution path and the agent-broker path, so that elevation is
/// requested consistently regardless of how the operation is executed.
/// </summary>
public void ApplyElevationRequirements(
IPackage package,
InstallOptions options,
OperationType operation
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,37 @@ operation is OperationType.Uninstall
}
}

ApplyElevationRequirements(package, options, operation);

if (!usePinget)
{
parameters.Add(WinGet.GetProxyArgument());
}

parameters.AddRange(
operation switch
{
OperationType.Update => options.CustomParameters_Update,
OperationType.Uninstall => options.CustomParameters_Uninstall,
_ => options.CustomParameters_Install,
}
);
return parameters;
}

/// <summary>
/// Consults the WinGet native installer metadata to detect packages that require (or
/// prohibit) elevation, and updates <c>package.OverridenOptions.RunAsAdministrator</c>
/// accordingly. Used by both the local execution path (via
/// <see cref="_getOperationParameters"/>) and the agent-broker path, so that the
/// requested elevation matches regardless of where the operation runs.
/// </summary>
public override void ApplyElevationRequirements(
IPackage package,
InstallOptions options,
OperationType operation
)
{
try
{
var installOptions = NativePackageHandler.GetInstallationOptions(
Expand Down Expand Up @@ -212,21 +243,6 @@ or ElevationRequirement.ElevatesSelf
Logger.Error("Recovered from fatal WinGet exception:");
Logger.Error(ex);
}

if (!usePinget)
{
parameters.Add(WinGet.GetProxyArgument());
}

parameters.AddRange(
operation switch
{
OperationType.Update => options.CustomParameters_Update,
OperationType.Uninstall => options.CustomParameters_Uninstall,
_ => options.CustomParameters_Install,
}
);
return parameters;
}

protected override OperationVeredict _getOperationResult(
Expand Down
10 changes: 10 additions & 0 deletions src/UniGetUI.PackageEngine.Operations/AbstractOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,16 @@ protected CancellationToken CancellationToken
}
}

/// <summary>
/// Test hook: installs the cancellation source that MainThread() would normally create,
/// so tests invoking PerformOperation() directly can exercise Cancel().
/// </summary>
internal void SetRunCancellationSourceForTests(CancellationTokenSource source)
{
lock (CancellationLock)
RunCancellationSource = source;
}

private bool TrySetActiveInnerOperation(AbstractOperation operation)
{
bool cancellationRequested;
Expand Down
542 changes: 498 additions & 44 deletions src/UniGetUI.PackageEngine.Operations/PackageOperations.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -158,5 +158,11 @@ public OperationVeredict GetResult(
IReadOnlyList<string> processOutput,
int returnCode
) => throw new NotImplementedException();

public void ApplyElevationRequirements(
IPackage package,
InstallOptions options,
OperationType operation
) => throw new NotImplementedException();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,16 @@ returnCode is 999

return _getOperationResult(package, operation, processOutput, returnCode);
}

/// <summary>
/// Default implementation: no manager-specific elevation requirements. Managers that
/// can detect that a package needs (or prohibits) elevation override this to update
/// <c>package.OverridenOptions.RunAsAdministrator</c> accordingly.
/// </summary>
public virtual void ApplyElevationRequirements(
IPackage package,
InstallOptions options,
OperationType operation
)
{ }
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@ public sealed class TestPackageOperationHelper(TestPackageManager manager)
public Func<IPackage, OperationType, IReadOnlyList<string>, int, OperationVeredict> ResultFactory { get; set; } =
static (_, _, _, returnCode) => returnCode == 0 ? OperationVeredict.Success : OperationVeredict.Failure;

public Action<IPackage, InstallOptions, OperationType>? ElevationRequirementsAction { get; set; }

public override void ApplyElevationRequirements(
IPackage package,
InstallOptions options,
OperationType operation
)
{
ElevationRequirementsAction?.Invoke(package, options, operation);
}

protected override IReadOnlyList<string> _getOperationParameters(
IPackage package,
InstallOptions options,
Expand Down
Loading
Loading