public async ValueTask <AuthlibInjector> GetLatest() { if (_cached != null) { return(_cached); } try { var json = await _client.GetByteArrayAsync(_downloadUrlService.Base.AuthlibInjector); var info = JsonDocument.Parse(json).RootElement; _cached = new AuthlibInjector { Build = info.GetProperty("build_number").GetInt32(), Version = info.GetProperty("version").GetString(), Url = info.GetProperty("download_url").GetString(), SHA256 = info.GetProperty("checksums").GetProperty("sha256").GetString(), }; return(_cached); } catch (Exception ex) { Debug.WriteLine(ex.Message); return(null); } }
public async ValueTask <AuthlibInjector> GetLatest() { if (_cached != null) { return(_cached); } _logService.Info(nameof(AuthlibInjectorService), "Fetching latest download info"); try { byte[] json = await _client.GetByteArrayAsync(_downloadUrlService.Base.AuthlibInjector); var info = JsonDocument.Parse(json).RootElement; _cached = new AuthlibInjector { Build = info.GetProperty("build_number").GetInt32(), Version = info.GetProperty("version").GetString(), Url = info.GetProperty("download_url").GetString(), SHA256 = info.GetProperty("checksums").GetProperty("sha256").GetString(), }; _logService.Info(nameof(AuthlibInjectorService), $"Download info fetched. Version: {_cached.Version} Build: {_cached.Build}"); return(_cached); } catch (Exception ex) { _logService.Error(nameof(AuthlibInjectorService), $"Failed to fetch download info\n{ex.Message}"); return(null); } }