OSDN Git Service

ソフトコレクションファイル対応(branch list4envtrans)をマージ
[applistation/AppliStation.git] / na-get-lib / NaGet.SubCommands / NaGetInstall.cs
index b2cd573..390f1a0 100644 (file)
@@ -1,4 +1,5 @@
 using System;\r
+using System.Collections.Generic;\r
 using NaGet.Packages.Install;\r
 using NaGet.Packages;\r
 using NaGet.Net;\r
@@ -20,6 +21,11 @@ namespace NaGet.SubCommands
                        get {\r
                                if (downloader == null) {\r
                                        downloader = new Downloader();\r
+                                       downloader.DownloadEventRaised += delegate(object sender, DownloadEventArgs e) {\r
+                                               if (e.Type == DownloadEventType.DOWNLOADING && e.TaskProgressPercent > 0) {\r
+                                                       RaiseTaskSetEvent(NaGetTaskSetEventType.PING, string.Empty, GetProgressPercent(NaGetTaskSetEventType.PING, e.TaskProgressPercent));\r
+                                               }\r
+                                       };\r
                                }\r
                                return downloader;\r
                        }\r
@@ -61,13 +67,13 @@ namespace NaGet.SubCommands
                \r
                private void initializeMainTaskSetNames()\r
                {\r
-                       System.Collections.Generic.List<string> taskSetNames = new System.Collections.Generic.List<string>();\r
+                       List<string> taskSetNames = new List<string>();\r
                        \r
                        for (int i =0; i < Installations.Length; i++) {\r
                                taskSetNames.Add(string.Format("取得: {0}", Installations[i].ToString()));\r
                                taskSetNames.Add(string.Format("ウイルススキャン: {0}", Installations[i].ToString()));\r
                        }\r
-                       taskSetNames.Add("インストーラの検証");\r
+                       taskSetNames.Add("ã\82¤ã\83³ã\82¹ã\83\88ã\83¼ã\83©ã\83¼ã\81®æ¤\9c証");\r
                        for (int i =0; i < Installations.Length; i++) {\r
                                taskSetNames.Add(string.Format("インストール: {0}", Installations[i].ToString()));\r
                        }\r
@@ -84,9 +90,9 @@ namespace NaGet.SubCommands
                        \r
                        {\r
                                // ハッシュ非適合なインストーラの表\r
-                               System.Collections.Generic.List<Installation> invalidInstallers = null;\r
+                               List<Installation> invalidInstallers = null;\r
                                \r
-                               while (invalidInstallers == null || invalidInstallers.Count > 0) {\r
+                               do {\r
                                        currentTaskSetIndex = 0;\r
                                        packageInstallerDownloaded = false;\r
                                        \r
@@ -95,16 +101,28 @@ namespace NaGet.SubCommands
                                        \r
                                        packageInstallerDownloaded = true;\r
                                        \r
-                                       // ハッシュの壊れているインストーラを取得\r
+                                       \r
+                                       RaiseTaskSetEvent(NaGetTaskSetEventType.STARTED_TASKSET, TaskSetNames[currentTaskSetIndex]);\r
+                                       \r
+                                       // ハッシュの壊れているインストーラーを取得\r
                                        invalidInstallers = runCheckHashForInstaller();\r
                                        \r
                                        // ハッシュが壊れているときの対策\r
                                        if (invalidInstallers.Count > 0) {\r
-                                               string msg = string.Format("{0}個のパッケージでファイルが壊れている可能性があります\n強制的にインストールを続行しますか?",\r
-                                                                          invalidInstallers.Count);\r
-                                               NaGetTaskQueryResult result = RaiseTaskSetQueryEvent(msg, NaGetTaskQueryResult.CONTINUE\r
-                                                                                                    | NaGetTaskQueryResult.RETRY\r
-                                                                                                    | NaGetTaskQueryResult.CANCEL);\r
+                                               System.Text.StringBuilder invalidInstallerNames = new System.Text.StringBuilder();\r
+                                               foreach (Installation invalidInst in invalidInstallers) {\r
+                                                       invalidInstallerNames.AppendFormat(" - {0}\n", invalidInst.ToString());\r
+                                               }\r
+                                               \r
+                                               string msg = string.Format("以下の{0}個のパッケージでファイルが壊れている可能性があります。\n{1}\n強制的にインストールを続行しますか?",\r
+                                                                          invalidInstallers.Count, invalidInstallerNames.ToString());\r
+                                               NaGetTaskQueryResult result = NaGetTaskQueryResult.CANCEL;\r
+                                               \r
+                                               if (!cancelCalled) {\r
+                                                       result = RaiseTaskSetQueryEvent(msg, NaGetTaskQueryResult.CONTINUE\r
+                                                                                       | NaGetTaskQueryResult.RETRY\r
+                                                                                       | NaGetTaskQueryResult.CANCEL);\r
+                                               }\r
                                                \r
                                                switch (result) {\r
                                                        case NaGetTaskQueryResult.CONTINUE:\r
@@ -126,8 +144,11 @@ namespace NaGet.SubCommands
                                                                return;\r
                                                }\r
                                        }\r
-                                       currentTaskSetIndex ++;\r
-                               }\r
+                                       \r
+                                       // もしハッシュが不適合なソフトがあるならばダウンロード処理からやり直す\r
+                               } while (invalidInstallers == null || invalidInstallers.Count > 0);\r
+                               RaiseTaskSetEvent(NaGetTaskSetEventType.COMPLETED_TASKSET, TaskSetNames[currentTaskSetIndex]);\r
+                               currentTaskSetIndex ++;\r
                        }\r
                        \r
                        foreach (Installation inst in Installations) {\r
@@ -144,7 +165,7 @@ namespace NaGet.SubCommands
                                        inst.OutputDataReceived += this.ReceivedOutputData;\r
                                        int exitCode = inst.Install();\r
                                        if (exitCode != 0) {\r
-                                               RaiseTaskSetEvent(NaGetTaskSetEventType.WARNING, "ã\82¤ã\83³ã\82¹ã\83\88ã\83¼ã\83«ã\81\8c正常ã\81«çµ\82ã\81\88ã\81¦ã\81\84ã\81ªã\81\84å\8f¯è\83½æ\80§ã\81\8cã\81\82ã\82\8aã\81¾ã\81\99ã\80\82ã\82¤ã\83³ã\82¹ã\83\88ã\83¼ã\83©の終了コード:"+exitCode);\r
+                                               RaiseTaskSetEvent(NaGetTaskSetEventType.WARNING, "ã\82¤ã\83³ã\82¹ã\83\88ã\83¼ã\83«ã\81\8c正常ã\81«çµ\82ã\81\88ã\81¦ã\81\84ã\81ªã\81\84å\8f¯è\83½æ\80§ã\81\8cã\81\82ã\82\8aã\81¾ã\81\99ã\80\82ã\83\97ã\83­ã\82»ã\82¹の終了コード:"+exitCode);\r
                                        }\r
                                        \r
                                        pkgListMan.WriteInstallationLog(inst);\r
@@ -153,9 +174,8 @@ namespace NaGet.SubCommands
                                        done = true;\r
                                        return;\r
                                }\r
-                               currentTaskSetIndex ++;\r
-                               \r
                                RaiseTaskSetEvent(NaGetTaskSetEventType.COMPLETED_TASKSET, installTaskMsg);\r
+                               currentTaskSetIndex ++;\r
                                \r
                                if (cancelCalled) {\r
                                        RaiseTaskSetEvent(NaGetTaskSetEventType.CANCELED, "パッケージのインストール処理がキャンセルされました");\r
@@ -163,7 +183,6 @@ namespace NaGet.SubCommands
                                        return;\r
                                }\r
                        }\r
