SHA256
Cleanup FolderDialogUtil
This commit is contained in:
1 file changed
+7
-7
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
@@ -9,6 +10,8 @@ using MelonLoader;
|
||||
|
||||
namespace ADOFAIRenderer.Util;
|
||||
|
||||
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
||||
[SuppressMessage("ReSharper", "UnusedMember.Local")]
|
||||
internal static class FolderDialogUtil
|
||||
{
|
||||
private static int _isDialogOpen;
|
||||
@@ -187,14 +190,12 @@ internal static class FolderDialogUtil
|
||||
|
||||
private static string? OpenWindowsFolderBrowserModern(string initialDirectory, IntPtr ownerHandle)
|
||||
{
|
||||
IFileOpenDialog? dialog = null;
|
||||
|
||||
// 1. Try native CoCreateInstance first (works on Mono and .NET without class registration)
|
||||
var clsid = CLSID_FileOpenDialog;
|
||||
var iid = IID_IFileOpenDialog;
|
||||
int createHr = CoCreateInstance(ref clsid, IntPtr.Zero, 1 /* CLSCTX_INPROC_SERVER */, ref iid, out dialog);
|
||||
int createHr = CoCreateInstance(ref clsid, IntPtr.Zero, 1 /* CLSCTX_INPROC_SERVER */, ref iid, out var dialog);
|
||||
|
||||
if (createHr != 0 || dialog == null)
|
||||
if (createHr != 0)
|
||||
{
|
||||
// 2. Fallback to Activator via Type.GetTypeFromCLSID
|
||||
var comType = Type.GetTypeFromCLSID(CLSID_FileOpenDialog);
|
||||
@@ -224,7 +225,7 @@ internal static class FolderDialogUtil
|
||||
{
|
||||
var shellItemGuid = IID_IShellItem;
|
||||
int itemHr = SHCreateItemFromParsingName(normalized, IntPtr.Zero, ref shellItemGuid, out var initialItem);
|
||||
if (itemHr == 0 && initialItem != null)
|
||||
if (itemHr == 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -263,7 +264,6 @@ internal static class FolderDialogUtil
|
||||
}
|
||||
|
||||
dialog.GetResult(out var resultItem);
|
||||
if (resultItem == null) return null;
|
||||
|
||||
try
|
||||
{
|
||||
@@ -319,7 +319,7 @@ internal static class FolderDialogUtil
|
||||
if (Directory.Exists(normalized))
|
||||
{
|
||||
initialDirPtr = Marshal.StringToHGlobalUni(normalized);
|
||||
callback = (hwnd, uMsg, lParam, lpData) =>
|
||||
callback = (hwnd, uMsg, _, lpData) =>
|
||||
{
|
||||
if (uMsg == BFFM_INITIALIZED && lpData != IntPtr.Zero)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user