UpdateDialog.cs 3.0 KB

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