Merge pull request #2 from DrHacknik/updater-melon

Updater done.
This commit is contained in:
MelonSpeedruns 2020-02-06 13:26:35 -05:00 committed by GitHub
commit 8ec63579f6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 319 additions and 271 deletions

122
Ryujinx.Updater/Program.cs Normal file
View file

@ -0,0 +1,122 @@
using System;
using System.Diagnostics;
using System.IO;
using System.IO.Compression;
using System.Net;
namespace Ryujinx.Updater
{
class Program
{
public static string localAppPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Ryujinx");
public static string ryuDir = Environment.CurrentDirectory;
public static string updateSaveLocation;
public static int lastPercentage;
private static void MoveAllFilesOver(string root, string dest)
{
foreach (var directory in Directory.GetDirectories(root))
{
string dirName = Path.GetFileName(directory);
try
{
if (!Directory.Exists(Path.Combine(dest, dirName)))
{
Directory.CreateDirectory(Path.Combine(dest, dirName));
}
}
catch
{
}
MoveAllFilesOver(directory, Path.Combine(dest, dirName));
}
foreach (var file in Directory.GetFiles(root))
{
try
{
File.Move(file, Path.Combine(dest, Path.GetFileName(file)), true);
}
catch
{
}
}
}
static void Main(string[] args)
{
if (args.Length < 2)
{
return;
}
if (!File.Exists(Path.Combine(localAppPath, "Version.json")))
{
File.Create(Path.Combine(localAppPath, "Version.json")).Close();
File.WriteAllText(Path.Combine(localAppPath, "Version.json"), "Unknown Version");
}
Console.WriteLine($"Updating Ryujinx... | {File.ReadAllText(Path.Combine(localAppPath, "Version.json"))} -> {args[1]}");
File.WriteAllText(Path.Combine(localAppPath, "Version.json"), args[1]);
// Create temp directory
if (!Directory.Exists(Path.Combine(localAppPath, "Temp")))
{
Directory.CreateDirectory(Path.Combine(localAppPath, "Temp"));
}
// Download latest update
string downloadUrl = args[0];
updateSaveLocation = Path.Combine(localAppPath, "Temp", "RyujinxPackage.zip");
Console.WriteLine($"Downloading latest Ryujinx package...");
WebClient client = new WebClient();
client.DownloadProgressChanged += (s, e) =>
{
if (e.ProgressPercentage != lastPercentage)
{
Console.WriteLine("Package downloading... " + e.ProgressPercentage + "%");
}
lastPercentage = e.ProgressPercentage;
};
client.DownloadFileTaskAsync(new Uri(downloadUrl), updateSaveLocation).Wait();
// Extract Update .zip
Console.WriteLine($"Extracting Ryujinx package...");
ZipFile.ExtractToDirectory(updateSaveLocation, localAppPath, true);
// Copy new files over to Ryujinx folder
Console.WriteLine($"Replacing old version...");
MoveAllFilesOver(Path.Combine(localAppPath, "publish"), ryuDir);
// Remove temp folders
Directory.Delete(Path.Combine(localAppPath, "publish"), true);
Directory.Delete(Path.Combine(localAppPath, "Temp"), true);
// Start new Ryujinx version and close Updater
ProcessStartInfo startInfo = new ProcessStartInfo(Path.Combine(ryuDir, "Ryujinx.exe"));
startInfo.UseShellExecute = true;
Process.Start(startInfo);
}
}
}

View file

@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
<RuntimeIdentifiers>win-x64;osx-x64;linux-x64;</RuntimeIdentifiers>
<Configurations>Debug;Release;Profile Debug;Profile Release</Configurations>
<ApplicationIcon>Updater.ico</ApplicationIcon>
<OutputType>Exe</OutputType>
<AssemblyName>Updater</AssemblyName>
</PropertyGroup>
<Target Name="AddRuntimeDependenciesToContent" Condition=" '$(TargetFrameworkIdentifier)' == '.NETCoreApp'" BeforeTargets="GetCopyToOutputDirectoryItems" DependsOnTargets="GenerateBuildDependencyFile;GenerateBuildRuntimeConfigurationFiles">
<ItemGroup>
<ContentWithTargetPath Include="$(ProjectDepsFilePath)" CopyToOutputDirectory="PreserveNewest" TargetPath="$(ProjectDepsFileName)" />
<ContentWithTargetPath Include="$(ProjectRuntimeConfigFilePath)" CopyToOutputDirectory="PreserveNewest" TargetPath="$(ProjectRuntimeConfigFileName)" />
</ItemGroup>
</Target>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
</Project>

