From 2e78632d4f80470a33adb2dcdbffc728cc8009fc Mon Sep 17 00:00:00 2001 From: Marc-Aurel Zent Date: Sun, 25 Jun 2023 16:33:16 +0300 Subject: [PATCH] dynamically retrieve mac zip url from sparkle feed --- .../GameFixes/Implementations/MacVideoFix.cs | 33 ++++++++++++++++--- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/src/XIVLauncher.Common.Unix/Compatibility/GameFixes/Implementations/MacVideoFix.cs b/src/XIVLauncher.Common.Unix/Compatibility/GameFixes/Implementations/MacVideoFix.cs index df9aa1d0..484992d9 100644 --- a/src/XIVLauncher.Common.Unix/Compatibility/GameFixes/Implementations/MacVideoFix.cs +++ b/src/XIVLauncher.Common.Unix/Compatibility/GameFixes/Implementations/MacVideoFix.cs @@ -2,13 +2,36 @@ using System.IO; using System.IO.Compression; using System.Linq; +using System.Net.Http; +using System.Threading.Tasks; +using System.Xml.Linq; +using Serilog; using XIVLauncher.Common.Util; namespace XIVLauncher.Common.Unix.Compatibility.GameFixes.Implementations; public class MacVideoFix : GameFix { - private const string MAC_ZIP_URL = "https://mac-dl.ffxiv.com/cw/finalfantasyxiv-1.1.2.zip"; + private static async Task GetLatestMacZipUrl() + { + const string sparkleFeedUrl = "https://mac-dl.ffxiv.com/cw/finalfantasy-mac.xml"; + const string fallbackUrl = "https://mac-dl.ffxiv.com/cw/finalfantasyxiv-1.1.2.zip"; + + try + { + using var client = new HttpClient { Timeout = TimeSpan.FromSeconds(10) }; + var sparkleFeed = XDocument.Parse(await client.GetStringAsync(sparkleFeedUrl)); + var latestItem = sparkleFeed.Descendants("item").FirstOrDefault(); + var enclosureElement = latestItem?.Element("enclosure"); + var urlAttribute = enclosureElement?.Attribute("url"); + return urlAttribute!.Value; + } + catch (Exception ex) + { + Log.Error(ex, "Failed to extract Mac Zip URL from Sparkle update feed, using static fallback"); + return fallbackUrl; + } + } public MacVideoFix(DirectoryInfo gameDirectory, DirectoryInfo configDirectory, DirectoryInfo winePrefixDirectory, DirectoryInfo tempDirectory) : base(gameDirectory, configDirectory, winePrefixDirectory, tempDirectory) @@ -27,7 +50,7 @@ public override void Apply() return; var zipFilePath = Path.Combine(TempDir.FullName, $"{Guid.NewGuid()}.zip"); - using var client = new HttpClientDownloadWithProgress(MAC_ZIP_URL, zipFilePath); + using var client = new HttpClientDownloadWithProgress(GetLatestMacZipUrl().GetAwaiter().GetResult(), zipFilePath); client.ProgressChanged += (size, downloaded, percentage) => { if (percentage != null && size != null) @@ -40,13 +63,13 @@ public override void Apply() var zipMovieFileNames = movieFileNames.Select(movie => Path.Combine("game", "movie", "ffxiv", movie)); - using (ZipArchive archive = ZipFile.OpenRead(zipFilePath)) + using (var archive = ZipFile.OpenRead(zipFilePath)) { - foreach (ZipArchiveEntry entry in archive.Entries) + foreach (var entry in archive.Entries) { if (zipMovieFileNames.Any((fileName) => entry.FullName.EndsWith(fileName, StringComparison.OrdinalIgnoreCase))) { - string destinationPath = Path.Combine(outputDirectory.FullName, entry.Name); + var destinationPath = Path.Combine(outputDirectory.FullName, entry.Name); if (!File.Exists(destinationPath)) entry.ExtractToFile(destinationPath); }