mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/PCK-Studio.git
synced 2026-05-28 20:44:34 +00:00
Add OpenFolderDialog.CheckPath & refactor ShowDialog to return DialogResult
This commit is contained in:
@@ -1325,7 +1325,7 @@ namespace PckStudio.Controls
|
||||
private void importExtractedSkinsFolder(object sender, EventArgs e)
|
||||
{
|
||||
OpenFolderDialog contents = new OpenFolderDialog();
|
||||
if (contents.ShowDialog(Handle) == true)
|
||||
if (contents.ShowDialog(Handle) == DialogResult.OK)
|
||||
{
|
||||
//checks to make sure selected path exist
|
||||
if (!Directory.Exists(contents.ResultPath))
|
||||
@@ -1503,7 +1503,7 @@ namespace PckStudio.Controls
|
||||
OpenFolderDialog dialog = new OpenFolderDialog();
|
||||
dialog.Title = @"Select destination folder";
|
||||
|
||||
if (dialog.ShowDialog(Handle) == true)
|
||||
if (dialog.ShowDialog(Handle) == DialogResult.OK)
|
||||
extractFolder(dialog.ResultPath);
|
||||
}
|
||||
else if (node.TryGetTagData(out PckAsset asset))
|
||||
|
||||
@@ -169,9 +169,10 @@ namespace PckStudio.Forms.Features
|
||||
{
|
||||
OpenFolderDialog openFolderDialog = new OpenFolderDialog
|
||||
{
|
||||
Title = "Select Cemu mlc01 Directory"
|
||||
Title = "Select Cemu mlc01 Directory",
|
||||
CheckPath = true
|
||||
};
|
||||
if (openFolderDialog.ShowDialog(Handle) == true && Directory.Exists(openFolderDialog.ResultPath))
|
||||
if (openFolderDialog.ShowDialog(Handle) == DialogResult.OK)
|
||||
{
|
||||
GameDirectoryTextBox.Text = openFolderDialog.ResultPath;
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ using System;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Runtime.InteropServices.ComTypes;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace PckStudio.Core.Misc
|
||||
{
|
||||
@@ -18,6 +19,7 @@ namespace PckStudio.Core.Misc
|
||||
public virtual string Title { get; set; }
|
||||
public virtual string OkButtonLabel { get; set; }
|
||||
public virtual string FileNameLabel { get; set; }
|
||||
public bool CheckPath { get; set; }
|
||||
|
||||
protected virtual int SetOptions(int options)
|
||||
{
|
||||
@@ -25,17 +27,21 @@ namespace PckStudio.Core.Misc
|
||||
{
|
||||
options |= (int)FOS.FOS_FORCEFILESYSTEM;
|
||||
}
|
||||
if (CheckPath)
|
||||
{
|
||||
options |= (int)FOS.FOS_PATHMUSTEXIST;
|
||||
}
|
||||
return options;
|
||||
}
|
||||
|
||||
// for all .NET
|
||||
public virtual bool? ShowDialog(IntPtr owner, bool throwOnError = false)
|
||||
public virtual DialogResult ShowDialog(IntPtr owner, bool throwOnError = false)
|
||||
{
|
||||
var dialog = (IFileOpenDialog)new FileOpenDialog();
|
||||
if (!string.IsNullOrEmpty(InputPath))
|
||||
{
|
||||
if (CheckHr(SHCreateItemFromParsingName(InputPath, null, typeof(IShellItem).GUID, out IShellItem item), throwOnError) != 0)
|
||||
return null;
|
||||
return DialogResult.Abort;
|
||||
|
||||
dialog.SetFolder(item);
|
||||
}
|
||||
@@ -70,16 +76,16 @@ namespace PckStudio.Core.Misc
|
||||
|
||||
var hr = dialog.Show(owner);
|
||||
if (hr == ERROR_CANCELLED)
|
||||
return null;
|
||||
return DialogResult.Cancel;
|
||||
|
||||
if (CheckHr(hr, throwOnError) != 0)
|
||||
return null;
|
||||
return DialogResult.Abort;
|
||||
|
||||
if (CheckHr(dialog.GetResult(out IShellItem result), throwOnError) != 0)
|
||||
return null;
|
||||
return DialogResult.Abort;
|
||||
|
||||
if (CheckHr(result.GetDisplayName(SIGDN.SIGDN_DESKTOPABSOLUTEPARSING, out var path), throwOnError) != 0)
|
||||
return null;
|
||||
return DialogResult.Abort;
|
||||
|
||||
ResultPath = path;
|
||||
|
||||
@@ -87,16 +93,13 @@ namespace PckStudio.Core.Misc
|
||||
{
|
||||
ResultName = path;
|
||||
}
|
||||
return true;
|
||||
return DialogResult.OK;
|
||||
}
|
||||
|
||||
private static int CheckHr(int hr, bool throwOnError)
|
||||
{
|
||||
if (hr != 0)
|
||||
{
|
||||
if (throwOnError)
|
||||
Marshal.ThrowExceptionForHR(hr);
|
||||
}
|
||||
if (hr != 0 && throwOnError)
|
||||
Marshal.ThrowExceptionForHR(hr);
|
||||
return hr;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user