OSDN Git Service

na-get-lib,起動高速化機能追加時にインストール済みソフトのバージョン認識がされていないことがあったのを修正。
[applistation/AppliStation.git] / all-get / Main.cs
index 1442635..876d8aa 100644 (file)
@@ -68,6 +68,11 @@ namespace AllGet
                \r
                private PackageListsManager pkgListMan;\r
                \r
+               /// <summary>\r
+               /// サイレントインストールをするか否か\r
+               /// </summary>\r
+               private bool silent = false;\r
+               \r
                public MainClass()\r
                {\r
                        downloader = new Downloader();\r
@@ -75,6 +80,7 @@ namespace AllGet
                        downloader.DownloadEventRaised += new EventHandler<DownloadEventArgs>(dl.OnDownload);\r
                        \r
                        pkgListMan = new PackageListsManager();\r
+                       pkgListMan.LoadPackageLists();\r
                }\r
                \r
                public void Update()\r
@@ -90,7 +96,6 @@ namespace AllGet
                public void update(bool downloadPackageListFlag)\r
                {\r
                        NaGet.SubCommands.NaGetUpdate tasks = new NaGet.SubCommands.NaGetUpdate(pkgListMan, downloadPackageListFlag);\r
-                       tasks.Downloader = this.downloader;\r
                        tasks.TaskSetRaised += delegate(object sender, NaGetTaskSetEventArgs e) { \r
                                switch (e.Type) {\r
 //                                     case NaGetTaskSetEventType.COMPLETED_TASKSET\r
@@ -113,6 +118,8 @@ namespace AllGet
                                                break;\r
                                }\r
                        };\r
+                       DownloadListener dl = new DownloadListener();\r
+                       tasks.Downloader.DownloadEventRaised += dl.OnDownload;\r
                        \r
                        tasks.Run();\r
                }\r
@@ -123,7 +130,7 @@ namespace AllGet
                        \r
                        VersionComparetor verComp = new VersionComparetor();\r
                        \r