BIN
Ryujinx.Updater/Updater.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 103 KiB

View file

@ -4,6 +4,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
VisualStudioVersion = 16.0.29613.14
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ryujinx", "Ryujinx\Ryujinx.csproj", "{074045D4-3ED2-4711-9169-E385F2BFB5A0}"
ProjectSection(ProjectDependencies) = postProject
{529E361C-FEF5-4C07-A2F4-3351C45CADDD} = {529E361C-FEF5-4C07-A2F4-3351C45CADDD}
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ryujinx.Tests", "Ryujinx.Tests\Ryujinx.Tests.csproj", "{EBB55AEA-C7D7-4DEB-BF96-FA1789E225E9}"
EndProject
@ -38,6 +41,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ryujinx.Graphics.Shader", "
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ryujinx.Graphics.Nvdec", "Ryujinx.Graphics.Nvdec\Ryujinx.Graphics.Nvdec.csproj", "{85A0FA56-DC01-4A42-8808-70DAC76BD66D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ryujinx.Updater", "Ryujinx.Updater\Ryujinx.Updater.csproj", "{529E361C-FEF5-4C07-A2F4-3351C45CADDD}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -174,6 +179,14 @@ Global
{85A0FA56-DC01-4A42-8808-70DAC76BD66D}.Profile Release|Any CPU.Build.0 = Release|Any CPU
{85A0FA56-DC01-4A42-8808-70DAC76BD66D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{85A0FA56-DC01-4A42-8808-70DAC76BD66D}.Release|Any CPU.Build.0 = Release|Any CPU
{529E361C-FEF5-4C07-A2F4-3351C45CADDD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{529E361C-FEF5-4C07-A2F4-3351C45CADDD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{529E361C-FEF5-4C07-A2F4-3351C45CADDD}.Profile Debug|Any CPU.ActiveCfg = Debug|Any CPU
{529E361C-FEF5-4C07-A2F4-3351C45CADDD}.Profile Debug|Any CPU.Build.0 = Debug|Any CPU
{529E361C-FEF5-4C07-A2F4-3351C45CADDD}.Profile Release|Any CPU.ActiveCfg = Release|Any CPU
{529E361C-FEF5-4C07-A2F4-3351C45CADDD}.Profile Release|Any CPU.Build.0 = Release|Any CPU
{529E361C-FEF5-4C07-A2F4-3351C45CADDD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{529E361C-FEF5-4C07-A2F4-3351C45CADDD}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View file

@ -63,8 +63,7 @@ namespace Ryujinx
{
switch (arg.Substring(0, 2).ToUpper())
{
case "/U": Updater.Update.PerformUpdate(); break;
case "/C": Updater.Update.Cleanup(); break;
case "/U": UpdateParser.BeginParse(); break;
default: mainWindow.LoadApplication(args[0]); break;
}
}

View file

@ -74,7 +74,7 @@
<ItemGroup>
<PackageReference Include="DiscordRichPresence" Version="1.0.147" />
<PackageReference Include="GtkSharp" Version="3.22.25.24" />
<PackageReference Include="GtkSharp" Version="3.22.25.56" />
<PackageReference Include="GtkSharp.Dependencies" Version="1.1.0" Condition="'$(RuntimeIdentifier)' != 'linux-x64' AND '$(RuntimeIdentifier)' != 'osx-x64'" />
<PackageReference Include="OpenTK.NetStandard" Version="1.0.4" />
</ItemGroup>
@ -87,6 +87,7 @@
<ProjectReference Include="..\ARMeilleure\ARMeilleure.csproj" />
<ProjectReference Include="..\Ryujinx.Graphics.OpenGL\Ryujinx.Graphics.OpenGL.csproj" />
<ProjectReference Include="..\Ryujinx.Graphics.Gpu\Ryujinx.Graphics.Gpu.csproj" />
<ProjectReference Include="..\Ryujinx.Updater\Ryujinx.Updater.csproj" />
</ItemGroup>
<ItemGroup>

View file

@ -4,8 +4,6 @@ using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
using Utf8Json;
using Utf8Json.Resolvers;
using GUI = Gtk.Builder.ObjectAttribute;
@ -16,30 +14,45 @@ namespace Ryujinx.Ui
#pragma warning disable CS0649
#pragma warning disable IDE0044
[GUI] Window _aboutWin;
[GUI] Label _versionText;
[GUI] Image _ryujinxLogo;
[GUI] Image _patreonLogo;
[GUI] Image _gitHubLogo;
[GUI] Image _discordLogo;
[GUI] Image _twitterLogo;
[GUI] Label _versionText;
[GUI] Image _ryujinxLogo;
[GUI] Image _patreonLogo;
[GUI] Image _gitHubLogo;
[GUI] Image _discordLogo;
[GUI] Image _twitterLogo;
#pragma warning restore CS0649
#pragma warning restore IDE0044
public string localAppPath = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Ryujinx");
public AboutWindow() : this(new Builder("Ryujinx.Ui.AboutWindow.glade")) { }
private AboutWindow(Builder builder) : base(builder.GetObject("_aboutWin").Handle)
{
builder.Autoconnect(this);
_aboutWin.Icon = new Gdk.Pixbuf(Assembly.GetExecutingAssembly(), "Ryujinx.Ui.assets.Icon.png");
_ryujinxLogo.Pixbuf = new Gdk.Pixbuf(Assembly.GetExecutingAssembly(), "Ryujinx.Ui.assets.Icon.png" , 100, 100);
_patreonLogo.Pixbuf = new Gdk.Pixbuf(Assembly.GetExecutingAssembly(), "Ryujinx.Ui.assets.PatreonLogo.png", 30 , 30 );
_gitHubLogo.Pixbuf = new Gdk.Pixbuf(Assembly.GetExecutingAssembly(), "Ryujinx.Ui.assets.GitHubLogo.png" , 30 , 30 );
_discordLogo.Pixbuf = new Gdk.Pixbuf(Assembly.GetExecutingAssembly(), "Ryujinx.Ui.assets.DiscordLogo.png", 30 , 30 );
_twitterLogo.Pixbuf = new Gdk.Pixbuf(Assembly.GetExecutingAssembly(), "Ryujinx.Ui.assets.TwitterLogo.png", 30 , 30 );
_aboutWin.Icon = new Gdk.Pixbuf(Assembly.GetExecutingAssembly(), "Ryujinx.Ui.assets.Icon.png");
_ryujinxLogo.Pixbuf = new Gdk.Pixbuf(Assembly.GetExecutingAssembly(), "Ryujinx.Ui.assets.Icon.png", 100, 100);
_patreonLogo.Pixbuf = new Gdk.Pixbuf(Assembly.GetExecutingAssembly(), "Ryujinx.Ui.assets.PatreonLogo.png", 30, 30);
_gitHubLogo.Pixbuf = new Gdk.Pixbuf(Assembly.GetExecutingAssembly(), "Ryujinx.Ui.assets.GitHubLogo.png", 30, 30);
_discordLogo.Pixbuf = new Gdk.Pixbuf(Assembly.GetExecutingAssembly(), "Ryujinx.Ui.assets.DiscordLogo.png", 30, 30);
_twitterLogo.Pixbuf = new Gdk.Pixbuf(Assembly.GetExecutingAssembly(), "Ryujinx.Ui.assets.TwitterLogo.png", 30, 30);
// todo: Get version string
_versionText.Text = "Unknown Version";
if (!Directory.Exists(localAppPath))
{
Directory.CreateDirectory(localAppPath);
}
string versionJsonFile = System.IO.Path.Combine(localAppPath, "Version.json");
try
{
_versionText.Text = "Version " + File.ReadAllText(versionJsonFile);
}
catch
{
_versionText.Text = "Unknown Version";
}
}
private static void OpenUrl(string url)
@ -94,4 +107,4 @@ namespace Ryujinx.Ui
Dispose();
}
}
}
}

View file

@ -1,5 +1,4 @@
using Gtk;
using Ryujinx.Updater.Parser;
using System;
using System.IO;
using System.Reflection;
@ -37,7 +36,7 @@ namespace Ryujinx.Ui
return messageDialog;
}
internal static MessageDialog CreateInfoDialog(string iconType, string titleMessage, string textMessage, string secText)
internal static void CreateInfoDialog(string iconType, string titleMessage, string textMessage, string secText)
{
MessageDialog messageDialog = new MessageDialog(null, DialogFlags.Modal, MessageType.Info, ButtonsType.Ok, null)
{
@ -48,24 +47,8 @@ namespace Ryujinx.Ui
WindowPosition = WindowPosition.Center
};
messageDialog.SetSizeRequest(100, 20);
return messageDialog;
}
internal static MessageDialog CreateProgressDialog(string iconType, string titleMessage, string textMessage, string secText)
{
MessageDialog messageDialog = new MessageDialog(null, DialogFlags.Modal, MessageType.Info, ButtonsType.None, null)
{
Title = titleMessage,
Icon = new Gdk.Pixbuf(Assembly.GetExecutingAssembly(), $"Ryujinx.Ui.assets.{iconType}.png"),
Text = textMessage,
SecondaryText = secText,
WindowPosition = WindowPosition.Center
};
Uri URL = new Uri(UpdateParser._buildArt);
UpdateParser.Package.DownloadFileAsync(URL, Path.Combine(UpdateParser.RyuDir, "Data", "Update", "RyujinxPackage.zip"));
messageDialog.SetSizeRequest(100, 20);
return messageDialog;
messageDialog.Run();
messageDialog.Dispose();
}
}
}

