From ff4217d2ac0a2f82d2020931b5695e53e6d06bc4 Mon Sep 17 00:00:00 2001 From: ttp Date: Sat, 5 Jul 2008 04:06:12 +0000 Subject: [PATCH] =?utf8?q?na-get,NaGetInstall(Update)=E3=81=AEDownloder?= =?utf8?q?=E3=82=92=E5=A4=96=E9=83=A8=E3=81=8B=E3=82=89=E6=9B=B8=E3=81=8D?= =?utf8?q?=E8=BE=BC=E3=81=BF=E3=81=A7=E3=81=8D=E3=81=AA=E3=81=84=E3=82=88?= =?utf8?q?=E3=81=86=E3=81=AB(=E3=81=93=E3=82=8C=E3=81=AB=E4=BC=B4=E3=81=86?= =?utf8?q?AppliStation-GUI,all-get=E3=81=AE=E5=A4=89=E6=9B=B4=E3=82=82?= =?utf8?q?=E5=90=8C=E6=99=82=E3=81=AB=E8=A1=8C=E3=81=A3=E3=81=9F)=20?= =?utf8?q?=E7=B5=90=E6=9E=9C=E3=80=81TODO=E3=81=8C2=E3=81=A4=E6=B8=9B?= =?utf8?q?=E3=81=A3=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit git-svn-id: http://localhost/svn/AppliStation/trunk@933 34ed2c89-c49f-4a4b-abdb-c318350108cf --- .../AppliStation.Util/ExecutionProgressViewer.cs | 56 ++++++------- AppliStation/PackageListViewForm.cs | 50 ++++++----- AppliStation/Program.cs | 20 ++--- all-get/Main.cs | 6 +- na-get-lib/NaGet.Net/Downloader.cs | 24 ++++-- na-get-lib/NaGet.SubCommands/NaGetInstall.cs | 96 ++++++++++++---------- na-get-lib/NaGet.SubCommands/NaGetUpdate.cs | 15 +++- 7 files changed, 151 insertions(+), 116 deletions(-) diff --git a/AppliStation/AppliStation.Util/ExecutionProgressViewer.cs b/AppliStation/AppliStation.Util/ExecutionProgressViewer.cs index 94dd6d5..de87382 100644 --- a/AppliStation/AppliStation.Util/ExecutionProgressViewer.cs +++ b/AppliStation/AppliStation.Util/ExecutionProgressViewer.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Drawing; using System.Windows.Forms; using System.Threading; @@ -14,12 +14,10 @@ namespace AppliStation.Util { private NaGetTaskSet taskSet; - private Downloader downloader; - private Thread tasksetRunningThread = null; /// - /// I—¹Žž‚ɉ½‚ðs‚¤‚©‚̃tƒ‰ƒO + /// 終了時に何を行うかのフラグ /// public enum ActionOnDoneFlags { None = 0, @@ -28,33 +26,26 @@ namespace AppliStation.Util } /// - /// I—¹Žž‚ɉ½‚ðs‚¤‚© + /// 終了時に何を行うか /// public ActionOnDoneFlags ActionOnDone = ActionOnDoneFlags.FlashWindow; - - public Downloader Downloader { - get { return downloader; } - } - + public ExecutionProgressViewer() { // // The InitializeComponent() call is required for Windows Forms designer support. // InitializeComponent(); - - downloader = new Downloader(); - downloader.DownloadEventRaised += delegate(object sender, DownloadEventArgs e) { - if (InvokeRequired) { - Invoke(new EventHandler(onDownloadEvent), sender, e); - } else { - onDownloadEvent(sender, e); - } - }; } - + private void onDownloadEvent(object sender, DownloadEventArgs a) { + if (InvokeRequired) { + Invoke(new EventHandler(onDownloadEvent), sender, a); + return; + } + + if (a.TaskProgressPercent >= 0) { progressBarSub.Value = (int) a.TaskProgressPercent; progressBarSub.Style = ProgressBarStyle.Continuous; @@ -82,13 +73,13 @@ namespace AppliStation.Util progressSubLabel.Visible = false; logBox.SelectionColor = System.Drawing.Color.Red; - logBox.AppendText(" [ƒGƒ‰[] " + a.TaskMessage + System.Environment.NewLine); + logBox.AppendText(" [エラー] " + a.TaskMessage + System.Environment.NewLine); logBox.SelectionColor = logBox.ForeColor; break; } } - #region NaGetTaskSetŠÖ˜A + #region NaGetTaskSet関連 private void onTaskSetRaised(object sender, NaGetTaskSetEventArgs e) { @@ -106,7 +97,7 @@ namespace AppliStation.Util switch (e.Type) { case NaGetTaskSetEventType.COMPLETED: - logBox.AppendText("Š®—¹." + System.Environment.NewLine); + logBox.AppendText("完了." + System.Environment.NewLine); if (taskSet.Done) { okButton.Enabled = true; cancelButton.Enabled = false; @@ -120,9 +111,9 @@ namespace AppliStation.Util if (progressBarSub.Visible) progressBarSub.Hide(); if (progressSubLabel.Visible) progressSubLabel.Hide(); - NativeMethods.ProgressBar_SetState(progressBar, 1); // VistaProgressFFƒm[ƒ}ƒ‹ + NativeMethods.ProgressBar_SetState(progressBar, 1); // VistaProgress色:ノーマル - logBox.AppendText(string.Format(" ... Š®—¹. [{0}%]", (int) e.TaskProgressPercent)); + logBox.AppendText(string.Format(" ... 完了. [{0}%]", (int) e.TaskProgressPercent)); logBox.AppendText(System.Environment.NewLine); break; case NaGetTaskSetEventType.INFO: @@ -130,10 +121,10 @@ namespace AppliStation.Util break; case NaGetTaskSetEventType.ERROR: logBox.SelectionColor = System.Drawing.Color.Red; - logBox.AppendText(" [ƒGƒ‰[] " + e.TaskMessage + System.Environment.NewLine); + logBox.AppendText(" [エラー] " + e.TaskMessage + System.Environment.NewLine); logBox.SelectionColor = logBox.ForeColor; - NativeMethods.ProgressBar_SetState(progressBar, 2); // VistaProgressFFƒGƒ‰[ + NativeMethods.ProgressBar_SetState(progressBar, 2); // VistaProgress色:エラー okButton.Enabled = true; cancelButton.Enabled = false; @@ -143,14 +134,14 @@ namespace AppliStation.Util logBox.AppendText(e.TaskMessage + System.Environment.NewLine); logBox.SelectionColor = logBox.ForeColor; - NativeMethods.ProgressBar_SetState(progressBar, 1); // VistaProgressFF’†’f + NativeMethods.ProgressBar_SetState(progressBar, 1); // VistaProgress色:中断 okButton.Enabled = true; cancelButton.Enabled = false; break; case NaGetTaskSetEventType.WARNING: logBox.SelectionColor = System.Drawing.Color.Red; - logBox.AppendText(" [ƒGƒ‰[] " + e.TaskMessage + System.Environment.NewLine); + logBox.AppendText(" [エラー] " + e.TaskMessage + System.Environment.NewLine); logBox.SelectionColor = logBox.ForeColor; break; @@ -209,6 +200,11 @@ namespace AppliStation.Util } }; + System.Reflection.PropertyInfo fDownloader = taskSet.GetType().GetProperty("Downloader"); + if (fDownloader != null && (fDownloader.PropertyType == typeof(Downloader))) { + ((Downloader) fDownloader.GetValue(taskSet, null)).DownloadEventRaised += onDownloadEvent; + } + taskSet.TaskQueryRaised += onTaskQueryRaised; } @@ -242,7 +238,7 @@ namespace AppliStation.Util if (taskSet != null && taskSet.Running && taskSet.Cancelable) { cancelButton.Enabled = false; - NativeMethods.ProgressBar_SetState(progressBar, 3); // VistaProgressFF’†’f + NativeMethods.ProgressBar_SetState(progressBar, 3); // VistaProgress色:中断 taskSet.Cancel(); } diff --git a/AppliStation/PackageListViewForm.cs b/AppliStation/PackageListViewForm.cs index 432f619..304db17 100644 --- a/AppliStation/PackageListViewForm.cs +++ b/AppliStation/PackageListViewForm.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Drawing; using System.Windows.Forms; using NaGet.Packages; @@ -47,16 +47,16 @@ namespace AppliStation detailBox.SelectedText += string.Format("{0} ({1})\r\n", pkg.Name, pkg.Version); if (! string.IsNullOrEmpty(pkg.Tags) ) { detailBox.SelectionFont = new Font(detailBox.Font.FontFamily, 8); - detailBox.SelectedText += string.Format("ƒ^ƒO: {0}\r\n", pkg.Tags); + detailBox.SelectedText += string.Format("タグ: {0}\r\n", pkg.Tags); } if (isInstalledPackage) { InstalledPackage iPkg = (InstalledPackage) pkg; System.Text.StringBuilder sb = new System.Text.StringBuilder(); if (iPkg.UninstallInfo.InstallDate != null) { - sb.AppendFormat("ƒCƒ“ƒXƒg[ƒ‹‚µ‚½“ú: {0:d} ", iPkg.UninstallInfo.InstallDate.Value); + sb.AppendFormat("インストールした日: {0:d} ", iPkg.UninstallInfo.InstallDate.Value); } if (iPkg.UninstallInfo.EstimatedSize > 0) { - sb.AppendFormat("ƒTƒCƒY: {0} ", NaGet.Utils.FormatSize(iPkg.UninstallInfo.EstimatedSize*1024)); + sb.AppendFormat("サイズ: {0} ", NaGet.Utils.FormatSize(iPkg.UninstallInfo.EstimatedSize*1024)); } if (sb.Length > 0) { @@ -67,7 +67,7 @@ namespace AppliStation } detailBox.SelectionFont = detailBox.Font; if (pkg.Url != null && pkg.Url.Href != null) { - detailBox.SelectedText += "ŒöŽ®ƒTƒCƒg: " + pkg.Url.Href + "\r\n"; + detailBox.SelectedText += "公式サイト: " + pkg.Url.Href + "\r\n"; } detailBox.SelectedText += pkg.Summary; @@ -81,8 +81,8 @@ namespace AppliStation if (packageListView.SelectedItems.Count <= 0) { detailBox.SelectionFont = detailBox.Font; int count = packageListView.Items.Count; - detailBox.Text = (count > 0) ? string.Format("{0}ŒÂ‚̃\ƒtƒg‚ª‚ ‚è‚Ü‚·B", count) - : "ŠY“–‚·‚éƒ\ƒtƒg‚ª‚ ‚è‚Ü‚¹‚ñB"; + detailBox.Text = (count > 0) ? string.Format("{0}個のソフトがあります。", count) + : "該当するソフトがありません。"; } detailBox.SelectionStart = 0; @@ -132,7 +132,7 @@ namespace AppliStation } AppliStation.Util.NativeMethods.ColumnHeader_SetSortState(packageListView, e.Column, order); - // ƒ\[ƒg‘Ώۗñ‚̐F•t‚¯ + // ソート対象列の色付け try { // SendMessage(hWnd, LVM_SETSELECTEDCOLUMN, column, NULL); AppliStation.Util.NativeMethods.SendMessage(packageListView.Handle, 0x1000+140, (uint) e.Column, 0); @@ -153,7 +153,7 @@ namespace AppliStation installedSysPackageFilterToolStripMenuItem.Image = ((Icon)(resources.GetObject("sysinstalled.Icon"))).ToBitmap(); } - #region PackageFilterŠÖ˜A + #region PackageFilter関連 private enum PackageFilterIndex : int { @@ -228,11 +228,11 @@ namespace AppliStation if (currentPackageFilter == PackageFilterIndex.All || currentPackageFilter == PackageFilterIndex.NotInstalled) { foreach (Package pkg in pkgListsMan.AvailablePkgList.Search(searchTextBox.Text)) { - if (Installation.GetPreferInstallerIndex(pkg) >= 0) { // ƒCƒ“ƒXƒg[ƒ‹‰Â”\ + if (Installation.GetPreferInstallerIndex(pkg) >= 0) { // インストール可能 if (currentPackageFilter == PackageFilterIndex.NotInstalled && (pkgListsMan.InstalledPkgList.GetPackageForName(pkg.Name) != null|| pkgListsMan.SystemInstalledPkgList.GetPackageForName(pkg.Name) != null) ) { - continue; // ƒCƒ“ƒXƒg[ƒ‹Ï‚Ý‚ÍŽŸ‚̃‹[ƒv‚Ö(–¢ƒCƒ“ƒXƒg[ƒ‹ƒ\ƒtƒg’ŠoŽž) + continue; // インストール済みは次のループへ(未インストールソフト抽出時) } ListViewItem item = new ListViewItem(new string[]{pkg.Name, pkg.Version, pkg.Summary}); @@ -282,12 +282,11 @@ namespace AppliStation AppliStation.Util.ExecutionProgressViewer prog = new AppliStation.Util.ExecutionProgressViewer(); prog.Shown += delegate(object sender2, EventArgs e2) { NaGet.SubCommands.NaGetUpdate tasks = new NaGet.SubCommands.NaGetUpdate(pkgListsMan, downloadPackageListsFlag); - tasks.Downloader = prog.Downloader; prog.SetTaskSet(tasks); prog.Refresh(); prog.StartTaskSet(); }; - prog.Text = "ƒŠƒXƒg‚̍XV"; + prog.Text = "リストの更新"; prog.ShowDialog(this); } @@ -305,7 +304,7 @@ namespace AppliStation UpdatePackageList(); } - #region searchTextBox‚Ü‚í‚è + #region searchTextBoxまわり void SearchTextBoxKeyPress(object sender, KeyPressEventArgs e) { @@ -331,12 +330,11 @@ namespace AppliStation AppliStation.Util.ExecutionProgressViewer prog = new AppliStation.Util.ExecutionProgressViewer(); prog.Shown += delegate(object sender2, EventArgs e2) { NaGet.SubCommands.NaGetInstall tasks = new NaGet.SubCommands.NaGetInstall(pkgListsMan, insts); - tasks.Downloader = prog.Downloader; prog.SetTaskSet(tasks); prog.Refresh(); prog.StartTaskSet(); }; - prog.Text = string.Format("ƒ\ƒtƒgƒEƒFƒA‚̃Cƒ“ƒXƒg[ƒ‹"); + prog.Text = string.Format("ソフトウェアのインストール"); prog.ShowDialog(this); } @@ -389,7 +387,7 @@ namespace AppliStation } }; } catch (System.ComponentModel.Win32Exception ex) { - MessageBox.Show(ex.Message, "ƒCƒ“ƒXƒg[ƒ‹", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show(ex.Message, "インストール", MessageBoxButtons.OK, MessageBoxIcon.Error); if (File.Exists(tmpfileName)) { File.Delete(tmpfileName); @@ -407,7 +405,7 @@ namespace AppliStation prog.Refresh(); prog.StartTaskSet(); }; - prog.Text = string.Format("ƒ\ƒtƒgƒEƒFƒA‚̃Aƒ“ƒCƒ“ƒXƒg[ƒ‹"); + prog.Text = string.Format("ソフトウェアのアンインストール"); prog.ShowDialog(this); } @@ -439,7 +437,7 @@ namespace AppliStation } }; } catch (System.ComponentModel.Win32Exception ex) { - MessageBox.Show(ex.Message, "ƒAƒ“ƒCƒ“ƒXƒg[ƒ‹", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show(ex.Message, "アンインストール", MessageBoxButtons.OK, MessageBoxIcon.Error); this.setWindowEnabled(true); if (File.Exists(tmpfileName)) { @@ -515,7 +513,7 @@ namespace AppliStation foreach (Package pkg in SelectedPackages()) { PackageInfoForm form = new PackageInfoForm(); form.SelectedObject = pkg; - form.Text = string.Format("{0}({1})‚̃vƒƒpƒeƒB", pkg.Name, pkg.Version); + form.Text = string.Format("{0}({1})のプロパティ", pkg.Name, pkg.Version); form.ShowDialog(this); @@ -525,7 +523,7 @@ namespace AppliStation void PackageListContextMenuStripOpening(object sender, System.ComponentModel.CancelEventArgs e) { - // ‘I‘ð‚³‚ê‚Ä‚¢‚È‚¢‚È‚çŠJ‚©‚È‚¢ + // 選択されていないなら開かない if (packageListView.SelectedItems.Count <= 0) { e.Cancel = true; return; @@ -539,7 +537,7 @@ namespace AppliStation webResourcesToolStripMenuItem.Text = string.Format( webResourcesToolStripMenuItem.Tag.ToString(), - pkg.Name.Replace("&", "&&")); // pkg.Name‚É&‚ªŠÜ‚Ü‚ê‚Ä‚¢‚é‚Æ‚«‚̓Gƒ“ƒR[ƒh + pkg.Name.Replace("&", "&&")); // pkg.Nameに&が含まれているときはエンコード webOfficialToolStripMenuItem.Enabled = ! (pkg.Url == null || string.IsNullOrEmpty(pkg.Url.Href)); // webGoogleSearchToolStripMenuItem always active. @@ -575,7 +573,7 @@ namespace AppliStation pkgs.AddRange(getUpdatedPackages(pkgListsMan.SystemInstalledPkgList, avaiablePackageList, verComp)); if (pkgs.Count <= 0) { - MessageBox.Show(this, "XV‚³‚ꂽƒ\ƒtƒg‚Í‚ ‚è‚Ü‚¹‚ñ", "ƒ\ƒtƒg‚̍XV"); + MessageBox.Show(this, "更新されたソフトはありません", "ソフトの更新"); return; } @@ -604,7 +602,7 @@ namespace AppliStation } /// - /// ƒCƒ“ƒXƒg[ƒ‹‚·‚é‚悤‘I‘ð‚³‚ê‚½ƒpƒbƒP[ƒW‚Ì”z—ñ + /// インストールするよう選択されたパッケージの配列 /// public TPackage[] SelectedPackages() where TPackage : Package { @@ -617,9 +615,9 @@ namespace AppliStation } /// - /// Ž©ƒEƒBƒ“ƒhƒE‚Ì—LŒø–³Œø(Enabled)‚ð(•K—v‚ ‚ê‚ÎInvoke‚µ‚Ä)ŽÀs‚·‚é + /// 自ウィンドウの有効無効(Enabled)を(必要あればInvokeして)実行する /// - /// —LŒø‚©”Û‚©BEnabled‚Ì’l‚É“ü‚ê‚ç‚ê‚é + /// 有効か否か。Enabledの値に入れられる private void setWindowEnabled(bool enabled) { MethodInvoker process = (MethodInvoker) delegate() { diff --git a/AppliStation/Program.cs b/AppliStation/Program.cs index 496f417..acae4af 100644 --- a/AppliStation/Program.cs +++ b/AppliStation/Program.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Windows.Forms; using System.IO; @@ -12,7 +12,7 @@ namespace AppliStation PackageListViewForm form; /// - /// ƒAƒvƒŠƒP[ƒVƒ‡ƒ“‚̃IƒvƒVƒ‡ƒ“ + /// アプリケーションのオプション /// Dictionary appArgs; @@ -48,10 +48,10 @@ namespace AppliStation hideSplashScreen(); form.installActionInvoke(insts); } catch (UnauthorizedAccessException e) { - MessageBox.Show(string.Format("ŠÇ—ŽÒŒ ŒÀ‚ɏ¸Ši‚µ‚Ä‚¢‚È‚¢‚©AŽÀsŒ ŒÀ‚É–â‘肪‚ ‚è‚Ü‚·B\n(Ú×:{0})", e.Message), + MessageBox.Show(string.Format("管理者権限に昇格していないか、実行権限に問題があります。\n(詳細:{0})", e.Message), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (FileNotFoundException e) { - MessageBox.Show(string.Format("ƒ\ƒtƒgŽw’èƒtƒ@ƒCƒ‹{0}‚ªŒ©‚‚©‚è‚Ü‚¹‚ñ", e.FileName), + MessageBox.Show(string.Format("ソフト指定ファイル{0}が見つかりません", e.FileName), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); } } @@ -64,10 +64,10 @@ namespace AppliStation hideSplashScreen(); form.uninstallActionInvoke(pkgs); } catch (UnauthorizedAccessException e) { - MessageBox.Show(string.Format("ŠÇ—ŽÒŒ ŒÀ‚ɏ¸Ši‚µ‚Ä‚¢‚È‚¢‚©AŽÀsŒ ŒÀ‚É–â‘肪‚ ‚è‚Ü‚·B\n(Ú×:{0})", e.Message), + MessageBox.Show(string.Format("管理者権限に昇格していないか、実行権限に問題があります。\n(詳細:{0})", e.Message), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (FileNotFoundException e) { - MessageBox.Show(string.Format("ƒ\ƒtƒgŽw’èƒtƒ@ƒCƒ‹{0}‚ªŒ©‚‚©‚è‚Ü‚¹‚ñ", e.FileName), + MessageBox.Show(string.Format("ソフト指定ファイル{0}が見つかりません", e.FileName), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); } } @@ -85,7 +85,7 @@ namespace AppliStation try { parseArgs(args); } catch (ApplicationException e) { - MessageBox.Show(e.Message, "AppliStation ‹N“®ˆø”ƒGƒ‰[", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show(e.Message, "AppliStation 起動引数エラー", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } @@ -114,7 +114,7 @@ namespace AppliStation Form splashScreen = null; try { - if (args.Length <= 0) { // HACK ˆø”ƒp[ƒX‚ÌŽžŠÔ‚³‚¦‘Ò‚Ä‚È‚¢‚̂ňø”‚Ì—L–³‚Å•\Ž¦‚ð”»’f + if (args.Length <= 0) { // HACK 引数パースの時間さえ待てないので引数の有無で表示を判断 splashScreen = new Form(); splashScreen.FormBorderStyle = FormBorderStyle.None; splashScreen.BackgroundImage = System.Drawing.Bitmap.FromFile(Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "SplashScreen.png")); @@ -125,8 +125,8 @@ namespace AppliStation splashScreen.Show(); } - ToolStripManager.VisualStylesEnabled = false; // ToolStrip‚ªLuna‚Ղ­‚È‚ç‚È‚¢‚悤‚É - Application.EnableVisualStyles(); // Luna‚âVista‚̃fƒUƒCƒ“‚ð—LŒø‚É + ToolStripManager.VisualStylesEnabled = false; // ToolStripがLunaで青くならないように + Application.EnableVisualStyles(); // LunaやVistaのデザインを有効に Application.ThreadException += AppliStation.Util.ExceptionDialogForm.Application_ThrowException; System.Threading.Thread.GetDomain().UnhandledException += AppliStation.Util.ExceptionDialogForm.Application_ThrowException; diff --git a/all-get/Main.cs b/all-get/Main.cs index 90eb234..592f7ef 100644 --- a/all-get/Main.cs +++ b/all-get/Main.cs @@ -95,7 +95,6 @@ namespace AllGet public void update(bool downloadPackageListFlag) { NaGet.SubCommands.NaGetUpdate tasks = new NaGet.SubCommands.NaGetUpdate(pkgListMan, downloadPackageListFlag); - tasks.Downloader = this.downloader; tasks.TaskSetRaised += delegate(object sender, NaGetTaskSetEventArgs e) { switch (e.Type) { // case NaGetTaskSetEventType.COMPLETED_TASKSET @@ -118,6 +117,8 @@ namespace AllGet break; } }; + DownloadListener dl = new DownloadListener(); + tasks.Downloader.DownloadEventRaised += dl.OnDownload; tasks.Run(); } @@ -296,7 +297,6 @@ namespace AllGet } NaGet.SubCommands.NaGetInstall tasks = new NaGet.SubCommands.NaGetInstall(pkgListMan, installations); - tasks.Downloader = this.downloader; tasks.TaskQueryRaised += delegate(object sender, NaGetTaskQueryArgs e) { char result = '\u0000'; if (e.SelectionFlag == (NaGetTaskQueryResult.CONTINUE | NaGetTaskQueryResult.RETRY | NaGetTaskQueryResult.CANCEL)) { @@ -342,6 +342,8 @@ namespace AllGet break; } }; + DownloadListener dl = new DownloadListener(); + tasks.Downloader.DownloadEventRaised += dl.OnDownload; tasks.Run(); } diff --git a/na-get-lib/NaGet.Net/Downloader.cs b/na-get-lib/NaGet.Net/Downloader.cs index 926f947..0920001 100644 --- a/na-get-lib/NaGet.Net/Downloader.cs +++ b/na-get-lib/NaGet.Net/Downloader.cs @@ -78,14 +78,31 @@ public class Downloader : NaGetTask /// public event EventHandler DownloadEventRaised; + /// + /// アクセスURL + /// protected string url; + /// + /// 保存先 + /// protected string filepath; + /// + /// リクエストオブジェクト + /// protected WebRequest request; + /// + /// レスポンスオブジェクト。応答がくるまではnullである。 + /// protected WebResponse response; + /// + /// ダウンロード要求時のキャッシュレベル。デフォルトではキャッシュ無視 + /// + public System.Net.Cache.RequestCacheLevel CacheLevel = System.Net.Cache.RequestCacheLevel.NoCacheNoStore; + private bool cancelCalled = false; private bool done = false; @@ -136,11 +153,8 @@ public class Downloader : NaGetTask try { request = WebRequest.Create(url); - request.Proxy = (Proxy == null)? DefaultProxy : Proxy; - if (request is HttpWebRequest) { - request.CachePolicy = new System.Net.Cache.HttpRequestCachePolicy( - System.Net.Cache.HttpRequestCacheLevel.NoCacheNoStore); - } + request.Proxy = (Proxy == null)? DefaultProxy : Proxy; + request.CachePolicy = new System.Net.Cache.RequestCachePolicy(CacheLevel); if (cancelCalled) { throw new NaGetTaskCanceledException(string.Empty); diff --git a/na-get-lib/NaGet.SubCommands/NaGetInstall.cs b/na-get-lib/NaGet.SubCommands/NaGetInstall.cs index e000ff7..9e626b8 100644 --- a/na-get-lib/NaGet.SubCommands/NaGetInstall.cs +++ b/na-get-lib/NaGet.SubCommands/NaGetInstall.cs @@ -1,4 +1,4 @@ -using System; +using System; using NaGet.Packages.Install; using NaGet.Packages; using NaGet.Net; @@ -13,7 +13,19 @@ namespace NaGet.SubCommands private PackageListsManager pkgListMan; - public Downloader Downloader; // TODO ŽQÆ‚ð‚µ‚ÄƒZƒbƒg‚·‚é‚悤‚É + /// + /// ダウンロードに使うダウンローダオブジェクト + /// + public Downloader Downloader { + get { + if (downloader == null) { + downloader = new Downloader(); + } + return downloader; + } + } + + private Downloader downloader; private bool packageInstallerDownloaded = false; @@ -22,23 +34,23 @@ namespace NaGet.SubCommands } /// - /// ƒCƒ“ƒXƒg[ƒ‹‚·‚éƒpƒbƒP[ƒW + /// インストールするパッケージ /// public Installation[] Installations; /// - /// ƒRƒ“ƒXƒgƒ‰ƒNƒ^ + /// コンストラクタ /// - /// ƒCƒ“ƒXƒg[ƒ‹‚·‚éƒpƒbƒP[ƒW + /// インストールするパッケージ public NaGetInstall(PackageListsManager pkgListMan, Package[] pkgs) : this(pkgListMan, Installation.ConvertInstallations(pkgs)) { } /// - /// ƒRƒ“ƒXƒgƒ‰ƒNƒ^ + /// コンストラクタ /// - /// ƒCƒ“ƒXƒg[ƒ‹ˆ—‚Ì”z—ñ + /// インストール処理の配列 public NaGetInstall(PackageListsManager pkgMan, Installation[] installations) { pkgListMan = pkgMan; @@ -52,14 +64,14 @@ namespace NaGet.SubCommands System.Collections.Generic.List taskSetNames = new System.Collections.Generic.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("ƒCƒ“ƒXƒg[ƒ‰‚ÌŒŸØ"); + taskSetNames.Add("インストーラの検証"); for (int i =0; i < Installations.Length; i++) { - taskSetNames.Add(string.Format("ƒCƒ“ƒXƒg[ƒ‹: {0}", Installations[i].ToString())); + taskSetNames.Add(string.Format("インストール: {0}", Installations[i].ToString())); } - taskSetNames.Add(string.Format("ƒŠƒXƒgXV: {0}", NaGet.Env.ArchiveInstalledPackageListFile)); - taskSetNames.Add(string.Format("ƒŠƒXƒgXV: {0}", NaGet.Env.SystemInstalledPackageListFile)); + taskSetNames.Add(string.Format("リスト更新: {0}", NaGet.Env.ArchiveInstalledPackageListFile)); + taskSetNames.Add(string.Format("リスト更新: {0}", NaGet.Env.SystemInstalledPackageListFile)); TaskSetNames = taskSetNames.ToArray(); } @@ -67,10 +79,10 @@ namespace NaGet.SubCommands public override void Run() { currentTaskSetIndex = 0; - RaiseTaskSetEvent(NaGetTaskSetEventType.STARTED, "ƒCƒ“ƒXƒg[ƒ‹ˆ—ŠJŽn"); + RaiseTaskSetEvent(NaGetTaskSetEventType.STARTED, "インストール処理開始"); { - // ƒnƒbƒVƒ…”ñ“K‡‚ȃCƒ“ƒXƒg[ƒ‰‚Ì•\ + // ハッシュ非適合なインストーラの表 System.Collections.Generic.List invalidInstallers = null; while (invalidInstallers == null || invalidInstallers.Count > 0) { @@ -78,16 +90,16 @@ namespace NaGet.SubCommands packageInstallerDownloaded = false; runDownloadInstallers(); - if (done) return; // ‚à‚µrunDownloadInstallers()“à‚ŃGƒ‰[I—¹‚µ‚Ä‚¢‚½‚È‚çI—¹ + if (done) return; // もしrunDownloadInstallers()内でエラー終了していたなら終了 packageInstallerDownloaded = true; - // ƒnƒbƒVƒ…‚̉ó‚ê‚Ä‚¢‚éƒCƒ“ƒXƒg[ƒ‰‚ðŽæ“¾ + // ハッシュの壊れているインストーラを取得 invalidInstallers = runCheckHashForInstaller(); - // ƒnƒbƒVƒ…‚ª‰ó‚ê‚Ä‚¢‚é‚Æ‚«‚̑΍ô + // ハッシュが壊れているときの対策 if (invalidInstallers.Count > 0) { - string msg = string.Format("{0}ŒÂ‚̃pƒbƒP[ƒW‚Ńtƒ@ƒCƒ‹‚ª‰ó‚ê‚Ä‚¢‚é‰Â”\«‚ª‚ ‚è‚Ü‚·\n‹­§“I‚ɃCƒ“ƒXƒg[ƒ‹‚𑱍s‚µ‚Ü‚·‚©?", + string msg = string.Format("{0}個のパッケージでファイルが壊れている可能性があります\n強制的にインストールを続行しますか?", invalidInstallers.Count); NaGetTaskQueryResult result = RaiseTaskSetQueryEvent(msg, NaGetTaskQueryResult.CONTINUE | NaGetTaskQueryResult.RETRY @@ -95,11 +107,11 @@ namespace NaGet.SubCommands switch (result) { case NaGetTaskQueryResult.CONTINUE: - RaiseTaskSetEvent(NaGetTaskSetEventType.WARNING, "ƒnƒbƒVƒ…‚Ì”ñ®‡‚𖳎‹‚µ‚ăCƒ“ƒXƒg[ƒ‹‚ðŒp‘±"); - invalidInstallers.Clear(); // ƒnƒbƒVƒ…”ñ“K‡ƒpƒbƒP[ƒW‚ð‹­§“I‚É–•Á + RaiseTaskSetEvent(NaGetTaskSetEventType.WARNING, "ハッシュの非整合を無視してインストールを継続"); + invalidInstallers.Clear(); // ハッシュ非適合パッケージを強制的に抹消 break; case NaGetTaskQueryResult.RETRY: - RaiseTaskSetEvent(NaGetTaskSetEventType.INFO, "ƒ_ƒEƒ“ƒ[ƒhˆ—‚ðÄŽŽs"); + RaiseTaskSetEvent(NaGetTaskSetEventType.INFO, "ダウンロード処理を再試行"); foreach (Installation invalidInst in invalidInstallers) { invalidInst.RemoveDownloadedFile(); @@ -108,7 +120,7 @@ namespace NaGet.SubCommands break; //case NaGetTaskQueryResult.CANCEL: default: - RaiseTaskSetEvent(NaGetTaskSetEventType.CANCELED, "ƒpƒbƒP[ƒW‚̃Cƒ“ƒXƒg[ƒ‹ˆ—‚ªƒLƒƒƒ“ƒZƒ‹‚³‚ê‚Ü‚µ‚½"); + RaiseTaskSetEvent(NaGetTaskSetEventType.CANCELED, "パッケージのインストール処理がキャンセルされました"); done = true; return; } @@ -120,7 +132,7 @@ namespace NaGet.SubCommands foreach (Installation inst in Installations) { string installTaskMsg = inst.ToString(); if (inst.Silent && (!inst.SupportsSilentOnly)) { - installTaskMsg += " (ƒTƒCƒŒƒ“ƒgƒCƒ“ƒXƒg[ƒ‹)"; + installTaskMsg += " (サイレントインストール)"; } RaiseTaskSetEvent(NaGetTaskSetEventType.STARTED_TASKSET, installTaskMsg); @@ -131,7 +143,7 @@ namespace NaGet.SubCommands inst.OutputDataReceived += this.ReceivedOutputData; int exitCode = inst.Install(); if (exitCode != 0) { - RaiseTaskSetEvent(NaGetTaskSetEventType.WARNING, "ƒCƒ“ƒXƒg[ƒ‹‚ª³í‚ɏI‚¦‚Ä‚¢‚È‚¢‰Â”\«‚ª‚ ‚è‚Ü‚·BƒCƒ“ƒXƒg[ƒ‰‚̏I—¹ƒR[ƒh:"+exitCode); + RaiseTaskSetEvent(NaGetTaskSetEventType.WARNING, "インストールが正常に終えていない可能性があります。インストーラの終了コード:"+exitCode); } pkgListMan.WriteInstallationLog(inst); @@ -145,29 +157,29 @@ namespace NaGet.SubCommands RaiseTaskSetEvent(NaGetTaskSetEventType.COMPLETED_TASKSET, installTaskMsg); if (cancelCalled) { - RaiseTaskSetEvent(NaGetTaskSetEventType.CANCELED, "ƒpƒbƒP[ƒW‚̃Cƒ“ƒXƒg[ƒ‹ˆ—‚ªƒLƒƒƒ“ƒZƒ‹‚³‚ê‚Ü‚µ‚½"); + RaiseTaskSetEvent(NaGetTaskSetEventType.CANCELED, "パッケージのインストール処理がキャンセルされました"); done = true; return; } } - pkgListMan.SaveSystemInstalledLogList(); // ƒƒO‚̃Rƒ~ƒbƒg + pkgListMan.SaveSystemInstalledLogList(); // ログのコミット runLocalUpdate(); done = true; - RaiseTaskSetEvent(NaGetTaskSetEventType.COMPLETED, "I—¹", 100); + RaiseTaskSetEvent(NaGetTaskSetEventType.COMPLETED, "終了", 100); } /// - /// ˆ—“à—e‚̃_ƒEƒ“ƒ[ƒh•”•ª‚̃Tƒuƒ‹[ƒ`ƒ“ + /// 処理内容のダウンロード部分のサブルーチン /// private void runDownloadInstallers() { foreach (Installation inst in Installations) { if (! inst.IsInstallablePackage()) { - string msg = string.Format("{0}‚̓Cƒ“ƒXƒg[ƒ‹‚·‚邱‚Æ‚ª‚Å‚«‚Ü‚¹‚ñ", inst.ToString()); + string msg = string.Format("{0}はインストールすることができません", inst.ToString()); RaiseTaskSetEvent(NaGetTaskSetEventType.ERROR, msg); done = true; @@ -180,15 +192,15 @@ namespace NaGet.SubCommands try { inst.Download(Downloader); } catch (NaGetTaskCanceledException) { - RaiseTaskSetEvent(NaGetTaskSetEventType.CANCELED, "ƒCƒ“ƒXƒg[ƒ‰‚̃_ƒEƒ“ƒ[ƒhˆ—‚ªƒLƒƒƒ“ƒZƒ‹‚³‚ê‚Ü‚µ‚½"); + 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, "ƒlƒbƒgƒ[ƒN‚ɐڑ±‚³‚ê‚Ä‚¢‚Ü‚¹‚ñB"); + RaiseTaskSetEvent(NaGetTaskSetEventType.ERROR, "ネットワークに接続されていません。"); } else { - RaiseTaskSetEvent(NaGetTaskSetEventType.ERROR, "ƒlƒbƒgƒ[ƒN‚ɐڑ±‚Å‚«‚Ü‚¹‚ñ‚Å‚µ‚½Bƒlƒbƒgƒ[ƒN‚ªØ’f‚³‚ê‚Ä‚¢‚é‚©Aƒtƒ@ƒCƒAƒEƒH[ƒ‹‚É‚æ‚Á‚ÄŽÕ’f‚³‚ꂽ‰Â”\«‚ª‚ ‚è‚Ü‚·B"); + RaiseTaskSetEvent(NaGetTaskSetEventType.ERROR, "ネットワークに接続できませんでした。ネットワークが切断されているか、ファイアウォールによって遮断された可能性があります。"); } done = true; return; @@ -200,18 +212,18 @@ namespace NaGet.SubCommands } currentTaskSetIndex ++; - if (inst.Downloaded) { // ³íI—¹ + if (inst.Downloaded) { // 正常終了 RaiseTaskSetEvent(NaGetTaskSetEventType.COMPLETED_TASKSET, inst.ToString()); - } else { // ƒCƒ“ƒXƒg[ƒ‹‚ªŠ®—¹‚¹‚¸‚ɏI‚í‚Á‚½=Ž¸”s=ƒGƒ‰[ - RaiseTaskSetEvent(NaGetTaskSetEventType.ERROR, string.Format("{0}‚̃Cƒ“ƒXƒg[ƒ‰‚𐳏í‚Ƀ_ƒEƒ“ƒ[ƒh‚Å‚«‚Ü‚¹‚ñ‚Å‚µ‚½", inst.ToString())); + } else { // インストールが完了せずに終わった=失敗=エラー + RaiseTaskSetEvent(NaGetTaskSetEventType.ERROR, string.Format("{0}のインストーラを正常にダウンロードできませんでした", inst.ToString())); } } } /// - /// ƒ_ƒEƒ“ƒ[ƒh‚µ‚½ƒpƒbƒP[ƒW‚ª®‡‚µ‚½‚©”Û‚©ƒnƒbƒVƒ…‚Ń`ƒFƒbƒN + /// ダウンロードしたパッケージが整合したか否かハッシュでチェック /// - /// ®‡‚µ‚È‚©‚Á‚½ƒCƒ“ƒXƒg[ƒ‰‚̃ŠƒXƒg + /// 整合しなかったインストーラのリスト private System.Collections.Generic.List runCheckHashForInstaller() { System.Collections.Generic.List invalidInstallers = new System.Collections.Generic.List(); @@ -221,13 +233,13 @@ namespace NaGet.SubCommands float percent = (CurrentTaskSetIndex+((float)i / Installations.Length))*100f/TaskSetNames.Length; if (inst.GetRegisteredHashCount() > 0) { - RaiseTaskSetEvent(NaGetTaskSetEventType.INFO, "ŒŸØ: "+inst.ToString(), percent); + RaiseTaskSetEvent(NaGetTaskSetEventType.INFO, "検証: "+inst.ToString(), percent); if (inst.IsInstallablePackage() && inst.VerifyHashValues() == false) { invalidInstallers.Add(inst); - RaiseTaskSetEvent(NaGetTaskSetEventType.WARNING, "ŒŸØ: "+inst.ToString() + " ”ñ®‡", percent); + RaiseTaskSetEvent(NaGetTaskSetEventType.WARNING, "検証: "+inst.ToString() + " 非整合", percent); } else { - RaiseTaskSetEvent(NaGetTaskSetEventType.INFO, "ŒŸØ: "+inst.ToString() + " OK", percent); + RaiseTaskSetEvent(NaGetTaskSetEventType.INFO, "検証: "+inst.ToString() + " OK", percent); } } i++; @@ -238,14 +250,14 @@ namespace NaGet.SubCommands private void runLocalUpdate() { - // ƒCƒ“ƒXƒg[ƒ‹ƒgƒŠƒXƒg‚̍XV + // インストールトリストの更新 RaiseTaskSetEvent(NaGetTaskSetEventType.STARTED_TASKSET, TaskSetNames[currentTaskSetIndex]); pkgListMan.DetectInstalledPkgs(); pkgListMan.SaveInstalledPackageList(); currentTaskSetIndex++; RaiseTaskSetEvent(NaGetTaskSetEventType.COMPLETED_TASKSET, TaskSetNames[currentTaskSetIndex-1]); - // ƒVƒXƒeƒ€‚ɃCƒ“ƒXƒg[ƒ‹‚³‚ê‚Ä‚¢‚郊ƒXƒg‚̍XV + // システムにインストールされているリストの更新 RaiseTaskSetEvent(NaGetTaskSetEventType.STARTED_TASKSET, TaskSetNames[currentTaskSetIndex]); pkgListMan.DetectSystemInstalledPkgs(); pkgListMan.SaveSystemInstalledPackageList(); diff --git a/na-get-lib/NaGet.SubCommands/NaGetUpdate.cs b/na-get-lib/NaGet.SubCommands/NaGetUpdate.cs index 0524292..9807e1a 100644 --- a/na-get-lib/NaGet.SubCommands/NaGetUpdate.cs +++ b/na-get-lib/NaGet.SubCommands/NaGetUpdate.cs @@ -17,7 +17,20 @@ namespace NaGet.SubCommands private bool packageListsDownloaded = true; - public Downloader Downloader; // TODO 参照をしてセットするように + + /// + /// ダウンロードに使うダウンローダオブジェクト + /// + public Downloader Downloader { + get { + if (downloader == null) { + downloader = new Downloader(); + } + return downloader; + } + } + + private Downloader downloader; private int currentTaskSetIndex = -1; -- 2.11.0