diff --git a/UWPHook/App.config b/UWPHook/App.config index f9ab9ff..7d012c2 100644 --- a/UWPHook/App.config +++ b/UWPHook/App.config @@ -23,7 +23,62 @@ False - + 617eb1e4ce186060a4b1e2ab0d468a44 + + + + + any + alternate + blurred + white_logo + material + no_logo + + + + + + + any + static + animated + + + + + + + false + any + true + + + + + + + false + any + true + + + + + 0 + + + 0 + + + 0 + + + 0 diff --git a/UWPHook/GamesWindow.xaml.cs b/UWPHook/GamesWindow.xaml.cs index 1baa8df..2c346ed 100644 --- a/UWPHook/GamesWindow.xaml.cs +++ b/UWPHook/GamesWindow.xaml.cs @@ -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); - } } diff --git a/UWPHook/Properties/Settings.Designer.cs b/UWPHook/Properties/Settings.Designer.cs index fc330f9..0faa694 100644 --- a/UWPHook/Properties/Settings.Designer.cs +++ b/UWPHook/Properties/Settings.Designer.cs @@ -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(@" + + any + alternate + blurred + white_logo + material + no_logo +")] + 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("\r\n\r\n any\r\n static\r\n animated\r\n")] + 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("\r\n\r\n false\r\n any\r\n true\r\n")] + 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("\r\n\r\n false\r\n any\r\n true\r\n")] + 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; + } + } } } diff --git a/UWPHook/Properties/Settings.settings b/UWPHook/Properties/Settings.settings index 339d33b..55767bc 100644 --- a/UWPHook/Properties/Settings.settings +++ b/UWPHook/Properties/Settings.settings @@ -15,7 +15,54 @@ False - + 617eb1e4ce186060a4b1e2ab0d468a44 + + + <?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> + + + <?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>static</string> + <string>animated</string> +</ArrayOfString> + + + <?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>false</string> + <string>any</string> + <string>true</string> +</ArrayOfString> + + + <?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>false</string> + <string>any</string> + <string>true</string> +</ArrayOfString> + + + 0 + + + 0 + + + 0 + + + 0 \ No newline at end of file diff --git a/UWPHook/SteamGridDb/GameResponse.cs b/UWPHook/SteamGridDb/GameResponse.cs index daafef5..32cf5bf 100644 --- a/UWPHook/SteamGridDb/GameResponse.cs +++ b/UWPHook/SteamGridDb/GameResponse.cs @@ -2,8 +2,13 @@ { class GameResponse { - + /// + /// SteamGridDB id of the game + /// public int Id { get; set; } + /// + /// Name of the game in SteamgridDB + /// public string Name { get; set; } } diff --git a/UWPHook/SteamGridDb/GridResponse.cs b/UWPHook/SteamGridDb/GridResponse.cs deleted file mode 100644 index 0f39b6e..0000000 --- a/UWPHook/SteamGridDb/GridResponse.cs +++ /dev/null @@ -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; } - } -} diff --git a/UWPHook/SteamGridDb/HeroResponse.cs b/UWPHook/SteamGridDb/HeroResponse.cs deleted file mode 100644 index 80c38ad..0000000 --- a/UWPHook/SteamGridDb/HeroResponse.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace UWPHook.SteamGridDb -{ - public class HeroResponse - { - public string Url { get; set; } - } -} \ No newline at end of file diff --git a/UWPHook/SteamGridDb/ImageResponse.cs b/UWPHook/SteamGridDb/ImageResponse.cs new file mode 100644 index 0000000..dc19d19 --- /dev/null +++ b/UWPHook/SteamGridDb/ImageResponse.cs @@ -0,0 +1,10 @@ +namespace UWPHook.SteamGridDb +{ + /// + /// Represents an image from SteamGridDB + /// + public class ImageResponse + { + public string Url { get; set; } + } +} \ No newline at end of file diff --git a/UWPHook/SteamGridDb/LogoResponse.cs b/UWPHook/SteamGridDb/LogoResponse.cs deleted file mode 100644 index 258f072..0000000 --- a/UWPHook/SteamGridDb/LogoResponse.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace UWPHook.SteamGridDb -{ - public class LogoResponse - { - public string Url { get; set; } - } -} \ No newline at end of file diff --git a/UWPHook/SteamGridDb/SteamGridDbApi.cs b/UWPHook/SteamGridDb/SteamGridDbApi.cs index 632cda5..3e375c1 100644 --- a/UWPHook/SteamGridDb/SteamGridDbApi.cs +++ b/UWPHook/SteamGridDb/SteamGridDbApi.cs @@ -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; + /// + /// Constructor + /// + /// An SteamGridDB api key retrieved from https://www.steamgriddb.com/profile/preferences public SteamGridDbApi(string apiKey) { + settings = Settings.Default; httpClient = new HttpClient(); httpClient.BaseAddress = new Uri(BASE_URL); httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", apiKey); } + /// + /// Gets a list of + /// + /// Name of the game + /// Array of games corresponding to the provided name public async Task 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>(); games = parsedResponse.Data; @@ -37,111 +46,76 @@ namespace UWPHook.SteamGridDb return games; } - public async Task GetGameGrids( - int gameId, - string dimensions = null, - string types = null, - string styles = null, - string nsfw = "any", - string humor = "any") + /// + /// Method responsible for transforming user selected settings + /// into a suitable parameter list for SteamGridDB requests + /// + /// Comma separated list of resolutions, see https://www.steamgriddb.com/api/v2#tag/GRIDS + /// A String with the formatted parameters + 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>(); - grids = parsedResponse.Data; - } + if (humor != "any") + result += $"humor={humor}&"; - return grids; + return result; } - public async Task GetGameHeroes( - int gameId, - string types = null, - string dimensions = null, - string styles = null, - string nsfw = "any", - string humor = "any") + /// + /// Performs a request on a given url + /// + /// The url to perform the request + /// An array of ImageResponse with their urls + public async Task 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>(); - heroes = parsedResponse.Data; + var parsedResponse = await response.Content.ReadAsAsync>(); + images = parsedResponse.Data; } - return heroes; + return images; } - public async Task GetGameLogos( - int gameId, - string types = null, - string styles = null, - string nsfw = "any", - string humor = "any") + public async Task 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 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>(); - logos = parsedResponse.Data; - } + public async Task GetGameLogos(int gameId, string dimensions = null) + { + string path = $"logos/game/{gameId}?{BuildParameters(dimensions)}"; - return logos; + return await getResponse(path); } private class ResponseWrapper diff --git a/UWPHook/UWPHook.csproj b/UWPHook/UWPHook.csproj index 66d1eee..5130dea 100644 --- a/UWPHook/UWPHook.csproj +++ b/UWPHook/UWPHook.csproj @@ -118,9 +118,7 @@ SettingsWindow.xaml - - - + MSBuild:Compile