App.xaml.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using System;
  2. using System.Diagnostics;
  3. using System.IO;
  4. using System.Threading.Tasks;
  5. using System.Windows;
  6. namespace Vinno.FIS.Sonopost.Upgrade
  7. {
  8. /// <summary>
  9. /// App.xaml 的交互逻辑
  10. /// </summary>
  11. public partial class App : Application
  12. {
  13. protected override void OnStartup(StartupEventArgs e)
  14. {
  15. base.OnStartup(e);
  16. if (e.Args.Length == 3)
  17. {
  18. var upgradePath = e.Args[0];
  19. var targetPath = e.Args[1];
  20. var deleteAllFiles = false;
  21. bool.TryParse(e.Args[2], out deleteAllFiles);
  22. StartUpgradeThread(upgradePath, targetPath, deleteAllFiles);
  23. }
  24. else
  25. {
  26. Process.GetCurrentProcess().Kill();
  27. }
  28. }
  29. private void StartUpgradeThread(string upgradePath, string targetPath, bool deleteAllFiles)
  30. {
  31. Task.Run(() =>
  32. {
  33. var upgrade = new UpgradeOperator(upgradePath, targetPath, deleteAllFiles);
  34. try
  35. {
  36. upgrade.StartUpgrade();
  37. }
  38. catch (Exception ex)
  39. {
  40. File.AppendAllText("UpgradeLog.txt", ex.ToString());
  41. upgrade.InstallSonopostTask();
  42. }
  43. finally
  44. {
  45. Process.GetCurrentProcess().Kill();
  46. }
  47. });
  48. }
  49. }
  50. }