mirror of
https://github.com/JustArchiNET/ArchiSteamFarm
synced 2024-11-10 07:04:27 +00:00
Misc optimization
This commit is contained in:
parent
f71b0bc945
commit
dc57860f0d
1 changed files with 23 additions and 16 deletions
|
@ -125,24 +125,31 @@ public interface IGitHubPluginUpdates : IPluginUpdates {
|
|||
throw new ArgumentNullException(nameof(releaseAssets));
|
||||
}
|
||||
|
||||
Dictionary<string, ReleaseAsset> assetsByName = releaseAssets.ToDictionary(static asset => asset.Name, StringComparer.OrdinalIgnoreCase);
|
||||
// Since we only find assets from available .zip files, we can filter out other assets right away
|
||||
Dictionary<string, ReleaseAsset> assetsByName = releaseAssets.Where(static asset => asset.Name.EndsWith(".zip", StringComparison.OrdinalIgnoreCase)).ToDictionary(static asset => asset.Name, StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
foreach (string possibleMatch in GetPossibleMatches(asfVersion)) {
|
||||
if (assetsByName.TryGetValue(possibleMatch, out ReleaseAsset? targetAsset)) {
|
||||
return targetAsset;
|
||||
}
|
||||
switch (assetsByName.Count) {
|
||||
case 0:
|
||||
// Release does not have a single zip file, so the matching has failed
|
||||
ASF.ArchiLogger.LogGenericWarning(string.Format(CultureInfo.CurrentCulture, Strings.PluginUpdateNoAssetFound, Name, Version, newPluginVersion));
|
||||
|
||||
return null;
|
||||
case 1:
|
||||
// If exactly one match is found, we can return it right away, as it'd be used as a fallback regardless of our matching
|
||||
return assetsByName.Values.First();
|
||||
default:
|
||||
// Otherwise, we have 2+ zip files, so either we match one of those, or fail
|
||||
foreach (string possibleMatch in GetPossibleMatches(asfVersion)) {
|
||||
if (assetsByName.TryGetValue(possibleMatch, out ReleaseAsset? targetAsset)) {
|
||||
return targetAsset;
|
||||
}
|
||||
}
|
||||
|
||||
// We can't possibly determine which zip file to use, the plugin author should either fix the release, or provide custom GetTargetReleaseAsset() implementation
|
||||
ASF.ArchiLogger.LogGenericWarning(string.Format(CultureInfo.CurrentCulture, Strings.PluginUpdateConflictingAssetsFound, Name, Version, newPluginVersion));
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// The very last fallback in case user uses different naming scheme
|
||||
HashSet<ReleaseAsset> zipAssets = releaseAssets.Where(static asset => asset.Name.EndsWith(".zip", StringComparison.OrdinalIgnoreCase)).ToHashSet();
|
||||
|
||||
if (zipAssets.Count == 1) {
|
||||
return zipAssets.First();
|
||||
}
|
||||
|
||||
ASF.ArchiLogger.LogGenericWarning(string.Format(CultureInfo.CurrentCulture, Strings.PluginUpdateConflictingAssetsFound, Name, Version, newPluginVersion));
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected async Task<Uri?> GetTargetReleaseURL(Version asfVersion, string asfVariant, bool asfUpdate, bool stable, bool forced) {
|
||||
|
|
Loading…
Reference in a new issue