App.xaml.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using PixiEditor.Models.DataHolders;
  2. using PixiEditor.Models.Dialogs;
  3. using PixiEditor.Models.Enums;
  4. using PixiEditor.ViewModels;
  5. using PixiEditor.Views.Dialogs;
  6. using System;
  7. using System.Diagnostics;
  8. using System.Linq;
  9. using System.Text.RegularExpressions;
  10. using System.Windows;
  11. namespace PixiEditor
  12. {
  13. /// <summary>
  14. /// Interaction logic for App.xaml.
  15. /// </summary>
  16. public partial class App : Application
  17. {
  18. protected override void OnStartup(StartupEventArgs e)
  19. {
  20. string arguments = string.Join(' ', e.Args);
  21. if (ParseArgument("--crash (\"?)([A-z0-9:\\/\\ -_.]+)\\1", arguments, out Group[] groups))
  22. {
  23. CrashReport report = CrashReport.Parse(groups[2].Value);
  24. MainWindow = new CrashReportDialog(report);
  25. }
  26. else
  27. {
  28. MainWindow = new MainWindow();
  29. }
  30. MainWindow.Show();
  31. }
  32. protected override void OnSessionEnding(SessionEndingCancelEventArgs e)
  33. {
  34. base.OnSessionEnding(e);
  35. if (ViewModelMain.Current.BitmapManager.Documents.Any(x => !x.ChangesSaved))
  36. {
  37. ConfirmationType confirmation = ConfirmationDialog.Show($"{e.ReasonSessionEnding} with unsaved data. Are you sure?", $"{e.ReasonSessionEnding}");
  38. e.Cancel = confirmation != ConfirmationType.Yes;
  39. }
  40. }
  41. private bool ParseArgument(string pattern, string args, out Group[] groups)
  42. {
  43. Match match = Regex.Match(args, pattern, RegexOptions.IgnoreCase);
  44. groups = null;
  45. if (match.Success)
  46. {
  47. groups = match.Groups.Values.ToArray();
  48. }
  49. return match.Success;
  50. }
  51. }
  52. }