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