예제 #1
0
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        private static int Main(string[] args)
        {
            ProgramUtils.Init();

            using var handler = new CliCommandHandler();
            return((int)ProgramUtils.Run("0install", args.Prepend(Run.Name), handler));
        }
예제 #2
0
        /// <summary>
        /// Checks the current <see cref="Locations.InstallBase"/> to determine whether it is suitable for operations that persist it.
        /// </summary>
        /// <remarks>
        /// This should be called before performing any operations that persist <see cref="Locations.InstallBase"/> somewhere, e.g. in generated shortcuts or stubs.
        /// It is not required for operations that only remove things from the system.
        /// </remarks>
        /// <exception cref="UnsuitableInstallBaseException">The current Zero Install instance is installed in a location unsuitable for the desired operation.</exception>
        protected void CheckInstallBase()
        {
            if (Locations.IsPortable)
            {
                // NOTE: Portable instances remain decoupled from local instances, so we do not use UnsuitableInstallBaseException here, which would redirect commands to other instances.
                if (Handler.Ask(Resources.AskDeployZeroInstall + Environment.NewLine + Resources.NoIntegrationFromPortable,
                                defaultAnswer: false, alternateMessage: Resources.NoIntegrationFromPortable))
                {
                    var deployArgs = new[] { MaintenanceMan.Name, MaintenanceMan.Deploy.Name, "--restart-central" };
                    if (MachineWide)
                    {
                        deployArgs = deployArgs.Append("--machine");
                    }
                    ProgramUtils.Run("0install", deployArgs, Handler);
                }
                throw new OperationCanceledException();
            }

            if (ProgramUtils.IsRunningFromCache)
            {
                throw new UnsuitableInstallBaseException(Resources.NoIntegrationFromCache, MachineWide);
            }
            if (MachineWide && ProgramUtils.IsRunningFromPerUserDir)
            {
                throw new UnsuitableInstallBaseException(Resources.NoMachineWideIntegrationFromPerUser, MachineWide);
            }
        }
예제 #3
0
        /// <summary>
        /// Executes a "0install-win" command in-process in a new thread. Returns immediately.
        /// </summary>
        /// <param name="callback">A callback method to be raised once the command has finished executing. Uses <see cref="SynchronizationContext"/> of calling thread. Can be <c>null</c>.</param>
        /// <param name="machineWide">Appends --machine to <paramref name="args"/> if <c>true</c>.</param>
        /// <param name="args">Command name with arguments to execute.</param>
        internal static void RunCommand(Action?callback, bool machineWide, params string[] args)
        {
            if (machineWide)
            {
                args = args.Append("--machine");
            }

            var context = SynchronizationContext.Current;

            ThreadUtils.StartAsync(
                () =>
            {
                Log.Debug($"Launching {Commands.WinForms.Program.ExeName} in-process with arguments: {args.JoinEscapeArguments()}");
                using (var handler = new GuiCommandHandler())
                    ProgramUtils.Run(Commands.WinForms.Program.ExeName, args, handler);

                if (callback != null)
                {
                    try
                    {
                        context.Send(state => callback(), null);
                    }
                    catch (InvalidAsynchronousStateException)
                    {
                        // Ignore callback if UI was closed in the meantime
                    }
                }
            },
                "0install-win (" + args.JoinEscapeArguments() + ")");
        }
예제 #4
0
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        private static int Main(string[] args)
        {
            ProgramUtils.Init();

            using var handler = new CliCommandHandler();
            return((int)ProgramUtils.Run(ExeName, args, handler));
        }
