Dry #50, parameterize SteamGridDB options

pull/70/head
Brian Lima 3 years ago
parent 100d40563f
commit fd50d457ce

@ -23,7 +23,62 @@
<value>False</value>
</setting>
<setting name="SteamGridDbApiKey" serializeAs="String">
<value />
<value>617eb1e4ce186060a4b1e2ab0d468a44</value>
</setting>
<setting name="SteamGridDB_Style" serializeAs="Xml">
<value>
<ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<string>any</string>
<string>alternate</string>
<string>blurred</string>
<string>white_logo</string>
<string>material</string>
<string>no_logo </string>
</ArrayOfString>
</value>
</setting>
<setting name="SteamGridDB_Type" serializeAs="Xml">
<value>
<ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<string>any</string>
<string>static</string>
<string>animated</string>
</ArrayOfString>
</value>
</setting>
<setting name="SteamGridDB_nfsw" serializeAs="Xml">
<value>
<ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<string>false</string>
<string>any</string>
<string>true</string>
</ArrayOfString>
</value>
</setting>
<setting name="SteamGridDB_Humor" serializeAs="Xml">
<value>
<ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<string>false</string>
<string>any</string>
<string>true</string>
</ArrayOfString>
</value>
</setting>
<setting name="SelectedSteamGridDB_Style" serializeAs="String">
<value>0</value>
</setting>
<setting name="SelectedSteamGridDB_Type" serializeAs="String">
<value>0</value>
</setting>
<setting name="SelectedSteamGridDB_nfsw" serializeAs="String">
<value>0</value>
</setting>
<setting name="SelectedSteamGridDB_Humor" serializeAs="String">
<value>0</value>
</setting>
</UWPHook.Properties.Settings>
</userSettings>

@ -38,7 +38,8 @@ namespace UWPHook
//When length is 1, the only argument is the path where the app is installed
if (Environment.GetCommandLineArgs().Length > 1)
{
LauncherAsync();
Task task = LauncherAsync();
task.RunSynchronously();
}
}
}
@ -191,10 +192,10 @@ namespace UWPHook
Directory.CreateDirectory(tmpGridDirectory);
}
var gameGridsVertical = api.GetGameGrids(game.Id, "600x900", "static");
var gameGridsHorizontal = api.GetGameGrids(game.Id, "460x215", "static");
var gameHeroes = api.GetGameHeroes(game.Id, "static");
var gameLogos = api.GetGameLogos(game.Id, "static");
var gameGridsVertical = api.GetGameGrids(game.Id, "600x900,342x482,660x930");
var gameGridsHorizontal = api.GetGameGrids(game.Id, "460x215,920x430");
var gameHeroes = api.GetGameHeroes(game.Id);
var gameLogos = api.GetGameLogos(game.Id);
await Task.WhenAll(
gameGridsVertical,
@ -235,7 +236,6 @@ namespace UWPHook
}
await Task.WhenAll(saveImagesTasks);
}
}

