mirror of
https://github.com/ShareX/ShareX.git
synced 2024-07-13 18:36:05 +12:00
Merge pull request #1677 from dannoe/enh-open-files-folders-filemanager
Files and folders are now opened in the default filemanager.
This commit is contained in:
commit
40fc977b7d
|
@ -417,7 +417,7 @@ public static bool OpenFolder(string folderPath)
|
|||
{
|
||||
try
|
||||
{
|
||||
Process.Start("explorer.exe", folderPath);
|
||||
Process.Start(folderPath);
|
||||
return true;
|
||||
}
|
||||
catch (Exception e)
|
||||
|
@ -439,7 +439,7 @@ public static bool OpenFolderWithFile(string filePath)
|
|||
{
|
||||
try
|
||||
{
|
||||
Process.Start("explorer.exe", $"/select,\"{filePath}\"");
|
||||
NativeMethods.OpenFolderAndSelectFile(filePath);
|
||||
return true;
|
||||
}
|
||||
catch (Exception e)
|
||||
|
|
|
@ -363,6 +363,16 @@ public static partial class NativeMethods
|
|||
[DllImport("shell32.dll")]
|
||||
public static extern IntPtr SHAppBarMessage(uint dwMessage, [In] ref APPBARDATA pData);
|
||||
|
||||
// http://stackoverflow.com/questions/14600987/code-to-open-windows-explorer-or-focus-if-exists-with-file-selected
|
||||
[DllImport("shell32.dll")]
|
||||
public static extern int SHOpenFolderAndSelectItems(IntPtr pidlFolder, int cild, IntPtr apidl, int dwFlags);
|
||||
|
||||
[DllImport("shell32.dll", CharSet = CharSet.Unicode)]
|
||||
public static extern IntPtr ILCreateFromPathW(string pszPath);
|
||||
|
||||
[DllImport("shell32.dll")]
|
||||
public static extern void ILFree(IntPtr pidl);
|
||||
|
||||
#endregion shell32.dll
|
||||
|
||||
#region dwmapi.dll
|
||||
|
|
|
@ -476,5 +476,16 @@ public static bool FlashWindowEx(Form frm, uint flashCount = uint.MaxValue)
|
|||
|
||||
return FlashWindowEx(ref fInfo);
|
||||
}
|
||||
|
||||
// http://stackoverflow.com/questions/14600987/code-to-open-windows-explorer-or-focus-if-exists-with-file-selected
|
||||
public static void OpenFolderAndSelectFile(string filePath)
|
||||
{
|
||||
if (filePath == null)
|
||||
throw new ArgumentNullException(nameof(filePath));
|
||||
|
||||
IntPtr pidl = ILCreateFromPathW(filePath);
|
||||
SHOpenFolderAndSelectItems(pidl, 0, IntPtr.Zero, 0);
|
||||
ILFree(pidl);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue