OSDN Git Service

Merge branch 'master' of git.sourceforge.jp:/gitroot/applistation/AppliStation
authorttp <ttp@users.sourceforge.jp>
Sat, 4 Dec 2010 03:39:18 +0000 (12:39 +0900)
committerttp <ttp@users.sourceforge.jp>
Sat, 4 Dec 2010 03:39:18 +0000 (12:39 +0900)
all-get/Main.cs
na-get-lib/NaGet.Packages.Install/UpgradeFinder.cs [new file with mode: 0644]
na-get-lib/NaGet/Env.cs
na-get-lib/NaGet/NaGetLibPref.cs
na-get-lib/na-get-lib.csproj

index 2989c34..0849124 100644 (file)
@@ -126,31 +126,23 @@ namespace AllGet
                \r
                public void CheckUpgrade()\r
                {\r
-                       PackageList<Package> packageList = pkgListMan.AvailablePkgList;\r
-                       \r
-                       VersionComparetor verComp = new VersionComparetor();\r
-                       \r
-                       foreach (InstalledPackage pkg in pkgListMan.InstalledPkgList) {\r
-                               Package avaiablePkg = packageList.GetPackageForName(pkg.Name);\r
+                       foreach (Package pkg in UpgradeFinder.GetUpgradePackages(pkgListMan)) {\r
+                               bool isSystem = false;\r
+                               Package instPkg = null;\r
                                \r
-                               if (avaiablePkg != null) {\r
-                                       if (verComp.Compare(pkg.Version, avaiablePkg.Version) < 0 &&\r
-                                           pkgListMan.InstalledPkgList.GetPackageForPackage(pkg.Name, avaiablePkg.Version) == null) {\r
-                                               \r
-                                               Console.WriteLine("{0} ({1}) => ({2})", pkg.Name, pkg.Version, avaiablePkg.Version);\r
+                               instPkg = pkgListMan.SystemInstalledPkgList.GetPackageForName(pkg.Name);\r
+                               if (instPkg != null) {\r
+                                       isSystem = true;\r
+                               } else {\r
+                                       instPkg = pkgListMan.InstalledPkgList.GetPackageForName(pkg.Name);\r
+                                       if (instPkg != null) {\r
+                                               isSystem = false;\r
+                                       } else {\r
+                                               System.Diagnostics.Debug.Fail("internal error.");\r
                                        }\r
                                }\r
-                       }\r
-                       foreach (InstalledPackage pkg in pkgListMan.SystemInstalledPkgList) {\r
-                               Package avaiablePkg = packageList.GetPackageForName(pkg.Name);\r
                                \r
-                               if (avaiablePkg != null) {\r
-                                       if (verComp.Compare(pkg.Version, avaiablePkg.Version) < 0 &&\r
-                                           pkgListMan.SystemInstalledPkgList.GetPackageForPackage(pkg.Name, avaiablePkg.Version) == null) {\r
-                                               \r
-                                               Console.WriteLine("{0} ({1})@sys => ({2})", pkg.Name, pkg.Version, avaiablePkg.Version);\r
-                                       }\r
-                               }\r
+                               Console.WriteLine("{0} ({1}){3} => ({2})", pkg.Name, instPkg.Version, pkg.Version, (isSystem)? "@sys" : "");\r
                        }\r
                }\r
                \r
diff --git a/na-get-lib/NaGet.Packages.Install/UpgradeFinder.cs b/na-get-lib/NaGet.Packages.Install/UpgradeFinder.cs
new file mode 100644 (file)
index 0000000..10bb800
--- /dev/null
@@ -0,0 +1,58 @@
+using System;
+using System.Collections.Generic;
+using System.Reflection;
+using NaGet.Packages;
+
+namespace NaGet.Packages.Install
+{
+       /// <summary>
+       /// \8dX\90V\83\\83t\83g\82ð\92T\82·
+       /// </summary>
+       public sealed class UpgradeFinder
+       {
+               private UpgradeFinder()
+               {
+               }
+               
+               private static Package getUpgradePkg(Package pkg, PackageList<Package> pkgList, PackageList<InstalledPackage> instPkgList, string[] exclude, IComparer<string> verComp)
+               {
+                       Package avaiablePkg = pkgList.GetPackageForName(pkg.Name);
+                       bool canUpgrade = false;
+                       
+                       if (avaiablePkg != null) {
+                               
+                               if (verComp.Compare(pkg.Version, avaiablePkg.Version) < 0 &&
+                                   instPkgList.GetPackageForPackage(pkg.Name, avaiablePkg.Version) == null) {
+                                       canUpgrade = true;
+                                       
+                                       if (Array.IndexOf(exclude, pkg.Name) >= 0) {
+                                               canUpgrade = false;
+                                       }
+                               }
+                       }
+                       
+                       return (canUpgrade)? avaiablePkg : null;
+               }
+               
+               public static IEnumerable<Package> GetUpgradePackages(PackageListsManager pkgListMan)
+               {
+                       PackageList<Package> packageList = pkgListMan.AvailablePkgList;
+                       string[] exclude = NaGet.Env.ExcludeUpdatePackageNames ?? new string[0];
+                       
+                       VersionComparetor verComp = new VersionComparetor();
+                       
+                       foreach (InstalledPackage pkg in pkgListMan.InstalledPkgList) {
+                               Package availablePkg = getUpgradePkg(pkg, packageList, pkgListMan.InstalledPkgList, exclude, verComp);
+                               if (availablePkg != null) { // if it has an upgrade, yield
+                                       yield return availablePkg;
+                               }
+                       }
+                       foreach (InstalledPackage pkg in pkgListMan.SystemInstalledPkgList) {
+                               Package availablePkg = getUpgradePkg(pkg, packageList, pkgListMan.SystemInstalledPkgList, exclude, verComp);
+                               if (availablePkg != null) { // if it has an upgrade, yield
+                                       yield return availablePkg;
+                               }
+                       }
+               }
+       }
+}
index 2f799d2..f2fc17b 100644 (file)
@@ -227,6 +227,19 @@ namespace NaGet
                        }\r
                }\r
                \r
+               /// <summary>\r
+               /// アップデートから除外するパッケージの名前\r
+               /// </summary>\r
+               public static string[] ExcludeUpdatePackageNames {\r
+                       get {\r
+                               if (pref == null) LoadPref();\r
+                               return pref.ExcludeUpdatePackageNames;\r
+                       }\r
+                       set {\r
+                               if (pref == null) LoadPref();\r
+                               pref.ExcludeUpdatePackageNames = value;\r
+                       }\r
+               }\r
                \r
                #endregion\r
                \r
index 78d3893..ed08a0f 100644 (file)
@@ -48,5 +48,12 @@ namespace NaGet
                [XmlElement]\r
                [DefaultValue(true)]\r
                public bool InstallOnBackground = true;\r
+               \r
+               /// <summary>\r
+               /// アップデートから除外するパッケージ名\r
+               /// </summary>\r
+               [XmlElement("ExcludeUpdatePackageName")]\r
+               [DefaultValue(null)]\r
+               public string[] ExcludeUpdatePackageNames = null;\r
        }\r
 }\r
index 6cfeb08..85deb06 100644 (file)
@@ -63,6 +63,7 @@
     <Compile Include="NaGet.Net\GuidEnumeratorForCategories.cs" />\r
     <Compile Include="NaGet.Packages.Install\DependeciesResolver.cs" />\r
     <Compile Include="NaGet.Packages.Install\InstallationLog.cs" />\r
+    <Compile Include="NaGet.Packages.Install\UpgradeFinder.cs" />\r
     <Compile Include="NaGet.Packages\PackageCollectionFileData.cs" />\r
     <Compile Include="NaGet.Packages\PackageListsManager.cs" />\r
     <Compile Include="NaGet.Packages\RepositoriesList.cs" />\r