Skip to content

Commit

Permalink
Minor download source changes
Browse files Browse the repository at this point in the history
  • Loading branch information
HimDek committed Feb 20, 2024
1 parent 6e71fd9 commit f911ca5
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 10 deletions.
125 changes: 118 additions & 7 deletions Form_yuzuEarlyAccessLauncher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
using System.Text.Json;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml.Linq;
using System.Collections.Generic;
using static System.Net.WebRequestMethods;
using System.Data.SqlTypes;
using System.Xml;
using System.Drawing.Drawing2D;

namespace yuzu_Early_Access_Launcher
{
Expand Down Expand Up @@ -58,7 +64,7 @@ public Form_yuzuEarlyAccessLauncher(String ver, String Theme, Color BackColor, C
Process.Start(UserProfile + "\\AppData\\Local\\yuzu\\yuzu Early Access Launcher.exe");
Environment.Exit(0);
}
else
else if (path.Split('\\').Last() != "Debug")
{
Process.Start(UserProfile + "\\AppData\\Local\\yuzu\\yuzu Early Access Launcher.exe");
Environment.Exit(0);
Expand Down Expand Up @@ -489,7 +495,7 @@ private void BackgroundWorker_Check_DoWork(object sender, DoWorkEventArgs e)
}

backgroundWorker_Check.ReportProgress(1);
String yuzulauncher = "", yuzu = "", firminf = "";
String yuzulauncher = "", yuzu = "", /*firminf = "",*/ firmdata = "", keysdata = "", lfirmfile = "";
try
{
WebClient wc = new WebClient();
Expand All @@ -500,7 +506,9 @@ private void BackgroundWorker_Check_DoWork(object sender, DoWorkEventArgs e)
wc.Headers.Add("user-agent", "request");
yuzu = wc.DownloadString(new System.Uri("https://api.github.com/repos/pineappleEA/pineapple-src/releases"));
wc.Headers.Add("user-agent", "request");
firminf = wc.DownloadString(new System.Uri("https://raw.githubusercontent.com/HiDe-Techno-Tips/Nothing/main/info.json"));
firmdata = wc.DownloadString(new System.Uri("https://archive.org/download/nintendo-switch-global-firmwares/nintendo-switch-global-firmwares_files.xml"));
wc.Headers.Add("user-agent", "request");
keysdata = wc.DownloadString(new System.Uri("https://archive.org/download/prod.keys/prod.keys_files.xml"));
Internet = true;
log.WriteLine(" Internet Connection is available");
}
Expand All @@ -512,10 +520,16 @@ private void BackgroundWorker_Check_DoWork(object sender, DoWorkEventArgs e)

if (Internet)
{
lfirm = JsonDocument.Parse("[" + JsonDocument.Parse("[ " + firminf + " ]").RootElement[0].GetProperty("firmware").ToString() + "]").RootElement[0].GetProperty("ver").ToString();
furl = JsonDocument.Parse("[" + JsonDocument.Parse("[ " + firminf + " ]").RootElement[0].GetProperty("firmware").ToString() + "]").RootElement[0].GetProperty("url").ToString();
fsize = JsonDocument.Parse("[" + JsonDocument.Parse("[ " + firminf + " ]").RootElement[0].GetProperty("firmware").ToString() + "]").RootElement[0].GetProperty("size").ToString();
kurl = JsonDocument.Parse("[" + JsonDocument.Parse("[ " + firminf + " ]").RootElement[0].GetProperty("keys").ToString() + "]").RootElement[0].GetProperty("url").ToString();
string[] firmparts = GetLatestFirmwareFileName(firmdata).Split(',');
fsize = firmparts[0];
lfirmfile = firmparts[1];
lfirm = lfirmfile.Replace(".zip", "").Replace("Firmware ", "");
furl = "https://archive.org/download/nintendo-switch-global-firmwares/Firmware%20" + lfirm + ".zip";
kurl = "https://archive.org/download/prod.keys/" + GetLatestKeysVersion(keysdata) + ".x.x/prod.keys";

log.WriteLine("Latest Firmware: " + furl);
log.WriteLine(" Size: " + fsize);
log.WriteLine("Latest Keys: " + kurl);

if (System.IO.File.Exists("prod.keys") || System.IO.File.Exists(UserProfile + "\\AppData\\Roaming\\yuzu\\keys\\prod.keys"))
{
Expand Down Expand Up @@ -1327,5 +1341,102 @@ public static long DirSize(DirectoryInfo d)
}
return size;
}

private string GetLatestFirmwareFileName(string xmlString)
{
string latestFirmwareName = "";
int size = 0;

XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(xmlString);

// Select the file node with the latest mtime
XmlNodeList fileNodes = xmlDoc.SelectNodes("//file");
if (fileNodes.Count > 0)
{
XmlNode latestFileNode = GetLatestFirmware(fileNodes);

if (latestFileNode != null)
{
latestFirmwareName = latestFileNode.Attributes["name"].Value;
size = int.Parse(latestFileNode.SelectSingleNode("size").InnerText);

log.WriteLine($"Latest Firmware Name: {latestFirmwareName}, Size: {size}");
}
else
{
log.WriteLine("No firmware files found.");
}
}
else
{
log.WriteLine("No firmware files found.");
}

return size + "," + latestFirmwareName;
}

static XmlNode GetLatestFirmware(XmlNodeList fileNodes)
{
XmlNode latestFileNode = null;
Version latestVersion = new Version(0, 0);

foreach (XmlNode fileNode in fileNodes)
{
Version currentVersion;
string name = fileNode.Attributes["name"].Value;
if (name.EndsWith(".zip") && name.StartsWith("Firmware ") && !name.Contains("("))
{
string versionString = name.Replace("Firmware ", "").Replace(".zip", "");
if (versionString != null)
currentVersion = new Version(versionString);
else
currentVersion = new Version(0, 0);

if (currentVersion > latestVersion)
{
latestVersion = currentVersion;
latestFileNode = fileNode;
}
}
}

return latestFileNode;
}

private string GetLatestKeysVersion(string xmlString)
{
int latestVersion = 0;

try
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(xmlString);

// Select the file node with the latest mtime
XmlNodeList FileNodes = xmlDoc.SelectNodes("//file");

foreach(XmlNode fileNode in FileNodes)
{
string name = fileNode.Attributes["name"].Value;
if (name.EndsWith(".keys"))
{
string versionString = name.Split('.')[0];
int currentVersion = int.Parse(versionString);

if (currentVersion > latestVersion)
{
latestVersion = currentVersion;
}
}
}
}
catch (Exception ex)
{
log.WriteLine("Error: " + ex.Message);
}

return latestVersion.ToString();
}
}
}
4 changes: 2 additions & 2 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.0.4.0")]
[assembly: AssemblyFileVersion("2.0.4.0")]
[assembly: AssemblyVersion("2.0.5.0")]
[assembly: AssemblyFileVersion("2.0.5.0")]
2 changes: 1 addition & 1 deletion yuzu-Early-Access-Launcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ static class yuzu_Early_Access_Launcher
[STAThread]
static int Main()
{
String theme = "", version = "2.0.4", UserProfile = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), path = Path.GetDirectoryName(Application.ExecutablePath);
String theme = "", version = "2.0.5", UserProfile = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), path = Path.GetDirectoryName(Application.ExecutablePath);
Directory.SetCurrentDirectory(path);

if (mutex.WaitOne(TimeSpan.Zero, true))
Expand Down

0 comments on commit f911ca5

Please sign in to comment.