X-Git-Url: http://git.sourceforge.jp/view?p=applistation%2FAppliStation.git;a=blobdiff_plain;f=na-get-lib%2FNaGet.SubCommands%2FNaGetInstall.cs;h=390f1a0a7d6f91f0546f6cddd6499904e0fdbbbd;hp=9e626b86b19f2bfd5ff090e3e83b24cf135b55b8;hb=76ea75be843be4d33ed9233162c4542096e3ffb6;hpb=ff4217d2ac0a2f82d2020931b5695e53e6d06bc4 diff --git a/na-get-lib/NaGet.SubCommands/NaGetInstall.cs b/na-get-lib/NaGet.SubCommands/NaGetInstall.cs index 9e626b8..390f1a0 100644 --- a/na-get-lib/NaGet.SubCommands/NaGetInstall.cs +++ b/na-get-lib/NaGet.SubCommands/NaGetInstall.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using NaGet.Packages.Install; using NaGet.Packages; using NaGet.Net; @@ -20,6 +21,11 @@ namespace NaGet.SubCommands get { if (downloader == null) { downloader = new Downloader(); + downloader.DownloadEventRaised += delegate(object sender, DownloadEventArgs e) { + if (e.Type == DownloadEventType.DOWNLOADING && e.TaskProgressPercent > 0) { + RaiseTaskSetEvent(NaGetTaskSetEventType.PING, string.Empty, GetProgressPercent(NaGetTaskSetEventType.PING, e.TaskProgressPercent)); + } + }; } return downloader; } @@ -61,12 +67,13 @@ namespace NaGet.SubCommands private void initializeMainTaskSetNames() { - System.Collections.Generic.List taskSetNames = new System.Collections.Generic.List(); + List taskSetNames = new List(); for (int i =0; i < Installations.Length; i++) { taskSetNames.Add(string.Format("取得: {0}", Installations[i].ToString())); + taskSetNames.Add(string.Format("ウイルススキャン: {0}", Installations[i].ToString())); } - taskSetNames.Add("インストーラの検証"); + taskSetNames.Add("インストーラーの検証"); for (int i =0; i < Installations.Length; i++) { taskSetNames.Add(string.Format("インストール: {0}", Installations[i].ToString())); } @@ -83,27 +90,39 @@ namespace NaGet.SubCommands { // ハッシュ非適合なインストーラの表 - System.Collections.Generic.List invalidInstallers = null; + List invalidInstallers = null; - while (invalidInstallers == null || invalidInstallers.Count > 0) { + do { currentTaskSetIndex = 0; packageInstallerDownloaded = false; - runDownloadInstallers(); + runDownloadAndVirusCheckInstallers(); if (done) return; // もしrunDownloadInstallers()内でエラー終了していたなら終了 packageInstallerDownloaded = true; - // ハッシュの壊れているインストーラを取得 + + RaiseTaskSetEvent(NaGetTaskSetEventType.STARTED_TASKSET, TaskSetNames[currentTaskSetIndex]); + + // ハッシュの壊れているインストーラーを取得 invalidInstallers = runCheckHashForInstaller(); // ハッシュが壊れているときの対策 if (invalidInstallers.Count > 0) { - string msg = string.Format("{0}個のパッケージでファイルが壊れている可能性があります\n強制的にインストールを続行しますか?", - invalidInstallers.Count); - NaGetTaskQueryResult result = RaiseTaskSetQueryEvent(msg, NaGetTaskQueryResult.CONTINUE - | NaGetTaskQueryResult.RETRY - | NaGetTaskQueryResult.CANCEL); + System.Text.StringBuilder invalidInstallerNames = new System.Text.StringBuilder(); + foreach (Installation invalidInst in invalidInstallers) { + invalidInstallerNames.AppendFormat(" - {0}\n", invalidInst.ToString()); + } + + string msg = string.Format("以下の{0}個のパッケージでファイルが壊れている可能性があります。\n{1}\n強制的にインストールを続行しますか?", + invalidInstallers.Count, invalidInstallerNames.ToString()); + NaGetTaskQueryResult result = NaGetTaskQueryResult.CANCEL; + + if (!cancelCalled) { + result = RaiseTaskSetQueryEvent(msg, NaGetTaskQueryResult.CONTINUE + | NaGetTaskQueryResult.RETRY + | NaGetTaskQueryResult.CANCEL); + } switch (result) { case NaGetTaskQueryResult.CONTINUE: @@ -125,12 +144,15 @@ namespace NaGet.SubCommands return; } } - currentTaskSetIndex ++; - } + + // もしハッシュが不適合なソフトがあるならばダウンロード処理からやり直す + } while (invalidInstallers == null || invalidInstallers.Count > 0); + RaiseTaskSetEvent(NaGetTaskSetEventType.COMPLETED_TASKSET, TaskSetNames[currentTaskSetIndex]); + currentTaskSetIndex ++; } foreach (Installation inst in Installations) { - string installTaskMsg = inst.ToString(); + string installTaskMsg = TaskSetNames[currentTaskSetIndex]; if (inst.Silent && (!inst.SupportsSilentOnly)) { installTaskMsg += " (サイレントインストール)"; } @@ -143,7 +165,7 @@ namespace NaGet.SubCommands inst.OutputDataReceived += this.ReceivedOutputData; int exitCode = inst.Install(); if (exitCode != 0) { - RaiseTaskSetEvent(NaGetTaskSetEventType.WARNING, "インストールが正常に終えていない可能性があります。インストーラの終了コード:"+exitCode); + RaiseTaskSetEvent(NaGetTaskSetEventType.WARNING, "インストールが正常に終えていない可能性があります。プロセスの終了コード:"+exitCode); } pkgListMan.WriteInstallationLog(inst); @@ -152,9 +174,8 @@ namespace NaGet.SubCommands done = true; return; } - currentTaskSetIndex ++; - RaiseTaskSetEvent(NaGetTaskSetEventType.COMPLETED_TASKSET, installTaskMsg); + currentTaskSetIndex ++; if (cancelCalled) { RaiseTaskSetEvent(NaGetTaskSetEventType.CANCELED, "パッケージのインストール処理がキャンセルされました"); @@ -162,7 +183,6 @@ namespace NaGet.SubCommands return; } } - pkgListMan.SaveSystemInstalledLogList(); // ログのコミット runLocalUpdate(); @@ -173,60 +193,114 @@ namespace NaGet.SubCommands /// - /// 処理内容のダウンロード部分のサブルーチン + /// 処理内容のダウンロード・ウイルススキャン部分のサブルーチン /// - private void runDownloadInstallers() + private void runDownloadAndVirusCheckInstallers() { - foreach (Installation inst in Installations) { - if (! inst.IsInstallablePackage()) { - string msg = string.Format("{0}はインストールすることができません", inst.ToString()); - - RaiseTaskSetEvent(NaGetTaskSetEventType.ERROR, msg); - done = true; - return; - } - - RaiseTaskSetEvent(NaGetTaskSetEventType.STARTED_TASKSET, inst.ToString()); - - if (! inst.Downloaded) { - try { - inst.Download(Downloader); - } catch (NaGetTaskCanceledException) { - RaiseTaskSetEvent(NaGetTaskSetEventType.CANCELED, "インストーラのダウンロード処理がキャンセルされました"); + using (DownloadScanner scanner = new DownloadScanner()) { + scanner.Init(); + foreach (Installation inst in Installations) { + if (! inst.IsInstallablePackage()) { + string msg = string.Format("{0}はインストールすることができません", inst.ToString()); + + RaiseTaskSetEvent(NaGetTaskSetEventType.ERROR, msg); done = true; return; - } catch (System.Net.WebException e) { - RaiseTaskSetEvent(NaGetTaskSetEventType.WARNING, e.Message); - if (System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable()) { - RaiseTaskSetEvent(NaGetTaskSetEventType.ERROR, "ネットワークに接続されていません。"); - } else { - RaiseTaskSetEvent(NaGetTaskSetEventType.ERROR, "ネットワークに接続できませんでした。ネットワークが切断されているか、ファイアウォールによって遮断された可能性があります。"); + } + + RaiseTaskSetEvent(NaGetTaskSetEventType.STARTED_TASKSET, TaskSetNames[currentTaskSetIndex]); + + if (! inst.Downloaded) { + try { + inst.Download(Downloader); + } catch (NaGetTaskCanceledException) { + RaiseTaskSetEvent(NaGetTaskSetEventType.CANCELED, "インストーラーのダウンロード処理がキャンセルされました"); + done = true; + return; + } catch (System.Net.WebException e) { + RaiseTaskSetEvent(NaGetTaskSetEventType.WARNING, e.Message); + if (System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable()) { + RaiseTaskSetEvent(NaGetTaskSetEventType.ERROR, "ネットワークに接続されていません。"); + } else { + RaiseTaskSetEvent(NaGetTaskSetEventType.ERROR, "ネットワークに接続できませんでした。ネットワークが切断されているか、ファイアウォールによって遮断された可能性があります。"); + } + done = true; + return; + } catch (Exception e) { + RaiseTaskSetEvent(NaGetTaskSetEventType.ERROR, e.Message); + done = true; + return; } + } + + if (! inst.Downloaded) { // インストールが完了せずに終わった=失敗=エラー + RaiseTaskSetEvent(NaGetTaskSetEventType.ERROR, string.Format("{0}のインストーラーファイルを正常にダウンロードできませんでした", inst.ToString())); done = true; return; - } catch (Exception e) { - RaiseTaskSetEvent(NaGetTaskSetEventType.ERROR, e.Message); + } + RaiseTaskSetEvent(NaGetTaskSetEventType.COMPLETED_TASKSET, TaskSetNames[currentTaskSetIndex]); + currentTaskSetIndex ++; + + RaiseTaskSetEvent(NaGetTaskSetEventType.STARTED_TASKSET, TaskSetNames[currentTaskSetIndex]); + if (! NaGet.Env.EnableScanInstallerFile) { + RaiseTaskSetEvent(NaGetTaskSetEventType.INFO, "ウイルススキャンを行わない設定のため、ダウンロードしたファイルはウイルススキャンされませんでした"); + } else if (!scanner.HasScanner) { + RaiseTaskSetEvent(NaGetTaskSetEventType.INFO, "ダウンロードしたファイルはウイルススキャンされませんでした(ウイルススキャンソフトが検出できませんでした)"); + } else { + try { + DownloadScannerResult result = inst.ScanInstallerFile(scanner); + + switch (result) { + case DownloadScannerResult.ScannerNotFound: + RaiseTaskSetEvent(NaGetTaskSetEventType.INFO, "ダウンロードしたファイルはウイルススキャンされませんでした(ウイルススキャンソフトが検出できませんでした)"); + break; + case DownloadScannerResult.InfectedAndCleaned: + RaiseTaskSetEvent(NaGetTaskSetEventType.ERROR, + "インストーラーファイルからウイルス感染が検出されたため、削除されました。"); + done = true; + return; + case DownloadScannerResult.InfectedButNotCleaned: + RaiseTaskSetEvent(NaGetTaskSetEventType.ERROR, + "インストーラーファイルからウイルス感染が検出されました。"); + done = true; + break; + case DownloadScannerResult.ErrorNotFound: + throw new System.IO.FileNotFoundException(string.Empty); + //break; + } + + } catch (System.Runtime.InteropServices.COMException ex) { + RaiseTaskSetEvent(NaGetTaskSetEventType.WARNING, + string.Format("{0} (E{1})", ex.Message, ex.ErrorCode)); + } catch (System.IO.FileNotFoundException ex) { + if (ex.InnerException is System.Runtime.InteropServices.COMException) { + RaiseTaskSetEvent(NaGetTaskSetEventType.WARNING, + string.Format("{0} (E{1})", ex.InnerException.Message, ((System.Runtime.InteropServices.COMException) ex.InnerException).ErrorCode)); + } + RaiseTaskSetEvent(NaGetTaskSetEventType.ERROR, "インストーラーファイルがウイルススキャナーによって削除されました。"); + done = true; + return; + } + } + RaiseTaskSetEvent(NaGetTaskSetEventType.COMPLETED_TASKSET, TaskSetNames[currentTaskSetIndex]); + currentTaskSetIndex ++; + + if (cancelCalled) { + RaiseTaskSetEvent(NaGetTaskSetEventType.CANCELED, "パッケージのインストール処理がキャンセルされました"); done = true; return; } } - currentTaskSetIndex ++; - - if (inst.Downloaded) { // 正常終了 - RaiseTaskSetEvent(NaGetTaskSetEventType.COMPLETED_TASKSET, inst.ToString()); - } else { // インストールが完了せずに終わった=失敗=エラー - RaiseTaskSetEvent(NaGetTaskSetEventType.ERROR, string.Format("{0}のインストーラを正常にダウンロードできませんでした", inst.ToString())); - } } } /// /// ダウンロードしたパッケージが整合したか否かハッシュでチェック /// - /// 整合しなかったインストーラのリスト - private System.Collections.Generic.List runCheckHashForInstaller() + /// 整合しなかったインストーラーのリスト + private List runCheckHashForInstaller() { - System.Collections.Generic.List invalidInstallers = new System.Collections.Generic.List(); + List invalidInstallers = new List(); int i = 0; foreach (Installation inst in Installations) { @@ -254,15 +328,15 @@ namespace NaGet.SubCommands RaiseTaskSetEvent(NaGetTaskSetEventType.STARTED_TASKSET, TaskSetNames[currentTaskSetIndex]); pkgListMan.DetectInstalledPkgs(); pkgListMan.SaveInstalledPackageList(); + RaiseTaskSetEvent(NaGetTaskSetEventType.COMPLETED_TASKSET, TaskSetNames[currentTaskSetIndex]); currentTaskSetIndex++; - RaiseTaskSetEvent(NaGetTaskSetEventType.COMPLETED_TASKSET, TaskSetNames[currentTaskSetIndex-1]); // システムにインストールされているリストの更新 RaiseTaskSetEvent(NaGetTaskSetEventType.STARTED_TASKSET, TaskSetNames[currentTaskSetIndex]); pkgListMan.DetectSystemInstalledPkgs(); pkgListMan.SaveSystemInstalledPackageList(); + RaiseTaskSetEvent(NaGetTaskSetEventType.COMPLETED_TASKSET, TaskSetNames[currentTaskSetIndex]); currentTaskSetIndex++; - RaiseTaskSetEvent(NaGetTaskSetEventType.COMPLETED_TASKSET, TaskSetNames[currentTaskSetIndex-1]); } public override bool Done {