예제 #5
0
    /// <summary>
    /// Checks the current <see cref="Locations.InstallBase"/> to determine whether it is suitable for operations that persist it.
    /// </summary>
    /// <remarks>
    /// This should be called before performing any operations that persist <see cref="Locations.InstallBase"/> somewhere, e.g. in generated shortcuts or stubs.
    /// It is not required for operations that only remove things from the system.
    /// </remarks>
    /// <exception cref="UnsuitableInstallBaseException">The current Zero Install instance is installed in a location unsuitable for the desired operation.</exception>
    protected void CheckInstallBase()
    {
        if (Locations.IsPortable)
        {
            Log.Warn(Resources.NoIntegrationFromPortable);

            if (Handler.Verbosity != Verbosity.Batch)
            {
                string[] deployArgs = MachineWide
                    ? new[] { Self.AltName, Self.Deploy.Name, "--restart-central", "--machine" }
                    : new[] { Self.AltName, Self.Deploy.Name, "--restart-central" };
                ProgramUtils.Run(ProgramUtils.CliAssemblyName, deployArgs, Handler);
            }

            // NOTE: Portable instances remain decoupled from local instances, so we do not use UnsuitableInstallBaseException here, which would redirect commands to other instances.
            throw new OperationCanceledException();
        }

        if (!ZeroInstallInstance.IsDeployed)
        {
            throw new UnsuitableInstallBaseException(Resources.NoIntegrationDeployRequired, MachineWide);
        }
        if (MachineWide && !ZeroInstallInstance.IsMachineWide)
        {
            throw new UnsuitableInstallBaseException(Resources.NoMachineWideIntegrationFromPerUser, MachineWide);
        }
    }
예제 #6
0
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        private static int Main(string[] args)
        {
            ProgramUtils.Init();
            Application.Init();

            using (var handler = new GuiCommandHandler())
                return((int)ProgramUtils.Run(ExeName, args, handler));
        }
예제 #7
0
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        // NOTE: No [STAThread] here, because it could block .NET remoting callbacks
        private static int Main(string[] args)
        {
            ProgramUtils.Init();
            WindowsUtils.SetCurrentProcessAppID("ZeroInstall");
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            ErrorReportForm.SetupMonitoring(new Uri("https://0install.de/error-report/"));

            using var handler = new GuiCommandHandler();
            return((int)ProgramUtils.Run(ExeName, args, handler));
        }
예제 #8
0
        /// <summary>
        /// Executes a "0install-win" command in-process in a new thread. Returns immediately.
        /// </summary>
        /// <param name="machineWide">Appends --machine to <paramref name="args"/> if <c>true</c>.</param>
        /// <param name="args">Command name with arguments to execute.</param>
        internal static Task RunCommandAsync(bool machineWide, params string[] args)
        {
            if (machineWide)
            {
                args = args.Append("--machine");
            }

            return(Task.Run(() => ThreadUtils.RunSta(() =>
            {
                Log.Debug($"Launching {Commands.WinForms.Program.ExeName} in-process with arguments: {args.JoinEscapeArguments()}");
                using var handler = new GuiCommandHandler();
                ProgramUtils.Run(Commands.WinForms.Program.ExeName, args, handler);
            })));
        }
예제 #9
0
        /// <summary>
        /// Executes a "0install-win" command in-process in a new thread. Returns immediately.
        /// </summary>
        /// <param name="machineWide">Appends --machine to <paramref name="args"/> if <c>true</c>.</param>
        /// <param name="args">Command name with arguments to execute.</param>
        internal static Task <ExitCode> RunCommandAsync(bool machineWide, params string[] args)
        {
            if (machineWide)
            {
                args = args.Append("--machine");
            }

            return(Task.Run(() => ThreadUtils.RunSta(() =>
            {
                Log.Debug($"Launching 0install-win in-process with arguments: {args.JoinEscapeArguments()}");
                using var handler = new GuiCommandHandler();
                return ProgramUtils.Run("0install-win", args, handler);
            })));
        }
예제 #10
0
        /// <summary>
        /// Executes a "0install-win" command in-process in a new thread. Returns immediately.
        /// </summary>
        /// <param name="callback">A callback method to be raised once the command has finished executing. Uses <see cref="SynchronizationContext"/> of calling thread. Can be <c>null</c>.</param>
        /// <param name="machineWide">Appends --machine to <paramref name="args"/> if <c>true</c>.</param>
        /// <param name="args">Command name with arguments to execute.</param>
        internal static void RunCommand([CanBeNull] Action callback, bool machineWide, [NotNull] params string[] args)
        {
            args = machineWide ? args.Append("--machine") : args;

            var context = SynchronizationContext.Current;

            ThreadUtils.StartAsync(
                () =>
            {
                Log.Debug("Launching " + Commands.WinForms.Program.ExeName + " in-process with arguments: " + args.JoinEscapeArguments());
                using (var handler = new GuiCommandHandler())
                    ProgramUtils.Run(Commands.WinForms.Program.ExeName, args, handler);

                if (callback != null)
                {
                    context.Send(state => callback(), null);
                }
            },
                "0install-win (" + args.JoinEscapeArguments() + ")");
        }