This commit is contained in:
MelonSpeedruns 2020-02-01 15:50:18 -05:00 committed by Ash
parent b756d61292
commit 73bba287c2
6 changed files with 44 additions and 117 deletions

View file

@ -1,26 +1,19 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Ryujinx.Updater
{
public class Program
{
public static string RyuDir = Environment.CurrentDirectory;
public static string RyuDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Ryujinx");
public static string launchDir = Environment.CurrentDirectory;
public static string updateSaveLocation;
public static string metaFilePath;
public static string versionNumber;
public static string downloadUrl;
private static void CloneDirectory(string root, string dest)
private static void MoveAllFilesOver(string root, string dest)
{
foreach (var directory in Directory.GetDirectories(root))
{
@ -38,7 +31,7 @@ namespace Ryujinx.Updater
}
CloneDirectory(directory, Path.Combine(dest, dirName));
MoveAllFilesOver(directory, Path.Combine(dest, dirName));
}
foreach (var file in Directory.GetFiles(root))
@ -55,54 +48,49 @@ namespace Ryujinx.Updater
}
[STAThread]
public static void Main()
public static void Main(string[] args)
{
// Create Temp Directory
if (args.Length < 2)
{
return;
}
File.WriteAllText(Path.Combine(launchDir, "Version.json"), args[1]);
// Create temp directory
if (!Directory.Exists(Path.Combine(RyuDir, "Temp")))
{
Directory.CreateDirectory(Path.Combine(RyuDir, "Temp"));
}
// Download latest update
string downloadUrl = args[0];
updateSaveLocation = Path.Combine(RyuDir, "Temp", "RyujinxPackage.zip");
metaFilePath = Path.Combine(RyuDir, "Meta.json");
string[] metaFileData = File.ReadAllLines(metaFilePath);
versionNumber = metaFileData[0];
downloadUrl = metaFileData[1];
MessageBox.Show(downloadUrl);
using (WebClient client = new WebClient())
{
client.DownloadFile(downloadUrl, updateSaveLocation);
}
foreach (string file in Directory.GetFiles(RyuDir, "*", SearchOption.AllDirectories))
{
if (Path.GetFileName(file) != "Config.json" && Path.GetFileName(file) != "Meta.json" && Path.GetFileName(file) != "RyujinxPackage.zip")
{
try
{
File.Delete(file);
}
catch
{
}
}
}
// Extract Update .zip
ZipFile.ExtractToDirectory(updateSaveLocation, RyuDir, true);
CloneDirectory(Path.Combine(RyuDir, "publish"), RyuDir);
// Copy new files over to Ryujinx folder
MoveAllFilesOver(Path.Combine(RyuDir, "publish"), launchDir);
// Remove temp folders
Directory.Delete(Path.Combine(RyuDir, "publish"), true);
Directory.Delete(Path.Combine(RyuDir, "Temp"), true);
Process.Start(Path.Combine(RyuDir, "Ryujinx.exe"));
// Start new Ryujinx version and close Updater
Application.Exit();
Process.Start(Path.Combine(launchDir, "Ryujinx.exe"));
}
}

View file

@ -1,12 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
<UseWindowsForms>true</UseWindowsForms>
<StartupObject></StartupObject>
<AssemblyName>Updater</AssemblyName>
<ApplicationIcon>Ryujinx.ico</ApplicationIcon>
</PropertyGroup>
<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>Ryujinx.ico</ApplicationIcon>
<OutputType>Exe</OutputType>
<AssemblyName>Updater</AssemblyName>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\ARMeilleure\ARMeilleure.csproj" />
</ItemGroup>
</Project>

View file

@ -3,6 +3,7 @@ using Ryujinx.Common.Logging;
using Ryujinx.Configuration;
using Ryujinx.Debugger.Profiler;
using Ryujinx.Ui;
using Ryujinx.Updater.Parser;
using OpenTK;
using System;
using System.IO;
@ -70,8 +71,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,9 +74,7 @@
<ItemGroup>
<PackageReference Include="DiscordRichPresence" Version="1.0.147" />
<PackageReference Include="GLWidget" Version="1.0.0" />
<PackageReference Include="GtkSharp" Version="3.22.25.56" />
<PackageReference Include="DotNetZip" Version="1.13.5" />
<PackageReference Include="GtkSharp" Version="3.22.25.24" />
<PackageReference Include="GtkSharp.Dependencies" Version="1.1.0" Condition="'$(RuntimeIdentifier)' != 'linux-x64' AND '$(RuntimeIdentifier)' != 'osx-x64'" />
<PackageReference Include="OpenTK.NetStandard" Version="1.0.5.12" />
</ItemGroup>

View file

@ -80,18 +80,11 @@ namespace Ryujinx.Updater.Parser
{
try
{
// Create Meta.json
List<String> metaFileContents = new List<string>();
metaFileContents.Add(_buildVer);
metaFileContents.Add(_buildArt);
File.WriteAllLines(Path.Combine(RyuDir, "Meta.json"), metaFileContents);
// Start Updater.exe
string updaterPath = Path.Combine(RyuDir, "Updater.exe");
Process.Start(updaterPath);
Process.Start(updaterPath, _buildArt + " " + _buildVer);
}
catch (Exception ex)

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(RyuDir, "Ryujinx.exe")) { 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);
}
}
}