Skip to content

Commit

Permalink
Merge pull request #1350 from marzent/dynamic-mac-video-url
Browse files Browse the repository at this point in the history
Dynamically retrieve Mac Zip URL from Sparkle update feed
  • Loading branch information
goaaats authored Jun 25, 2023
2 parents 2844c3d + 2e78632 commit 410cc9e
Showing 1 changed file with 28 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> 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)
Expand All @@ -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)
Expand All @@ -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);
}
Expand Down

0 comments on commit 410cc9e

Please sign in to comment.