mirror of
https://github.com/MrUnknownDE/VRCX.git
synced 2026-05-05 14:26:06 +02:00
Small changes and fixes
This commit is contained in:
@@ -9,6 +9,8 @@ namespace VRCX
|
||||
{
|
||||
public static readonly AppApiVr Instance;
|
||||
|
||||
private readonly PerformanceCounter _uptime = new PerformanceCounter("System", "System Up Time");
|
||||
|
||||
static AppApiVr()
|
||||
{
|
||||
Instance = new AppApiVr();
|
||||
@@ -45,9 +47,8 @@ namespace VRCX
|
||||
/// <returns>The number of milliseconds that the system has been running.</returns>
|
||||
public double GetUptime()
|
||||
{
|
||||
using var uptime = new PerformanceCounter("System", "System Up Time");
|
||||
uptime.NextValue();
|
||||
return TimeSpan.FromSeconds(uptime.NextValue()).TotalMilliseconds;
|
||||
_uptime.NextValue();
|
||||
return TimeSpan.FromSeconds(_uptime.NextValue()).TotalMilliseconds;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -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