From 09d2c09137c9c62127d0aea826bae12836b40a74 Mon Sep 17 00:00:00 2001 From: ttp Date: Sat, 23 Aug 2008 07:42:13 +0000 Subject: [PATCH] =?utf8?q?AppliStation-*,=E3=81=A8=E3=82=8A=E3=81=82?= =?utf8?q?=E3=81=88=E3=81=9A=E3=81=AE=E5=AE=9F=E8=A3=85=20of=20=E3=80=8C?= =?utf8?q?=E3=82=A4=E3=83=B3=E3=82=B9=E3=83=88=E3=83=BC=E3=83=AB=E5=85=88?= =?utf8?q?=E3=83=95=E3=82=A9=E3=83=AB=E3=83=80=E3=80=8D=E3=81=AE=E3=81=A8?= =?utf8?q?=E3=81=93=E3=82=8D=E3=81=A7=E5=AE=9F=E8=A1=8C=E3=83=95=E3=82=A1?= =?utf8?q?=E3=82=A4=E3=83=AB=E3=82=92=E7=9B=B4=E6=8E=A5=20=E5=AE=9F?= =?utf8?q?=E8=A1=8C=E3=81=A7=E3=81=8D=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit * これに伴い、ShellLink生成のルーチンも一部変更となった。動作確認済み * とりあえずの動作がしている。 * アイコン取得か何かは不明だが、ファイル数が多いところでやけに遅いので、一瞬フリーズする * 実行ファイルを右クリック…はできかねます。ご了承くださいませ git-svn-id: http://localhost/svn/AppliStation/trunk@950 34ed2c89-c49f-4a4b-abdb-c318350108cf --- AppliStation/AppliStation.Util/GUIUtils.cs | 37 +++++++++++++++++++++++++ AppliStation/PackageListViewForm.Designer.cs | 31 +++++++++++---------- AppliStation/PackageListViewForm.cs | 39 +++++++++++++++++++++++++-- archive-inst/Program.cs | 14 +++------- na-get-lib/NaGet.InteropServices/ShellLink.cs | 36 ++++++++++++++++++++++++- 5 files changed, 128 insertions(+), 29 deletions(-) diff --git a/AppliStation/AppliStation.Util/GUIUtils.cs b/AppliStation/AppliStation.Util/GUIUtils.cs index 37a98f9..4f63287 100644 --- a/AppliStation/AppliStation.Util/GUIUtils.cs +++ b/AppliStation/AppliStation.Util/GUIUtils.cs @@ -90,5 +90,42 @@ namespace AppliStation.Util 0, 0, img.Width, img.Height, GraphicsUnit.Pixel, ia); } + + /// + /// 与えられたファイルのランチャーに相当するメニューアイテムを生成する + /// + /// ファイルパス + /// 生成されたメニューアイテム + public static System.Windows.Forms.ToolStripMenuItem CreateMenuItemForFile(string filePath) + { + System.Windows.Forms.ToolStripMenuItem item = new System.Windows.Forms.ToolStripMenuItem(); + string fileName = Path.GetFileName(filePath); + + item.Text = fileName; + item.ShowShortcutKeys = false; + item.Tag = filePath; + item.ToolTipText = string.Format("場所: {0}", filePath); + item.Click += new System.EventHandler(GUIUtils.menuItemForFileClicked); + try { + item.Image = Icon.ExtractAssociatedIcon(filePath).ToBitmap(); + } catch (Exception) {} + + return item; + } + + /// + /// により使われるイベントハンドラ + /// + /// + /// + private static void menuItemForFileClicked(object sender, EventArgs e) + { + System.Windows.Forms.ToolStripMenuItem item = (System.Windows.Forms.ToolStripMenuItem) sender; + + System.Diagnostics.ProcessStartInfo procInfo = new System.Diagnostics.ProcessStartInfo(item.Tag.ToString()); + procInfo.WorkingDirectory = Path.GetDirectoryName(procInfo.FileName); + System.Diagnostics.Process.Start(procInfo); + } + } } diff --git a/AppliStation/PackageListViewForm.Designer.cs b/AppliStation/PackageListViewForm.Designer.cs index 2ac2548..e9eafd0 100644 --- a/AppliStation/PackageListViewForm.Designer.cs +++ b/AppliStation/PackageListViewForm.Designer.cs @@ -58,7 +58,7 @@ this.webResourcesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.webOfficialToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.webGoogleSearchToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.openInstalledDirectoryStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.installedDirectoryStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.propertiesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.detailBox = new System.Windows.Forms.RichTextBox(); this.tableLayoutPanel1.SuspendLayout(); @@ -74,7 +74,7 @@ // toolStripSeparator1 // this.toolStripSeparator1.Name = "toolStripSeparator1"; - this.toolStripSeparator1.Size = new System.Drawing.Size(228, 6); + this.toolStripSeparator1.Size = new System.Drawing.Size(201, 6); // // tableLayoutPanel1 // @@ -293,23 +293,23 @@ this.uninstallToolStripMenuItem, this.toolStripSeparator1, this.webResourcesToolStripMenuItem, - this.openInstalledDirectoryStripMenuItem, + this.installedDirectoryStripMenuItem, this.propertiesToolStripMenuItem}); this.packageListContextMenuStrip.Name = "packageListContextMenuStrip"; - this.packageListContextMenuStrip.Size = new System.Drawing.Size(232, 142); + this.packageListContextMenuStrip.Size = new System.Drawing.Size(205, 142); this.packageListContextMenuStrip.Opening += new System.ComponentModel.CancelEventHandler(this.PackageListContextMenuStripOpening); // // installToolStripMenuItem // this.installToolStripMenuItem.Name = "installToolStripMenuItem"; - this.installToolStripMenuItem.Size = new System.Drawing.Size(231, 22); + this.installToolStripMenuItem.Size = new System.Drawing.Size(204, 22); this.installToolStripMenuItem.Text = "インストール(&I)..."; this.installToolStripMenuItem.Click += new System.EventHandler(this.InstallToolStripButtonClick); // // uninstallToolStripMenuItem // this.uninstallToolStripMenuItem.Name = "uninstallToolStripMenuItem"; - this.uninstallToolStripMenuItem.Size = new System.Drawing.Size(231, 22); + this.uninstallToolStripMenuItem.Size = new System.Drawing.Size(204, 22); this.uninstallToolStripMenuItem.Text = "アンインストール(&U)..."; this.uninstallToolStripMenuItem.Click += new System.EventHandler(this.UninstallToolStripButtonClick); // @@ -319,34 +319,33 @@ this.webOfficialToolStripMenuItem, this.webGoogleSearchToolStripMenuItem}); this.webResourcesToolStripMenuItem.Name = "webResourcesToolStripMenuItem"; - this.webResourcesToolStripMenuItem.Size = new System.Drawing.Size(231, 22); + this.webResourcesToolStripMenuItem.Size = new System.Drawing.Size(204, 22); this.webResourcesToolStripMenuItem.Tag = "\"{0}\"に関するWebページ(&W)"; // // webOfficialToolStripMenuItem // this.webOfficialToolStripMenuItem.Name = "webOfficialToolStripMenuItem"; - this.webOfficialToolStripMenuItem.Size = new System.Drawing.Size(151, 22); + this.webOfficialToolStripMenuItem.Size = new System.Drawing.Size(152, 22); this.webOfficialToolStripMenuItem.Text = "公式サイト(&O)"; this.webOfficialToolStripMenuItem.Click += new System.EventHandler(this.WebOfficialToolStripMenuItemClick); // // webGoogleSearchToolStripMenuItem // this.webGoogleSearchToolStripMenuItem.Name = "webGoogleSearchToolStripMenuItem"; - this.webGoogleSearchToolStripMenuItem.Size = new System.Drawing.Size(151, 22); + this.webGoogleSearchToolStripMenuItem.Size = new System.Drawing.Size(152, 22); this.webGoogleSearchToolStripMenuItem.Text = "Google検索(&G)"; this.webGoogleSearchToolStripMenuItem.Click += new System.EventHandler(this.WebGoogleSearchToolStripMenuItemClick); // - // openInstalledDirectoryStripMenuItem + // installedDirectoryStripMenuItem // - this.openInstalledDirectoryStripMenuItem.Name = "openInstalledDirectoryStripMenuItem"; - this.openInstalledDirectoryStripMenuItem.Size = new System.Drawing.Size(231, 22); - this.openInstalledDirectoryStripMenuItem.Text = "インストール先のフォルダを開く(&O)"; - this.openInstalledDirectoryStripMenuItem.Click += new System.EventHandler(this.OpenInstalledDirectoryStripMenuItemClick); + this.installedDirectoryStripMenuItem.Name = "installedDirectoryStripMenuItem"; + this.installedDirectoryStripMenuItem.Size = new System.Drawing.Size(204, 22); + this.installedDirectoryStripMenuItem.Text = "インストール先のフォルダ(&O)"; // // propertiesToolStripMenuItem // this.propertiesToolStripMenuItem.Name = "propertiesToolStripMenuItem"; - this.propertiesToolStripMenuItem.Size = new System.Drawing.Size(231, 22); + this.propertiesToolStripMenuItem.Size = new System.Drawing.Size(204, 22); this.propertiesToolStripMenuItem.Text = "プロパティ(&R)"; this.propertiesToolStripMenuItem.Click += new System.EventHandler(this.PropertiesToolStripMenuItemClick); // @@ -388,10 +387,10 @@ this.packageListContextMenuStrip.ResumeLayout(false); this.ResumeLayout(false); } + private System.Windows.Forms.ToolStripMenuItem installedDirectoryStripMenuItem; private System.Windows.Forms.ToolStripSeparator packageCommandsToolStripSeparator; private System.Windows.Forms.ToolStripMenuItem propertiesToolStripMenuItem; private System.Windows.Forms.ToolStripSeparator toolStripSeparator1; - private System.Windows.Forms.ToolStripMenuItem openInstalledDirectoryStripMenuItem; private System.Windows.Forms.ToolStripMenuItem webGoogleSearchToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem webOfficialToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem webResourcesToolStripMenuItem; diff --git a/AppliStation/PackageListViewForm.cs b/AppliStation/PackageListViewForm.cs index 4c96fa4..3a8b0d2 100644 --- a/AppliStation/PackageListViewForm.cs +++ b/AppliStation/PackageListViewForm.cs @@ -125,6 +125,35 @@ namespace AppliStation } } + private void buildInstalledDirectoryMenuItemStripChildren(InstalledPackage pkg) + { + string targetDir = pkg.UninstallInfo.InstallLocation; + System.Collections.Generic.List items = new System.Collections.Generic.List(); + + if (Directory.Exists(targetDir)) { + foreach (string exeFile in Directory.GetFiles(targetDir, "*.exe")) { + if (NaGet.InteropServices.PEFileInfoUtils.GetPEFileType(exeFile) == NaGet.InteropServices.PEFileInfoUtils.PEFileType.WinGUI) { + items.Add(AppliStation.Util.GUIUtils.CreateMenuItemForFile(exeFile)); + } + } + + if (items.Count > 0) { + items.Add(new ToolStripSeparator()); + } + + { + ToolStripMenuItem item = AppliStation.Util.GUIUtils.CreateMenuItemForFile(targetDir); + item.Text = "フォルダを開く(&O)"; + items.Add(item); + } + } + + installedDirectoryStripMenuItem.DropDownItems.Clear(); + installedDirectoryStripMenuItem.DropDownItems.AddRange(items.ToArray()); + } + + #region packageListViewのSort関連 + AppliStation.Util.ListViewItemSortComparer packageListViewSortComparer; void PackageListViewColumnClick(object sender, ColumnClickEventArgs e) @@ -157,6 +186,8 @@ namespace AppliStation } } + #endregion + void Form_OnLoad(object sender, EventArgs e) { System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(PackageListViewForm)); @@ -562,13 +593,17 @@ namespace AppliStation webOfficialToolStripMenuItem.Enabled = ! (pkg.Url == null || string.IsNullOrEmpty(pkg.Url.Href)); // webGoogleSearchToolStripMenuItem always active. - openInstalledDirectoryStripMenuItem.Visible = isInstalledPackage && + bool installedDirectoryStripMenuItemVisible = isInstalledPackage && ( (pkg.Type == InstallerType.ARCHIVE) || Directory.Exists(((InstalledPackage) pkg).UninstallInfo.InstallLocation) ); + installedDirectoryStripMenuItem.Visible = installedDirectoryStripMenuItemVisible; + if (installedDirectoryStripMenuItemVisible) { + buildInstalledDirectoryMenuItemStripChildren((InstalledPackage) pkg); + } } toolStripSeparator1.Visible = selectionIsOnlyOne; webResourcesToolStripMenuItem.Visible = selectionIsOnlyOne; - if (! selectionIsOnlyOne) openInstalledDirectoryStripMenuItem.Visible = false; + if (! selectionIsOnlyOne) installedDirectoryStripMenuItem.Visible = false; propertiesToolStripMenuItem.Visible = selectionIsOnlyOne; } diff --git a/archive-inst/Program.cs b/archive-inst/Program.cs index 1a44c1c..75ac08c 100644 --- a/archive-inst/Program.cs +++ b/archive-inst/Program.cs @@ -128,19 +128,13 @@ namespace ArchiveInstall //lnk.SetIconLocation(path, 0); // .lnk ファイル名 - string lnkFileName; - System.Diagnostics.FileVersionInfo vInfo = System.Diagnostics.FileVersionInfo.GetVersionInfo(exeFile); - if (vInfo.ProductName != null && vInfo.ProductName != string.Empty - && (!File.Exists(Path.Combine(progGrpPath, vInfo.ProductName+".lnk")))) { - // 原則、lnkファイル名に製品名を採用 - lnkFileName = vInfo.ProductName; - } else { - // そのほかの場合は、*.exeファイルの名前をそのまま使用 - lnkFileName = Path.GetFileNameWithoutExtension(exeFile); + string lnkFilePath = Path.Combine(progGrpPath, lnk.GetSuitableShellLinkNameFor() + ".lnk"); + if (File.Exists(lnkFilePath)) { // ファイル名がかぶってしまったとき + lnkFilePath = Path.Combine(progGrpPath, Path.GetFileNameWithoutExtension(exeFile) + ".lnk"); } // 保存 - lnk.ToPersistFile().Save(Path.Combine(progGrpPath, lnkFileName+".lnk"), true); + lnk.ToPersistFile().Save(lnkFilePath, true); } } } diff --git a/na-get-lib/NaGet.InteropServices/ShellLink.cs b/na-get-lib/NaGet.InteropServices/ShellLink.cs index f243c01..12bf1eb 100644 --- a/na-get-lib/NaGet.InteropServices/ShellLink.cs +++ b/na-get-lib/NaGet.InteropServices/ShellLink.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Text; using System.Runtime.InteropServices; using System.Runtime.InteropServices.ComTypes; @@ -100,12 +100,19 @@ namespace NaGet.InteropServices protected const int MAX_PATH = 260; + /// + /// 新しいシェルリンクを作成する形のコンストラクタ + /// public ShellLink() { Type shellLinkType = Type.GetTypeFromCLSID(new Guid(ShellLinkGuid)); shellLink = (IShellLinkW) Activator.CreateInstance(shellLinkType); } + /// + /// 既存のシェルリンクを開くコンストラクタ + /// + /// 既存のシェルリンクのパス public ShellLink(string path) : this() { if (! System.IO.File.Exists(path)) { @@ -276,5 +283,32 @@ namespace NaGet.InteropServices return shelllink; } + + /// + /// ショートカット先のEXEファイルに対して適切な名前を生成する。 + /// + /// 具体的には、アセンブリの製品名をまず優先的に使い、 + /// それがなければ、exeファイルのファイル名(拡張子を除いたもの)を返す。 + /// + /// 拡張子はつかないので、lnkファイル名に使う場合は、手動で + /// ".lnk"を追加すること。 + /// + /// 拡張子を含まない、適切な名前 + public string GetSuitableShellLinkNameFor() + { + string exeFile = GetPath(0); + + try { + FileVersionInfo vInfo = FileVersionInfo.GetVersionInfo(exeFile); + if (vInfo.ProductName != null && vInfo.ProductName != string.Empty + && vInfo.ProductName.IndexOfAny(System.IO.Path.GetInvalidFileNameChars()) < 0) { + // 原則、製品名を採用 + return vInfo.ProductName; + } + } catch (Exception) {} + + // そのほかの場合は、*.exeファイルの名前をそのまま使用 + return System.IO.Path.GetFileNameWithoutExtension(exeFile); + } } } -- 2.11.0