-                       pkgListMan.SaveSystemInstalledLogList(); // ログのコミット\r
                        \r
                        runLocalUpdate();\r
                        \r
@@ -195,7 +214,7 @@ namespace NaGet.SubCommands
                                                try {\r
                                                        inst.Download(Downloader);\r
                                                } catch (NaGetTaskCanceledException) {\r
-                                                       RaiseTaskSetEvent(NaGetTaskSetEventType.CANCELED, "インストーラのダウンロード処理がキャンセルされました");\r
+                                                       RaiseTaskSetEvent(NaGetTaskSetEventType.CANCELED, "ã\82¤ã\83³ã\82¹ã\83\88ã\83¼ã\83©ã\83¼ã\81®ã\83\80ã\82¦ã\83³ã\83­ã\83¼ã\83\89å\87¦ç\90\86ã\81\8cã\82­ã\83£ã\83³ã\82»ã\83«ã\81\95ã\82\8cã\81¾ã\81\97ã\81\9f");\r
                                                        done = true;\r
                                                        return;\r
                                                } catch (System.Net.WebException e) {\r
@@ -213,20 +232,43 @@ namespace NaGet.SubCommands
                                                        return;\r
                                                }\r
                                        }\r
-                                       currentTaskSetIndex ++;\r
                                        \r
