Manages an AppList and desktop integration via AccessPoints.
To prevent race-conditions there may only be one desktop integration class instance active at any given time. This class acquires a mutex upon calling its constructor and releases it upon calling IDisposable.Dispose.
Inheritance: IntegrationManagerBase
Example #1
0
        /// <inheritdoc/>
        public override ExitCode Execute()
        {
            using (var integrationManager = new IntegrationManager(Handler, MachineWide))
                integrationManager.Repair(FeedManager.GetFeed);

            return ExitCode.OK;
        }
Example #2
0
        /// <inheritdoc/>
        public override ExitCode Execute()
        {
            CheckInstallBase();

            using (var integrationManager = new IntegrationManager(Handler, MachineWide))
                integrationManager.Repair(FeedManager.GetFresh);

            return ExitCode.OK;
        }
Example #3
0
        /// <summary>
        /// Removes all applications from the <see cref="AppList"/> and undoes any desktop environment integration.
        /// </summary>
        /// <param name="handler">A callback object used when the the user is to be informed about the progress of long-running operations such as downloads.</param>
        /// <param name="machineWide">Apply the operation machine-wide instead of just for the current user.</param>
        public static void RemoveAllApps(ITaskHandler handler, bool machineWide)
        {
            #region Sanity checks
            if (handler == null) throw new ArgumentNullException(nameof(handler));
            #endregion

            using (var integrationManager = new IntegrationManager(handler, machineWide))
            {
                handler.RunTask(ForEachTask.Create(Resources.RemovingApplications, integrationManager.AppList.Entries.ToList(), integrationManager.RemoveApp));

                // Purge sync status, otherwise next sync would remove everything from server as well instead of restoring from there
                File.Delete(AppList.GetDefaultPath(machineWide) + SyncIntegrationManager.AppListLastSyncSuffix);
            }
        }
Example #4
0
        /// <inheritdoc/>
        public override ExitCode Execute()
        {
            var importList = XmlStorage.LoadXml<AppList>(AdditionalArgs[0]);

            using (var integrationManager = new IntegrationManager(Handler, MachineWide))
            {
                foreach (var importEntry in importList.Entries)
                {
                    var interfaceUri = importEntry.InterfaceUri;
                    var appEntry = GetAppEntry(integrationManager, ref interfaceUri);

                    if (importEntry.AccessPoints != null)
                    {
                        var feed = FeedManager[interfaceUri];
                        integrationManager.AddAccessPoints(appEntry, feed, importEntry.AccessPoints.Entries);
                    }
                }
            }

            return ExitCode.OK;
        }
Example #5
0
        /// <summary>
        /// Resolves or removes existing aliases.
        /// </summary>
        /// <param name="aliasName">The name of the existing alias.</param>
        /// <returns>The exit status code to end the process with.</returns>
        private ExitCode ResolveOrRemove(string aliasName)
        {
            using (var integrationManager = new IntegrationManager(Handler, MachineWide))
            {
                AppEntry appEntry;
                var appAlias = GetAppAlias(integrationManager.AppList, aliasName, out appEntry);
                if (appAlias == null)
                {
                    Handler.Output(Resources.AppAlias, string.Format(Resources.AliasNotFound, aliasName));
                    return ExitCode.InvalidArguments;
                }

                if (_resolve)
                {
                    string result = appEntry.InterfaceUri.ToStringRfc();
                    if (!string.IsNullOrEmpty(appAlias.Command)) result += Environment.NewLine + "Command: " + appAlias.Command;
                    Handler.OutputLow(Resources.AppAlias, result);
                }
                if (_remove)
                {
                    integrationManager.RemoveAccessPoints(appEntry, new AccessPoint[] {appAlias});

                    Handler.OutputLow(Resources.AppAlias, string.Format(Resources.AliasRemoved, aliasName, appEntry.Name));
                }
                return ExitCode.OK;
            }
        }
Example #6
0
        /// <summary>
        /// Creates a new alias.
        /// </summary>
        /// <param name="aliasName">The name of the alias to create.</param>
        /// <param name="interfaceUri">The interface URI the alias shall point to.</param>
        /// <param name="command">A command within the interface the alias shall point to; can be <c>null</c>.</param>
        /// <returns>The exit status code to end the process with.</returns>
        private ExitCode CreateAlias(string aliasName, FeedUri interfaceUri, string command = null)
        {
            CheckInstallBase();

            using (var integrationManager = new IntegrationManager(Handler, MachineWide))
            {
                // Check this before modifying the environment
                bool needsReopenTerminal = NeedsReopenTerminal(integrationManager.MachineWide);

                var appEntry = GetAppEntry(integrationManager, ref interfaceUri);

                // Apply the new alias
                var alias = new AppAlias {Name = aliasName, Command = command};
                integrationManager.AddAccessPoints(appEntry, FeedManager[interfaceUri], new AccessPoint[] {alias});

                string message = string.Format(Resources.AliasCreated, aliasName, appEntry.Name);
                if (needsReopenTerminal) message += Environment.NewLine + Resources.ReopenTerminal;
                Handler.OutputLow(Resources.DesktopIntegration, message);
                return ExitCode.OK;
            }
        }
 public void SetUp()
 {
     _appListFile = new TemporaryFile("0install-unit-tests");
     new AppList().SaveXml(_appListFile);
     _integrationManager = new IntegrationManager(_appListFile, new MockTaskHandler());
 }
        public void UninstallPackage([NotNull] string fastPackageReference)
        {
            var requirements = ParseReference(fastPackageReference);

            using (var integrationManager = new IntegrationManager(Handler, _machineWide))
                integrationManager.RemoveApp(integrationManager.AppList[requirements.InterfaceUri]);
        }
 public IntegrationManagerTest()
 {
     _integrationManager = new IntegrationManager(new Config(), new MockTaskHandler());
 }
Example #10
0
 public void SetUp()
 {
     _appListFile = new TemporaryFile("0install-unit-tests");
     new AppList().SaveXml(_appListFile);
     _integrationManager = new IntegrationManager(_appListFile, new MockTaskHandler());
 }
Example #11
0
        /// <inheritdoc/>
        public override ExitCode Execute()
        {
            using (var integrationManager = new IntegrationManager(Handler, MachineWide))
            {
                if (integrationManager.AppList.Entries.Count == 0) return ExitCode.OK;

                if (Handler.Ask(Resources.ConfirmRemoveAll, defaultAnswer: true))
                {
                    Handler.RunTask(new ForEachTask<AppEntry>(Resources.RemovingApplications, integrationManager.AppList.Entries.ToList(), integrationManager.RemoveApp));

                    // Purge sync status, otherwise next sync would remove everything from server as well instead of restoring from there
                    File.Delete(AppList.GetDefaultPath(MachineWide) + SyncIntegrationManager.AppListLastSyncSuffix);
                }
                else throw new OperationCanceledException();
            }

            return ExitCode.OK;
        }
Example #12
0
        public void UninstallPackage(string fastPackageReference)
        {
            if (MachineWide && !WindowsUtils.IsAdministrator) throw new NotAdminException(Resources.MustBeAdminForMachineWide);

            var requirements = ParseReference(fastPackageReference);

            using (var integrationManager = new IntegrationManager(Handler, MachineWide))
                integrationManager.RemoveApp(integrationManager.AppList[requirements.InterfaceUri]);
        }