-                       foreach (InstalledPackage pkg in pkgListMan.InstalledPkgList.Packages) {\r
+                       foreach (InstalledPackage pkg in pkgListMan.InstalledPkgList) {\r
                                Package avaiablePkg = packageList.GetPackageForName(pkg.Name);\r
                                \r
                                if (avaiablePkg != null) {\r
@@ -136,7 +143,7 @@ namespace AllGet
                                        Console.ResetColor();\r
                                }\r
                        }\r
-                       foreach (InstalledPackage pkg in pkgListMan.SystemInstalledPkgList.Packages) {\r
+                       foreach (InstalledPackage pkg in pkgListMan.SystemInstalledPkgList) {\r
                                Package avaiablePkg = packageList.GetPackageForName(pkg.Name);\r
                                \r
                                if (avaiablePkg != null) {\r
@@ -274,6 +281,8 @@ namespace AllGet
                                for (int i = 0; i < installations.Length; i++) {\r
                                        installations[i] = new Installation((Package) downloadList[i]);\r
                                        \r
+                                       installations[i].Silent = silent; // サイレントインストールのフラグの設定\r
+                                       \r
                                        if (! installations[i].IsInstallablePackage()) {\r
                                                Console.WriteLine("E: Can not install package {0} to your PC.", installations[i].ToString());\r
                                                Environment.Exit(1);\r
@@ -281,6 +290,13 @@ namespace AllGet
                                }\r
                        }\r
                        \r
+                       Installation[] depInstallations;\r
+                       {\r
+                               Installation[] resolved;\r
+                               DependeciesResolver.ResolveInstallations(installations, pkgListMan, out resolved, out depInstallations);\r
+                               installations = resolved;\r
+                       }\r
+                       \r
                        Console.WriteLine("The following packages will be downloaded:");\r
                        Console.WriteLine("  {0}", Installation.ToString(installations));\r
                        if (AllGet.Util.Confirm("Do you want to continue [Y/n]?", true) == false) {\r
@@ -289,7 +305,29 @@ namespace AllGet
                        }\r
                        \r
                        NaGet.SubCommands.NaGetInstall tasks = new NaGet.SubCommands.NaGetInstall(pkgListMan, installations);\r
-                       tasks.Downloader = this.downloader;\r
+                       tasks.TaskQueryRaised += delegate(object sender, NaGetTaskQueryArgs e) {\r
+                               char result = '\u0000';\r
+                               if (e.SelectionFlag == (NaGetTaskQueryResult.CONTINUE | NaGetTaskQueryResult.RETRY | NaGetTaskQueryResult.CANCEL)) {\r
+                                       result = AllGet.Util.Query(e.Message + " [y/R/n]?", "yrn", 'r');\r
+                               } else if (e.SelectionFlag == (NaGetTaskQueryResult.RETRY | NaGetTaskQueryResult.CANCEL)) {\r
+                                       result = AllGet.Util.Query(e.Message + " [R/n]?", "rn", 'r');\r
+                               } else if (e.SelectionFlag == NaGetTaskQueryResult.CONTINUE) {\r
+                                       result = AllGet.Util.Query(e.Message + " [Y]?", "y", 'y');\r
+                               } else {\r
+                                       result = AllGet.Util.Query(e.Message + " [Y/n]?", "yn", 'y');\r
+                               }\r
+                               \r
+                               switch (result) {\r
+                                       case 'y':\r
+                                               return NaGetTaskQueryResult.CONTINUE;\r
+                                       case 'n':\r
+                                               return NaGetTaskQueryResult.CANCEL;\r
+                                       case 'r':\r
+                                               return NaGetTaskQueryResult.RETRY;\r
+                                       default:\r
+                                               return NaGetTaskQueryResult.CANCELED_AUTOMATICALLY;\r
+                               }\r
+                       };\r
                        tasks.TaskSetRaised += delegate(object sender, NaGetTaskSetEventArgs e) { \r
                                switch (e.Type) {\r
 //                                     case NaGetTaskSetEventType.COMPLETED_TASKSET\r
@@ -312,6 +350,8 @@ namespace AllGet
                                                break;\r
                                }\r
                        };\r
+                       DownloadListener dl = new DownloadListener();\r
+                       tasks.Downloader.DownloadEventRaised += dl.OnDownload;\r
                        \r
                        tasks.Run();\r
                }\r
@@ -405,7 +445,7 @@ namespace AllGet
                        Console.WriteLine("\t{0} search|show pkg1 [pkg2 ...]", executeFileName);\r
                        Console.WriteLine("\t{0} cleancache [pkg ...]", executeFileName);\r
                        Console.WriteLine("\t{0} download pkg1 [pkg2 ...]", executeFileName);\r
-                       Console.WriteLine("\t{0} install|uninstall pkg1 [pkg2 ...]", executeFileName);\r
+                       Console.WriteLine("\t{0} [--quiet] install|uninstall pkg1 [pkg2 ...]", executeFileName);\r
                        Console.WriteLine();\r
                        Console.WriteLine("{0} is a simple command line interface for downloading and "+\r
                                          "installing packages. The most frequently used commands are update "+\r
@@ -426,7 +466,7 @@ namespace AllGet
                \r
                public void FooBar()\r
                {\r
-                       foreach (InstalledPackage pkg in pkgListMan.SystemInstalledPkgList.Packages) {\r
+                       foreach (InstalledPackage pkg in pkgListMan.SystemInstalledPkgList) {\r
                                Console.WriteLine("{0} : {1}", pkg.Name, pkg.UninstallInfo.UninstallString);\r
                        }\r
                }\r
@@ -448,6 +488,7 @@ namespace AllGet
                        Console.WriteLine("誰か {0} をスーパー牛さんパワー化してくれ", executeFileName);\r
                }\r
                \r
+               [STAThread]\r
                public static void Main(string[] args)\r
                {\r
                        // アーカイブSYSTEM32をパスに足す\r
@@ -457,81 +498,113 @@ namespace AllGet
                        \r
                        if (args.Length == 0) {\r
                                mc.Help();\r
-                       } else if (args[0] == "update") {\r
-                               if (args.Length != 1) {\r
-                                       Console.WriteLine("E: The update command takes no arguments");\r
-                                       Environment.Exit(1);\r
-                               }\r
-                               mc.Update();\r
-                       } else if (args[0] == "localupdate") {\r
-                               if (args.Length != 1) {\r
-                                       Console.WriteLine("E: The update command takes no arguments");\r
-                                       Environment.Exit(1);\r
-                               }\r
-                               mc.LocalUpdate();\r
-                       } else if (args[0] == "search") {\r
-                               if (args.Length <= 1) {\r
-                                       Console.WriteLine("E: You must give exactly one pattern");\r
-                                       Environment.Exit(1);\r
-                               }\r
-                               \r
-                               mc.Search(string.Join(" ", args, 1, args.Length - 1));\r
-                       } else if (args[0] == "show") {\r
-                               if (args.Length <= 1) {\r
-                                       Console.WriteLine("E: You must give exactly one pattern");\r
-                                       Environment.Exit(1);\r
-                               }\r
                                \r
-                               for (int i = 1; i < args.Length; i++) {\r
-                                       mc.Show(args[i]);\r
-                               }\r
-                       } else if (args[0] == "download") {\r
-                               if (args.Length <= 1) {\r
-                                       Console.WriteLine("E: Invalid operation download");\r
-                                       Environment.Exit(1);\r
-                               }\r
-                               \r
-                               string[] packages = new string[args.Length - 1];\r
-                               Array.Copy(args, 1, packages, 0, packages.Length);\r
-                               \r
-                               mc.Download(packages);\r
-                       } else if (args[0] == "install") {\r
-                               if (args.Length <= 1) {\r
-                                       Console.WriteLine("E: Invalid operation install");\r
+                               Environment.Exit(1);\r
+                       } else {\r
+                               try {\r
+                                       NaGet.ArgParser argParser = new NaGet.ArgParser();\r
+                                       argParser["quiet"] = false;\r
+                                       args = argParser.Parse(args);\r
+                                       mc.silent = (bool) argParser["quiet"];\r
+                               } catch (ApplicationException e) {\r
+                                       Console.WriteLine(e.Message);\r
                                        Environment.Exit(1);\r
                                }\r
-                               \r
-                               string[] packages = new string[args.Length - 1];\r
-                               Array.Copy(args, 1, packages, 0, packages.Length);\r
-                               \r
-                               mc.Install(packages);\r
-                       } else if (args[0] == "checkupgrade") {\r
-                               mc.CheckUpgrade();\r
-                       } else if (args[0] == "remove") {\r
-                               if (args.Length <= 1) {\r
-                                       Console.WriteLine("E: Invalid operation remove");\r
+                       }\r
+                       \r
+                       // 引数ごとに操作を決定\r
+                       switch (args[0])\r
+                       {\r
+                               case "update":\r
+                                       if (args.Length != 1) {\r
+                                               Console.WriteLine("E: The update command takes no arguments");\r
+                                               Environment.Exit(1);\r
+                                       }\r
+                                       mc.Update();\r
+                                       break;\r
+                               case "localupate":\r
+                                       if (args.Length != 1) {\r
+                                               Console.WriteLine("E: The update command takes no arguments");\r
+                                               Environment.Exit(1);\r
+                                       }\r
+                                       mc.LocalUpdate();\r
+                                       break;\r
+                               case "search":\r
+                                       if (args.Length <= 1) {\r
+                                               Console.WriteLine("E: You must give exactly one pattern");\r
+                                               Environment.Exit(1);\r
+                                       }\r
+                                       \r
+                                       mc.Search(string.Join(" ", args, 1, args.Length - 1));\r
+                                       break;\r
+                               case "show":\r
+                                       if (args.Length <= 1) {\r
+                                               Console.WriteLine("E: You must give exactly one pattern");\r
+                                               Environment.Exit(1);\r
+                                       }\r
+                                       \r
+                                       for (int i = 1; i < args.Length; i++) {\r
+                                               mc.Show(args[i]);\r
+                                       }\r
+                                       break;\r
+                               case "download":\r
+                                       if (args.Length <= 1) {\r
+                                               Console.WriteLine("E: Invalid operation download");\r
+                                               Environment.Exit(1);\r
+                                       } else {\r
+                                               string[] packages = new string[args.Length - 1];\r
+                                               Array.Copy(args, 1, packages, 0, packages.Length);\r
+                                               \r
+                                               mc.Download(packages);\r
+                                       }\r
+                                       break;\r
+                               case "install":\r
+                                       if (args.Length <= 1) {\r
+                                               Console.WriteLine("E: Invalid operation install");\r
+                                               Environment.Exit(1);\r
+                                       } else {\r
+                                               string[] packages = new string[args.Length - 1];\r
+                                               Array.Copy(args, 1, packages, 0, packages.Length);\r
+                                               \r
+                                               mc.Install(packages);\r
+                                       }\r
+                                       break;\r
+                               case "checkupgrade":\r
+                                       mc.CheckUpgrade();\r
+                                       break;\r
+                               case "remove":\r
+                                       if (args.Length <= 1) {\r
+                                               Console.WriteLine("E: Invalid operation remove");\r
+                                               Environment.Exit(1);\r
+                                       } else {\r
+                                               string[] packages = new string[args.Length - 1];\r
+                                               Array.Copy(args, 1, packages, 0, packages.Length);\r
+                                               \r
+                                               mc.Remove(packages);\r
+                                       }\r
+                                       break;\r
+                               case "cleancache":\r
+                                       {\r
+                                               string[] packages = new string[args.Length - 1];\r
+                                               Array.Copy(args, 1, packages, 0, packages.Length);\r
+                                               \r
+                                               mc.CleanCache(packages);\r
+                                       }\r
+                                       break;\r
+                               case "foobar":\r
+                                       mc.FooBar();\r
+                                       break;\r
+                               case "hoge":\r
+                                       mc.Hoge();\r
+                                       break;\r
+                               case "moo":\r
+                                       mc.Moo();\r
+                                       break;\r
+                               default:\r
+                                       mc.Help();\r
+                                       \r
                                        Environment.Exit(1);\r
-                               }\r
-                               \r
-                               string[] packages = new string[args.Length - 1];\r
-                               Array.Copy(args, 1, packages, 0, packages.Length);\r
-                               \r
-                               mc.Remove(packages);\r
-                       } else if (args[0] == "cleancache") {\r
-                               string[] packages = new string[args.Length - 1];\r
-                               Array.Copy(args, 1, packages, 0, packages.Length);\r
-                               \r
-                               mc.CleanCache(packages);\r
-                       } else if (args[0] == "foobar") {\r
-                               mc.FooBar();\r
-                       } else if (args[0] == "hoge") {\r
-                               mc.Hoge();\r
-                       } else if (args[0] == "moo") {\r
-                               mc.Moo();\r
-                       } else {\r
-                               mc.Help();\r
-                               \r
-                               Environment.Exit(1);\r
+                                       break;\r
                        }\r
                }\r
        }\r