EditConfigDlg.xaml.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. using MeterVision.Config;
  2. using Ookii.Dialogs.Wpf;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Collections.ObjectModel;
  6. using System.ComponentModel;
  7. using System.IO;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows;
  12. using System.Windows.Controls;
  13. using System.Windows.Data;
  14. using System.Windows.Documents;
  15. using System.Windows.Input;
  16. using System.Windows.Media;
  17. using System.Windows.Media.Imaging;
  18. //using System.Windows.Shapes;
  19. namespace MeterVision.Dlg
  20. {
  21. /// <summary>
  22. /// EditConfigDlg.xaml 的交互逻辑
  23. /// </summary>
  24. public partial class EditConfigDlg : Window, INotifyPropertyChanged
  25. {
  26. public event PropertyChangedEventHandler PropertyChanged;
  27. protected void OnPropertyChanged(string propertyName)
  28. {
  29. PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
  30. }
  31. public ObservableCollection<string> AiDlls { get; set; }
  32. public ObservableCollection<string> Onnxs { get; set; }
  33. public CfginiItem mConfigItem { get; set; }
  34. public EditConfigDlg()
  35. {
  36. InitializeComponent();
  37. mConfigItem = CfginiItem.GetConfigItem();
  38. FindFreeAIDllFiles();
  39. FindOnnxFiles();
  40. this.DataContext = this;
  41. }
  42. private void FindFreeAIDllFiles()
  43. {
  44. // 获取当前应用程序的 EXE 文件路径
  45. string exeDirectory = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
  46. // 使用通配符查询符合条件的 DLL 文件
  47. string[] files = Directory.GetFiles(exeDirectory, "*freeAI*.dll");
  48. if (AiDlls == null)
  49. {
  50. AiDlls = new ObservableCollection<string>();
  51. }
  52. else
  53. {
  54. AiDlls.Clear();
  55. }
  56. // 输出找到的所有文件
  57. foreach (var file in files)
  58. {
  59. //Console.WriteLine(file);
  60. // 获取文件名(包含扩展名)
  61. string fileNameWithExtension = Path.GetFileName(file);
  62. // 获取文件名(不包含扩展名)
  63. string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(file);
  64. AiDlls.Add(fileNameWithExtension);
  65. }
  66. }
  67. private void FindOnnxFiles()
  68. {
  69. // 获取当前应用程序的 EXE 文件路径
  70. string exeDirectory = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
  71. // 使用通配符查询符合条件的 DLL 文件
  72. string[] files = Directory.GetFiles(exeDirectory, "*.onnx");
  73. if (Onnxs == null)
  74. {
  75. Onnxs = new ObservableCollection<string>();
  76. }
  77. else
  78. {
  79. Onnxs.Clear();
  80. }
  81. // 输出找到的所有文件
  82. foreach (var file in files)
  83. {
  84. //Console.WriteLine(file);
  85. // 获取文件名(包含扩展名)
  86. string fileNameWithExtension = Path.GetFileName(file);
  87. // 获取文件名(不包含扩展名)
  88. string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(file);
  89. Onnxs.Add(fileNameWithExtension);
  90. }
  91. }
  92. private void BtnClose_Click(object sender, RoutedEventArgs e)
  93. {
  94. this.Close();
  95. }
  96. private void BtnDstImgPath_Click(object sender, RoutedEventArgs e)
  97. {
  98. var dialog = new VistaFolderBrowserDialog();
  99. //dialog.Description = "请选择目标图像输出文件夹";
  100. dialog.Description = "请选择识别数据输出文件夹";
  101. dialog.UseDescriptionForTitle = true; // 使用 Description 作为窗口标题
  102. // 显示对话框并检查用户是否点击了“确定”
  103. if (dialog.ShowDialog() == true)
  104. {
  105. // 获取用户选择的文件夹路径
  106. string selectedFolderPath = dialog.SelectedPath;
  107. mConfigItem.Output = selectedFolderPath;
  108. }
  109. }
  110. //---------------------------
  111. }
  112. }