/
Central.cs
42 lines (35 loc) · 1.31 KB
/
Central.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Copyright Bastian Eicher et al.
// Licensed under the GNU Lesser Public License
using NanoByte.Common.Native;
namespace ZeroInstall.Commands.Desktop;
/// <summary>
/// Opens the central graphical user interface for launching and managing applications.
/// </summary>
public class Central : CliCommand
{
public const string Name = "central";
public override string Description => Resources.DescriptionCentral;
public override string Usage => "[OPTIONS] [URI]";
protected override int AdditionalArgsMax => 1;
private bool _machineWide;
/// <inheritdoc/>
public Central(ICommandHandler handler)
: base(handler)
{
Options.Add("m|machine", () => Resources.OptionMachine, _ => _machineWide = true);
}
/// <inheritdoc/>
public override ExitCode Execute()
{
if (_machineWide && WindowsUtils.IsWindows && !WindowsUtils.IsAdministrator)
throw new NotAdminException(Resources.MustBeAdminForMachineWide);
var startInfo = ProcessUtils.Assembly(
"ZeroInstall",
AdditionalArgs is [var uri]
? [GetCanonicalUri(uri).ToStringRfc()]
: _machineWide
? ["--machine"]
: []);
return (ExitCode)startInfo.Run();
}
}