mirror of
https://github.com/MrUnknownDE/VRCX.git
synced 2026-05-06 22:46:06 +02:00
Small changes and fixes
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using Newtonsoft.Json;
|
||||
@@ -170,6 +171,7 @@ namespace VRCX
|
||||
var result = WinApi.SHParseDisplayName(folderPath, IntPtr.Zero, out pidlFolder, 0, out psfgaoOut);
|
||||
if (result != 0)
|
||||
{
|
||||
OpenFolderAndSelectItemFallback(path);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -178,6 +180,7 @@ namespace VRCX
|
||||
{
|
||||
// Free the PIDL we allocated earlier if we failed to parse the display name of the file.
|
||||
Marshal.FreeCoTaskMem(pidlFolder);
|
||||
OpenFolderAndSelectItemFallback(path);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -189,6 +192,10 @@ namespace VRCX
|
||||
// It can select multiple items, but we only need to select one.
|
||||
WinApi.SHOpenFolderAndSelectItems(pidlFolder, (uint)files.Length, files, 0);
|
||||
}
|
||||
catch
|
||||
{
|
||||
OpenFolderAndSelectItemFallback(path);
|
||||
}
|
||||
finally
|
||||
{
|
||||
// Free the PIDLs we allocated earlier
|
||||
@@ -196,5 +203,21 @@ namespace VRCX
|
||||
Marshal.FreeCoTaskMem(pidlFile);
|
||||
}
|
||||
}
|
||||
|
||||
public void OpenFolderAndSelectItemFallback(string path)
|
||||
{
|
||||
if (!File.Exists(path) && !Directory.Exists(path))
|
||||
return;
|
||||
|
||||
if (Directory.Exists(path))
|
||||
{
|
||||
Process.Start("explorer.exe", path);
|
||||
}
|
||||
else
|
||||
{
|
||||
// open folder with file highlighted
|
||||
Process.Start("explorer.exe", $"/select,\"{path}\"");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user