UpdaterWindow.axaml.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. using Avalonia;
  2. using Avalonia.Controls;
  3. using Avalonia.Markup.Xaml;
  4. using Ryujinx.Ava.Common.Locale;
  5. using Ryujinx.Modules;
  6. using System;
  7. using System.Diagnostics;
  8. using System.IO;
  9. using System.Linq;
  10. using System.Runtime.InteropServices;
  11. namespace Ryujinx.Ava.Ui.Windows
  12. {
  13. public partial class UpdaterWindow : StyleableWindow
  14. {
  15. private readonly string _buildUrl;
  16. private readonly MainWindow _mainWindow;
  17. private readonly Version _newVersion;
  18. private bool _restartQuery;
  19. public UpdaterWindow()
  20. {
  21. DataContext = this;
  22. InitializeComponent();
  23. #if DEBUG
  24. this.AttachDevTools();
  25. #endif
  26. Title = LocaleManager.Instance["RyujinxUpdater"];
  27. }
  28. public UpdaterWindow(MainWindow mainWindow, Version newVersion, string buildUrl) : this()
  29. {
  30. _mainWindow = mainWindow;
  31. _newVersion = newVersion;
  32. _buildUrl = buildUrl;
  33. }
  34. [DllImport("libc", SetLastError = true)]
  35. private static extern int chmod(string path, uint mode);
  36. public void YesPressed()
  37. {
  38. if (_restartQuery)
  39. {
  40. string ryuName = OperatingSystem.IsWindows() ? "Ryujinx.Ava.exe" : "Ryujinx.Ava";
  41. string ryuExe = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, ryuName);
  42. string ryuArg = string.Join(" ", Environment.GetCommandLineArgs().AsEnumerable().Skip(1).ToArray());
  43. if (!OperatingSystem.IsWindows())
  44. {
  45. chmod(ryuExe, 0777);
  46. }
  47. Process.Start(ryuExe, ryuArg);
  48. Environment.Exit(0);
  49. }
  50. else
  51. {
  52. ButtonBox.IsVisible = false;
  53. ProgressBar.IsVisible = true;
  54. SecondaryText.Text = "";
  55. _restartQuery = true;
  56. Updater.UpdateRyujinx(this, _buildUrl);
  57. }
  58. }
  59. public void NoPressed()
  60. {
  61. _mainWindow.UpdateMenuItem.IsEnabled = true;
  62. Close();
  63. }
  64. }
  65. }