OSDN Git Service

AppliStation-*,とりあえずの実装 of 「インストール先フォルダ」のところで実行ファイルを直接 実行できるように
authorttp <ttp@users.sourceforge.jp>
Sat, 23 Aug 2008 07:42:13 +0000 (07:42 +0000)
committerttp <ttp@users.sourceforge.jp>
Sat, 23 Aug 2008 07:42:13 +0000 (07:42 +0000)
 * これに伴い、ShellLink生成のルーチンも一部変更となった。動作確認済み
 * とりあえずの動作がしている。
 * アイコン取得か何かは不明だが、ファイル数が多いところでやけに遅いので、一瞬フリーズする
 * 実行ファイルを右クリック…はできかねます。ご了承くださいませ

git-svn-id: http://localhost/svn/AppliStation/trunk@950 34ed2c89-c49f-4a4b-abdb-c318350108cf

AppliStation/AppliStation.Util/GUIUtils.cs
AppliStation/PackageListViewForm.Designer.cs
AppliStation/PackageListViewForm.cs
archive-inst/Program.cs
na-get-lib/NaGet.InteropServices/ShellLink.cs

index 37a98f9..4f63287 100644 (file)
@@ -90,5 +90,42 @@ namespace AppliStation.Util
                                    0, 0, img.Width, img.Height,\r
                                    GraphicsUnit.Pixel, ia);\r
                }\r
                                    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
        }\r
 }\r
index 2ac2548..e9eafd0 100644 (file)
@@ -58,7 +58,7 @@
                        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.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
                        this.propertiesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();\r
                        this.detailBox = new System.Windows.Forms.RichTextBox();\r
                        this.tableLayoutPanel1.SuspendLayout();\r
@@ -74,7 +74,7 @@
                        // toolStripSeparator1\r
                        // \r
                        this.toolStripSeparator1.Name = "toolStripSeparator1";\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
                        // \r
                        // tableLayoutPanel1\r
                        // \r
                                                                        this.uninstallToolStripMenuItem,\r
                                                                        this.toolStripSeparator1,\r
                                                                        this.webResourcesToolStripMenuItem,\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.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.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.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.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.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.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.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
                        this.webGoogleSearchToolStripMenuItem.Text = "Google検索(&G)";\r
                        this.webGoogleSearchToolStripMenuItem.Click += new System.EventHandler(this.WebGoogleSearchToolStripMenuItemClick);\r
                        // \r
-                       // openInstalledDirectoryStripMenuItem\r
+                       // installedDirectoryStripMenuItem\r
                        // \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
                        // \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.propertiesToolStripMenuItem.Text = "プロパティ(&R)";\r
                        this.propertiesToolStripMenuItem.Click += new System.EventHandler(this.PropertiesToolStripMenuItemClick);\r
                        // \r
                        this.packageListContextMenuStrip.ResumeLayout(false);\r
                        this.ResumeLayout(false);\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.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
                private System.Windows.Forms.ToolStripMenuItem webGoogleSearchToolStripMenuItem;\r
                private System.Windows.Forms.ToolStripMenuItem webOfficialToolStripMenuItem;\r
                private System.Windows.Forms.ToolStripMenuItem webResourcesToolStripMenuItem;\r
index 4c96fa4..3a8b0d2 100644 (file)
@@ -125,6 +125,35 @@ namespace AppliStation
                        }\r
                }\r
                \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
                AppliStation.Util.ListViewItemSortComparer packageListViewSortComparer;\r
 \r
                void PackageListViewColumnClick(object sender, ColumnClickEventArgs e)\r
@@ -157,6 +186,8 @@ namespace AppliStation
                        }\r
                }\r
                \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
                void Form_OnLoad(object sender, EventArgs e)\r
                {\r
                        System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(PackageListViewForm));\r
@@ -562,13 +593,17 @@ namespace AppliStation
                                webOfficialToolStripMenuItem.Enabled = ! (pkg.Url == null || string.IsNullOrEmpty(pkg.Url.Href));\r
                                // webGoogleSearchToolStripMenuItem always active.\r
                                \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
                                        ( (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
                        }\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
                        propertiesToolStripMenuItem.Visible = selectionIsOnlyOne;\r
                }\r
                \r
index 1a44c1c..75ac08c 100644 (file)
@@ -128,19 +128,13 @@ namespace ArchiveInstall
                                                //lnk.SetIconLocation(path, 0);\r
                                                \r
                                                // .lnk ファイル名\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
                                                }\r
                                                \r
                                                // 保存\r
-                                               lnk.ToPersistFile().Save(Path.Combine(progGrpPath, lnkFileName+".lnk"), true);\r
+                                               lnk.ToPersistFile().Save(lnkFilePath, true);\r
                                        }\r
                                }\r
                        }\r
                                        }\r
                                }\r
                        }\r
index f243c01..12bf1eb 100644 (file)
@@ -1,4 +1,4 @@
-using System;\r
+using System;\r
 using System.Text;\r
 using System.Runtime.InteropServices;\r
 using System.Runtime.InteropServices.ComTypes;\r
 using System.Text;\r
 using System.Runtime.InteropServices;\r
 using System.Runtime.InteropServices.ComTypes;\r
@@ -100,12 +100,19 @@ namespace NaGet.InteropServices
                \r
                protected const int MAX_PATH = 260;\r
                \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
                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
                public ShellLink(string path) : this()\r
                {\r
                        if (! System.IO.File.Exists(path)) {\r
@@ -276,5 +283,32 @@ namespace NaGet.InteropServices
                        \r
                        return shelllink;\r
                }\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
        }\r
 }\r