0, 0, img.Width, img.Height,\r
GraphicsUnit.Pixel, ia);\r
}\r
+\r
+ /// <summary>\r
+ /// 与えられたファイルのランチャーに相当するメニューアイテムを生成する\r
+ /// </summary>\r
+ /// <param name="filePath">ファイルパス</param>\r
+ /// <returns>生成されたメニューアイテム</returns>\r
+ public static System.Windows.Forms.ToolStripMenuItem CreateMenuItemForFile(string filePath)\r
+ {\r
+ System.Windows.Forms.ToolStripMenuItem item = new System.Windows.Forms.ToolStripMenuItem();\r
+ string fileName = Path.GetFileName(filePath);\r
+ \r
+ item.Text = fileName;\r
+ item.ShowShortcutKeys = false;\r
+ item.Tag = filePath;\r
+ item.ToolTipText = string.Format("場所: {0}", filePath);\r
+ item.Click += new System.EventHandler(GUIUtils.menuItemForFileClicked);\r
+ try {\r
+ item.Image = Icon.ExtractAssociatedIcon(filePath).ToBitmap();\r
+ } catch (Exception) {}\r
+ \r
+ return item;\r
+ }\r
+ \r
+ /// <summary>\r
+ /// <see cref="CreateMenuItemForFile" />により使われるイベントハンドラ\r
+ /// </summary>\r
+ /// <param name="sender"></param>\r
+ /// <param name="e"></param>\r
+ private static void menuItemForFileClicked(object sender, EventArgs e)\r
+ {\r
+ System.Windows.Forms.ToolStripMenuItem item = (System.Windows.Forms.ToolStripMenuItem) sender;\r
+ \r
+ System.Diagnostics.ProcessStartInfo procInfo = new System.Diagnostics.ProcessStartInfo(item.Tag.ToString());\r
+ procInfo.WorkingDirectory = Path.GetDirectoryName(procInfo.FileName);\r
+ System.Diagnostics.Process.Start(procInfo);\r
+ }\r
+ \r
}\r
}\r
this.webResourcesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();\r
this.webOfficialToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();\r
this.webGoogleSearchToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();\r
- this.openInstalledDirectoryStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();\r
+ this.installedDirectoryStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();\r
this.propertiesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();\r
this.detailBox = new System.Windows.Forms.RichTextBox();\r
this.tableLayoutPanel1.SuspendLayout();\r
// toolStripSeparator1\r
// \r
this.toolStripSeparator1.Name = "toolStripSeparator1";\r
- this.toolStripSeparator1.Size = new System.Drawing.Size(228, 6);\r
+ this.toolStripSeparator1.Size = new System.Drawing.Size(201, 6);\r
// \r
// tableLayoutPanel1\r
// \r
this.uninstallToolStripMenuItem,\r
this.toolStripSeparator1,\r
this.webResourcesToolStripMenuItem,\r
- this.openInstalledDirectoryStripMenuItem,\r
+ this.installedDirectoryStripMenuItem,\r
this.propertiesToolStripMenuItem});\r
this.packageListContextMenuStrip.Name = "packageListContextMenuStrip";\r
- this.packageListContextMenuStrip.Size = new System.Drawing.Size(232, 142);\r
+ this.packageListContextMenuStrip.Size = new System.Drawing.Size(205, 142);\r
this.packageListContextMenuStrip.Opening += new System.ComponentModel.CancelEventHandler(this.PackageListContextMenuStripOpening);\r
// \r
// installToolStripMenuItem\r
// \r
this.installToolStripMenuItem.Name = "installToolStripMenuItem";\r
- this.installToolStripMenuItem.Size = new System.Drawing.Size(231, 22);\r
+ this.installToolStripMenuItem.Size = new System.Drawing.Size(204, 22);\r
this.installToolStripMenuItem.Text = "インストール(&I)...";\r
this.installToolStripMenuItem.Click += new System.EventHandler(this.InstallToolStripButtonClick);\r
// \r
// uninstallToolStripMenuItem\r
// \r
this.uninstallToolStripMenuItem.Name = "uninstallToolStripMenuItem";\r
- this.uninstallToolStripMenuItem.Size = new System.Drawing.Size(231, 22);\r
+ this.uninstallToolStripMenuItem.Size = new System.Drawing.Size(204, 22);\r
this.uninstallToolStripMenuItem.Text = "アンインストール(&U)...";\r
this.uninstallToolStripMenuItem.Click += new System.EventHandler(this.UninstallToolStripButtonClick);\r
// \r
this.webOfficialToolStripMenuItem,\r
this.webGoogleSearchToolStripMenuItem});\r
this.webResourcesToolStripMenuItem.Name = "webResourcesToolStripMenuItem";\r
- this.webResourcesToolStripMenuItem.Size = new System.Drawing.Size(231, 22);\r
+ this.webResourcesToolStripMenuItem.Size = new System.Drawing.Size(204, 22);\r
this.webResourcesToolStripMenuItem.Tag = "\"{0}\"に関するWebページ(&W)";\r
// \r
// webOfficialToolStripMenuItem\r
// \r
this.webOfficialToolStripMenuItem.Name = "webOfficialToolStripMenuItem";\r
- this.webOfficialToolStripMenuItem.Size = new System.Drawing.Size(151, 22);\r
+ this.webOfficialToolStripMenuItem.Size = new System.Drawing.Size(152, 22);\r
this.webOfficialToolStripMenuItem.Text = "公式サイト(&O)";\r
this.webOfficialToolStripMenuItem.Click += new System.EventHandler(this.WebOfficialToolStripMenuItemClick);\r
// \r
// webGoogleSearchToolStripMenuItem\r
// \r
this.webGoogleSearchToolStripMenuItem.Name = "webGoogleSearchToolStripMenuItem";\r
- this.webGoogleSearchToolStripMenuItem.Size = new System.Drawing.Size(151, 22);\r
+ this.webGoogleSearchToolStripMenuItem.Size = new System.Drawing.Size(152, 22);\r
this.webGoogleSearchToolStripMenuItem.Text = "Google検索(&G)";\r
this.webGoogleSearchToolStripMenuItem.Click += new System.EventHandler(this.WebGoogleSearchToolStripMenuItemClick);\r
// \r
- // openInstalledDirectoryStripMenuItem\r
+ // installedDirectoryStripMenuItem\r
// \r
- this.openInstalledDirectoryStripMenuItem.Name = "openInstalledDirectoryStripMenuItem";\r
- this.openInstalledDirectoryStripMenuItem.Size = new System.Drawing.Size(231, 22);\r
- this.openInstalledDirectoryStripMenuItem.Text = "インストール先のフォルダを開く(&O)";\r
- this.openInstalledDirectoryStripMenuItem.Click += new System.EventHandler(this.OpenInstalledDirectoryStripMenuItemClick);\r
+ this.installedDirectoryStripMenuItem.Name = "installedDirectoryStripMenuItem";\r
+ this.installedDirectoryStripMenuItem.Size = new System.Drawing.Size(204, 22);\r
+ this.installedDirectoryStripMenuItem.Text = "インストール先のフォルダ(&O)";\r
// \r
// propertiesToolStripMenuItem\r
// \r
this.propertiesToolStripMenuItem.Name = "propertiesToolStripMenuItem";\r
- this.propertiesToolStripMenuItem.Size = new System.Drawing.Size(231, 22);\r
+ this.propertiesToolStripMenuItem.Size = new System.Drawing.Size(204, 22);\r
this.propertiesToolStripMenuItem.Text = "プロパティ(&R)";\r
this.propertiesToolStripMenuItem.Click += new System.EventHandler(this.PropertiesToolStripMenuItemClick);\r
// \r
this.packageListContextMenuStrip.ResumeLayout(false);\r
this.ResumeLayout(false);\r
}\r
+ private System.Windows.Forms.ToolStripMenuItem installedDirectoryStripMenuItem;\r
private System.Windows.Forms.ToolStripSeparator packageCommandsToolStripSeparator;\r
private System.Windows.Forms.ToolStripMenuItem propertiesToolStripMenuItem;\r
private System.Windows.Forms.ToolStripSeparator toolStripSeparator1;\r
- private System.Windows.Forms.ToolStripMenuItem openInstalledDirectoryStripMenuItem;\r
private System.Windows.Forms.ToolStripMenuItem webGoogleSearchToolStripMenuItem;\r
private System.Windows.Forms.ToolStripMenuItem webOfficialToolStripMenuItem;\r
private System.Windows.Forms.ToolStripMenuItem webResourcesToolStripMenuItem;\r
}\r
}\r
\r
+ private void buildInstalledDirectoryMenuItemStripChildren(InstalledPackage pkg)\r
+ {\r
+ string targetDir = pkg.UninstallInfo.InstallLocation; \r
+ System.Collections.Generic.List<ToolStripItem> items = new System.Collections.Generic.List<ToolStripItem>();\r
+ \r
+ if (Directory.Exists(targetDir)) {\r
+ foreach (string exeFile in Directory.GetFiles(targetDir, "*.exe")) {\r
+ if (NaGet.InteropServices.PEFileInfoUtils.GetPEFileType(exeFile) == NaGet.InteropServices.PEFileInfoUtils.PEFileType.WinGUI) {\r
+ items.Add(AppliStation.Util.GUIUtils.CreateMenuItemForFile(exeFile));\r
+ }\r
+ }\r
+ \r
+ if (items.Count > 0) {\r
+ items.Add(new ToolStripSeparator());\r
+ }\r
+ \r
+ {\r
+ ToolStripMenuItem item = AppliStation.Util.GUIUtils.CreateMenuItemForFile(targetDir);\r
+ item.Text = "フォルダを開く(&O)";\r
+ items.Add(item);\r
+ }\r
+ }\r
+ \r
+ installedDirectoryStripMenuItem.DropDownItems.Clear();\r
+ installedDirectoryStripMenuItem.DropDownItems.AddRange(items.ToArray());\r
+ }\r
+ \r
+ #region packageListViewのSort関連\r
+ \r
AppliStation.Util.ListViewItemSortComparer packageListViewSortComparer;\r
\r
void PackageListViewColumnClick(object sender, ColumnClickEventArgs e)\r
}\r
}\r
\r
+ #endregion\r
+ \r
void Form_OnLoad(object sender, EventArgs e)\r
{\r
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(PackageListViewForm));\r
webOfficialToolStripMenuItem.Enabled = ! (pkg.Url == null || string.IsNullOrEmpty(pkg.Url.Href));\r
// webGoogleSearchToolStripMenuItem always active.\r
\r
- openInstalledDirectoryStripMenuItem.Visible = isInstalledPackage &&\r
+ bool installedDirectoryStripMenuItemVisible = isInstalledPackage &&\r
( (pkg.Type == InstallerType.ARCHIVE) || Directory.Exists(((InstalledPackage) pkg).UninstallInfo.InstallLocation) );\r
+ installedDirectoryStripMenuItem.Visible = installedDirectoryStripMenuItemVisible;\r
+ if (installedDirectoryStripMenuItemVisible) {\r
+ buildInstalledDirectoryMenuItemStripChildren((InstalledPackage) pkg);\r
+ }\r
}\r
\r
toolStripSeparator1.Visible = selectionIsOnlyOne;\r
webResourcesToolStripMenuItem.Visible = selectionIsOnlyOne;\r
- if (! selectionIsOnlyOne) openInstalledDirectoryStripMenuItem.Visible = false;\r
+ if (! selectionIsOnlyOne) installedDirectoryStripMenuItem.Visible = false;\r
propertiesToolStripMenuItem.Visible = selectionIsOnlyOne;\r
}\r
\r
//lnk.SetIconLocation(path, 0);\r
\r
// .lnk ファイル名\r
- string lnkFileName;\r
- System.Diagnostics.FileVersionInfo vInfo = System.Diagnostics.FileVersionInfo.GetVersionInfo(exeFile);\r
- if (vInfo.ProductName != null && vInfo.ProductName != string.Empty\r
- && (!File.Exists(Path.Combine(progGrpPath, vInfo.ProductName+".lnk")))) {\r
- // 原則、lnkファイル名に製品名を採用\r
- lnkFileName = vInfo.ProductName;\r
- } else {\r
- // そのほかの場合は、*.exeファイルの名前をそのまま使用\r
- lnkFileName = Path.GetFileNameWithoutExtension(exeFile);\r
+ string lnkFilePath = Path.Combine(progGrpPath, lnk.GetSuitableShellLinkNameFor() + ".lnk");\r
+ if (File.Exists(lnkFilePath)) { // ファイル名がかぶってしまったとき\r
+ lnkFilePath = Path.Combine(progGrpPath, Path.GetFileNameWithoutExtension(exeFile) + ".lnk");\r
}\r
\r
// 保存\r
- lnk.ToPersistFile().Save(Path.Combine(progGrpPath, lnkFileName+".lnk"), true);\r
+ lnk.ToPersistFile().Save(lnkFilePath, true);\r
}\r
}\r
}\r
-using System;\r
+using System;\r
using System.Text;\r
using System.Runtime.InteropServices;\r
using System.Runtime.InteropServices.ComTypes;\r
\r
protected const int MAX_PATH = 260;\r
\r
+ /// <summary>\r
+ /// 新しいシェルリンクを作成する形のコンストラクタ\r
+ /// </summary>\r
public ShellLink()\r
{\r
Type shellLinkType = Type.GetTypeFromCLSID(new Guid(ShellLinkGuid));\r
shellLink = (IShellLinkW) Activator.CreateInstance(shellLinkType);\r
}\r
\r
+ /// <summary>\r
+ /// 既存のシェルリンクを開くコンストラクタ\r
+ /// </summary>\r
+ /// <param name="path">既存のシェルリンクのパス</param>\r
public ShellLink(string path) : this()\r
{\r
if (! System.IO.File.Exists(path)) {\r
\r
return shelllink;\r
}\r
+ \r
+ /// <summary>\r
+ /// ショートカット先のEXEファイルに対して適切な名前を生成する。\r
+ /// \r
+ /// 具体的には、アセンブリの製品名をまず優先的に使い、\r
+ /// それがなければ、exeファイルのファイル名(拡張子を除いたもの)を返す。\r
+ /// \r
+ /// 拡張子はつかないので、lnkファイル名に使う場合は、手動で\r
+ /// <code>".lnk"</code>を追加すること。\r
+ /// </summary>\r
+ /// <returns>拡張子を含まない、適切な名前</returns>\r
+ public string GetSuitableShellLinkNameFor()\r
+ {\r
+ string exeFile = GetPath(0);\r
+ \r
+ try {\r
+ FileVersionInfo vInfo = FileVersionInfo.GetVersionInfo(exeFile);\r
+ if (vInfo.ProductName != null && vInfo.ProductName != string.Empty\r
+ && vInfo.ProductName.IndexOfAny(System.IO.Path.GetInvalidFileNameChars()) < 0) {\r
+ // 原則、製品名を採用\r
+ return vInfo.ProductName;\r
+ }\r
+ } catch (Exception) {}\r
+\r
+ // そのほかの場合は、*.exeファイルの名前をそのまま使用\r
+ return System.IO.Path.GetFileNameWithoutExtension(exeFile);\r
+ }\r
}\r
}\r