OSDN Git Service

AppliStation-All, アセンブリバージョンを1.4.5に
[applistation/AppliStation.git] / na-get-lib / NaGet.Packages.Install / UpgradeFinder.cs
1 using System;
2 using System.Collections.Generic;
3 using System.Reflection;
4 using NaGet.Packages;
5
6 namespace NaGet.Packages.Install
7 {
8         /// <summary>
9         /// \8dX\90V\83\\83t\83g\82ð\92T\82·
10         /// </summary>
11         public sealed class UpgradeFinder
12         {
13                 private UpgradeFinder()
14                 {
15                 }
16                 
17                 private static Package getUpgradePkg(Package pkg, PackageList<Package> pkgList, PackageList<InstalledPackage> instPkgList, string[] exclude, IComparer<string> verComp)
18                 {
19                         Package avaiablePkg = pkgList.GetPackageForName(pkg.Name);
20                         bool canUpgrade = false;
21                         
22                         if (avaiablePkg != null) {
23                                 
24                                 if (verComp.Compare(pkg.Version, avaiablePkg.Version) < 0 &&
25                                     instPkgList.GetPackageForPackage(pkg.Name, avaiablePkg.Version) == null) {
26                                         canUpgrade = true;
27                                         
28                                         if (Array.IndexOf(exclude, pkg.Name) >= 0) {
29                                                 canUpgrade = false;
30                                         }
31                                 }
32                         }
33                         
34                         return (canUpgrade)? avaiablePkg : null;
35                 }
36                 
37                 public static IEnumerable<Package> GetUpgradePackages(PackageListsManager pkgListMan)
38                 {
39                         PackageList<Package> packageList = pkgListMan.AvailablePkgList;
40                         string[] exclude = NaGet.Env.ExcludeUpdatePackageNames ?? new string[0];
41                         
42                         VersionComparetor verComp = new VersionComparetor();
43                         
44                         foreach (InstalledPackage pkg in pkgListMan.InstalledPkgList) {
45                                 Package availablePkg = getUpgradePkg(pkg, packageList, pkgListMan.InstalledPkgList, exclude, verComp);
46                                 if (availablePkg != null) { // if it has an upgrade, yield
47                                         yield return availablePkg;
48                                 }
49                         }
50                         foreach (InstalledPackage pkg in pkgListMan.SystemInstalledPkgList) {
51                                 Package availablePkg = getUpgradePkg(pkg, packageList, pkgListMan.SystemInstalledPkgList, exclude, verComp);
52                                 if (availablePkg != null) { // if it has an upgrade, yield
53                                         yield return availablePkg;
54                                 }
55                         }
56                 }
57         }
58 }