2020-09-29 20:05:25 +00:00
|
|
|
using Gdk;
|
|
|
|
using Gtk;
|
|
|
|
using Mono.Unix;
|
2021-01-08 08:14:13 +00:00
|
|
|
using Ryujinx.Ui;
|
2020-09-29 20:05:25 +00:00
|
|
|
using System;
|
|
|
|
using System.Diagnostics;
|
2020-11-06 18:46:22 +00:00
|
|
|
using System.Linq;
|
2020-09-29 20:05:25 +00:00
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
2021-01-08 08:14:13 +00:00
|
|
|
namespace Ryujinx.Modules
|
2020-09-29 20:05:25 +00:00
|
|
|
{
|
|
|
|
public class UpdateDialog : Gtk.Window
|
|
|
|
{
|
|
|
|
#pragma warning disable CS0649, IDE0044
|
2021-01-08 08:14:13 +00:00
|
|
|
[Builder.Object] public Label MainText;
|
|
|
|
[Builder.Object] public Label SecondaryText;
|
2020-09-29 20:05:25 +00:00
|
|
|
[Builder.Object] public LevelBar ProgressBar;
|
2021-01-08 08:14:13 +00:00
|
|
|
[Builder.Object] public Button YesButton;
|
|
|
|
[Builder.Object] public Button NoButton;
|
2020-09-29 20:05:25 +00:00
|
|
|
#pragma warning restore CS0649, IDE0044
|
|
|
|
|
|
|
|
private readonly MainWindow _mainWindow;
|
2021-01-08 08:14:13 +00:00
|
|
|
private readonly string _buildUrl;
|
|
|
|
private bool _restartQuery;
|
2020-09-29 20:05:25 +00:00
|
|
|
|
2021-01-08 08:14:13 +00:00
|
|
|
public UpdateDialog(MainWindow mainWindow, Version newVersion, string buildUrl) : this(new Builder("Ryujinx..Modules.Updater.UpdateDialog.glade"), mainWindow, newVersion, buildUrl) { }
|
2020-09-29 20:05:25 +00:00
|
|
|
|
|
|
|
private UpdateDialog(Builder builder, MainWindow mainWindow, Version newVersion, string buildUrl) : base(builder.GetObject("UpdateDialog").Handle)
|
|
|
|
{
|
|
|
|
builder.Autoconnect(this);
|
|
|
|
|
|
|
|
_mainWindow = mainWindow;
|
|
|
|
_buildUrl = buildUrl;
|
|
|
|
|
|
|
|
MainText.Text = "Do you want to update Ryujinx to the latest version?";
|
|
|
|
SecondaryText.Text = $"{Program.Version} -> {newVersion}";
|
|
|
|
|
|
|
|
ProgressBar.Hide();
|
|
|
|
|
2021-01-08 08:14:13 +00:00
|
|
|
YesButton.Clicked += YesButton_Clicked;
|
|
|
|
NoButton.Clicked += NoButton_Clicked;
|
2020-09-29 20:05:25 +00:00
|
|
|
}
|
|
|
|
|
2021-01-08 08:14:13 +00:00
|
|
|
private void YesButton_Clicked(object sender, EventArgs args)
|
2020-09-29 20:05:25 +00:00
|
|
|
{
|
|
|
|
if (_restartQuery)
|
|
|
|
{
|
|
|
|
string ryuName = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "Ryujinx.exe" : "Ryujinx";
|
|
|
|
string ryuExe = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, ryuName);
|
2021-01-08 08:14:13 +00:00
|
|
|
string ryuArg = string.Join(" ", Environment.GetCommandLineArgs().AsEnumerable().Skip(1).ToArray());
|
2020-09-29 20:05:25 +00:00
|
|
|
|
|
|
|
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
|
|
|
{
|
|
|
|
UnixFileInfo unixFileInfo = new UnixFileInfo(ryuExe);
|
|
|
|
unixFileInfo.FileAccessPermissions |= FileAccessPermissions.UserExecute;
|
|
|
|
}
|
|
|
|
|
2020-10-29 22:07:10 +00:00
|
|
|
Process.Start(ryuExe, ryuArg);
|
2020-09-29 20:05:25 +00:00
|
|
|
|
|
|
|
Environment.Exit(0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-01-08 08:14:13 +00:00
|
|
|
Window.Functions = _mainWindow.Window.Functions = WMFunction.All & WMFunction.Close;
|
2020-09-29 20:05:25 +00:00
|
|
|
_mainWindow.ExitMenuItem.Sensitive = false;
|
|
|
|
|
|
|
|
YesButton.Hide();
|
|
|
|
NoButton.Hide();
|
|
|
|
ProgressBar.Show();
|
|
|
|
|
|
|
|
SecondaryText.Text = "";
|
|
|
|
_restartQuery = true;
|
|
|
|
|
2020-11-27 17:57:20 +00:00
|
|
|
_ = Updater.UpdateRyujinx(this, _buildUrl);
|
2020-09-29 20:05:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-08 08:14:13 +00:00
|
|
|
private void NoButton_Clicked(object sender, EventArgs args)
|
2020-09-29 20:05:25 +00:00
|
|
|
{
|
|
|
|
Updater.Running = false;
|
|
|
|
_mainWindow.Window.Functions = WMFunction.All;
|
|
|
|
|
|
|
|
_mainWindow.ExitMenuItem.Sensitive = true;
|
|
|
|
_mainWindow.UpdateMenuItem.Sensitive = true;
|
|
|
|
|
2021-01-08 08:14:13 +00:00
|
|
|
Dispose();
|
2020-09-29 20:05:25 +00:00
|
|
|
}
|
|
|
|
}
|
2021-01-08 08:14:13 +00:00
|
|
|
}
|