using OpenTap; using OpenTap.Addin.Util; using System.IO; using System.Security.Cryptography; using System.Windows; using System.Windows.Forms; namespace OpenTapEditor.UI { /// /// FileSelector.xaml 的交互逻辑 /// public partial class LocationSelector : System.Windows.Controls.UserControl { public static readonly DependencyProperty LocationProperty = DependencyProperty.Register( "Location", typeof(LocationString), typeof(LocationSelector), new FrameworkPropertyMetadata()); public static readonly DependencyProperty RelativeProperty = DependencyProperty.Register( "Relative", typeof(string), typeof(LocationSelector), new FrameworkPropertyMetadata()); public static readonly DependencyProperty AbsoluteProperty = DependencyProperty.Register( "Absolute", typeof(string), typeof(LocationSelector), new FrameworkPropertyMetadata()); public static readonly DependencyProperty PlanProperty = DependencyProperty.Register( "Plan", typeof(TestPlan), typeof(LocationSelector), new FrameworkPropertyMetadata()); public static readonly DependencyProperty ModeProperty = DependencyProperty.Register( "Mode", typeof(int), typeof(LocationSelector), new FrameworkPropertyMetadata(0)); public static readonly DependencyProperty FilterProperty = DependencyProperty.Register( "Filter", typeof(string), typeof(LocationSelector), new FrameworkPropertyMetadata(null)); public static readonly DependencyProperty ExtProperty = DependencyProperty.Register( "Ext", typeof(string), typeof(LocationSelector), new FrameworkPropertyMetadata(null)); public static readonly DependencyProperty IsFolderProperty = DependencyProperty.Register( "IsFolder", typeof(bool), typeof(LocationSelector), new FrameworkPropertyMetadata(false)); public LocationString Location { get => (LocationString)GetValue(LocationProperty); set { SetValue(LocationProperty, value); } } public string Relative { get => (string)GetValue(RelativeProperty); set { SetValue(RelativeProperty, value); } } public string Absolute { get => (string)GetValue(AbsoluteProperty); set { SetValue(AbsoluteProperty, value); } } public TestPlan Plan { get => (TestPlan)GetValue(PlanProperty); set { SetValue(PlanProperty, value); } } public int Mode { get => (int)GetValue(ModeProperty); set { SetValue(ModeProperty, value); } } public string Filter { get => (string)GetValue(FilterProperty); set { SetValue(FilterProperty, value); } } public string Ext { get => (string)GetValue(ExtProperty); set { SetValue(ExtProperty, value); } } public bool IsFolder { get => (bool)GetValue(IsFolderProperty); set { SetValue(IsFolderProperty, value); } } public LocationSelector() { DataContext = this; InitializeComponent(); } private void Button_Click(object sender, RoutedEventArgs e) { if (IsFolder) { FolderBrowserDialog fbd = new FolderBrowserDialog(); fbd.Description = "请选择"; if (fbd.ShowDialog() == DialogResult.OK) { string relative = fbd.SelectedPath; if (!string.IsNullOrEmpty(Plan?.Path)) { relative = LocationString.GetRelativePath(Plan.Path, fbd.SelectedPath); } string absolute = fbd.SelectedPath; if (Mode == 1) { Relative = "\"" + relative.Replace("\\", "\\\\") + "\""; Absolute = "\"" + absolute.Replace("\\", "\\\\") + "\""; } else { Relative = relative; Absolute = absolute; } } } else { OpenFileDialog ofd = new OpenFileDialog { Filter = this.Filter, DefaultExt = this.Ext, Multiselect = false }; if (ofd.ShowDialog() == DialogResult.OK) { string relative = ofd.FileName; if (!string.IsNullOrEmpty(Plan?.Path)) { relative = LocationString.GetRelativePath(Plan.Path, ofd.FileName); } string absolute = ofd.FileName; if (Mode == 1) { Relative = "\"" + relative.Replace("\\", "\\\\") + "\""; Absolute = "\"" + absolute.Replace("\\", "\\\\") + "\""; } else { Relative = relative; Absolute = absolute; } } } } private void Button_Click_1(object sender, RoutedEventArgs e) { Location.Refresh(Plan?.Path); } } }