1
0
mirror of synced 2024-12-11 07:16:05 +01:00
Switch-Toolbox/Switch_Toolbox_Library/Forms/Dialogs/FolderSelectDialog.cs

336 lines
12 KiB
C#
Raw Normal View History

Add files for the new one. Rework UI from scratch with proper themes and custom controls. MDI windows are now used for workspaces, comparing docs, and multiple usages. Tabs organise multiple workspaces and you can keep mdi windows maximized if you want to only use tabs. Themes currently include dark and white theme but plan to have XML files with list of color and styles Alot of things optimized. UI is very fast and snappy now Dae rigging fixed. Dae bones can be imported. Dae with textures can be imported and exported to a folder Custom sampler editor for sampler data. Texture refs, shader options, params, render info, and basically all material data can be added/removed and edited User data editor Update opengl framework by JuPaHe64 to the newest. Includes an origintation cube, multiple models in a scene, and many improvements Skeleton can be viewed GFPAK with some fixes in saving NUTEXB has proper mip map viewing PTCL Editor (Wii U and Switch). Can edit colors ( Wii U) and view textures. Also EFFN files in smash ultimate can be previewed Files can be associated with the program and opened with on clicking them ASTC textures can be viewed UVs can be viewed. Includes wrap modes and also translating and scaling for some basic edits Textures use a new editor. It includes channel viewing and some new editing options Fixed black textures on some wii u bfres Fixed saving sarcs in sarcs Shortcut keys have been added in. CTRL + S can save the active file in the currently used window Fix more issues with bfres crashing File - New includes BNTX for creating new bntx files from scatch Raw shader binaries can be extracted from bnsh and bfsha. Yuzu and Ryujinx can decompile these Sharc files can have source data previewed and shader programs in XML Aamp v1 and v2 data can be previewed. v1 can be edited and saved atm, v2 will be at a later update Byaml uses it's own editor instead of a seperate window for easy saving within sarcs Archives have a hex viewer Dae exporting greatly improved and can export rigged meshes Scene, shader param, srt, color, and texture pattern animations can all be previewed (in a list) Memory usage is greatly improved Narc (Nitro Archives) can be viewed and extracted. Fixed importing TGA images Support importing ASTC textures for bntx Added in PBR lighting for bfres from my implimentaion in forge Added gradient background for viewport. This can be edited in the settings Added skybox background option for viewport. Can load cubemaps Added grid with customizable cells for viewport. DDS decompression no longer requires Direct X tex. Zlib decompression has been improved for opening files that use it Rigid bones are properly ordered on importing a mesh. May fix some exploding issues. Endianness for KCL can be toggled for saving. Will be set to what it was using orignally Tangents can be filled with a constant value. Will allow them to not cause seams nor flat lighting however normal maps may not work as good Vertex buffers can be added and removed. Also re encoded Parameters now use drop down panels with values for easier editing Reworked the bone editor. Everything for a bone can be fully edited now besides the index, billboard index and parent index which get set automatically Fixed animation scaling for skeletal animations finally! Textures can be loaded in a tab now with thumbnail displaying for easy real time edits while previewing in the viewport Fixed support for audio files to be big endian in BARS Textures for switch now use their own folder. You can easily add textures to this and add textures to bfres that have no bntx. If there are no textures then the bfres will automatically not have one on save. Animations are split into multiple sub sections for switch's material animation for easier access Bfres for wii u has better binary exporting and is fully compatiable with Wexos Toolbox (to and from) Every section can be added in as new for both wii u and switch. Every section can be renamed properly and mostly everything can be edited. (Key frame editing and a more in depth curve editor later) Added option to copy UV channel Bone weights can be previewed Tons of fixes for the switch bfres library with more games working. Splatoon 2 (more work now), BOTW, Kirby Star Allies, and more! Fixed 3.3 Wii U bfres from not opening Wii U Sharcfb files can have shader program data previewed (XML) And possibly alot more things i missed! All this is still experimental but will improve over the next few weeks
2019-03-23 17:55:09 +01:00
using System.ComponentModel;
using System.Reflection;
namespace System.Windows.Forms
{
/// <summary>
/// Wraps System.Windows.Forms.OpenFileDialog to make it present
/// a vista-style dialog.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
[Browsable(false)]
[DesignTimeVisible(false)]
public partial class FolderSelectDialog : Component
{
// Wrapped dialog
System.Windows.Forms.OpenFileDialog ofd = null;
/// <summary>
/// Default constructor
/// </summary>
public FolderSelectDialog()
{
ofd = new System.Windows.Forms.OpenFileDialog();
ofd.Filter = "Folders|\n";
ofd.AddExtension = false;
ofd.CheckFileExists = false;
ofd.DereferenceLinks = true;
ofd.Multiselect = false;
}
#region Properties
/// <summary>
/// Gets/Sets the initial folder to be selected. A null value selects the current directory.
/// </summary>
public string InitialDirectory
{
get { return ofd.InitialDirectory; }
set { ofd.InitialDirectory = value == null || value.Length == 0 ? Environment.CurrentDirectory : value; }
}
/// <summary>
/// Gets/Sets the title to show in the dialog
/// </summary>
public string Title
{
get { return ofd.Title; }
set { ofd.Title = value == null ? "Select a folder" : value; }
}
/// <summary>
/// Gets the selected folder
/// </summary>
public string SelectedPath
{
get { return ofd.FileName; }
}
#endregion
#region Methods
/// <summary>
/// Shows the dialog
/// </summary>
/// <returns>DialogResult.OK if user presses OK, else DialogResult.Cancel</returns>
public DialogResult ShowDialog()
{
return ShowDialog(IntPtr.Zero);
}
/// <summary>
/// Shows the dialog
/// </summary>
/// <param name="hWndOwner">Handle of the control to be parent</param>
/// <returns>DialogResult.OK if user presses OK, else DialogResult.Cancel</returns>
public DialogResult ShowDialog(IntPtr hWndOwner)
{
bool flag = false;
if (Environment.OSVersion.Version.Major >= 6)
{
var r = new Reflector("System.Windows.Forms");
uint num = 0;
Type typeIFileDialog = r.GetType("FileDialogNative.IFileDialog");
object dialog = r.Call(ofd, "CreateVistaDialog");
r.Call(ofd, "OnBeforeVistaDialog", dialog);
uint options = (uint)r.CallAs(typeof(System.Windows.Forms.FileDialog), ofd, "GetOptions");
options |= (uint)r.GetEnum("FileDialogNative.FOS", "FOS_PICKFOLDERS");
r.CallAs(typeIFileDialog, dialog, "SetOptions", options);
object pfde = r.New("FileDialog.VistaDialogEvents", ofd);
object[] parameters = new object[] { pfde, num };
r.CallAs2(typeIFileDialog, dialog, "Advise", parameters);
num = (uint)parameters[1];
try
{
int num2 = (int)r.CallAs(typeIFileDialog, dialog, "Show", hWndOwner);
flag = 0 == num2;
}
finally
{
r.CallAs(typeIFileDialog, dialog, "Unadvise", num);
GC.KeepAlive(pfde);
}
}
else
{
var fbd = new FolderBrowserDialog();
fbd.Description = this.Title;
fbd.SelectedPath = this.InitialDirectory;
fbd.ShowNewFolderButton = false;
if (fbd.ShowDialog(new WindowWrapper(hWndOwner)) != DialogResult.OK) return DialogResult.Cancel;
ofd.FileName = fbd.SelectedPath;
flag = true;
}
return flag ? DialogResult.OK : DialogResult.Cancel;
}
#endregion
}
/// <summary>
/// Creates IWin32Window around an IntPtr
/// </summary>
public class WindowWrapper : System.Windows.Forms.IWin32Window
{
/// <summary>
/// Constructor
/// </summary>
/// <param name="handle">Handle to wrap</param>
public WindowWrapper(IntPtr handle)
{
_hwnd = handle;
}
/// <summary>
/// Original ptr
/// </summary>
public IntPtr Handle
{
get { return _hwnd; }
}
private IntPtr _hwnd;
}
/// <summary>
/// This class is from the Front-End for Dosbox and is used to present a 'vista' dialog box to select folders.
/// Being able to use a vista style dialog box to select folders is much better then using the shell folder browser.
/// http://code.google.com/p/fed/
///
/// Example:
/// var r = new Reflector("System.Windows.Forms");
/// </summary>
public class Reflector
{
#region variables
string m_ns;
Assembly m_asmb;
#endregion
#region Constructors
/// <summary>
/// Constructor
/// </summary>
/// <param name="ns">The namespace containing types to be used</param>
public Reflector(string ns)
: this(ns, ns)
{ }
/// <summary>
/// Constructor
/// </summary>
/// <param name="an">A specific assembly name (used if the assembly name does not tie exactly with the namespace)</param>
/// <param name="ns">The namespace containing types to be used</param>
public Reflector(string an, string ns)
{
m_ns = ns;
m_asmb = null;
foreach (AssemblyName aN in Assembly.GetExecutingAssembly().GetReferencedAssemblies())
{
if (aN.FullName.StartsWith(an))
{
m_asmb = Assembly.Load(aN);
break;
}
}
}
#endregion
#region Methods
/// <summary>
/// Return a Type instance for a type 'typeName'
/// </summary>
/// <param name="typeName">The name of the type</param>
/// <returns>A type instance</returns>
public Type GetType(string typeName)
{
Type type = null;
string[] names = typeName.Split('.');
if (names.Length > 0)
type = m_asmb.GetType(m_ns + "." + names[0]);
for (int i = 1; i < names.Length; ++i)
{
type = type.GetNestedType(names[i], BindingFlags.NonPublic);
}
return type;
}
/// <summary>
/// Create a new object of a named type passing along any params
/// </summary>
/// <param name="name">The name of the type to create</param>
/// <param name="parameters"></param>
/// <returns>An instantiated type</returns>
public object New(string name, params object[] parameters)
{
Type type = GetType(name);
ConstructorInfo[] ctorInfos = type.GetConstructors();
foreach (ConstructorInfo ci in ctorInfos)
{
try
{
return ci.Invoke(parameters);
}
catch { }
}
return null;
}
/// <summary>
/// Calls method 'func' on object 'obj' passing parameters 'parameters'
/// </summary>
/// <param name="obj">The object on which to excute function 'func'</param>
/// <param name="func">The function to execute</param>
/// <param name="parameters">The parameters to pass to function 'func'</param>
/// <returns>The result of the function invocation</returns>
public object Call(object obj, string func, params object[] parameters)
{
return Call2(obj, func, parameters);
}
/// <summary>
/// Calls method 'func' on object 'obj' passing parameters 'parameters'
/// </summary>
/// <param name="obj">The object on which to excute function 'func'</param>
/// <param name="func">The function to execute</param>
/// <param name="parameters">The parameters to pass to function 'func'</param>
/// <returns>The result of the function invocation</returns>
public object Call2(object obj, string func, object[] parameters)
{
return CallAs2(obj.GetType(), obj, func, parameters);
}
/// <summary>
/// Calls method 'func' on object 'obj' which is of type 'type' passing parameters 'parameters'
/// </summary>
/// <param name="type">The type of 'obj'</param>
/// <param name="obj">The object on which to excute function 'func'</param>
/// <param name="func">The function to execute</param>
/// <param name="parameters">The parameters to pass to function 'func'</param>
/// <returns>The result of the function invocation</returns>
public object CallAs(Type type, object obj, string func, params object[] parameters)
{
return CallAs2(type, obj, func, parameters);
}
/// <summary>
/// Calls method 'func' on object 'obj' which is of type 'type' passing parameters 'parameters'
/// </summary>
/// <param name="type">The type of 'obj'</param>
/// <param name="obj">The object on which to excute function 'func'</param>
/// <param name="func">The function to execute</param>
/// <param name="parameters">The parameters to pass to function 'func'</param>
/// <returns>The result of the function invocation</returns>
public object CallAs2(Type type, object obj, string func, object[] parameters)
{
MethodInfo methInfo = type.GetMethod(func, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
return methInfo.Invoke(obj, parameters);
}
/// <summary>
/// Returns the value of property 'prop' of object 'obj'
/// </summary>
/// <param name="obj">The object containing 'prop'</param>
/// <param name="prop">The property name</param>
/// <returns>The property value</returns>
public object Get(object obj, string prop)
{
return GetAs(obj.GetType(), obj, prop);
}
/// <summary>
/// Returns the value of property 'prop' of object 'obj' which has type 'type'
/// </summary>
/// <param name="type">The type of 'obj'</param>
/// <param name="obj">The object containing 'prop'</param>
/// <param name="prop">The property name</param>
/// <returns>The property value</returns>
public static object GetAs(Type type, object obj, string prop)
{
PropertyInfo propInfo = type.GetProperty(prop, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
return propInfo.GetValue(obj, null);
}
/// <summary>
/// Returns an enum value
/// </summary>
/// <param name="typeName">The name of enum type</param>
/// <param name="name">The name of the value</param>
/// <returns>The enum value</returns>
public object GetEnum(string typeName, string name)
{
Type type = GetType(typeName);
FieldInfo fieldInfo = type.GetField(name);
return fieldInfo.GetValue(null);
}
#endregion
}
}