-                                       if (inst.Downloaded) { // 正常終了\r
-                                               RaiseTaskSetEvent(NaGetTaskSetEventType.COMPLETED_TASKSET, TaskSetNames[currentTaskSetIndex]);\r
-                                       } else { // インストールが完了せずに終わった=失敗=エラー\r
-                                               RaiseTaskSetEvent(NaGetTaskSetEventType.ERROR, string.Format("{0}のインストーラを正常にダウンロードできませんでした", inst.ToString()));\r
+                                       if (! inst.Downloaded) { // インストールが完了せずに終わった=失敗=エラー\r
+                                               RaiseTaskSetEvent(NaGetTaskSetEventType.ERROR, string.Format("{0}のインストーラーファイルを正常にダウンロードできませんでした", inst.ToString()));\r
                                                done = true;\r
                                                return;\r
                                        }\r
+                                       RaiseTaskSetEvent(NaGetTaskSetEventType.COMPLETED_TASKSET, TaskSetNames[currentTaskSetIndex]);\r
+                                       currentTaskSetIndex ++;\r
                                        \r
                                        RaiseTaskSetEvent(NaGetTaskSetEventType.STARTED_TASKSET, TaskSetNames[currentTaskSetIndex]);\r
-                                       if (scanner.HasScanner) {\r
+                                       if (! NaGet.Env.EnableScanInstallerFile) {\r
+                                               RaiseTaskSetEvent(NaGetTaskSetEventType.INFO, "ウイルススキャンを行わない設定のため、ダウンロードしたファイルはウイルススキャンされませんでした");\r
+                                       } else if (!scanner.HasScanner) {\r
+                                               RaiseTaskSetEvent(NaGetTaskSetEventType.INFO, "ダウンロードしたファイルはウイルススキャンされませんでした(ウイルススキャンソフトが検出できませんでした)");\r
+                                       } else {\r
                                                try {\r
-                                                       inst.ScanInstallerFile(scanner);\r
+                                                       DownloadScannerResult result = inst.ScanInstallerFile(scanner);\r
+                                                       \r
+                                                       switch (result) {\r
+                                                               case DownloadScannerResult.ScannerNotFound:\r
+                                                                       RaiseTaskSetEvent(NaGetTaskSetEventType.INFO, "ダウンロードしたファイルはウイルススキャンされませんでした(ウイルススキャンソフトが検出できませんでした)");\r
+                                                                       break;\r
+                                                               case DownloadScannerResult.InfectedAndCleaned:\r
+                                                                       RaiseTaskSetEvent(NaGetTaskSetEventType.ERROR,\r
+                                                                                 "インストーラーファイルからウイルス感染が検出されたため、削除されました。");\r
+                                                                       done = true;\r
+                                                                       return;\r
+                                                               case DownloadScannerResult.InfectedButNotCleaned:\r
+                                                                       RaiseTaskSetEvent(NaGetTaskSetEventType.ERROR,\r
+                                                                                 "インストーラーファイルからウイルス感染が検出されました。");\r
+                                                                       done = true;\r
+                                                                       break;\r
+                                                               case DownloadScannerResult.ErrorNotFound:\r
+                                                                       throw new System.IO.FileNotFoundException(string.Empty);\r
+                                                                       //break;\r
+                                                       }\r
+                                                       \r
                                                } catch (System.Runtime.InteropServices.COMException ex) {\r
                                                        RaiseTaskSetEvent(NaGetTaskSetEventType.WARNING,\r
                                                                          string.Format("{0} (E{1})", ex.Message, ex.ErrorCode));\r
@@ -235,14 +277,19 @@ namespace NaGet.SubCommands
                                                                RaiseTaskSetEvent(NaGetTaskSetEventType.WARNING,\r
                                                                                  string.Format("{0} (E{1})", ex.InnerException.Message, ((System.Runtime.InteropServices.COMException) ex.InnerException).ErrorCode));\r
                                                        }\r
-                                                       RaiseTaskSetEvent(NaGetTaskSetEventType.ERROR, "ã\82¤ã\83³ã\82¹ã\83\88ã\83¼ã\83©ã\81\8cã\82¦ã\82¤ã\83«ã\82¹ã\82¹ã\82­ã\83£ã\83\8aによって削除されました。");\r
+                                                       RaiseTaskSetEvent(NaGetTaskSetEventType.ERROR, "ã\82¤ã\83³ã\82¹ã\83\88ã\83¼ã\83©ã\83¼ã\83\95ã\82¡ã\82¤ã\83«ã\81\8cã\82¦ã\82¤ã\83«ã\82¹ã\82¹ã\82­ã\83£ã\83\8aã\83¼によって削除されました。");\r
                                                        done = true;\r
                                                        return;\r
                                                }\r
-                                       } else {\r
-                                               RaiseTaskSetEvent(NaGetTaskSetEventType.INFO, string.Format("ダウンロードしたファイルはウイルススキャンされませんでした(ウイルススキャンソフトが検出できませんでした)"));\r
                                        }\r
                                        RaiseTaskSetEvent(NaGetTaskSetEventType.COMPLETED_TASKSET, TaskSetNames[currentTaskSetIndex]);\r
+                                       currentTaskSetIndex ++;\r
+                                       \r
+                                       if (cancelCalled) {\r
+                                               RaiseTaskSetEvent(NaGetTaskSetEventType.CANCELED, "パッケージのインストール処理がキャンセルされました");\r
+                                               done = true;\r
+                                               return;\r
+                                       }\r
                                }\r
                        }\r
                }\r
