/*************************************************************************************************************************/ // SHORTCUTS /// <summary> /// get path from lnk file in windows </summary> public static string[] GetShortcutTargetFile(string shortcutFilename) { try { string pathOnly = Os.GetDirectoryName(shortcutFilename); string filenameOnly = Os.GetFileName(shortcutFilename); Shell shell = new Shell(); Folder folder = shell.NameSpace(pathOnly); FolderItem folderItem = folder.ParseName(filenameOnly); if (folderItem != null) { Shell32.ShellLinkObject link = (Shell32.ShellLinkObject)folderItem.GetLink; if (link.Arguments != "") { return(new string[] { link.Path, link.Arguments }); } return(new string[] { link.Path, "" }); } } catch (Exception e) { Program.log.Write("GetShortcutTargetFile error: " + e.Message); } return(new string[] { "", "" }); }
/// <summary> /// meke filePath relative to currentPath. /// If is set inCurrentDir path is converted to relative only /// if currentPath is parent of filePath</summary> public static string MakeRelative(string filePath, string currentPath, bool inCurrentDir = true) { filePath = filePath.Trim(); currentPath = currentPath.Trim(); if (currentPath == "") { return(filePath); } if (!Os.FileExists(filePath) && !Os.DirectoryExists(filePath)) { return(filePath); } filePath = Os.GetFullPath(filePath); if (Os.FileExists(currentPath)) { currentPath = Os.GetDirectoryName(currentPath); } if (!Os.DirectoryExists(currentPath)) { return(filePath); } currentPath = Os.GetFullPath(currentPath); Uri pathUri = new Uri(filePath); // Folders must end in a slash if (!currentPath.EndsWith(Path.DirectorySeparatorChar.ToString())) { currentPath += Path.DirectorySeparatorChar; } int pos = filePath.ToLower().IndexOf(currentPath.ToLower()); if (inCurrentDir && pos != 0) // skip files outside of currentPath { return(filePath); } Uri folderUri = new Uri(currentPath); return(Uri.UnescapeDataString( folderUri.MakeRelativeUri(pathUri) .ToString() .Replace('/', Path.DirectorySeparatorChar) )); }
/// <summary> ///get icon from lnk file in windows </summary> public static string GetShortcutIcon(String shortcutFilename) { String pathOnly = Os.GetDirectoryName(shortcutFilename); String filenameOnly = Os.GetFileName(shortcutFilename); Shell shell = new Shell(); Folder folder = shell.NameSpace(pathOnly); FolderItem folderItem = folder.ParseName(filenameOnly); if (folderItem != null) { Shell32.ShellLinkObject link = (Shell32.ShellLinkObject)folderItem.GetLink; link.GetIconLocation(out String iconlocation); return(iconlocation); } return(String.Empty); }
/// <summary> /// get current running application executable directory /// Example: c:\Program Files\Infinite Diagram\ /// </summary> public static String GetCurrentApplicationDirectory() { return(Os.GetDirectoryName(Application.ExecutablePath)); }
/// <summary> /// open directori with global configuration</summary> public void OpenConfigDir() { Os.ShowDirectoryInExternalApplication(Os.GetDirectoryName(this.programOptionsFile.optionsFilePath)); }