OSDN Git Service

na-get-lib,UserAgentをアセンブリバージョンなどから取得するよう変更
[applistation/AppliStation.git] / all-get / Main.cs
index d34737a..a4be970 100644 (file)
@@ -2,7 +2,6 @@
 using System;\r
 using System.IO;\r
 using System.Collections.Generic;\r
-using NaGet.Net;\r
 using NaGet.Packages;\r
 using NaGet.Packages.Install;\r
 using NaGet.SubCommands;\r
@@ -10,59 +9,6 @@ using NaGet.Tasks;
 \r
 namespace AllGet\r
 {\r
-\r
-       class DownloadListener\r
-       {\r
-               private string line = null;\r
-               \r
-               /// <summary>\r
-               /// lineのコンソール上における長さ\r
-               /// </summary>\r
-               private int lineWidth = 0;\r
-       \r
-               public void OnDownload(object sender, DownloadEventArgs a) {\r
-                       if (line != null) {\r
-                               lock (line) {\r
-                                       int newpos = (lineWidth <= 0)? 0 : Console.CursorLeft - lineWidth;\r
-                                       if (newpos < 0) newpos = 0;\r
-                                       \r
-                                       // 空白で埋める\r
-                                       Console.CursorLeft = newpos;\r
-                                       for (int i = 0; i < lineWidth && Console.CursorLeft < Console.BufferWidth; i++) {\r
-                                               Console.Write(' ');\r
-                                       }\r
-                                       Console.CursorLeft = newpos;\r
-                                       \r
-                                       line = null; lineWidth = 0;\r
-                               }\r
-                       }\r
-                       \r
-                       switch (a.DownloadTaskType) {\r
-                       case DownloadEventType.INITED:\r
-                               line = "starting...";\r
-                               break;\r
-                       case DownloadEventType.CONNECTED:\r
-                       case DownloadEventType.DOWNLOADING:\r
-                               line = a.TaskMessage;\r
-                               break;\r
-                       case DownloadEventType.COMPLETED:\r
-                               //\r
-                               line = null;\r
-                               break;\r
-                       case DownloadEventType.ERROR:\r
-                               Console.Write("interrupted! ERROR!");\r
-                               line = null;\r
-                               break;\r
-                       }\r
-                       \r
-                       if (line != null) {\r
-                               int posOld = Console.CursorLeft;\r
-                               Console.Write(line);\r
-                               lineWidth = Console.CursorLeft - posOld;\r
-                       }\r
-               }\r
-       }\r
-\r
        sealed class TaskSetEventHandlers\r
        {\r
                public static void OnTaskSetEvent(object sender, TaskEventArgs e) { \r
@@ -149,8 +95,6 @@ namespace AllGet
        \r
        class MainClass\r
        {\r
-               private Downloader downloader;\r
-               \r
                private PackageListsManager pkgListMan;\r
                \r
                /// <summary>\r
@@ -160,10 +104,6 @@ namespace AllGet
                \r
                public MainClass()\r
                {\r
-                       downloader = new Downloader();\r
-                       DownloadListener dl = new DownloadListener();\r
-                       downloader.DownloadEventRaised += new EventHandler<DownloadEventArgs>(dl.OnDownload);\r
-                       \r
                        pkgListMan = new PackageListsManager();\r
                        pkgListMan.LoadPackageLists();\r
                }\r
@@ -311,13 +251,6 @@ namespace AllGet
                                installations = new Installation[downloadList.Count];\r
                                for (int i = 0; i < installations.Length; i++) {\r
                                        installations[i] = new Installation(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
-                                       }\r
                                }\r
                        }\r
                        \r
@@ -335,54 +268,10 @@ namespace AllGet
                                Environment.Exit(0);\r
                        }\r
                        \r
-                       NaGet.SubCommands.NaGetInstall tasks = new NaGet.SubCommands.NaGetInstall(pkgListMan, installations);\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.TaskEventRaised += delegate(object sender, TaskEventArgs e) { \r
-                               switch (e.Type) {\r
-//                                     case NaGetTaskSetEventType.COMPLETED_TASKSET\r
-//                                             break;\r
-                                       case TaskEventType.COMPLETED:\r
-                                               Console.WriteLine("Done.");\r
-                                               break;\r
-                                       case TaskEventType.STARTED_SUBTASK:\r
-                                               Console.Write("  " + e.TaskMessage);\r
-                                               break;\r
-                                       case TaskEventType.COMPLETED_SUBTASK:\r
-                                               Console.WriteLine(" ... Done. [{0}%]", (int) e.ProgressPercent);\r
-                                               break;\r
-                                       case TaskEventType.INFO:\r
-                                               Console.WriteLine("  " + e.TaskMessage);\r
-                                               break;\r
-                                       case TaskEventType.ERROR:\r
-                                       case TaskEventType.WARNING:\r
-                                               Console.WriteLine("  [Error] " + e.TaskMessage);\r
-                                               break;\r
-                               }\r
-                       };\r
-                       DownloadListener dl = new DownloadListener();\r
-                       tasks.Downloader.DownloadEventRaised += dl.OnDownload;\r
+                       NaGet.SubCommands.NaGetInstall2 tasks = new NaGet.SubCommands.NaGetInstall2(pkgListMan, installations);\r
+                       tasks.TaskEventRaised += TaskSetEventHandlers.OnTaskSetEvent;\r
+                       tasks.SubTaskEventRaised += TaskSetEventHandlers.OnDownloadSubTaskEvent;\r
+                       tasks.TaskQueryRaised += TaskSetEventHandlers.OnTaskQueryEvent;\r
                        \r
                        tasks.Run();\r
                }\r