diff --git a/Il2CppInspector.Common/Plugins/API/V100/IPluginOption.cs b/Il2CppInspector.Common/Plugins/API/V100/IPluginOption.cs index 7a59c4b..8e3d6b2 100644 --- a/Il2CppInspector.Common/Plugins/API/V100/IPluginOption.cs +++ b/Il2CppInspector.Common/Plugins/API/V100/IPluginOption.cs @@ -6,6 +6,7 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; namespace Il2CppInspector.PluginAPI.V100 @@ -148,8 +149,37 @@ namespace Il2CppInspector.PluginAPI.V100 throw new ArgumentException("Path name is required"); // Throws an exception if the path is invalid (file or folder may or may not exist) - System.IO.Path.GetFullPath(path ?? ""); + var fullPath = Path.GetFullPath(path ?? ""); + var fileName = Path.GetFileName(fullPath); + + if (IsFolder) { + if (MustExist && !Directory.Exists(fullPath)) + throw new ArgumentException($"Directory {fileName} does not exist"); + if (MustNotExist && Directory.Exists(fullPath)) + throw new ArgumentException($"Directory {fileName} already exists"); + } + else { + if (MustExist && !File.Exists(fullPath)) + throw new ArgumentException($"File {fileName} does not exist"); + if (MustNotExist && File.Exists(fullPath)) + throw new ArgumentException($"File {fileName} already exists"); + } } + + /// + /// Set this to true if you want the user to specify a folder rather than a file + /// + public bool IsFolder = false; + + /// + /// Set this to true if the specified file or folder must exist + /// + public bool MustExist = false; + + /// + /// Set this to true if the specified file or folder must not exist + /// + public bool MustNotExist = false; } /// diff --git a/Il2CppInspector.GUI/Il2CppInspector.GUI.csproj b/Il2CppInspector.GUI/Il2CppInspector.GUI.csproj index 8dd6d85..68bd20f 100644 --- a/Il2CppInspector.GUI/Il2CppInspector.GUI.csproj +++ b/Il2CppInspector.GUI/Il2CppInspector.GUI.csproj @@ -9,12 +9,14 @@ win-x64 true Il2CppInspector - 2020.2.1 + 2021.1 Katy Coe Noisy Cow Studios Il2CppInspector Windows Edition app.manifest Il2CppInspector.ico + 2021.1.0.0 + 2021.1.0.0 diff --git a/Il2CppInspector.GUI/PluginConfigurationDialog.xaml.cs b/Il2CppInspector.GUI/PluginConfigurationDialog.xaml.cs index 20a62a2..78c40ac 100644 --- a/Il2CppInspector.GUI/PluginConfigurationDialog.xaml.cs +++ b/Il2CppInspector.GUI/PluginConfigurationDialog.xaml.cs @@ -25,6 +25,7 @@ using System.Linq; using Il2CppInspector.PluginAPI.V100; using Il2CppInspector.Reflection; using Il2CppInspector; +using Ookii.Dialogs.Wpf; namespace Il2CppInspectorGUI { @@ -134,22 +135,49 @@ namespace Il2CppInspectorGUI var option = (PluginOptionFilePath) ((Button) sender).DataContext; - var openFileDialog = new OpenFileDialog { - Title = option.Description, - Filter = "All files (*.*)|*.*", - FileName = option.Value, - CheckFileExists = false, - CheckPathExists = false - }; + string path = null; - if (openFileDialog.ShowDialog() == true) { + if (option.IsFolder && option.MustExist) { + var openFolderDialog = new VistaFolderBrowserDialog { + SelectedPath = option.Value, + Description = option.Description, + UseDescriptionForTitle = true + }; + if (openFolderDialog.ShowDialog() == true) { + path = openFolderDialog.SelectedPath; + } + } else if (option.MustExist) { + var openFileDialog = new OpenFileDialog { + Title = option.Description, + Filter = "All files (*.*)|*.*", + FileName = option.Value, + CheckFileExists = true, + CheckPathExists = true + }; + if (openFileDialog.ShowDialog() == true) { + path = openFileDialog.FileName; + } + } else { + var saveFileDialog = new SaveFileDialog { + Title = option.Description, + Filter = "All files (*.*)|*.*", + FileName = option.Value, + CheckFileExists = false, + OverwritePrompt = false + }; + if (saveFileDialog.ShowDialog() == true) { + path = saveFileDialog.FileName; + } + } + + if (path != null) { // This spaghetti saves us from implementing INotifyPropertyChanged on Plugin.Options // (we don't want to expose WPF stuff in our SDK) // Will break if we change the format of the FilePathDataTemplate too much var tb = ((DockPanel) ((Button) sender).Parent).Children.OfType().First().Children.OfType().First(n => n.Name == "valueControl"); try { tb.Clear(); - tb.AppendText(openFileDialog.FileName); + tb.AppendText(path); tb.GetBindingExpression(TextBox.TextProperty).UpdateSource(); } catch { }