MainWindow.xaml.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using System;
  2. using System.Diagnostics;
  3. using System.IO;
  4. using System.Threading.Tasks;
  5. using System.Windows;
  6. namespace PixiEditor.UpdateInstaller
  7. {
  8. /// <summary>
  9. /// Interaction logic for MainWindow.xaml.
  10. /// </summary>
  11. public partial class MainWindow
  12. {
  13. public MainWindow()
  14. {
  15. InitializeComponent();
  16. DataContext = new ViewModelMain();
  17. }
  18. private async void Window_Loaded(object sender, RoutedEventArgs e)
  19. {
  20. ViewModelMain vmm = (ViewModelMain)DataContext;
  21. await Task.Run(() =>
  22. {
  23. try
  24. {
  25. vmm.InstallUpdate();
  26. }
  27. catch (Exception ex)
  28. {
  29. MessageBox.Show(ex.Message, "Update error", MessageBoxButton.OK, MessageBoxImage.Error);
  30. File.AppendAllText("ErrorLog.txt", $"Error PixiEditor.UpdateInstaller: {DateTime.Now}\n{ex.Message}\n{ex.StackTrace}\n-----\n");
  31. }
  32. finally
  33. {
  34. string pixiEditorExecutablePath = Directory.GetFiles(vmm.UpdateDirectory, "PixiEditor.exe")[0];
  35. Process.Start(pixiEditorExecutablePath);
  36. }
  37. });
  38. Close();
  39. }
  40. }
  41. }