UpdaterWindow.axaml.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 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. public TextBlock MainText { get; set; }
  35. public TextBlock SecondaryText { get; set; }
  36. public ProgressBar ProgressBar { get; set; }
  37. public StackPanel ButtonBox { get; set; }
  38. private void InitializeComponent()
  39. {
  40. AvaloniaXamlLoader.Load(this);
  41. MainText = this.FindControl<TextBlock>("MainText");
  42. SecondaryText = this.FindControl<TextBlock>("SecondaryText");
  43. ProgressBar = this.FindControl<ProgressBar>("ProgressBar");
  44. ButtonBox = this.FindControl<StackPanel>("ButtonBox");
  45. }
  46. [DllImport("libc", SetLastError = true)]
  47. private static extern int chmod(string path, uint mode);
  48. public void YesPressed()
  49. {
  50. if (_restartQuery)
  51. {
  52. string ryuName = OperatingSystem.IsWindows() ? "Ryujinx.Ava.exe" : "Ryujinx.Ava";
  53. string ryuExe = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, ryuName);
  54. string ryuArg = string.Join(" ", Environment.GetCommandLineArgs().AsEnumerable().Skip(1).ToArray());
  55. if (!OperatingSystem.IsWindows())
  56. {
  57. chmod(ryuExe, 0777);
  58. }
  59. Process.Start(ryuExe, ryuArg);
  60. Environment.Exit(0);
  61. }
  62. else
  63. {
  64. ButtonBox.IsVisible = false;
  65. ProgressBar.IsVisible = true;
  66. SecondaryText.Text = "";
  67. _restartQuery = true;
  68. Updater.UpdateRyujinx(this, _buildUrl);
  69. }
  70. }
  71. public void NoPressed()
  72. {
  73. _mainWindow.UpdateMenuItem.IsEnabled = true;
  74. Close();
  75. }
  76. }
  77. }