UpdateDialog.cs 3.2 KB

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