@ -12,7 +12,7 @@ namespace UWPHook.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.7.0.0")]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.8.1.0")]
public sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
@ -73,7 +73,7 @@ namespace UWPHook.Properties {
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("")]
[global::System.Configuration.DefaultSettingValueAttribute("617eb1e4ce186060a4b1e2ab0d468a44")]
public string SteamGridDbApiKey {
get {
return ((string)(this["SteamGridDbApiKey"]));
@ -82,5 +82,118 @@ namespace UWPHook.Properties {
this["SteamGridDbApiKey"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute(@"<?xml version=""1.0"" encoding=""utf-16""?>
<ArrayOfString xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">
<string>any</string>
<string>alternate</string>
<string>blurred</string>
<string>white_logo</string>
<string>material</string>
<string>no_logo </string>
</ArrayOfString>")]
public global::System.Collections.Specialized.StringCollection SteamGridDB_Style {
get {
return ((global::System.Collections.Specialized.StringCollection)(this["SteamGridDB_Style"]));
}
set {
this["SteamGridDB_Style"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n<ArrayOfString xmlns:xsi=\"http://www.w3." +
"org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">\r\n <s" +
"tring>any</string>\r\n <string>static</string>\r\n <string>animated</string>\r\n</Ar" +
"rayOfString>")]
public global::System.Collections.Specialized.StringCollection SteamGridDB_Type {
get {
return ((global::System.Collections.Specialized.StringCollection)(this["SteamGridDB_Type"]));
}
set {
this["SteamGridDB_Type"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n<ArrayOfString xmlns:xsi=\"http://www.w3." +
"org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">\r\n <s" +
"tring>false</string>\r\n <string>any</string>\r\n <string>true</string>\r\n</ArrayOf" +
"String>")]
public global::System.Collections.Specialized.StringCollection SteamGridDB_nfsw {
get {
return ((global::System.Collections.Specialized.StringCollection)(this["SteamGridDB_nfsw"]));
}
set {
this["SteamGridDB_nfsw"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n<ArrayOfString xmlns:xsi=\"http://www.w3." +
"org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">\r\n <s" +
"tring>false</string>\r\n <string>any</string>\r\n <string>true</string>\r\n</ArrayOf" +
"String>")]
public global::System.Collections.Specialized.StringCollection SteamGridDB_Humor {
get {
return ((global::System.Collections.Specialized.StringCollection)(this["SteamGridDB_Humor"]));
}
set {
this["SteamGridDB_Humor"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("0")]
public int SelectedSteamGridDB_Style {
get {
return ((int)(this["SelectedSteamGridDB_Style"]));
}
set {
this["SelectedSteamGridDB_Style"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("0")]
public int SelectedSteamGridDB_Type {
get {
return ((int)(this["SelectedSteamGridDB_Type"]));
}
set {
this["SelectedSteamGridDB_Type"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("0")]
public int SelectedSteamGridDB_nfsw {
get {
return ((int)(this["SelectedSteamGridDB_nfsw"]));
}
set {
this["SelectedSteamGridDB_nfsw"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("0")]
public int SelectedSteamGridDB_Humor {
get {
return ((int)(this["SelectedSteamGridDB_Humor"]));
}
set {
this["SelectedSteamGridDB_Humor"] = value;
}
}
}
}

@ -15,7 +15,54 @@
<Value Profile="(Default)">False</Value>
</Setting>
<Setting Name="SteamGridDbApiKey" Type="System.String" Scope="User">
<Value Profile="(Default)" />
<Value Profile="(Default)">617eb1e4ce186060a4b1e2ab0d468a44</Value>
</Setting>
<Setting Name="SteamGridDB_Style" Type="System.Collections.Specialized.StringCollection" Scope="User">
<Value Profile="(Default)">&lt;?xml version="1.0" encoding="utf-16"?&gt;
&lt;ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
&lt;string&gt;any&lt;/string&gt;
&lt;string&gt;alternate&lt;/string&gt;
&lt;string&gt;blurred&lt;/string&gt;
&lt;string&gt;white_logo&lt;/string&gt;
&lt;string&gt;material&lt;/string&gt;
&lt;string&gt;no_logo &lt;/string&gt;
&lt;/ArrayOfString&gt;</Value>
</Setting>
<Setting Name="SteamGridDB_Type" Type="System.Collections.Specialized.StringCollection" Scope="User">
<Value Profile="(Default)">&lt;?xml version="1.0" encoding="utf-16"?&gt;
&lt;ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
&lt;string&gt;any&lt;/string&gt;
&lt;string&gt;static&lt;/string&gt;
&lt;string&gt;animated&lt;/string&gt;
&lt;/ArrayOfString&gt;</Value>
</Setting>
<Setting Name="SteamGridDB_nfsw" Type="System.Collections.Specialized.StringCollection" Scope="User">
<Value Profile="(Default)">&lt;?xml version="1.0" encoding="utf-16"?&gt;
&lt;ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
&lt;string&gt;false&lt;/string&gt;
&lt;string&gt;any&lt;/string&gt;
&lt;string&gt;true&lt;/string&gt;
&lt;/ArrayOfString&gt;</Value>
</Setting>
<Setting Name="SteamGridDB_Humor" Type="System.Collections.Specialized.StringCollection" Scope="User">
<Value Profile="(Default)">&lt;?xml version="1.0" encoding="utf-16"?&gt;
&lt;ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
&lt;string&gt;false&lt;/string&gt;
&lt;string&gt;any&lt;/string&gt;
&lt;string&gt;true&lt;/string&gt;
&lt;/ArrayOfString&gt;</Value>
</Setting>
<Setting Name="SelectedSteamGridDB_Style" Type="System.Int32" Scope="User">
<Value Profile="(Default)">0</Value>
</Setting>
<Setting Name="SelectedSteamGridDB_Type" Type="System.Int32" Scope="User">
<Value Profile="(Default)">0</Value>
</Setting>
<Setting Name="SelectedSteamGridDB_nfsw" Type="System.Int32" Scope="User">
<Value Profile="(Default)">0</Value>
</Setting>
<Setting Name="SelectedSteamGridDB_Humor" Type="System.Int32" Scope="User">
<Value Profile="(Default)">0</Value>
</Setting>
</Settings>
</SettingsFile>

@ -2,8 +2,13 @@
{
class GameResponse
{
/// <summary>
/// SteamGridDB id of the game
/// </summary>
public int Id { get; set; }
/// <summary>
/// Name of the game in SteamgridDB
/// </summary>
public string Name { get; set; }
}

@ -1,13 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace UWPHook.SteamGridDb
{
class GridResponse
{
public string Url { get; set; }
}
}

@ -1,7 +0,0 @@
namespace UWPHook.SteamGridDb
{
public class HeroResponse
{
public string Url { get; set; }
}
}

@ -0,0 +1,10 @@
namespace UWPHook.SteamGridDb
{
/// <summary>
/// Represents an image from SteamGridDB
/// </summary>
public class ImageResponse
{
public string Url { get; set; }
}
}

@ -1,7 +0,0 @@
namespace UWPHook.SteamGridDb
{
public class LogoResponse
{
public string Url { get; set; }
}
}

@ -1,10 +1,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
using UWPHook.Properties;
namespace UWPHook.SteamGridDb
{
@ -13,14 +11,25 @@ namespace UWPHook.SteamGridDb
private const string BASE_URL = "https://www.steamgriddb.com/api/v2/";
private HttpClient httpClient;
private Settings settings;
/// <summary>
/// Constructor
/// </summary>
/// <param name="apiKey"> An SteamGridDB api key retrieved from https://www.steamgriddb.com/profile/preferences </param>
public SteamGridDbApi(string apiKey)
{
settings = Settings.Default;
httpClient = new HttpClient();
httpClient.BaseAddress = new Uri(BASE_URL);
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", apiKey);
}
/// <summary>
/// Gets a list of
/// </summary>
/// <param name="gameName" type="String">Name of the game</param>
/// <returns>Array of games corresponding to the provided name</returns>
public async Task<GameResponse[]> SearchGame(string gameName)
{
string path = $"search/autocomplete/{gameName}";
@ -28,7 +37,7 @@ namespace UWPHook.SteamGridDb
GameResponse[] games = null;
HttpResponseMessage response = await httpClient.GetAsync(path);
if(response.IsSuccessStatusCode)
if (response.IsSuccessStatusCode)
{
var parsedResponse = await response.Content.ReadAsAsync<ResponseWrapper<GameResponse>>();
games = parsedResponse.Data;
@ -37,111 +46,76 @@ namespace UWPHook.SteamGridDb
return games;
}
public async Task<GridResponse[]> GetGameGrids(
int gameId,
string dimensions = null,
string types = null,
string styles = null,
string nsfw = "any",
string humor = "any")
/// <summary>
/// Method responsible for transforming user selected settings
/// into a suitable parameter list for SteamGridDB requests
/// </summary>
/// <param name="dimensions">Comma separated list of resolutions, see https://www.steamgriddb.com/api/v2#tag/GRIDS</param>
/// <returns>A String with the formatted parameters</returns>
public string BuildParameters(string dimensions)
{
string path = $"grids/game/{gameId}?";
String result = String.Empty;
var style = settings.SteamGridDB_Style[settings.SelectedSteamGridDB_Style];
var type = settings.SteamGridDB_Type[settings.SelectedSteamGridDB_Type];
var nsfw = settings.SteamGridDB_nfsw[settings.SelectedSteamGridDB_nfsw];
var humor = settings.SteamGridDB_Humor[settings.SelectedSteamGridDB_Humor];
if (!String.IsNullOrEmpty(dimensions))
path += $"dimensions={dimensions}&";
if (!String.IsNullOrEmpty(types))
path += $"types={types}&";
result += $"dimensions={dimensions}&";
if (!String.IsNullOrEmpty(styles))
path += $"styles={styles}&";
if (type != "any")
result += $"types={type}&";
if (!String.IsNullOrEmpty(nsfw))
path += $"nsfw={nsfw}&";
if (style != "any")
result += $"styles={style}&";
if (!String.IsNullOrEmpty(humor))
path += $"humor={humor}&";
GridResponse[] grids = null;
HttpResponseMessage response = await httpClient.GetAsync(path);
if (nsfw != "any")
result += $"nsfw={nsfw}&";
if (response.IsSuccessStatusCode)
{
var parsedResponse = await response.Content.ReadAsAsync<ResponseWrapper<GridResponse>>();
grids = parsedResponse.Data;
}
if (humor != "any")
result += $"humor={humor}&";
return grids;
return result;
}
public async Task<HeroResponse[]> GetGameHeroes(
int gameId,
string types = null,
string dimensions = null,
string styles = null,
string nsfw = "any",
string humor = "any")
/// <summary>
/// Performs a request on a given url
/// </summary>
/// <param name="url">The url to perform the request</param>
/// <returns>An array of ImageResponse with their urls</returns>
public async Task<ImageResponse[]> getResponse(string url)
{
string path = $"heroes/game/{gameId}?";
if (!String.IsNullOrEmpty(dimensions))
path += $"dimensions={dimensions}&";
if (!String.IsNullOrEmpty(types))
path += $"types={types}&";
if (!String.IsNullOrEmpty(styles))
path += $"styles={styles}&";
if (!String.IsNullOrEmpty(nsfw))
path += $"nsfw={nsfw}&";
if (!String.IsNullOrEmpty(humor))
path += $"humor={humor}&";
HeroResponse[] heroes = null;
HttpResponseMessage response = await httpClient.GetAsync(path);
HttpResponseMessage response = await httpClient.GetAsync(url);
ImageResponse[] images = null;
if (response.IsSuccessStatusCode)
{
var parsedResponse = await response.Content.ReadAsAsync<ResponseWrapper<HeroResponse>>();
heroes = parsedResponse.Data;
var parsedResponse = await response.Content.ReadAsAsync<ResponseWrapper<ImageResponse>>();
images = parsedResponse.Data;
}
return heroes;
return images;
}
public async Task<LogoResponse[]> GetGameLogos(
int gameId,
string types = null,
string styles = null,
string nsfw = "any",
string humor = "any")
public async Task<ImageResponse[]> GetGameGrids(int gameId, string dimensions = null)
{
string path = $"logos/game/{gameId}?";
if (!String.IsNullOrEmpty(types))
path += $"types={types}&";
string path = $"grids/game/{gameId}?{BuildParameters(dimensions)}";
if (!String.IsNullOrEmpty(styles))
path += $"styles={styles}&";
if (!String.IsNullOrEmpty(nsfw))
path += $"nsfw={nsfw}&";
return await getResponse(path);
}
if (!String.IsNullOrEmpty(humor))
path += $"humor={humor}&";
public async Task<ImageResponse[]> GetGameHeroes(int gameId, string dimensions = null)
{
string path = $"heroes/game/{gameId}?{BuildParameters(dimensions)}";
LogoResponse[] logos = null;
HttpResponseMessage response = await httpClient.GetAsync(path);
return await getResponse(path);
}
if (response.IsSuccessStatusCode)
{
var parsedResponse = await response.Content.ReadAsAsync<ResponseWrapper<LogoResponse>>();
logos = parsedResponse.Data;
}
public async Task<ImageResponse[]> GetGameLogos(int gameId, string dimensions = null)
{
string path = $"logos/game/{gameId}?{BuildParameters(dimensions)}";
return logos;
return await getResponse(path);
}
private class ResponseWrapper<T>

@ -118,9 +118,7 @@
<DependentUpon>SettingsWindow.xaml</DependentUpon>
</Compile>
<Compile Include="SteamGridDb\GameResponse.cs" />
<Compile Include="SteamGridDb\GridResponse.cs" />
<Compile Include="SteamGridDb\HeroResponse.cs" />
<Compile Include="SteamGridDb\LogoResponse.cs" />
<Compile Include="SteamGridDb\ImageResponse.cs" />
<Compile Include="SteamGridDb\SteamGridDbApi.cs" />
<Page Include="FullScreenLauncher.xaml">
<Generator>MSBuild:Compile</Generator>

Loading…
Cancel
Save