From a92d8c617c4250612b4e0be1d89027cefc4023e6 Mon Sep 17 00:00:00 2001 From: Jeddunk Date: Wed, 30 Dec 2020 12:09:57 +0100 Subject: [PATCH 01/30] Update README.md --- auto-creamapi/README.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/auto-creamapi/README.md b/auto-creamapi/README.md index 0ec37d3..ae07184 100644 --- a/auto-creamapi/README.md +++ b/auto-creamapi/README.md @@ -1,10 +1,8 @@ # Auto-CreamAPI 2 +[![ko-fi](https://www.ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/H2H4330U3) Set your game automatically up for use with CreamAPI. -[![](https://jeddunk.xyz/jetbrains-small.png)](https://www.jetbrains.com/?from=Auto-CreamAPI) -[Made with software provided by JetBrains s.r.o.](https://www.jetbrains.com/?from=Auto-CreamAPI) - ## Features * Setup CreamAPI’s DLLs and configuration file automatically. * Find the AppID by providing the game’s name without having to look it up manually. @@ -12,11 +10,9 @@ Set your game automatically up for use with CreamAPI. * Set flags like "offline mode" and "extra protection" and select a language from a list. ## Installation - Download the latest release and extract it into any folder (e.g. `%USERPROFILE%\Desktop\auto-creamapi`). ## Usage - * Double-click `auto-creamapi.exe` to open the application. (When starting it for the first time, it might take a few seconds since it needs to cache a list of games available on the Steam Store and download the latest CreamAPI DLL files.) * Click on the *Open File* button on the top right and select the *steam_api.dll* or *steam_api64.dll* @@ -29,9 +25,13 @@ Download the latest release and extract it into any folder (e.g. `%USERPROFILE%\ * Click on *"Save"*. ## License - Auto-CreamAPI itself is licensed under the GNU General Public License v3.0 -CreamAPI © 2016-2019, deadmau5. All Rights Reserved. +CreamAPI © 2016-2020, deadmau5. All Rights Reserved. *Dependencies will be listed ASAP.* + +## Software used + +[![](https://jeddunk.xyz/jetbrains-small.png)](https://www.jetbrains.com/?from=Auto-CreamAPI) +[Made with software provided by JetBrains s.r.o.](https://www.jetbrains.com/?from=Auto-CreamAPI) From 717960c6b55cfdad3da265cbbb7f0c08761f283b Mon Sep 17 00:00:00 2001 From: Jeddunk Date: Wed, 30 Dec 2020 12:11:15 +0100 Subject: [PATCH 02/30] Update README.md --- README.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 0ec37d3..ae07184 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,8 @@ # Auto-CreamAPI 2 +[![ko-fi](https://www.ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/H2H4330U3) Set your game automatically up for use with CreamAPI. -[![](https://jeddunk.xyz/jetbrains-small.png)](https://www.jetbrains.com/?from=Auto-CreamAPI) -[Made with software provided by JetBrains s.r.o.](https://www.jetbrains.com/?from=Auto-CreamAPI) - ## Features * Setup CreamAPI’s DLLs and configuration file automatically. * Find the AppID by providing the game’s name without having to look it up manually. @@ -12,11 +10,9 @@ Set your game automatically up for use with CreamAPI. * Set flags like "offline mode" and "extra protection" and select a language from a list. ## Installation - Download the latest release and extract it into any folder (e.g. `%USERPROFILE%\Desktop\auto-creamapi`). ## Usage - * Double-click `auto-creamapi.exe` to open the application. (When starting it for the first time, it might take a few seconds since it needs to cache a list of games available on the Steam Store and download the latest CreamAPI DLL files.) * Click on the *Open File* button on the top right and select the *steam_api.dll* or *steam_api64.dll* @@ -29,9 +25,13 @@ Download the latest release and extract it into any folder (e.g. `%USERPROFILE%\ * Click on *"Save"*. ## License - Auto-CreamAPI itself is licensed under the GNU General Public License v3.0 -CreamAPI © 2016-2019, deadmau5. All Rights Reserved. +CreamAPI © 2016-2020, deadmau5. All Rights Reserved. *Dependencies will be listed ASAP.* + +## Software used + +[![](https://jeddunk.xyz/jetbrains-small.png)](https://www.jetbrains.com/?from=Auto-CreamAPI) +[Made with software provided by JetBrains s.r.o.](https://www.jetbrains.com/?from=Auto-CreamAPI) From 201e122e8ba3b2a77dc8381e9ffc84ae891a6940 Mon Sep 17 00:00:00 2001 From: Jeddunk Date: Fri, 1 Jan 2021 14:53:02 +0100 Subject: [PATCH 03/30] Fixed app not launching properly --- auto-creamapi/Services/CacheService.cs | 2 +- auto-creamapi/Services/CreamDllService.cs | 27 ++++++++++--------- auto-creamapi/ViewModels/DownloadViewModel.cs | 3 ++- 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/auto-creamapi/Services/CacheService.cs b/auto-creamapi/Services/CacheService.cs index 2f2544d..1be6d7f 100644 --- a/auto-creamapi/Services/CacheService.cs +++ b/auto-creamapi/Services/CacheService.cs @@ -64,7 +64,7 @@ namespace auto_creamapi.Services MyLogger.Log.Information("Getting content from API..."); var client = new HttpClient(); var httpCall = client.GetAsync(SteamUri); - var response = await httpCall; + var response = await httpCall.ConfigureAwait(false); var readAsStringAsync = response.Content.ReadAsStringAsync(); var responseBody = await readAsStringAsync; MyLogger.Log.Information("Got content from API successfully. Writing to file..."); diff --git a/auto-creamapi/Services/CreamDllService.cs b/auto-creamapi/Services/CreamDllService.cs index de0470c..d41c35a 100644 --- a/auto-creamapi/Services/CreamDllService.cs +++ b/auto-creamapi/Services/CreamDllService.cs @@ -15,6 +15,7 @@ namespace auto_creamapi.Services public void Save(); public void CheckIfDllExistsAtTarget(); public bool CreamApiApplied(); + public bool CreamApiApplied(string arch); } public class CreamDllService : ICreamDllService @@ -23,7 +24,7 @@ namespace auto_creamapi.Services private const string X64Arch = "x64"; private static readonly string HashPath = Path.Combine(Directory.GetCurrentDirectory(), "cream_api.md5"); - private readonly Dictionary _creamDlls = new Dictionary(); + private Dictionary _creamDlls; private bool _x64Exists; private bool _x86Exists; @@ -33,9 +34,11 @@ namespace auto_creamapi.Services public async Task Initialize() { MyLogger.Log.Debug("CreamDllService: Initialize begin"); - - _creamDlls.Add(X86Arch, new CreamDll("steam_api.dll", "steam_api_o.dll")); - _creamDlls.Add(X64Arch, new CreamDll("steam_api64.dll", "steam_api64_o.dll")); + _creamDlls = new Dictionary + { + {X86Arch, new CreamDll("steam_api.dll", "steam_api_o.dll")}, + {X64Arch, new CreamDll("steam_api64.dll", "steam_api64_o.dll")} + }; if (!File.Exists(HashPath)) { @@ -45,7 +48,7 @@ namespace auto_creamapi.Services { $"{_creamDlls[X86Arch].Hash} {_creamDlls[X86Arch].Filename}", $"{_creamDlls[X64Arch].Hash} {_creamDlls[X64Arch].Filename}" - }); + }).ConfigureAwait(false); } MyLogger.Log.Debug("CreamDllService: Initialize end"); @@ -59,12 +62,12 @@ namespace auto_creamapi.Services public void CheckIfDllExistsAtTarget() { - var x86file = Path.Combine(TargetPath, "steam_api.dll"); - var x64file = Path.Combine(TargetPath, "steam_api64.dll"); - _x86Exists = File.Exists(x86file); - _x64Exists = File.Exists(x64file); - if (_x86Exists) MyLogger.Log.Information($"x86 SteamAPI DLL found: {x86file}"); - if (_x64Exists) MyLogger.Log.Information($"x64 SteamAPI DLL found: {x64file}"); + var x86File = Path.Combine(TargetPath, "steam_api.dll"); + var x64File = Path.Combine(TargetPath, "steam_api64.dll"); + _x86Exists = File.Exists(x86File); + _x64Exists = File.Exists(x64File); + if (_x86Exists) MyLogger.Log.Information($"x86 SteamAPI DLL found: {x86File}"); + if (_x64Exists) MyLogger.Log.Information($"x64 SteamAPI DLL found: {x64File}"); } public bool CreamApiApplied() @@ -98,7 +101,7 @@ namespace auto_creamapi.Services return a & b; } - private string GetHash(string filename) + private static string GetHash(string filename) { if (File.Exists(filename)) { diff --git a/auto-creamapi/ViewModels/DownloadViewModel.cs b/auto-creamapi/ViewModels/DownloadViewModel.cs index 63475f3..ef83b23 100644 --- a/auto-creamapi/ViewModels/DownloadViewModel.cs +++ b/auto-creamapi/ViewModels/DownloadViewModel.cs @@ -71,7 +71,8 @@ namespace auto_creamapi.ViewModels var filename = await download; /*var extract = _download.Extract(filename); await extract;*/ - await Task.Run(() => _download.Extract(filename)); + var extract = Task.Run(() => _download.Extract(filename)); + await extract.ConfigureAwait(false); _token.Dispose(); await _navigationService.Close(this); } From 10429232499605fbc7b1a34c082e6599ff7ed791 Mon Sep 17 00:00:00 2001 From: Jeddunk Date: Fri, 1 Jan 2021 16:27:42 +0100 Subject: [PATCH 04/30] Improved search performance Pressing enter in the game name field now also starts a search. --- auto-creamapi/Models/SteamAppModel.cs | 26 +++++++++--- auto-creamapi/Services/CacheService.cs | 35 ++++----------- auto-creamapi/Utils/Misc.cs | 2 +- auto-creamapi/ViewModels/MainViewModel.cs | 28 ++++++------ auto-creamapi/Views/MainView.xaml | 52 ++++++++++++++--------- auto-creamapi/Views/MainView.xaml.cs | 1 + 6 files changed, 75 insertions(+), 69 deletions(-) diff --git a/auto-creamapi/Models/SteamAppModel.cs b/auto-creamapi/Models/SteamAppModel.cs index 5c85687..3f74258 100644 --- a/auto-creamapi/Models/SteamAppModel.cs +++ b/auto-creamapi/Models/SteamAppModel.cs @@ -1,24 +1,36 @@ using System.Collections.Generic; using System.Text.Json.Serialization; +using System.Text.RegularExpressions; +using auto_creamapi.Utils; namespace auto_creamapi.Models { public class SteamApp { + private string _name; + private string _comparableName; [JsonPropertyName("appid")] public int AppId { get; set; } - [JsonPropertyName("name")] public string Name { get; set; } + [JsonPropertyName("name")] + public string Name + { + get => _name; + set + { + _name = value; + _comparableName = Regex.Replace(value, Misc.SpecialCharsRegex, "").ToLower(); + } + } + + public bool CompareName(string value) + { + return _comparableName.Equals(value); + } public override string ToString() { - //return $"AppId: {AppId}, Name: {Name}"; return $"{AppId}={Name}"; } - - public bool CompareId(SteamApp steamApp) - { - return AppId.Equals(steamApp.AppId); - } } public class AppList diff --git a/auto-creamapi/Services/CacheService.cs b/auto-creamapi/Services/CacheService.cs index 1be6d7f..efacfd2 100644 --- a/auto-creamapi/Services/CacheService.cs +++ b/auto-creamapi/Services/CacheService.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Linq; using System.Net.Http; using System.Text; using System.Text.Json; @@ -35,24 +36,7 @@ namespace auto_creamapi.Services "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) " + "Chrome/87.0.4280.88 Safari/537.36"; - private const string SpecialCharsRegex = "[^0-9a-zA-Z]+"; - - private List _cache = new List(); - - /*private static readonly Lazy Lazy = - new Lazy(() => new CacheService()); - - public static CacheService Instance => Lazy.Value;*/ - - public CacheService() - { - } - - /*public async void Initialize() - { - //Languages = _defaultLanguages; - await UpdateCache(); - }*/ + private HashSet _cache = new HashSet(); public async Task Initialize() { @@ -81,7 +65,7 @@ namespace auto_creamapi.Services } var steamApps = JsonSerializer.Deserialize(cacheString); - _cache = steamApps.AppList.Apps; + _cache = new HashSet(steamApps.AppList.Apps); MyLogger.Log.Information("Loaded cache into memory!"); } @@ -96,9 +80,8 @@ namespace auto_creamapi.Services public SteamApp GetAppByName(string name) { MyLogger.Log.Information($"Trying to get app {name}"); - var app = _cache.Find(x => - Regex.Replace(x.Name, SpecialCharsRegex, "").ToLower() - .Equals(Regex.Replace(name, SpecialCharsRegex, "").ToLower())); + var comparableName = Regex.Replace(name, Misc.SpecialCharsRegex, "").ToLower(); + var app = _cache.FirstOrDefault(x => x.CompareName(comparableName)); if (app != null) MyLogger.Log.Information($"Successfully got app {app}"); return app; } @@ -106,7 +89,7 @@ namespace auto_creamapi.Services public SteamApp GetAppById(int appid) { MyLogger.Log.Information($"Trying to get app with ID {appid}"); - var app = _cache.Find(x => x.AppId.Equals(appid)); + var app = _cache.FirstOrDefault(x => x.AppId.Equals(appid)); if (app != null) MyLogger.Log.Information($"Successfully got app {app}"); return app; } @@ -121,7 +104,7 @@ namespace auto_creamapi.Services var steamAppDetails = await task; steamAppDetails?.DLC.ForEach(x => { - var result = _cache.Find(y => y.AppId.Equals(x)) ?? + var result = _cache.FirstOrDefault(y => y.AppId.Equals(x)) ?? new SteamApp {AppId = x, Name = $"Unknown DLC {x}"}; dlcList.Add(result); }); @@ -173,7 +156,7 @@ namespace auto_creamapi.Services if (query3 != null) dlcName = query3[1].Text().Replace("\n", "").Trim(); var dlcApp = new SteamApp {AppId = Convert.ToInt32(dlcId), Name = dlcName}; - var i = dlcList.FindIndex(x => x.CompareId(dlcApp)); + var i = dlcList.FindIndex(x => x.AppId.Equals(dlcApp.AppId)); if (i > -1) { if (dlcList[i].Name.Contains("Unknown DLC")) dlcList[i] = dlcApp; @@ -189,7 +172,7 @@ namespace auto_creamapi.Services } else { - MyLogger.Log.Error("Could not get DLC from SteamDB1"); + MyLogger.Log.Error("Could not get DLC from SteamDB!"); } } } diff --git a/auto-creamapi/Utils/Misc.cs b/auto-creamapi/Utils/Misc.cs index 2bd85a2..3290f47 100644 --- a/auto-creamapi/Utils/Misc.cs +++ b/auto-creamapi/Utils/Misc.cs @@ -5,7 +5,7 @@ namespace auto_creamapi.Utils { public class Misc { - + public const string SpecialCharsRegex = "[^0-9a-zA-Z]+"; public const string DefaultLanguageSelection = "english"; public static readonly ObservableCollection DefaultLanguages = new ObservableCollection(new[] { diff --git a/auto-creamapi/ViewModels/MainViewModel.cs b/auto-creamapi/ViewModels/MainViewModel.cs index b4ee4d9..7479306 100644 --- a/auto-creamapi/ViewModels/MainViewModel.cs +++ b/auto-creamapi/ViewModels/MainViewModel.cs @@ -26,7 +26,7 @@ namespace auto_creamapi.ViewModels private ObservableCollection _dlcs; private bool _dllApplied; private string _dllPath; - private bool _extraprotection; + private bool _extraProtection; private string _gameName; private string _lang; private ObservableCollection _languages; @@ -35,7 +35,7 @@ namespace auto_creamapi.ViewModels private bool _mainWindowEnabled; private bool _offline; private string _status; - private bool _unlockall; + private bool _unlockAll; private bool _useSteamDb; //private const string DlcRegexPattern = @"(?.*) *= *(?.*)"; @@ -144,23 +144,23 @@ namespace auto_creamapi.ViewModels } } - public bool Extraprotection + public bool ExtraProtection { - get => _extraprotection; + get => _extraProtection; set { - _extraprotection = value; - RaisePropertyChanged(() => Extraprotection); + _extraProtection = value; + RaisePropertyChanged(() => ExtraProtection); } } - public bool Unlockall + public bool UnlockAll { - get => _unlockall; + get => _unlockAll; set { - _unlockall = value; - RaisePropertyChanged(() => Unlockall); + _unlockAll = value; + RaisePropertyChanged(() => UnlockAll); } } @@ -319,8 +319,8 @@ namespace auto_creamapi.ViewModels _config.SetConfigData( AppId, Lang, - Unlockall, - Extraprotection, + UnlockAll, + ExtraProtection, Offline, Dlcs ); @@ -334,8 +334,8 @@ namespace auto_creamapi.ViewModels { AppId = _config.Config.AppId; Lang = _config.Config.Language; - Unlockall = _config.Config.UnlockAll; - Extraprotection = _config.Config.ExtraProtection; + UnlockAll = _config.Config.UnlockAll; + ExtraProtection = _config.Config.ExtraProtection; Offline = _config.Config.ForceOffline; Dlcs = new ObservableCollection(_config.Config.DlcList); Status = "Changes have been reset."; diff --git a/auto-creamapi/Views/MainView.xaml b/auto-creamapi/Views/MainView.xaml index 7324e3d..021d61b 100644 --- a/auto-creamapi/Views/MainView.xaml +++ b/auto-creamapi/Views/MainView.xaml @@ -1,3 +1,4 @@ + - - +