DownloadSupportAppWindow.xaml.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. using System;
  2. using System.IO;
  3. using System.Windows;
  4. using InABox.Core;
  5. using Microsoft.Web.WebView2.Core;
  6. namespace PRSDesktop;
  7. public partial class DownloadSupportAppWindow : Window
  8. {
  9. public DownloadSupportAppWindow()
  10. {
  11. InitializeComponent();
  12. }
  13. private void Download_Click(object sender, RoutedEventArgs e)
  14. {
  15. Browser.Source = new Uri(URL.Text);
  16. }
  17. private void Browser_OnNavigationStarting(object? sender, CoreWebView2NavigationStartingEventArgs e)
  18. {
  19. Browser.CoreWebView2.DownloadStarting += (o, args) =>
  20. {
  21. args.ResultFilePath = System.IO.Path.Combine(CoreUtils.GetPath(), "helpwire.exe");
  22. args.DownloadOperation.StateChanged += (o, e) =>
  23. {
  24. if (args.DownloadOperation.State == CoreWebView2DownloadState.Interrupted)
  25. {
  26. if (File.Exists(args.ResultFilePath))
  27. File.Delete(args.ResultFilePath);
  28. }
  29. if (args.DownloadOperation.State == CoreWebView2DownloadState.Completed)
  30. Close();
  31. };
  32. };
  33. }
  34. }