Skip to content

Commit 03e460e

Browse files
committed
Adjust FFmpeg mirror list URL to support relative path
1 parent 7e11b2e commit 03e460e

File tree

2 files changed

+48
-5
lines changed

2 files changed

+48
-5
lines changed

CollapseLauncher/Classes/Helper/FFmpegCodecInstaller.cs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@
22
using CollapseLauncher.GameManagement.ImageBackground;
33
using CollapseLauncher.Helper.StreamUtility;
44
using CollapseLauncher.Interfaces;
5+
using Hi3Helper.Data;
56
using Hi3Helper.EncTool;
67
using Hi3Helper.Http;
8+
using Hi3Helper.Shared.Region;
79
using System;
10+
using System.Collections.Generic;
811
using System.IO;
12+
using System.Linq;
913
using System.Net.Http;
1014
using System.Text.Json.Serialization;
1115
using System.Threading;
@@ -141,7 +145,7 @@ private static async Task<string[]> GetMirrorList(CancellationToken token)
141145

142146
private async Task<UrlStatus> FindAvailableMirrors(HttpClient client, params string[] urls)
143147
{
144-
foreach (string url in urls)
148+
foreach (string url in urls.SelectMany(SelectManyUrlFromCdnMirrors))
145149
{
146150
Status.ActivityAll = $"Checking Mirror URL: {url}...";
147151

@@ -154,4 +158,23 @@ private async Task<UrlStatus> FindAvailableMirrors(HttpClient client, params str
154158

155159
throw new HttpRequestException("No available mirrors are reachable!");
156160
}
161+
162+
private static IEnumerable<string> SelectManyUrlFromCdnMirrors(string url)
163+
{
164+
if (Uri.TryCreate(url, UriKind.Absolute, out _))
165+
{
166+
yield return url;
167+
yield break;
168+
}
169+
170+
CDNURLProperty preferredCdn = FallbackCDNUtil.GetPreferredCDN();
171+
yield return preferredCdn.URLPrefix.CombineURLFromString(url);
172+
173+
foreach (CDNURLProperty otherCdn in FallbackCDNUtil
174+
.CDNList
175+
.Where(x => x != preferredCdn))
176+
{
177+
yield return otherCdn.URLPrefix.CombineURLFromString(url);
178+
}
179+
}
157180
}

Hi3Helper.Core/Classes/Shared/Region/LauncherConfig.cs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,30 @@ namespace Hi3Helper.Shared.Region
2323
public string Description { get; init; }
2424
public bool PartialDownloadSupport { get; init; }
2525

26-
public bool Equals(CDNURLProperty other)
27-
{
28-
return URLPrefix == other.URLPrefix && Name == other.Name && Description == other.Description;
29-
}
26+
public bool Equals(CDNURLProperty other) => other.GetHashCode() == GetHashCode();
27+
28+
public override int GetHashCode() => HashCode.Combine(URLPrefix, Name, PartialDownloadSupport);
29+
30+
public override bool Equals([NotNullWhen(true)] object? obj) =>
31+
obj is CDNURLProperty asCdnProperty && Equals(asCdnProperty);
32+
33+
public static bool operator ==(CDNURLProperty from, CDNURLProperty to)
34+
=> from.Equals(to);
35+
36+
public static bool operator !=(CDNURLProperty from, CDNURLProperty to)
37+
=> !(from == to);
38+
39+
public static bool operator ==(object? from, CDNURLProperty to)
40+
=> to.Equals(from);
41+
42+
public static bool operator !=(object? from, CDNURLProperty to)
43+
=> !(from == to);
44+
45+
public static bool operator ==(CDNURLProperty from, object? to)
46+
=> from.Equals(to);
47+
48+
public static bool operator !=(CDNURLProperty from, object? to)
49+
=> !(from == to);
3050
}
3151
#endregion
3252

0 commit comments

Comments
 (0)