Fixed all the reviewer's complains

This commit is contained in:
MelonSpeedruns 2020-01-26 12:35:22 -05:00 committed by Ash
commit 8e75c2952d
6 changed files with 90 additions and 128 deletions

View file

@ -54,7 +54,7 @@ namespace Ryujinx
Application.Init(); Application.Init();
string appDataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Ryujinx", "system", "prod.keys"); string appDataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Ryujinx", "system", "prod.keys");
string userProfilePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".switch", "prod.keys"); string userProfilePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".switch", "prod.keys");
if (!File.Exists(appDataPath) && !File.Exists(userProfilePath) && !Migration.IsMigrationNeeded()) if (!File.Exists(appDataPath) && !File.Exists(userProfilePath) && !Migration.IsMigrationNeeded())
{ {
@ -64,26 +64,17 @@ namespace Ryujinx
MainWindow mainWindow = new MainWindow(); MainWindow mainWindow = new MainWindow();
mainWindow.Show(); mainWindow.Show();
if (args.Length == 1) if (args.Length > 1)
{ {
foreach (string arg in args) foreach (string arg in args)
{ {
switch (arg.Substring(0, 2).ToUpper()) switch (arg.Substring(0, 2).ToUpper())
{ {
case "/U": case "/U": Updater.Update.PerformUpdate(); break;
//Do that update stuffs case "/C": Updater.Update.Cleanup(); break;
Updater.Update.PerformUpdate(); default: mainWindow.LoadApplication(args[0]); break;
break;
case "/C":
//Do that update stuffs
Updater.Update.Cleanup();
break;
default:
mainWindow.LoadApplication(args[0]);
break;
} }
} }
} }
Application.Run(); Application.Run();

View file

@ -1,8 +1,8 @@
using Gtk; using Gtk;
using System.Reflection;
using Ryujinx.Updater.Parser; using Ryujinx.Updater.Parser;
using System.IO;
using System; using System;
using System.IO;
using System.Reflection;
namespace Ryujinx.Ui namespace Ryujinx.Ui
{ {
@ -23,24 +23,14 @@ namespace Ryujinx.Ui
errorDialog.Dispose(); errorDialog.Dispose();
} }
internal static void CreateWarningDialog(string text, string secondaryText) internal static MessageDialog CreateAcceptDialog(string iconType, string titleMessage, string textMessage, string secText)
{
CreateDialog("Ryujinx - Warning", text, secondaryText);
}
internal static void CreateErrorDialog(string errorMessage)
{
CreateDialog("Ryujinx - Error", "Ryujinx has encountered an error", errorMessage);
}
internal static MessageDialog CreateAcceptDialog(string iconType, string acceptMessage)
{ {
MessageDialog messageDialog = new MessageDialog(null, DialogFlags.Modal, MessageType.Question, ButtonsType.YesNo, null) MessageDialog messageDialog = new MessageDialog(null, DialogFlags.Modal, MessageType.Question, ButtonsType.YesNo, null)
{ {
Title = "Ryujinx - Update", Title = titleMessage,
Icon = new Gdk.Pixbuf(Assembly.GetExecutingAssembly(), "Ryujinx.Ui.assets.Update.png"), Icon = new Gdk.Pixbuf(Assembly.GetExecutingAssembly(), $"Ryujinx.Ui.assets.{iconType}.png"),
Text = "Would you like to update?", Text = textMessage,
SecondaryText = "Version " + acceptMessage + " is available.", SecondaryText = secText,
WindowPosition = WindowPosition.Center WindowPosition = WindowPosition.Center
}; };
messageDialog.SetSizeRequest(100, 20); messageDialog.SetSizeRequest(100, 20);
@ -52,7 +42,7 @@ namespace Ryujinx.Ui
MessageDialog messageDialog = new MessageDialog(null, DialogFlags.Modal, MessageType.Info, ButtonsType.Ok, null) MessageDialog messageDialog = new MessageDialog(null, DialogFlags.Modal, MessageType.Info, ButtonsType.Ok, null)
{ {
Title = titleMessage, Title = titleMessage,
Icon = new Gdk.Pixbuf(Assembly.GetExecutingAssembly(), "Ryujinx.Ui.assets." + iconType +".png"), Icon = new Gdk.Pixbuf(Assembly.GetExecutingAssembly(), $"Ryujinx.Ui.assets.{iconType}.png"),
Text = textMessage, Text = textMessage,
SecondaryText = secText, SecondaryText = secText,
WindowPosition = WindowPosition.Center WindowPosition = WindowPosition.Center
@ -66,7 +56,7 @@ namespace Ryujinx.Ui
MessageDialog messageDialog = new MessageDialog(null, DialogFlags.Modal, MessageType.Info, ButtonsType.None, null) MessageDialog messageDialog = new MessageDialog(null, DialogFlags.Modal, MessageType.Info, ButtonsType.None, null)
{ {
Title = titleMessage, Title = titleMessage,
Icon = new Gdk.Pixbuf(Assembly.GetExecutingAssembly(), "Ryujinx.Ui.assets." + iconType + ".png"), Icon = new Gdk.Pixbuf(Assembly.GetExecutingAssembly(), $"Ryujinx.Ui.assets.{iconType}.png"),
Text = textMessage, Text = textMessage,
SecondaryText = secText, SecondaryText = secText,
WindowPosition = WindowPosition.Center WindowPosition = WindowPosition.Center
@ -74,6 +64,7 @@ namespace Ryujinx.Ui
Uri URL = new Uri(UpdateParser.BuildArt); Uri URL = new Uri(UpdateParser.BuildArt);
UpdateParser.Package.DownloadFileAsync(URL, Path.Combine(UpdateParser.RyuDir, "Data", "Update", "RyujinxPackage.zip")); UpdateParser.Package.DownloadFileAsync(URL, Path.Combine(UpdateParser.RyuDir, "Data", "Update", "RyujinxPackage.zip"));
messageDialog.SetSizeRequest(100, 20); messageDialog.SetSizeRequest(100, 20);
return messageDialog; return messageDialog;
} }
} }

View file

@ -1,6 +1,7 @@
using Gtk; using Gtk;
using JsonPrettyPrinterPlus; using JsonPrettyPrinterPlus;
using Ryujinx.Audio; using Ryujinx.Audio;
using Ryujinx.Updater.Parser;
using Ryujinx.Common.Logging; using Ryujinx.Common.Logging;
using Ryujinx.Configuration; using Ryujinx.Configuration;
using Ryujinx.Debugger.Profiler; using Ryujinx.Debugger.Profiler;
@ -896,7 +897,7 @@ namespace Ryujinx.Ui
private void Update_Pressed(object sender, EventArgs args) private void Update_Pressed(object sender, EventArgs args)
{ {
Ryujinx.Updater.Parser.UpdateParser.BeginParse(); UpdateParser.BeginParse();
} }
private void About_Pressed(object sender, EventArgs args) private void About_Pressed(object sender, EventArgs args)

View file

@ -1,20 +1,15 @@
using Gtk; using Gtk;
using Ionic.Zip;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using Ryujinx.Common.Logging; using Ryujinx.Common.Logging;
using Ryujinx.HLE.FileSystem;
using Ryujinx.Ui; using Ryujinx.Ui;
using System; using System;
using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using System.IO.Compression; using System.IO.Compression;
using System.Net; using System.Net;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using ZipFile = System.IO.Compression.ZipFile;
namespace Ryujinx.Updater.Parser namespace Ryujinx.Updater.Parser
{ {
@ -22,46 +17,62 @@ namespace Ryujinx.Updater.Parser
{ {
private static string _jobid; private static string _jobid;
private static string _buildver; private static string _buildver;
private static string _buildurl = "https://ci.appveyor.com/api/projects/gdkchan/ryujinx/branch/master"; private static string _buildurl = "https://ci.appveyor.com/api/projects/gdkchan/ryujinx/branch/master";
private static string _buildcommit; private static string _buildcommit;
private static string _branch; private static string _branch;
private static string _platformext; private static string _platformext;
public static string BuildArt; public static string BuildArt;
public static string RyuDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Ryujinx"); public static string RyuDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Ryujinx");
public static WebClient Package = new WebClient(); public static WebClient Package = new WebClient();
public static int PackageProgress; public static int PackageProgress;
public static double Percentage; public static double Percentage;
public static void BeginParse() public static void BeginParse()
{ {
try try
{ {
//Detect current platform // Detect current platform
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
_platformext = "osx_x64.zip"; if (RuntimeInformation.ProcessArchitecture == Architecture.X64)
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) {
_platformext = "win_x64.zip"; if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) {
_platformext = "linux_x64.tar.gz"; _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;
//Begin the Appveyor parsing
WebClient JSONClient = new WebClient();
string FetchedJSON = JSONClient.DownloadString(_buildurl);
var __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, "Fetched JSON and Parsed:" + Environment.NewLine + "MetaData: JobID(" + __JobsID + ") BuildVer(" + __Version + ")" + Environment.NewLine + "BuildURL(" + BuildArt + ")");
Logger.PrintInfo(LogClass.Application, "Commit-id: (" + _buildcommit + ")" + " Branch: (" + _branch + ")"); Logger.PrintInfo(LogClass.Application, "Commit-id: (" + _buildcommit + ")" + " Branch: (" + _branch + ")");
using (MessageDialog dialog = GtkDialog.CreateAcceptDialog("Update", _buildver)) using (MessageDialog dialog = GtkDialog.CreateAcceptDialog("Update", "Ryujinx - Update", "Would you like to update?", "Version " + _buildver + " is available."))
{ {
if (dialog.Run() == (int)ResponseType.Yes) if (dialog.Run() == (int)ResponseType.Yes)
{ {
@ -69,28 +80,19 @@ namespace Ryujinx.Updater.Parser
GrabPackage(); GrabPackage();
} }
} }
} }
catch (Exception ex) catch (Exception ex)
{ {
Logger.PrintError(LogClass.Application, ex.Message); 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."); 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.");
return;
} }
//UpdateData data = new UpdateData()
//{
// JobID = _jobid,
// BuildVer = _buildver,
// BuildURL = _buildurl,
// BuildArt = BuildArt,
// BuildCommit = _buildcommit,
// Branch = _branch
//};
} }
private static async void GrabPackage() private static async void GrabPackage()
{ {
//Check if paths exist // 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"))) 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", "Update"));
@ -100,7 +102,8 @@ namespace Ryujinx.Updater.Parser
try try
{ {
//Attempt to grab the latest package // Attempt to grab the latest package
Package.DownloadProgressChanged += new DownloadProgressChangedEventHandler(PackageDownloadProgress); Package.DownloadProgressChanged += new DownloadProgressChangedEventHandler(PackageDownloadProgress);
Package.DownloadFileCompleted += new AsyncCompletedEventHandler(PackageDownloadedAsync); 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.")) using (MessageDialog dialog = GtkDialog.CreateProgressDialog("Update", "Ryujinx - Update", "Downloading update " + _buildver, "Please wait while we download the latest package and extract it."))
@ -112,21 +115,19 @@ namespace Ryujinx.Updater.Parser
{ {
Logger.PrintError(LogClass.Application, ex.InnerException.ToString()); Logger.PrintError(LogClass.Application, ex.InnerException.ToString());
GtkDialog.CreateErrorDialog(ex.Message); GtkDialog.CreateErrorDialog(ex.Message);
return;
} }
} }
private static async void PackageDownloadedAsync(object sender, AsyncCompletedEventArgs e) private static async void PackageDownloadedAsync(object sender, AsyncCompletedEventArgs e)
{ {
if (e.Cancelled == true) if (e.Cancelled == true)
{ {
Logger.PrintError(LogClass.Application, "Package download failed or cancelled"); Logger.PrintError(LogClass.Application, "Package download failed or cancelled");
return;
} }
else else
{ {
Logger.PrintWarning(LogClass.Application, "Package is now installing"); Logger.PrintWarning(LogClass.Application, "Package is now installing");
await ExtractPackageAsync(); await ExtractPackageAsync();
return;
} }
} }
@ -135,30 +136,34 @@ namespace Ryujinx.Updater.Parser
Percentage = e.ProgressPercentage; Percentage = e.ProgressPercentage;
PackageProgress = e.ProgressPercentage; PackageProgress = e.ProgressPercentage;
} }
public static async Task ExtractPackageAsync() public static async Task ExtractPackageAsync()
{ {
try try
{ {
//Begin the extaction process // Begin the extaction process
await Task.Run(() => ZipFile.ExtractToDirectory(Path.Combine(RyuDir, "Data", "Update", "RyujinxPackage.zip"), Path.Combine(Environment.CurrentDirectory, "temp"))); await Task.Run(() => ZipFile.ExtractToDirectory(Path.Combine(RyuDir, "Data", "Update", "RyujinxPackage.zip"), Path.Combine(Environment.CurrentDirectory, "temp")));
try try
{ {
Process.Start(new ProcessStartInfo(Path.Combine(Environment.CurrentDirectory, "temp", "publish", "Ryujinx.exe"), "/U") { UseShellExecute = true }); Process.Start(new ProcessStartInfo(Path.Combine(Environment.CurrentDirectory, "temp", "publish", "Ryujinx.exe"), "/U") { UseShellExecute = true });
Application.Quit();
} }
catch (Exception ex) catch (Exception ex)
{ {
GtkDialog.CreateErrorDialog("Package installation has failed\nCheck the log for more information."); GtkDialog.CreateErrorDialog("Package installation has failed\nCheck the log for more information.");
Logger.PrintError(LogClass.Application, "Package installation has failed\n" + ex.InnerException.ToString()); Logger.PrintError(LogClass.Application, "Package installation has failed\n" + ex.InnerException.ToString());
return; return;
} }
Application.Quit();
} }
catch (Exception ex) catch (Exception ex)
{ {
Logger.PrintError(LogClass.Application, "Package installation has failed\n" + ex.InnerException.ToString()); Logger.PrintError(LogClass.Application, "Package installation has failed\n" + ex.InnerException.ToString());
GtkDialog.CreateErrorDialog("Package installation has failed\nCheck the log for more information."); GtkDialog.CreateErrorDialog("Package installation has failed\nCheck the log for more information.");
return;
} }
} }
} }
} }

View file

@ -11,38 +11,41 @@ namespace Ryujinx.Updater
{ {
public class Update public class Update
{ {
private static string[] _updatefiles = Directory.GetFiles(Path.Combine(Environment.CurrentDirectory),"*", SearchOption.AllDirectories);
private static string _parentdir = Path.Combine(@"..\.."); private static string _parentdir = Path.Combine(@"..\..");
public static string RyuDir = Environment.CurrentDirectory; public static string RyuDir = Environment.CurrentDirectory;
public static void PerformUpdate() public static void PerformUpdate()
{ {
try try
{ {
//Get list of files from the current directory, and copy them to the parent directory. //Get list of files from the current directory, and copy them to the parent directory.
foreach (string _PathDir in Directory.GetDirectories(RyuDir, "*", foreach (string _PathDir in Directory.GetDirectories(RyuDir, "*", SearchOption.AllDirectories))
SearchOption.AllDirectories)) {
Directory.CreateDirectory(_PathDir.Replace(RyuDir, _parentdir)); Directory.CreateDirectory(_PathDir.Replace(RyuDir, _parentdir));
foreach (string _PathNew in Directory.GetFiles(RyuDir, "*.*", }
SearchOption.AllDirectories))
foreach (string _PathNew in Directory.GetFiles(RyuDir, "*.*", SearchOption.AllDirectories))
{
File.Copy(_PathNew, _PathNew.Replace(RyuDir, _parentdir), true); File.Copy(_PathNew, _PathNew.Replace(RyuDir, _parentdir), true);
}
Logger.PrintInfo(LogClass.Application, "Package installation was completed.\n"); 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."); GtkDialog.CreateInfoDialog("Update", "Ryujinx - Update", "Almost finished", "The package was installed.\nPlease click ok, and the update will complete.");
try try
{ {
Process.Start(new ProcessStartInfo(Path.Combine(_parentdir, "Ryujinx.exe"), "/C") { UseShellExecute = true }); Process.Start(new ProcessStartInfo(Path.Combine(_parentdir, "Ryujinx.exe"), "/C") { UseShellExecute = true });
Application.Quit();
} }
catch (System.ComponentModel.Win32Exception) catch (Exception ex)
{ {
GtkDialog.CreateErrorDialog("Update canceled by user or the installation was not found"); GtkDialog.CreateErrorDialog(ex.Message);
return;
} }
Application.Quit();
} }
catch (System.ComponentModel.Win32Exception) catch (Exception ex)
{ {
GtkDialog.CreateErrorDialog("Package installation has failed\nCheck the log for more information."); GtkDialog.CreateErrorDialog(ex.Message);
} }
} }
public static void Cleanup() public static void Cleanup()

View file

@ -1,29 +0,0 @@
/* =========================================
* This service is responsible for parsing
* the appveyor json.
*
* =========================================
*
* Strings and other variables: These are stored for the config page.
*
* JobID: String, stores the parsed JobID.
* BuildVer: String, stores the parsed BuildVersion.
* BuildURL: String, stores the BuildURL.
* BuildArt: String, stores the parsed build artifact (URL).
* BuildCommit: String, stores the parsed build commit; and is stored in a five character substring.
* Branch: String, stores the parsed branch for the build.
* =========================================
*/
namespace Ryujinx.Updater
{
public struct UpdateData
{
public string JobID { get; set; }
public string BuildVer { get; set; }
public string BuildURL { get; set; }
public string BuildArt { get; set; }
public string BuildCommit { get; set; }
public string Branch { get; set; }
}
}