App.xaml.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using GalaSoft.MvvmLight.Threading;
  2. using System;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Windows;
  6. namespace MuchInfo.Chart.App
  7. {
  8. /// <summary>
  9. /// App.xaml 的交互逻辑
  10. /// </summary>
  11. public partial class App : Application
  12. {
  13. static App()
  14. {
  15. CopySqliteFile();
  16. DispatcherHelper.Initialize();
  17. }
  18. public App()
  19. {
  20. this.DispatcherUnhandledException += App_DispatcherUnhandledException;
  21. AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
  22. }
  23. /// <summary>
  24. /// 处理Dispatcher线程异常
  25. /// </summary>
  26. /// <param name="sender">The source of the event.</param>
  27. /// <param name="e">The <see cref="System.Windows.Threading.DispatcherUnhandledExceptionEventArgs"/> instance containing the event data.</param>
  28. private void App_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
  29. {
  30. MessageBox.Show(e.Exception.Message);
  31. }
  32. /// <summary>
  33. /// 处理Domain异常
  34. /// </summary>
  35. /// <param name="sender">The source of the event.</param>
  36. /// <param name="e">The <see cref="UnhandledExceptionEventArgs"/> instance containing the event data.</param>
  37. private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
  38. {
  39. MessageBox.Show((e.ExceptionObject as Exception).Message);
  40. }
  41. private static void CopySqliteFile()
  42. {
  43. var is64 = Environment.Is64BitOperatingSystem;
  44. var sqliteFilePath = Environment.CurrentDirectory;
  45. sqliteFilePath = Path.Combine(sqliteFilePath, is64 ? "x64" : "x86");
  46. var dirInfo = new DirectoryInfo(sqliteFilePath);
  47. if (dirInfo.Exists)
  48. {
  49. var fileInfos = dirInfo.GetFiles("*.dll", SearchOption.TopDirectoryOnly);
  50. if (!fileInfos.Any()) return;
  51. foreach (var fileInfo in fileInfos)
  52. {
  53. fileInfo.CopyTo(Path.Combine(Environment.CurrentDirectory, fileInfo.Name), true);
  54. }
  55. }
  56. }
  57. }
  58. }