UpdaterWindow.axaml.cs 2.0 KB

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