MainWindow.xaml.cs 1.3 KB

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