View file

@ -1,7 +1,5 @@
using Gtk;
using JsonPrettyPrinterPlus;
using Ryujinx.Audio;
using Ryujinx.Updater.Parser;
using Ryujinx.Common.Logging;
using Ryujinx.Configuration;
using Ryujinx.Graphics.GAL;
@ -13,11 +11,8 @@ using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Utf8Json;
using Utf8Json.Resolvers;
using GUI = Gtk.Builder.ObjectAttribute;

Binary file not shown.

Before

Width:  |  Height:  |  Size: 60 KiB

After

Width:  |  Height:  |  Size: 10 KiB

View file

@ -1,170 +0,0 @@
using Gtk;
using Newtonsoft.Json.Linq;
using Ryujinx.Common.Logging;
using Ryujinx.Ui;
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.IO.Compression;
using System.Net;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
namespace Ryujinx.Updater.Parser
{
public class UpdateParser
{
private static string _jobId;
private static string _buildVer;
private static string _buildUrl = "https://ci.appveyor.com/api/projects/gdkchan/ryujinx/branch/master";
private static string _buildCommit;
private static string _branch;
private static string _platformExt;
public static string _buildArt;
public static string RyuDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Ryujinx");
public static WebClient Package = new WebClient();
public static int PackageProgress;
public static double Percentage;
public static void BeginParse()
{
try
{
// Detect current platform
if (RuntimeInformation.ProcessArchitecture == Architecture.X64)
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
_platformExt = "osx_x64.zip";
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
_platformExt = "win_x64.zip";
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
_platformExt = "linux_x64.tar.gz";
}
}
// Begin the Appveyor parsing
WebClient jsonClient = new WebClient();
string fetchedJSON = jsonClient.DownloadString(_buildUrl);
JObject jsonRoot = JObject.Parse(fetchedJSON);
var __Build = jsonRoot["build"];
string __Version = (string)__Build["version"];
string __JobsId = (string)__Build["jobs"][0]["jobId"];
string __branch = (string)__Build["branch"];
string __buildCommit = (string)__Build["commitId"];
_jobId = __JobsId;
_buildVer = __Version;
_buildArt = "https://ci.appveyor.com/api/buildjobs/" + _jobId + "/artifacts/ryujinx-" + _buildVer + "-" + _platformExt;
_buildCommit = __buildCommit.Substring(0, 7);
_branch = __branch;
Logger.PrintInfo(LogClass.Application, "Fetched JSON and Parsed:" + Environment.NewLine + "MetaData: JobID(" + __JobsId + ") BuildVer(" + __Version + ")" + Environment.NewLine + "BuildURL(" + _buildArt + ")");
Logger.PrintInfo(LogClass.Application, "Commit-id: (" + _buildCommit + ")" + " Branch: (" + _branch + ")");
using (MessageDialog dialog = GtkDialog.CreateAcceptDialog("Update", "Ryujinx - Update", "Would you like to update?", "Version " + _buildVer + " is available."))
{
if (dialog.Run() == (int)ResponseType.Yes)
{
dialog.Dispose();
GrabPackage();
}
}
}
catch (Exception ex)
{
Logger.PrintError(LogClass.Application, ex.Message);
GtkDialog.CreateErrorDialog("Update canceled by user or failed to grab or parse the information.\nPlease try at a later time, or report the error to our GitHub.");
}
}
private static async void GrabPackage()
{
// Check if paths exist
if (!Directory.Exists(Path.Combine(RyuDir, "Data", "Update")) || !Directory.Exists(Path.Combine(RyuDir, "Data")) || !Directory.Exists(Path.Combine(Environment.CurrentDirectory, "temp")))
{
Directory.CreateDirectory(Path.Combine(RyuDir, "Data", "Update"));
Directory.CreateDirectory(Path.Combine(RyuDir, "Data"));
Directory.CreateDirectory(Path.Combine(Environment.CurrentDirectory, "temp"));
}
try
{
// Attempt to grab the latest package
Package.DownloadProgressChanged += new DownloadProgressChangedEventHandler(PackageDownloadProgress);
Package.DownloadFileCompleted += new AsyncCompletedEventHandler(PackageDownloadedAsync);
using (MessageDialog dialog = GtkDialog.CreateProgressDialog("Update", "Ryujinx - Update", "Downloading update " + _buildVer, "Please wait while we download the latest package and extract it."))
{
dialog.Run();
}
}
catch (Exception ex)
{
Logger.PrintError(LogClass.Application, ex.InnerException.ToString());
GtkDialog.CreateErrorDialog(ex.Message);
}
}
private static async void PackageDownloadedAsync(object sender, AsyncCompletedEventArgs e)
{
if (e.Cancelled == true)
{
Logger.PrintError(LogClass.Application, "Package download failed or cancelled");
}
else
{
Logger.PrintWarning(LogClass.Application, "Package is now installing");
await ExtractPackageAsync();
}
}
private static void PackageDownloadProgress(object sender, DownloadProgressChangedEventArgs e)
{
Percentage = e.ProgressPercentage;
PackageProgress = e.ProgressPercentage;
}
public static async Task ExtractPackageAsync()
{
try
{
// Begin the extaction process
await Task.Run(() => ZipFile.ExtractToDirectory(Path.Combine(RyuDir, "Data", "Update", "RyujinxPackage.zip"), Path.Combine(Environment.CurrentDirectory, "temp")));
try
{
Process.Start(new ProcessStartInfo(Path.Combine(Environment.CurrentDirectory, "temp", "publish", "Ryujinx.exe"), "/U") { UseShellExecute = true });
Application.Quit();
}
catch (Exception ex)
{
GtkDialog.CreateErrorDialog("Package installation has failed\nCheck the log for more information.");
Logger.PrintError(LogClass.Application, "Package installation has failed\n" + ex.InnerException.ToString());
return;
}
}
catch (Exception ex)
{
Logger.PrintError(LogClass.Application, "Package installation has failed\n" + ex.InnerException.ToString());
GtkDialog.CreateErrorDialog("Package installation has failed\nCheck the log for more information.");
}
}
}
}

