UpdateDialog.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. using Gdk;
  2. using Gtk;
  3. using Mono.Unix;
  4. using System;
  5. using System.Diagnostics;
  6. using System.Runtime.InteropServices;
  7. namespace Ryujinx.Ui
  8. {
  9. public class UpdateDialog : Gtk.Window
  10. {
  11. #pragma warning disable CS0649, IDE0044
  12. [Builder.Object] public Label MainText;
  13. [Builder.Object] public Label SecondaryText;
  14. [Builder.Object] public LevelBar ProgressBar;
  15. [Builder.Object] public Button YesButton;
  16. [Builder.Object] public Button NoButton;
  17. #pragma warning restore CS0649, IDE0044
  18. private readonly MainWindow _mainWindow;
  19. private readonly string _buildUrl;
  20. private bool _restartQuery;
  21. public UpdateDialog(MainWindow mainWindow, Version newVersion, string buildUrl) : this(new Builder("Ryujinx.Updater.UpdateDialog.glade"), mainWindow, newVersion, buildUrl) { }
  22. private UpdateDialog(Builder builder, MainWindow mainWindow, Version newVersion, string buildUrl) : base(builder.GetObject("UpdateDialog").Handle)
  23. {
  24. builder.Autoconnect(this);
  25. _mainWindow = mainWindow;
  26. _buildUrl = buildUrl;
  27. MainText.Text = "Do you want to update Ryujinx to the latest version?";
  28. SecondaryText.Text = $"{Program.Version} -> {newVersion}";
  29. ProgressBar.Hide();
  30. YesButton.Pressed += YesButton_Pressed;
  31. NoButton.Pressed += NoButton_Pressed;
  32. }
  33. private void YesButton_Pressed(object sender, EventArgs args)
  34. {
  35. if (_restartQuery)
  36. {
  37. string ryuName = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "Ryujinx.exe" : "Ryujinx";
  38. string ryuExe = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, ryuName);
  39. string ryuArg = String.Join(" ", Environment.GetCommandLineArgs());
  40. if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
  41. {
  42. UnixFileInfo unixFileInfo = new UnixFileInfo(ryuExe);
  43. unixFileInfo.FileAccessPermissions |= FileAccessPermissions.UserExecute;
  44. }
  45. Process.Start(ryuExe, ryuArg);
  46. Environment.Exit(0);
  47. }
  48. else
  49. {
  50. this.Window.Functions = _mainWindow.Window.Functions = WMFunction.All & WMFunction.Close;
  51. _mainWindow.ExitMenuItem.Sensitive = false;
  52. YesButton.Hide();
  53. NoButton.Hide();
  54. ProgressBar.Show();
  55. SecondaryText.Text = "";
  56. _restartQuery = true;
  57. Updater.UpdateRyujinx(this, _buildUrl);
  58. }
  59. }
  60. private void NoButton_Pressed(object sender, EventArgs args)
  61. {
  62. Updater.Running = false;
  63. _mainWindow.Window.Functions = WMFunction.All;
  64. _mainWindow.ExitMenuItem.Sensitive = true;
  65. _mainWindow.UpdateMenuItem.Sensitive = true;
  66. this.Dispose();
  67. }
  68. }
  69. }