diff options
author | Lluis Sanchez Gual <lluis@novell.com> | 2011-04-04 21:32:05 +0400 |
---|---|---|
committer | Lluis Sanchez Gual <lluis@novell.com> | 2011-04-04 21:32:05 +0400 |
commit | 75b002e8898deadc4aa38105b10eaece5150ecaa (patch) | |
tree | d2c1500a432c5d25eabb73db064bef6a3bc998ff | |
parent | 2c9f3e29df87f4002c6c7be70418ecc7ec566209 (diff) |
Allow getting the latest version of addins.
Added a flags parameter to GetAvailableAddins and GetAvailableUpdates
which allow getting the latest versions of the add-ins.
-rw-r--r-- | Mono.Addins.Setup/Mono.Addins.Setup/RepositoryRegistry.cs | 122 |
1 files changed, 110 insertions, 12 deletions
diff --git a/Mono.Addins.Setup/Mono.Addins.Setup/RepositoryRegistry.cs b/Mono.Addins.Setup/Mono.Addins.Setup/RepositoryRegistry.cs index 5db9755..d13d72f 100644 --- a/Mono.Addins.Setup/Mono.Addins.Setup/RepositoryRegistry.cs +++ b/Mono.Addins.Setup/Mono.Addins.Setup/RepositoryRegistry.cs @@ -32,6 +32,7 @@ using System.Linq; using System.IO; using System.Collections; using Mono.Addins.Setup.ProgressMonitoring; +using System.Collections.Generic; namespace Mono.Addins.Setup { @@ -358,7 +359,27 @@ namespace Mono.Addins.Setup /// </remarks> public AddinRepositoryEntry[] GetAvailableUpdates () { - return GetAvailableAddin (null, null, null, true); + return GetAvailableAddin (null, null, null, true, RepositorySearchFlags.None); + } + + /// <summary> + /// Gets a list of available add-in updates. + /// </summary> + /// <param name="flags"> + /// Search flags + /// </param> + /// <returns> + /// A list of add-in references. + /// </returns> + /// <remarks> + /// The list is generated by looking at the add-ins currently installed and checking if there is any + /// add-in with a newer version number in any of the subscribed repositories. This method uses cached + /// information from on-line repositories. Make sure you call UpdateRepository or UpdateAllRepositories + /// before using this method to ensure that the latest information is available. + /// </remarks> + public AddinRepositoryEntry[] GetAvailableUpdates (RepositorySearchFlags flags) + { + return GetAvailableAddin (null, null, null, true, flags); } /// <summary> @@ -378,20 +399,20 @@ namespace Mono.Addins.Setup /// </remarks> public AddinRepositoryEntry[] GetAvailableUpdates (string repositoryUrl) { - return GetAvailableAddin (repositoryUrl, null, null, true); + return GetAvailableAddin (repositoryUrl, null, null, true, RepositorySearchFlags.None); } #pragma warning disable 1591 [Obsolete ("Use GetAvailableAddinUpdates (id) instead")] public AddinRepositoryEntry[] GetAvailableUpdates (string id, string version) { - return GetAvailableAddin (null, id, version, true); + return GetAvailableAddin (null, id, version, true, RepositorySearchFlags.None); } [Obsolete ("Use GetAvailableAddinUpdates (repositoryUrl, id) instead")] public AddinRepositoryEntry[] GetAvailableUpdates (string repositoryUrl, string id, string version) { - return GetAvailableAddin (repositoryUrl, id, version, true); + return GetAvailableAddin (repositoryUrl, id, version, true, RepositorySearchFlags.None); } #pragma warning restore 1591 @@ -412,7 +433,7 @@ namespace Mono.Addins.Setup /// </remarks> public AddinRepositoryEntry[] GetAvailableAddinUpdates (string id) { - return GetAvailableAddin (null, id, null, true); + return GetAvailableAddin (null, id, null, true, RepositorySearchFlags.None); } /// <summary> @@ -435,7 +456,7 @@ namespace Mono.Addins.Setup /// </remarks> public AddinRepositoryEntry[] GetAvailableAddinUpdates (string repositoryUrl, string id) { - return GetAvailableAddin (repositoryUrl, id, null, true); + return GetAvailableAddin (repositoryUrl, id, null, true, RepositorySearchFlags.None); } /// <summary> @@ -451,9 +472,28 @@ namespace Mono.Addins.Setup /// </remarks> public AddinRepositoryEntry[] GetAvailableAddins () { - return GetAvailableAddin (null, null, null, false); + return GetAvailableAddin (null, null, null, false, RepositorySearchFlags.None); } - + + /// <summary> + /// Gets a list of all available add-ins + /// </summary> + /// <returns> + /// The available addins. + /// </returns> + /// <param name='flags'> + /// Search flags. + /// </param> + /// <remarks> + /// This method uses cached + /// information from on-line repositories. Make sure you call UpdateRepository or UpdateAllRepositories + /// before using this method to ensure that the latest information is available. + /// </remarks> + public AddinRepositoryEntry[] GetAvailableAddins (RepositorySearchFlags flags) + { + return GetAvailableAddin (null, null, null, false, flags); + } + /// <summary> /// Gets a list of all available add-ins in a repository /// </summary> @@ -474,6 +514,28 @@ namespace Mono.Addins.Setup } /// <summary> + /// Gets a list of all available add-ins in a repository + /// </summary> + /// <param name="repositoryUrl"> + /// A repository URL + /// </param> + /// <param name='flags'> + /// Search flags. + /// </param> + /// <returns> + /// A list of add-ins + /// </returns> + /// <remarks> + /// This method uses cached + /// information from on-line repositories. Make sure you call UpdateRepository or UpdateAllRepositories + /// before using this method to ensure that the latest information is available. + /// </remarks> + public AddinRepositoryEntry[] GetAvailableAddins (string repositoryUrl, RepositorySearchFlags flags) + { + return GetAvailableAddin (repositoryUrl, null, null, false, flags); + } + + /// <summary> /// Checks if an add-in is available to be installed /// </summary> /// <param name="id"> @@ -517,12 +579,12 @@ namespace Mono.Addins.Setup /// </remarks> public AddinRepositoryEntry[] GetAvailableAddin (string repositoryUrl, string id, string version) { - return GetAvailableAddin (repositoryUrl, id, version, false); + return GetAvailableAddin (repositoryUrl, id, version, false, RepositorySearchFlags.None); } - PackageRepositoryEntry[] GetAvailableAddin (string repositoryUrl, string id, string version, bool updates) + PackageRepositoryEntry[] GetAvailableAddin (string repositoryUrl, string id, string version, bool updates, RepositorySearchFlags flags) { - ArrayList list = new ArrayList (); + List<PackageRepositoryEntry> list = new List<PackageRepositoryEntry> (); IEnumerable ee; if (repositoryUrl != null) { @@ -548,9 +610,32 @@ namespace Mono.Addins.Setup } } } + + if ((flags & RepositorySearchFlags.LatestVersionsOnly) != 0) + FilterOldVersions (list); + // Old versions are returned first list.Sort (); - return (PackageRepositoryEntry[]) list.ToArray (typeof(PackageRepositoryEntry)); + return list.ToArray (); + } + + void FilterOldVersions (List<PackageRepositoryEntry> addins) + { + Dictionary<string,string> versions = new Dictionary<string, string> (); + foreach (PackageRepositoryEntry a in addins) { + string last; + string id, version; + Addin.GetIdParts (a.Addin.Id, out id, out version); + if (!versions.TryGetValue (id, out last) || Addin.CompareVersions (last, version) > 0) + versions [id] = version; + } + for (int n=0; n<addins.Count; n++) { + PackageRepositoryEntry a = addins [n]; + string id, version; + Addin.GetIdParts (a.Addin.Id, out id, out version); + if (versions [id] != version) + addins.RemoveAt (n--); + } } void GetRepositoryTree (string url, ArrayList list) @@ -573,4 +658,17 @@ namespace Mono.Addins.Setup } } } + + public enum RepositorySearchFlags + { + /// <summary> + /// No special search options + /// </summary> + None, + + /// <summary> + /// Only the latest version of every add-in is included in the search + /// </summary> + LatestVersionsOnly = 1, + } } |