Ejemplo n.º 1
0
    /// <inheritdoc/>
    protected override ExitCode ExecuteHelper()
    {
        try
        {
            var appEntry = GetAppEntry(IntegrationManager, ref InterfaceUri);

            if (AdditionalArgs.Count == 2)
            {
                CreateAlias(appEntry, AdditionalArgs[0], _command);
            }
            else if (_command != null)
            {
                throw new OptionException(string.Format(Resources.NoAddCommandWithoutAlias, "--command"), "command");
            }

            if (WindowsUtils.IsWindows && !CatalogManager.GetCachedSafe().ContainsFeed(appEntry.InterfaceUri))
            {
                WindowsUtils.BroadcastMessage(AddedNonCatalogAppWindowMessageID); // Notify Zero Install GUIs of changes
            }
            return(ExitCode.OK);
        }
        #region Error handling
        catch (InvalidOperationException ex)
            // WebException is a subclass of InvalidOperationException but we don't want to catch it here
            when(ex is not WebException)
            { // Application already in AppList
                Handler.OutputLow(Resources.DesktopIntegration, ex.Message);
                return(ExitCode.NoChanges);
            }
        #endregion
    }
Ejemplo n.º 2
0
        /// <inheritdoc/>
        protected override ExitCode ExecuteHelper(ICategoryIntegrationManager integrationManager, FeedUri interfaceUri)
        {
            #region Sanity checks
            if (integrationManager == null)
            {
                throw new ArgumentNullException(nameof(integrationManager));
            }
            if (interfaceUri == null)
            {
                throw new ArgumentNullException(nameof(interfaceUri));
            }
            #endregion

            try
            {
                var entry = CreateAppEntry(integrationManager, ref interfaceUri);

                if (!CatalogManager.GetCachedSafe().ContainsFeed(entry.InterfaceUri))
                {
                    WindowsUtils.BroadcastMessage(AddedNonCatalogAppWindowMessageID); // Notify Zero Install GUIs of changes
                }
                return(ExitCode.OK);
            }
            #region Error handling
            catch (InvalidOperationException ex)
                // WebException is a subclass of InvalidOperationException but we don't want to catch it here
                when(!(ex is WebException))
                { // Application already in AppList
                    Handler.OutputLow(Resources.DesktopIntegration, ex.Message);
                    return(ExitCode.NoChanges);
                }
            #endregion
        }
        /// <inheritdoc/>
        protected override void Finish()
        {
            Log.Debug("Saving AppList to: " + AppListPath);
            // Retry to handle race conditions with read-only access to the file
            ExceptionUtils.Retry <IOException>(delegate { AppList.SaveXml(AppListPath); });

            WindowsUtils.NotifyAssocChanged();                     // Notify Windows Explorer of changes
            WindowsUtils.BroadcastMessage(ChangedWindowMessageID); // Notify Zero Install GUIs of changes
        }
Ejemplo n.º 4
0
        /// <inheritdoc/>
        protected override void Finish()
        {
            try
            {
                Log.Debug("Saving AppList to: " + AppListPath);
                AppList.SaveXml(AppListPath);
            }
            catch (IOException)
            {
                Log.Info("Race condition encountered while saving AppList. Waiting for a moment and then retrying.");
                Thread.Sleep(_random.Next(250, 1500));
                AppList.SaveXml(AppListPath);
            }

            WindowsUtils.NotifyAssocChanged();                     // Notify Windows Explorer of changes
            WindowsUtils.BroadcastMessage(ChangedWindowMessageID); // Notify Zero Install GUIs of changes
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Runs the deployment process.
        /// </summary>
        /// <exception cref="UnauthorizedAccessException">Access to a resource was denied.</exception>
        /// <exception cref="IOException">An IO operation failed.</exception>
        public void Deploy()
        {
            if (TargetDir == Locations.InstallBase)
            {
                throw new InvalidOperationException(string.Format(Resources.SourceAndTargetSame, TargetDir));
            }

            var newManifest = LoadManifest(Locations.InstallBase);

            if (newManifest == null)
            {
                throw new IOException(Resources.MaintenanceMissingManifest);
            }
            var oldManifest = LoadManifest(TargetDir) ?? LegacyManifest;

            if (WindowsUtils.IsWindows && MachineWide)
            {
                ServiceStop();
            }

            try
            {
                TargetMutexAquire();

                using (var clearDir = new ClearDirectory(TargetDir, oldManifest, Handler))
                    using (var deployDir = new DeployDirectory(Locations.InstallBase, newManifest, TargetDir, Handler))
                    {
                        deployDir.Stage();
                        clearDir.Stage();
                        if (Portable)
                        {
                            FileUtils.Touch(Path.Combine(TargetDir, Locations.PortableFlagName));
                        }
                        deployDir.Commit();
                        clearDir.Commit();
                    }

                if (!Portable)
                {
                    DesktopIntegrationApply();

                    if (WindowsUtils.IsWindows)
                    {
                        RegistryApply();
                        WindowsUtils.BroadcastMessage(PerformedWindowMessageID);
                        RemoveOneGetBootstrap();
                    }
                }

                TargetMutexRelease();

                if (WindowsUtils.IsWindows && MachineWide)
                {
                    NgenApply();
                    ServiceInstall();
                    ServiceStart();
                }
            }
            catch
            {
                TargetMutexRelease();
                throw;
            }
        }