View file

@ -1,56 +0,0 @@
using Gtk;
using Ryujinx.Common.Logging;
using Ryujinx.Ui;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Text;
namespace Ryujinx.Updater
{
public class Update
{
private static string _parentdir = Path.Combine(@"..\..");
public static string RyuDir = Environment.CurrentDirectory;
public static void PerformUpdate()
{
try
{
//Get list of files from the current directory, and copy them to the parent directory.
foreach (string _PathDir in Directory.GetDirectories(RyuDir, "*", SearchOption.AllDirectories))
{
Directory.CreateDirectory(_PathDir.Replace(RyuDir, _parentdir));
}
foreach (string _PathNew in Directory.GetFiles(RyuDir, "*.*", SearchOption.AllDirectories))
{
File.Copy(_PathNew, _PathNew.Replace(RyuDir, _parentdir), true);
}
Logger.PrintInfo(LogClass.Application, "Package installation was completed.\n");
GtkDialog.CreateInfoDialog("Update", "Ryujinx - Update", "Almost finished", "The package was installed.\nPlease click ok, and the update will complete.");
try
{
Process.Start(new ProcessStartInfo(Path.Combine(_parentdir, "Ryujinx.exe"), "/C") { UseShellExecute = true });
Application.Quit();
}
catch (Exception ex)
{
GtkDialog.CreateErrorDialog(ex.Message);
}
}
catch (Exception ex)
{
GtkDialog.CreateErrorDialog(ex.Message);
}
}
public static void Cleanup()
{
Directory.Delete(Path.Combine(RyuDir, "temp"), true);
}
}
}

