UpdaterWindow.axaml.cs 2.0 KB

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