Small changes and fixes

This commit is contained in:
Natsumi
2024-03-16 04:06:59 +13:00
parent 00489dfd53
commit 3479746c8c
7 changed files with 109 additions and 27 deletions
+4 -3
View File
@@ -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>
+23
View File
@@ -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}\"");
}
}
}
}