public HttpTool(CoreProps cprops) { _client = new HttpClient() { BaseAddress = new Uri(cprops.BaseAddress) }; }
// ReSharper restore InconsistentNaming #endregion #region Methods internal static bool Initialize() { try { string corePropsPath = GetCorePropsPath(); if (!string.IsNullOrWhiteSpace(corePropsPath) && File.Exists(corePropsPath)) { CoreProps coreProps = JsonConvert.DeserializeObject <CoreProps>(File.ReadAllText(corePropsPath)); _baseUrl = coreProps.Address; if (!_baseUrl.StartsWith("http://", StringComparison.Ordinal)) { _baseUrl = "http://" + _baseUrl; } RegisterGame(_game); RegisterGoLispHandler(new GoLispHandler(_game, HANDLER)); } } catch { _baseUrl = null; } return(IsInitialized); }
private void Login() { WriteLog("Attempting to find coreProps.json"); int tries = 0; string coreProps = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + "\\SteelSeries\\SteelSeries Engine 3\\coreProps.json"; while (tries < 10 && !File.Exists(coreProps)) { Thread.Sleep(5000); ++tries; } if (tries == 10) { WriteLog($"Error: Couldn't find coreProps.json at path {coreProps}"); Stop(); return; } CoreProps output = new CoreProps(); // Read coreProps.json using (StreamReader sr = File.OpenText(coreProps)) { output = JsonConvert.DeserializeObject <CoreProps>(sr.ReadToEnd()); } // Initialize HTTP string formatted = $"http://{output.address}/"; WriteLog($"coreProps.json found with address {formatted}"); steelSeries = new SteelSeries(formatted); // SteelSeries Engine has been identified and connection has been initialized. Time to move on to Spotify var creds = ReadOAuthCreds(); // If creds are already present if (creds != null) { var newResponse = new OAuthClient().RequestToken( new PKCETokenRefreshRequest(clientId, creds.RefreshToken) ); newResponse.Wait(); WriteOAuthCreds(newResponse.Result); spotifyClient = new SpotifyClient(newResponse.Result.AccessToken); } else { WriteLog("Failed to load Spotify credentials, please use the helper program (SSMIHelper.exe)"); Stop(); return; } WriteLog("Loading completed, registering event"); var task = steelSeries.AddMetadata(); task.Wait(); WriteLog($"Metadata: {task.Result.StatusCode}"); task = steelSeries.RegisterEvent(); task.Wait(); WriteLog($"Event: {task.Result.StatusCode}"); ssLoggedIn = true; ServiceStatus status = new ServiceStatus { dwCurrentState = ServiceState.SERVICE_RUNNING }; SetServiceStatus(ServiceHandle, ref status); }