Skip to content

Commit

Permalink
Fixed installer downloading pre-release version even when set to false (
Browse files Browse the repository at this point in the history
#2367)

* Fix

* Change
  • Loading branch information
BoltonDev authored Dec 30, 2023
1 parent 9bcf764 commit 3a11321
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Exiled.Installer/CommandSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ internal sealed class CommandSettings
/// </summary>
public bool Exit { get; set; }

public async static Task Parse(string[] args)
public static async Task Parse(string[] args)
{
RootCommand.Handler = CommandHandler.Create<CommandSettings>(async args => await Program.MainSafe(args).ConfigureAwait(false));
RootCommand.TreatUnmatchedTokensAsErrors = false;
Expand Down
42 changes: 24 additions & 18 deletions Exiled.Installer/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ internal static class Program
// Force use of LF because the file uses LF
private static readonly Dictionary<string, string> Markup = Resources.Markup.Trim().Split('\n').ToDictionary(s => s.Split(':')[0], s => s.Split(':', 2)[1]);

private async static Task Main(string[] args)
private static async Task Main(string[] args)
{
Console.OutputEncoding = new UTF8Encoding(false, false);
await CommandSettings.Parse(args).ConfigureAwait(false);
}

internal async static Task MainSafe(CommandSettings args)
internal static async Task MainSafe(CommandSettings args)
{
bool error = false;
try
Expand Down Expand Up @@ -111,10 +111,8 @@ internal async static Task MainSafe(CommandSettings args)
Console.WriteLine(Resources.Program_MainSafe_Asset_found_);
Console.WriteLine(FormatAsset(exiledAsset));

using HttpClient httpClient = new()
{
Timeout = TimeSpan.FromSeconds(SecondsWaitForDownload),
};
using HttpClient httpClient = new();
httpClient.Timeout = TimeSpan.FromSeconds(SecondsWaitForDownload);
httpClient.DefaultRequestHeaders.Add("User-Agent", Header);

using HttpResponseMessage downloadResult = await httpClient.GetAsync(exiledAsset.BrowserDownloadUrl).ConfigureAwait(false);
Expand Down Expand Up @@ -144,12 +142,12 @@ internal async static Task MainSafe(CommandSettings args)
Environment.Exit(error ? 1 : 0);
}

private async static Task<IEnumerable<Release>> GetReleases()
private static async Task<IEnumerable<Release>> GetReleases()
{
IEnumerable<Release> releases = (await GitHubClient.Repository.Release.GetAll(RepoID).ConfigureAwait(false))
.Where(
r => Version.TryParse(r.TagName, out Version version)
&& (version > VersionLimit));
&& version > VersionLimit);

return releases.OrderByDescending(r => r.CreatedAt.Ticks);
}
Expand Down Expand Up @@ -267,7 +265,8 @@ static PathResolution TryParse(string s)
{
return TryParse(pair.Value);
}
else if (!fileInFolder && !isFolder &&

if (!fileInFolder && !isFolder &&
pair.Key.Equals(fileName, StringComparison.OrdinalIgnoreCase))
{
return TryParse(pair.Value);
Expand All @@ -280,20 +279,27 @@ static PathResolution TryParse(string s)
private static Release FindRelease(CommandSettings args, IEnumerable<Release> releases)
{
Console.WriteLine(Resources.Program_TryFindRelease_Trying_to_find_release__);
Version targetVersion = args.TargetVersion is not null ? new Version(args.TargetVersion) : new Version(releases.First().TagName);
Version? targetVersion = args.TargetVersion is not null ? new Version(args.TargetVersion) : null;

foreach (Release r in releases)
{
if (targetVersion != new Version(r.TagName))
continue;
List<Release> enumerable = releases.ToList();

if (targetVersion.IsPreRelease && !args.PreReleases)
continue;
foreach (Release release in enumerable)
{
if (targetVersion != null)
{
if (targetVersion == new Version(release.TagName))
return release;
}
else
{
if (release.Prerelease && !args.PreReleases)
continue;

return r;
return release;
}
}

return releases.First();
return enumerable.First();
}
}
}

0 comments on commit 3a11321

Please sign in to comment.