Пример #1
0
    /// <summary>
    /// Tries to fulfill the specified <paramref name="demand"/>. Adds the result to <see cref="Selections"/> if successful.
    /// </summary>
    /// <returns><c>true</c> if the demand could be met, <c>false</c> if not.</returns>
    protected bool TryFulfill(SolverDemand demand)
    {
        var candidates = GetCompatibleCandidates(demand);

        var existingSelection = Selections.GetImplementation(demand.Requirements.InterfaceUri);

        if (existingSelection == null)
        { // Try to make new selection
            return(TryFulfill(demand, candidates));
        }
        else
        { // Try to use existing selection
            // Ensure existing selection is one of the compatible candidates
            if (candidates.All(x => x.Implementation.ID != existingSelection.ID))
            {
                return(false);
            }

            if (!existingSelection.ContainsCommand(demand.Requirements.Command ?? Command.NameRun))
            { // Add additional command to selection if needed
                var command = existingSelection.AddCommand(demand.Requirements, from: CandidateProvider.LookupOriginalImplementation(existingSelection));
                return((command == null) || TryFulfill(DemandsFor(command, demand.Requirements.InterfaceUri)));
            }
            return(true);
        }
    }
Пример #2
0
        /// <summary>
        /// Shows a list of changes found by the update process.
        /// </summary>
        protected override ExitCode ShowOutput()
        {
            var builder = new StringBuilder();

            foreach (var oldImplementation in _oldSelections.Implementations)
            {
                var interfaceUri = oldImplementation.InterfaceUri;

                var newImplementation = Selections.GetImplementation(interfaceUri);
                if (newImplementation == null)
                { // Implementation removed
                    builder.AppendLine(Resources.NoLongerUsed + interfaceUri);
                }
                else if (oldImplementation.Version != newImplementation.Version)
                { // Implementation updated
                    builder.AppendLine(interfaceUri + ": " + oldImplementation.Version + " -> " + newImplementation.Version);
                }
            }
            foreach (var newImplementation in Selections.Implementations)
            {
                var interfaceUri = newImplementation.InterfaceUri;
                if (!_oldSelections.ContainsImplementation(interfaceUri))
                { // Implementation added
                    builder.AppendLine(interfaceUri + ": new -> " + newImplementation.Version);
                }
            }

            // Detect replaced feeds
            try
            {
                var feed = FeedCache.GetFeed(Requirements.InterfaceUri);
                if (feed.ReplacedBy != null)
                {
                    builder.AppendLine(string.Format(Resources.FeedReplaced, Requirements.InterfaceUri, feed.ReplacedBy.Target));
                }
            }
            catch (KeyNotFoundException)
            {
            }

            if (builder.Length == 0)
            {
                Handler.OutputLow(Resources.NoUpdatesFound, Resources.NoUpdatesFound);
                return(ExitCode.NoChanges);
            }
            else
            {
                Handler.Output(Resources.ChangesFound, builder.ToString());
                return(ExitCode.OK);
            }
        }
Пример #3
0
        private static void ApplyVersionRestrictions(Requirements requirements, Selections selections)
        {
            if (requirements.ExtraRestrictions.Count == 0)
            {
                return;
            }

            // TODO
            Log.Warn($"You have applied a version restriction to this app. Zero Install will continue to apply this restriction to any future updates. You will need to run '0install select --customize {requirements.InterfaceUri}' to undo this.");

            foreach (var restriction in requirements.ExtraRestrictions)
            {
                var selection = selections.GetImplementation(restriction.Key);
                if (selection != null)
                {
                    var pref = FeedPreferences.LoadForSafe(restriction.Key);
                    pref.Implementations.Clear();
                    pref[selection.ID].UserStability = Stability.Preferred;
                    pref.SaveFor(restriction.Key);
                }
            }
        }
Пример #4
0
    /// <inheritdoc/>
    public IEnumerable <SelectionsDiffNode> GetDiff(Selections oldSelections, Selections newSelections)
    {
        #region Sanity checks
        if (oldSelections == null)
        {
            throw new ArgumentNullException(nameof(oldSelections));
        }
        if (newSelections == null)
        {
            throw new ArgumentNullException(nameof(newSelections));
        }
        #endregion

        foreach (var newImplementation in newSelections.Implementations)
        {
            var interfaceUri = newImplementation.InterfaceUri;
            if (!oldSelections.ContainsImplementation(interfaceUri))
            { // Implementation added
                yield return(new(interfaceUri, newVersion : newImplementation.Version));
            }
        }

        foreach (var oldImplementation in oldSelections.Implementations)
        {
            var interfaceUri = oldImplementation.InterfaceUri;

            var newImplementation = newSelections.GetImplementation(interfaceUri);
            if (newImplementation == null)
            { // Implementation removed
                yield return(new(interfaceUri, oldVersion : oldImplementation.Version));
            }
            else if (oldImplementation.Version != newImplementation.Version)
            { // Implementation updated
                yield return(new(interfaceUri, oldVersion : oldImplementation.Version, newVersion : newImplementation.Version));
            }
        }
    }
Пример #5
0
        private static void ApplyVersionRestrictions(Requirements requirements, Selections selections)
        {
            if (requirements.ExtraRestrictions.Count == 0) return;

            // TODO
            Log.Warn(string.Format("You have applied a version restriction to this app. Zero Install will continue to apply this restriction to any future updates. You will need to run '0install select --customize {0}' to undo this.", requirements.InterfaceUri));

            foreach (var restriction in requirements.ExtraRestrictions)
            {
                var selection = selections.GetImplementation(restriction.Key);
                if (selection != null)
                {
                    var pref = FeedPreferences.LoadForSafe(restriction.Key);
                    pref.Implementations.Clear();
                    pref[selection.ID].UserStability = Stability.Preferred;
                    pref.SaveFor(restriction.Key);
                }
            }
        }