diff --git a/Netch/3rd/FS/FolderSelect.cs b/Netch/3rd/FS/FolderSelect.cs deleted file mode 100644 index bb4634a3..00000000 --- a/Netch/3rd/FS/FolderSelect.cs +++ /dev/null @@ -1,155 +0,0 @@ -using System; -using System.Windows.Forms; - -// ------------------------------------------------------------------ -// Wraps System.Windows.Forms.OpenFileDialog to make it present -// a vista-style dialog. -// source: http://www.lyquidity.com/devblog/?p=136 -// ------------------------------------------------------------------ - -namespace FolderSelect -{ - /// - /// Wraps System.Windows.Forms.OpenFileDialog to make it present - /// a vista-style dialog. - /// - public class FolderSelectDialog - { - // Wrapped dialog - System.Windows.Forms.OpenFileDialog ofd = null; - - /// - /// Default constructor - /// - 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 - - /// - /// Gets/Sets the initial folder to be selected. A null value selects the current directory. - /// - public string InitialDirectory - { - get { return ofd.InitialDirectory; } - set { ofd.InitialDirectory = value == null || value.Length == 0 ? Environment.CurrentDirectory : value; } - } - - /// - /// Gets/Sets the title to show in the dialog - /// - public string Title - { - get { return ofd.Title; } - set { ofd.Title = value == null ? "Select a folder" : value; } - } - - /// - /// Gets the selected folder - /// - public string FileName - { - get { return ofd.FileName; } - } - - #endregion - - #region Methods - - /// - /// Shows the dialog - /// - /// True if the user presses OK else false - public bool ShowDialog() - { - return ShowDialog(IntPtr.Zero); - } - - /// - /// Shows the dialog - /// - /// Handle of the control to be parent - /// True if the user presses OK else false - public bool 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 false; - ofd.FileName = fbd.SelectedPath; - flag = true; - } - - return flag; - } - - #endregion - } - - /// - /// Creates IWin32Window around an IntPtr - /// - public class WindowWrapper : System.Windows.Forms.IWin32Window - { - /// - /// Constructor - /// - /// Handle to wrap - public WindowWrapper(IntPtr handle) - { - _hwnd = handle; - } - - /// - /// Original ptr - /// - public IntPtr Handle - { - get { return _hwnd; } - } - - private IntPtr _hwnd; - } - -} diff --git a/Netch/3rd/FS/Reflector.cs b/Netch/3rd/FS/Reflector.cs deleted file mode 100644 index ab225d11..00000000 --- a/Netch/3rd/FS/Reflector.cs +++ /dev/null @@ -1,190 +0,0 @@ -using System; -using System.Reflection; - -namespace FolderSelect -{ - /// - /// 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"); - /// - public class Reflector - { - #region variables - - string m_ns; - Assembly m_asmb; - - #endregion - - #region Constructors - - /// - /// Constructor - /// - /// The namespace containing types to be used - public Reflector(string ns) - : this(ns, ns) - { } - - /// - /// Constructor - /// - /// A specific assembly name (used if the assembly name does not tie exactly with the namespace) - /// The namespace containing types to be used - 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 - - /// - /// Return a Type instance for a type 'typeName' - /// - /// The name of the type - /// A type instance - 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; - } - - /// - /// Create a new object of a named type passing along any params - /// - /// The name of the type to create - /// - /// An instantiated type - 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; - } - - /// - /// Calls method 'func' on object 'obj' passing parameters 'parameters' - /// - /// The object on which to excute function 'func' - /// The function to execute - /// The parameters to pass to function 'func' - /// The result of the function invocation - public object Call(object obj, string func, params object[] parameters) - { - return Call2(obj, func, parameters); - } - - /// - /// Calls method 'func' on object 'obj' passing parameters 'parameters' - /// - /// The object on which to excute function 'func' - /// The function to execute - /// The parameters to pass to function 'func' - /// The result of the function invocation - public object Call2(object obj, string func, object[] parameters) - { - return CallAs2(obj.GetType(), obj, func, parameters); - } - - /// - /// Calls method 'func' on object 'obj' which is of type 'type' passing parameters 'parameters' - /// - /// The type of 'obj' - /// The object on which to excute function 'func' - /// The function to execute - /// The parameters to pass to function 'func' - /// The result of the function invocation - public object CallAs(Type type, object obj, string func, params object[] parameters) - { - return CallAs2(type, obj, func, parameters); - } - - /// - /// Calls method 'func' on object 'obj' which is of type 'type' passing parameters 'parameters' - /// - /// The type of 'obj' - /// The object on which to excute function 'func' - /// The function to execute - /// The parameters to pass to function 'func' - /// The result of the function invocation - 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); - } - - /// - /// Returns the value of property 'prop' of object 'obj' - /// - /// The object containing 'prop' - /// The property name - /// The property value - public object Get(object obj, string prop) - { - return GetAs(obj.GetType(), obj, prop); - } - - /// - /// Returns the value of property 'prop' of object 'obj' which has type 'type' - /// - /// The type of 'obj' - /// The object containing 'prop' - /// The property name - /// The property value - public object GetAs(Type type, object obj, string prop) - { - PropertyInfo propInfo = type.GetProperty(prop, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); - return propInfo.GetValue(obj, null); - } - - /// - /// Returns an enum value - /// - /// The name of enum type - /// The name of the value - /// The enum value - public object GetEnum(string typeName, string name) - { - Type type = GetType(typeName); - FieldInfo fieldInfo = type.GetField(name); - return fieldInfo.GetValue(null); - } - - #endregion - - } -} diff --git a/Netch/Forms/Mode/Process.cs b/Netch/Forms/Mode/Process.cs index 96a18b2e..bb2f9641 100644 --- a/Netch/Forms/Mode/Process.cs +++ b/Netch/Forms/Mode/Process.cs @@ -1,4 +1,5 @@ -using System; +using Microsoft.WindowsAPICodePack.Dialogs; +using System; using System.IO; using System.Windows.Forms; @@ -115,9 +116,16 @@ namespace Netch.Forms.Mode private void ScanButton_Click(object sender, EventArgs e) { - var dialog = new FolderSelect.FolderSelectDialog(); - dialog.Title = Utils.i18N.Translate("Select a folder"); - if (dialog.ShowDialog(Win32Native.GetForegroundWindow())) + var dialog = new CommonOpenFileDialog + { + IsFolderPicker = true, + Multiselect = false, + Title = Utils.i18N.Translate("Select a folder"), + AddToMostRecentlyUsedList = false, + EnsurePathExists = true, + NavigateToShortcut = true + }; + if (dialog.ShowDialog(Win32Native.GetForegroundWindow()) == CommonFileDialogResult.Ok) { ScanDirectory(dialog.FileName); MessageBox.Show(Utils.i18N.Translate("Scan completed"), Utils.i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information); diff --git a/Netch/Netch.csproj b/Netch/Netch.csproj index 7577bfb4..e836d149 100644 --- a/Netch/Netch.csproj +++ b/Netch/Netch.csproj @@ -4,6 +4,7 @@ WinExe net48 true + true false Netch.Netch App.manifest @@ -57,6 +58,7 @@ +