WinMd5Test.xaml.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. using FWindSoft.WindowsApi;
  2. using FWindSoft.Wpf;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Collections.ObjectModel;
  6. using System.ComponentModel;
  7. using System.Diagnostics;
  8. using System.Globalization;
  9. using System.Linq;
  10. using System.Reflection;
  11. using System.Runtime.CompilerServices;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14. using System.Windows;
  15. using System.Windows.Controls;
  16. using System.Windows.Data;
  17. using System.Windows.Documents;
  18. using System.Windows.Input;
  19. using System.Windows.Media;
  20. using System.Windows.Media.Imaging;
  21. using System.Windows.Shapes;
  22. namespace Test.MD5Test
  23. {
  24. /// <summary>
  25. /// WinMd5Test.xaml 的交互逻辑
  26. /// </summary>
  27. public partial class WinMd5Test : HWindow
  28. {
  29. KeyboardHook m_Hook;
  30. public WinMd5Test()
  31. {
  32. InitializeComponent();
  33. this.RecordLocation = true;
  34. MD5Results = new ObservableCollection<string>();
  35. this.DataContext = this;
  36. //几千倍的数据访问速度提高
  37. string path = @"E:\立项\SAGA.MBI.exe";
  38. // var ff=Assembly.ReflectionOnlyLoadFrom(path).GetName().Version;
  39. LoadData();
  40. //this.AddHandler(ComboBox.DropDownOpened, cmb_DropDownOpened)
  41. m_Hook = new KeyboardHook(true, Process.GetCurrentProcess().MainWindowHandle);
  42. m_Hook.KeyUp += Hook_KeyUp;
  43. m_Hook.Install();
  44. }
  45. private void Hook_KeyUp(object sender, FWindSoft.WindowsApi.KeyEventArgs e)
  46. {
  47. // MessageBox.Show(e.KeyData.ToString());
  48. Debug.WriteLine(e.KeyData.ToString());
  49. }
  50. void cmb_DropDownOpened(object sender, EventArgs e)
  51. {
  52. }
  53. private string m_Path;
  54. public string Path
  55. {
  56. get { return m_Path; }
  57. set { SetPropertyValue(ref m_Path, value); }
  58. }
  59. private ObservableCollection<string> m_MD5Results;
  60. public ObservableCollection<string> MD5Results
  61. {
  62. get { return m_MD5Results; }
  63. set { SetPropertyValue(ref m_MD5Results, value); }
  64. }
  65. private void Button_Click(object sender, RoutedEventArgs e)
  66. {
  67. //MessageBox.Show("路径为空");
  68. //return;
  69. if (string.IsNullOrWhiteSpace(Path))
  70. {
  71. MessageBox.Show("路径为空");
  72. return;
  73. }
  74. var attach = MD5Utils.GetVersionRevitFile(Path);
  75. var md5 = MD5Utils.GetMD5HashFromFile(Path);
  76. string useMd5 = md5 ?? "无";
  77. string item = string.Format("{0}-----{1}", DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"), useMd5);
  78. MD5Results.Add(item);
  79. }
  80. }
  81. public partial class WinMd5Test : INotifyPropertyChanged
  82. {
  83. public event PropertyChangedEventHandler PropertyChanged;
  84. /// <summary>
  85. /// 提交变更
  86. /// </summary>
  87. /// <param name="propertyName">变更属性名称</param>
  88. protected void RaiseChanged(String propertyName = "")
  89. {
  90. if (PropertyChanged != null)
  91. {
  92. PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
  93. }
  94. }
  95. protected void SetPropertyValue<T>(ref T old, T value, [CallerMemberName] string propertyName = "")
  96. {
  97. old = value;
  98. RaiseChanged(propertyName);
  99. }
  100. }
  101. }