-
-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #563 from sailro/refine-installer
Refine installer
- Loading branch information
Showing
5 changed files
with
107 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Net.Http; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Spectre.Console; | ||
|
||
namespace Installer; | ||
|
||
internal class VersionChecker | ||
{ | ||
|
||
private static readonly Dictionary<Version, bool> _versions = []; | ||
private static readonly HttpClient _client = new(); | ||
private static readonly SemaphoreSlim _semaphore = new(1, 1); | ||
|
||
public static async Task<bool> IsVersionSupportedAsync(Version version) | ||
{ | ||
await _semaphore.WaitAsync(); | ||
|
||
try | ||
{ | ||
if (_versions.TryGetValue(version, out var supported)) | ||
return supported; | ||
|
||
var branch = $"dev-{version}"; | ||
var uri = new Uri($"https:/sailro/EscapeFromTarkov-Trainer/tree/{branch}"); | ||
var result = await _client.GetAsync(uri); | ||
_versions[version] = result.IsSuccessStatusCode; | ||
} | ||
catch (Exception e) | ||
Check warning on line 31 in Installer/VersionChecker.cs GitHub Actions / windows
Check warning on line 31 in Installer/VersionChecker.cs GitHub Actions / windows
Check warning on line 31 in Installer/VersionChecker.cs GitHub Actions / windows
|
||
{ | ||
#if DEBUG | ||
AnsiConsole.WriteException(e); | ||
#endif | ||
|
||
_versions[version] = false; | ||
} | ||
finally | ||
{ | ||
_semaphore.Release(); | ||
} | ||
|
||
return _versions[version]; | ||
} | ||
|
||
public static bool IsVersionSupported(Version version) | ||
{ | ||
#pragma warning disable VSTHRD002 | ||
return IsVersionSupportedAsync(version) | ||
.GetAwaiter() | ||
.GetResult(); | ||
#pragma warning restore VSTHRD002 | ||
} | ||
} |