@@ -250,10 +297,10 @@ namespace NaGet.SubCommands
                /// <summary>\r
                /// ダウンロードしたパッケージが整合したか否かハッシュでチェック\r
                /// </summary>\r
-               /// <returns>整合しなかったインストーラのリスト</returns>\r
-               private System.Collections.Generic.List<Installation> runCheckHashForInstaller()\r
+               /// <returns>æ\95´å\90\88ã\81\97ã\81ªã\81\8bã\81£ã\81\9fã\82¤ã\83³ã\82¹ã\83\88ã\83¼ã\83©ã\83¼ã\81®ã\83ªã\82¹ã\83\88</returns>\r
+               private List<Installation> runCheckHashForInstaller()\r
                {\r
-                       System.Collections.Generic.List<Installation> invalidInstallers = new System.Collections.Generic.List<Installation>();\r
+                       List<Installation> invalidInstallers = new List<Installation>();\r
                        \r
                        int i = 0;\r
                        foreach (Installation inst in Installations) {\r
@@ -281,15 +328,15 @@ namespace NaGet.SubCommands
                        RaiseTaskSetEvent(NaGetTaskSetEventType.STARTED_TASKSET, TaskSetNames[currentTaskSetIndex]);\r
                        pkgListMan.DetectInstalledPkgs();\r
                        pkgListMan.SaveInstalledPackageList();\r
+                       RaiseTaskSetEvent(NaGetTaskSetEventType.COMPLETED_TASKSET, TaskSetNames[currentTaskSetIndex]);\r
                        currentTaskSetIndex++;\r
-                       RaiseTaskSetEvent(NaGetTaskSetEventType.COMPLETED_TASKSET, TaskSetNames[currentTaskSetIndex-1]);\r
                \r
                        // システムにインストールされているリストの更新\r
                        RaiseTaskSetEvent(NaGetTaskSetEventType.STARTED_TASKSET, TaskSetNames[currentTaskSetIndex]);\r
                        pkgListMan.DetectSystemInstalledPkgs();\r
                        pkgListMan.SaveSystemInstalledPackageList();\r
+                       RaiseTaskSetEvent(NaGetTaskSetEventType.COMPLETED_TASKSET, TaskSetNames[currentTaskSetIndex]);\r
                        currentTaskSetIndex++;\r
-                       RaiseTaskSetEvent(NaGetTaskSetEventType.COMPLETED_TASKSET, TaskSetNames[currentTaskSetIndex-1]);\r
                }\r
                \r
                public override bool Done {\r