diff --git a/renderdocui/Code/Helpers.cs b/renderdocui/Code/Helpers.cs index e8f2f26dd..bf56eee37 100644 --- a/renderdocui/Code/Helpers.cs +++ b/renderdocui/Code/Helpers.cs @@ -187,9 +187,9 @@ namespace renderdocui.Code RefreshAssociations(); } - private static string GetVulkanJSONPath(bool wow6432) + public static string GetVulkanJSONPath(bool wow6432) { - string basepath = Path.GetDirectoryName(Application.ExecutablePath); + string basepath = Win32PInvoke.GetUniversalName(Path.GetDirectoryName(Application.ExecutablePath)); if (wow6432) basepath = Path.Combine(basepath, "x86"); diff --git a/renderdocui/Code/Win32PInvoke.cs b/renderdocui/Code/Win32PInvoke.cs index 7cbd5541f..2f56f9406 100644 --- a/renderdocui/Code/Win32PInvoke.cs +++ b/renderdocui/Code/Win32PInvoke.cs @@ -117,5 +117,40 @@ namespace renderdocui.Code return new string(buffer); } + + [DllImport("mpr.dll", CharSet = CharSet.Unicode)] + private static extern uint WNetGetUniversalNameW(string lpLocalPath, int dwInfoLevel, IntPtr lpBuffer, ref int lpBufferSize); + private const int UNIVERSAL_NAME_INFO_LEVEL = 0x00000001; + private const uint ERROR_MORE_DATA = 234; + + public static string GetUniversalName(string localPath) + { + int size = 0; + + IntPtr buf = (IntPtr)IntPtr.Size; // don't initialise to zero, as otherwise the call fails + + uint ret = WNetGetUniversalNameW(localPath, UNIVERSAL_NAME_INFO_LEVEL, buf, ref size); + + if (ret != ERROR_MORE_DATA) + return localPath; + + buf = Marshal.AllocHGlobal(size); + + ret = WNetGetUniversalNameW(localPath, UNIVERSAL_NAME_INFO_LEVEL, buf, ref size); + + string universalPath = localPath; + + if (ret == 0) + { + // buf points to a struct that contains just a string pointer, that points + // immediately after it. So we need to advance by one IntPtr to get to the + // actual string + universalPath = Marshal.PtrToStringUni(IntPtr.Add(buf, IntPtr.Size)); + } + + Marshal.FreeHGlobal(buf); + + return universalPath; + } } } diff --git a/renderdocui/Windows/Dialogs/CaptureDialog.cs b/renderdocui/Windows/Dialogs/CaptureDialog.cs index d00c33c58..ef36b013a 100644 --- a/renderdocui/Windows/Dialogs/CaptureDialog.cs +++ b/renderdocui/Windows/Dialogs/CaptureDialog.cs @@ -904,7 +904,7 @@ namespace renderdocui.Windows.Dialogs Helpers.CheckVulkanLayerRegistration(out hasOtherJSON, out thisRegistered, out otherJSONs); - string myJSON = Path.GetDirectoryName(Application.ExecutablePath) + Path.DirectorySeparatorChar + "renderdoc.json"; + string myJSON = Helpers.GetVulkanJSONPath(false); string msg = "Vulkan capture happens through the API's layer mechanism. RenderDoc has detected that "; @@ -938,7 +938,7 @@ namespace renderdocui.Windows.Dialogs { msg += "Register: " + myJSON + "\n"; if (Environment.Is64BitProcess) - msg += "Register: " + myJSON.Replace("renderdoc.json", @"x86\renderdoc.json") + "\n"; + msg += "Register: " + Helpers.GetVulkanJSONPath(true) + "\n"; msg += "\n"; }