OSDN Git Service

AppliStation-all,アセンブリバージョンを1.4.6に
[applistation/AppliStation.git] / na-get-lib / NaGet.InteropServices / ShellLink.cs
index f243c01..976e099 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
@@ -9,7 +9,6 @@ namespace NaGet.InteropServices
        /// <summary>\r
        /// ShellLinkの更新フラグ\r
        /// </summary>\r
-       [Flags]\r
        public enum ShellLinkResolve : uint\r
        {\r
                // AnyMatch = 0x02, // winMe,win2k以降無効\r
@@ -100,12 +99,19 @@ namespace NaGet.InteropServices
                \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
@@ -168,7 +174,7 @@ namespace NaGet.InteropServices
                }\r
                \r
                /// <summary>\r
-               /// 作業フォルダ\r
+               /// 作業フォルダ\r
                /// </summary>\r
                public string WorkingDirectory {\r
                        get {\r
@@ -244,6 +250,7 @@ namespace NaGet.InteropServices
                                Marshal.ReleaseComObject(shellLink);\r
                                shellLink = null;\r
                        }\r
+                       GC.SuppressFinalize(this);\r
                }\r
 \r
                /// <summary>\r
@@ -276,5 +283,32 @@ namespace NaGet.InteropServices
                        \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 ( (!string.IsNullOrEmpty(vInfo.ProductName))\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