View file

@ -0,0 +1,125 @@
using Gtk;
using Newtonsoft.Json.Linq;
using Ryujinx.Common.Logging;
using Ryujinx.Ui;
using System;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Runtime.InteropServices;
namespace Ryujinx
{
public class UpdateParser
{
private static string _jobId;
private static string _buildVer;
private static string _platformExt;
private static string _masterUrl = "https://ci.appveyor.com/api/projects/gdkchan/ryujinx/branch/master";
private static string _buildUrl;
public static string RyuDir = Environment.CurrentDirectory;
public static string localAppPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Ryujinx");
public static WebClient Package = new WebClient();
public static int PackageProgress;
public static double Percentage;
public static void BeginParse()
{
try
{
// Detect current platform
if (RuntimeInformation.ProcessArchitecture == Architecture.X64)
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
_platformExt = "osx_x64.zip";
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
_platformExt = "win_x64.zip";
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
_platformExt = "linux_x64.tar.gz";
}
}
// Begin the Appveyor parsing
WebClient jsonClient = new WebClient();
string fetchedJSON = jsonClient.DownloadString(_masterUrl);
JObject jsonRoot = JObject.Parse(fetchedJSON);
JToken _buildToken = jsonRoot["build"];
_jobId = (string)_buildToken["jobs"][0]["jobId"];
_buildVer = (string)_buildToken["version"];
_buildUrl = "https://ci.appveyor.com/api/buildjobs/" + _jobId + "/artifacts/ryujinx-" + _buildVer + "-" + _platformExt;
if (!Directory.Exists(localAppPath))
{
Directory.CreateDirectory(localAppPath);
}
// Get Version.json to compare versions
if (File.Exists(Path.Combine(localAppPath, "Version.json")))
{
try
{
Version newVersion = Version.Parse(_buildVer);
string currentVersionJson = File.ReadAllLines(Path.Combine(localAppPath, "Version.json"))[0];
Version currentVersion = Version.Parse(currentVersionJson);
if (newVersion.CompareTo(currentVersion) == 0)
{
GtkDialog.CreateInfoDialog("Update", "Ryujinx - Updater", "You are already using the most updated version of Ryujinx!", "");
return;
}
}
catch
{
}
}
// Show a message asking the user if they want to update
using (MessageDialog dialog = GtkDialog.CreateAcceptDialog("Update", "Ryujinx - Update", "Would you like to update?", "Version " + _buildVer + " is available."))
{
if (dialog.Run() == (int)ResponseType.Yes)
{
try
{
// Start Updater.exe
string updaterPath = Path.Combine(RyuDir, "Updater.exe");
ProcessStartInfo startInfo = new ProcessStartInfo(updaterPath);
startInfo.Arguments = _buildUrl + " " + _buildVer;
startInfo.UseShellExecute = true;
Process.Start(startInfo);
Application.Quit();
}
catch (Exception ex)
{
GtkDialog.CreateErrorDialog(ex.Message);
}
}
}
}
catch (Exception ex)
{
Logger.PrintError(LogClass.Application, ex.Message);
GtkDialog.CreateErrorDialog("Update failed to grab or parse the information.\nPlease try at a later time, or report the error to our GitHub.");
}
}
}
}