X-Git-Url: http://git.sourceforge.jp/view?p=applistation%2FAppliStation.git;a=blobdiff_plain;f=na-get-lib%2FNaGet.InteropServices%2FShellLink.cs;h=12bf1eb0acbfe9c7a4f95bf9a737e31c5c62c06c;hp=f243c01216c14bed389742cbc5f07ba73e55a096;hb=09d2c09137c9c62127d0aea826bae12836b40a74;hpb=83a5af8064fd41874873b329abd3cf6ee8acdf1e 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); + } } }