From 81bd241e26ec968df2ce12a24134c5ab1e07d91b Mon Sep 17 00:00:00 2001 From: Jeddunk Date: Fri, 15 Jan 2021 16:59:47 +0100 Subject: [PATCH 01/17] Fixed crash when trying to get DLCs for certain games. --- auto-creamapi/Services/CacheService.cs | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/auto-creamapi/Services/CacheService.cs b/auto-creamapi/Services/CacheService.cs index ca2af53..e7637db 100644 --- a/auto-creamapi/Services/CacheService.cs +++ b/auto-creamapi/Services/CacheService.cs @@ -114,15 +114,11 @@ namespace auto_creamapi.Services steamAppDetails.DLC.ForEach(x => { var result = _cache.FirstOrDefault(y => y.AppId.Equals(x)); - if (result == null) - { - var dlcDetails = AppDetails.GetAsync(x).Result; - result = dlcDetails != null - ? new SteamApp { AppId = dlcDetails.SteamAppId, Name = dlcDetails.Name } - : new SteamApp { AppId = x, Name = $"Unknown DLC {x}" }; - } - - dlcList.Add(result); + if (result == null) return; + var dlcDetails = AppDetails.GetAsync(x).Result; + dlcList.Add(dlcDetails != null + ? new SteamApp { AppId = dlcDetails.SteamAppId, Name = dlcDetails.Name } + : new SteamApp { AppId = x, Name = $"Unknown DLC {x}" }); }); dlcList.ForEach(x => MyLogger.Log.Debug($"{x.AppId}={x.Name}")); @@ -160,9 +156,10 @@ namespace auto_creamapi.Services foreach (var element in query2) { var dlcId = element.GetAttribute("data-appid"); - var dlcName = $"Unknown DLC {dlcId}"; var query3 = element.QuerySelectorAll("td"); - if (query3 != null) dlcName = query3[1].Text().Replace("\n", "").Trim(); + var dlcName = query3 == null + ? $"Unknown DLC {dlcId}" + : query3[1].Text().Replace("\n", "").Trim(); if (ignoreUnknown && dlcName.Contains("SteamDB Unknown App")) { From 178b7427b8c06077a5d98fa13bb1c02f250dfb92 Mon Sep 17 00:00:00 2001 From: Jeddunk Date: Fri, 15 Jan 2021 17:00:38 +0100 Subject: [PATCH 02/17] Fixed crash when trying to get DLCs for certain games. --- auto-creamapi/auto-creamapi.csproj | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/auto-creamapi/auto-creamapi.csproj b/auto-creamapi/auto-creamapi.csproj index cb35c41..07f982d 100644 --- a/auto-creamapi/auto-creamapi.csproj +++ b/auto-creamapi/auto-creamapi.csproj @@ -5,12 +5,12 @@ netcoreapp3.1 auto_creamapi true - 2.1.5 + 2.1.6 auto-creamapi Jeddunk jeddunk.xyz - 2.1.5 - 2.1.5 + 2.1.6 + 2.1.6 From 8ade832b429a67c22608de8fac5e501f5266386c Mon Sep 17 00:00:00 2001 From: Jeddunk Date: Sun, 14 Feb 2021 15:02:02 +0100 Subject: [PATCH 03/17] Error message is now displayed if CreamAPI cannot be downloaded. Fixed incorrect logging syntax. --- auto-creamapi/Services/CacheService.cs | 22 +++++----- auto-creamapi/Services/CreamConfigService.cs | 4 +- auto-creamapi/Services/CreamDllService.cs | 6 +-- .../Services/DownloadCreamApiService.cs | 18 ++++---- auto-creamapi/ViewModels/DownloadViewModel.cs | 41 ++++++++++++++----- auto-creamapi/ViewModels/MainViewModel.cs | 9 +--- .../ViewModels/SearchResultViewModel.cs | 2 +- 7 files changed, 59 insertions(+), 43 deletions(-) diff --git a/auto-creamapi/Services/CacheService.cs b/auto-creamapi/Services/CacheService.cs index e7637db..85f2864 100644 --- a/auto-creamapi/Services/CacheService.cs +++ b/auto-creamapi/Services/CacheService.cs @@ -84,18 +84,18 @@ namespace auto_creamapi.Services public SteamApp GetAppByName(string name) { - MyLogger.Log.Information($"Trying to get app {name}"); + MyLogger.Log.Information("Trying to get app {Name}", name); 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}"); + if (app != null) MyLogger.Log.Information("Successfully got app {App}", app); return app; } public SteamApp GetAppById(int appid) { - MyLogger.Log.Information($"Trying to get app with ID {appid}"); + MyLogger.Log.Information("Trying to get app with ID {AppId}", appid); var app = _cache.FirstOrDefault(x => x.AppId.Equals(appid)); - if (app != null) MyLogger.Log.Information($"Successfully got app {app}"); + if (app != null) MyLogger.Log.Information("Successfully got app {App}", app); return app; } @@ -108,7 +108,7 @@ namespace auto_creamapi.Services var steamAppDetails = await AppDetails.GetAsync(steamApp.AppId).ConfigureAwait(false); if (steamAppDetails != null) { - MyLogger.Log.Debug($"Type for Steam App {steamApp.Name}: \"{steamAppDetails.Type}\""); + MyLogger.Log.Debug("Type for Steam App {Name}: \"{Type}\"", steamApp.Name, steamAppDetails.Type); if (steamAppDetails.Type == "game" | steamAppDetails.Type == "demo") { steamAppDetails.DLC.ForEach(x => @@ -121,7 +121,7 @@ namespace auto_creamapi.Services : new SteamApp { AppId = x, Name = $"Unknown DLC {x}" }); }); - dlcList.ForEach(x => MyLogger.Log.Debug($"{x.AppId}={x.Name}")); + dlcList.ForEach(x => MyLogger.Log.Debug("{AppId}={Name}", x.AppId, x.Name)); MyLogger.Log.Information("Got DLC successfully..."); if (!useSteamDb) return dlcList; @@ -138,12 +138,12 @@ namespace auto_creamapi.Services MyLogger.Log.Information("Get SteamDB App"); var httpCall = client.GetAsync(steamDbUri); var response = await httpCall.ConfigureAwait(false); - MyLogger.Log.Debug(httpCall.Status.ToString()); - MyLogger.Log.Debug(response.EnsureSuccessStatusCode().ToString()); + MyLogger.Log.Debug("{Status}", httpCall.Status.ToString()); + MyLogger.Log.Debug("{Boolean}", response.EnsureSuccessStatusCode().ToString()); var readAsStringAsync = response.Content.ReadAsStringAsync(); var responseBody = await readAsStringAsync.ConfigureAwait(false); - MyLogger.Log.Debug(readAsStringAsync.Status.ToString()); + MyLogger.Log.Debug("{Status}", readAsStringAsync.Status.ToString()); var parser = new HtmlParser(); var doc = parser.ParseDocument(responseBody); @@ -163,7 +163,7 @@ namespace auto_creamapi.Services if (ignoreUnknown && dlcName.Contains("SteamDB Unknown App")) { - MyLogger.Log.Information($"Skipping SteamDB Unknown App {dlcId}"); + MyLogger.Log.Information("Skipping SteamDB Unknown App {DlcId}", dlcId); } else { @@ -179,7 +179,7 @@ namespace auto_creamapi.Services } } } - dlcList.ForEach(x => MyLogger.Log.Debug($"{x.AppId}={x.Name}")); + dlcList.ForEach(x => MyLogger.Log.Debug("{AppId}={Name}", x.AppId, x.Name)); MyLogger.Log.Information("Got DLC from SteamDB successfully..."); } else diff --git a/auto-creamapi/Services/CreamConfigService.cs b/auto-creamapi/Services/CreamConfigService.cs index acd2a3e..d21f13d 100644 --- a/auto-creamapi/Services/CreamConfigService.cs +++ b/auto-creamapi/Services/CreamConfigService.cs @@ -65,7 +65,7 @@ namespace auto_creamapi.Services _configFilePath = configFilePath; if (File.Exists(configFilePath)) { - MyLogger.Log.Information($"Config file found @ {configFilePath}, parsing..."); + MyLogger.Log.Information("Config file found @ {ConfigFilePath}, parsing...", configFilePath); var parser = new FileIniDataParser(); var data = parser.ReadFile(_configFilePath, Encoding.UTF8); @@ -83,7 +83,7 @@ namespace auto_creamapi.Services } else { - MyLogger.Log.Information($"Config file does not exist @ {configFilePath}, skipping..."); + MyLogger.Log.Information("Config file does not exist @ {ConfigFilePath}, skipping...", configFilePath); ResetConfigData(); } } diff --git a/auto-creamapi/Services/CreamDllService.cs b/auto-creamapi/Services/CreamDllService.cs index 9cee2df..de3c9b7 100644 --- a/auto-creamapi/Services/CreamDllService.cs +++ b/auto-creamapi/Services/CreamDllService.cs @@ -66,8 +66,8 @@ namespace auto_creamapi.Services 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}"); + if (_x86Exists) MyLogger.Log.Information("x86 SteamAPI DLL found: {X}", x86File); + if (_x64Exists) MyLogger.Log.Information("x64 SteamAPI DLL found: {X}", x64File); } public bool CreamApiApplied() @@ -83,7 +83,7 @@ namespace auto_creamapi.Services var targetSteamApiDll = Path.Combine(TargetPath, _creamDlls[arch].Filename); var targetSteamApiOrigDll = Path.Combine(TargetPath, _creamDlls[arch].OrigFilename); var targetSteamApiDllBackup = Path.Combine(TargetPath, $"{_creamDlls[arch].Filename}.backup"); - MyLogger.Log.Information($"Setting up CreamAPI DLL @ {TargetPath} (arch :{arch})"); + MyLogger.Log.Information("Setting up CreamAPI DLL @ {TargetPath} (arch :{Arch})", TargetPath, arch); // Create backup of steam_api.dll File.Copy(targetSteamApiDll, targetSteamApiDllBackup, true); // Check if steam_api_o.dll already exists diff --git a/auto-creamapi/Services/DownloadCreamApiService.cs b/auto-creamapi/Services/DownloadCreamApiService.cs index 870c755..ba9f75c 100644 --- a/auto-creamapi/Services/DownloadCreamApiService.cs +++ b/auto-creamapi/Services/DownloadCreamApiService.cs @@ -4,7 +4,6 @@ using System.IO; using System.Linq; using System.Net; using System.Net.Http; -using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using auto_creamapi.Messenger; @@ -37,6 +36,8 @@ namespace auto_creamapi.Services var container = new CookieContainer(); var handler = new HttpClientHandler {CookieContainer = container}; var client = new HttpClient(handler); + client.DefaultRequestHeaders.UserAgent.ParseAdd("Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:86.0) " + + "Gecko/20100101 Firefox/86.0"); var formContent = new FormUrlEncodedContent(new[] { new KeyValuePair("username", username), @@ -47,14 +48,15 @@ namespace auto_creamapi.Services MyLogger.Log.Debug("Download: post login"); var response1 = await client.PostAsync("https://cs.rin.ru/forum/ucp.php?mode=login", formContent) .ConfigureAwait(false); - MyLogger.Log.Debug($"Login Status Code: {response1.EnsureSuccessStatusCode().StatusCode.ToString()}"); + MyLogger.Log.Debug("Login Status Code: {StatusCode}", + response1.EnsureSuccessStatusCode().StatusCode); var cookie = container.GetCookies(new Uri("https://cs.rin.ru/forum/ucp.php?mode=login")) .FirstOrDefault(c => c.Name.Contains("_sid")); - MyLogger.Log.Debug($"Login Cookie: {cookie}"); + MyLogger.Log.Debug("Login Cookie: {Cookie}", cookie); var response2 = await client.GetAsync("https://cs.rin.ru/forum/viewtopic.php?t=70576") .ConfigureAwait(false); - MyLogger.Log.Debug( - $"Download Page Status Code: {response2.EnsureSuccessStatusCode().StatusCode.ToString()}"); + MyLogger.Log.Debug("Download Page Status Code: {StatusCode}", + response2.EnsureSuccessStatusCode().StatusCode); var content = response2.Content.ReadAsStringAsync(); var contentResult = await content.ConfigureAwait(false); @@ -71,7 +73,7 @@ namespace auto_creamapi.Services { archiveFileList.Add(match.Groups["filename"].Value, $"https://cs.rin.ru/forum{match.Groups["url"].Value}"); - MyLogger.Log.Debug(archiveFileList.LastOrDefault().Key); + MyLogger.Log.Debug("{X}", archiveFileList.LastOrDefault().Key); } } @@ -79,7 +81,7 @@ namespace auto_creamapi.Services var (filename, url) = archiveFileList.FirstOrDefault(); if (File.Exists(filename)) { - MyLogger.Log.Information($"{filename} already exists, skipping download..."); + MyLogger.Log.Information("{Filename} already exists, skipping download...", filename); return filename; } @@ -102,7 +104,7 @@ namespace auto_creamapi.Services const string nonlogBuild = "nonlog_build"; const string steamApi64Dll = "steam_api64.dll"; const string steamApiDll = "steam_api.dll"; - MyLogger.Log.Information($@"Start extraction of ""{filename}""..."); + MyLogger.Log.Information(@"Start extraction of ""{Filename}""...", filename); var nonlogBuildPath = Path.Combine(cwd, nonlogBuild); if (Directory.Exists(nonlogBuildPath)) Directory.Delete(nonlogBuildPath, true); diff --git a/auto-creamapi/ViewModels/DownloadViewModel.cs b/auto-creamapi/ViewModels/DownloadViewModel.cs index c580d8d..ba3230d 100644 --- a/auto-creamapi/ViewModels/DownloadViewModel.cs +++ b/auto-creamapi/ViewModels/DownloadViewModel.cs @@ -1,4 +1,7 @@ +using System; +using System.Net.Http; using System.Threading.Tasks; +using System.Windows; using auto_creamapi.Messenger; using auto_creamapi.Services; using auto_creamapi.Utils; @@ -26,7 +29,7 @@ namespace auto_creamapi.ViewModels _navigationService = navigationService; _download = download; _token = messenger.Subscribe(OnProgressMessage); - MyLogger.Log.Debug(messenger.CountSubscriptionsFor().ToString()); + MyLogger.Log.Debug("{Count}", messenger.CountSubscriptionsFor()); } public string InfoLabel @@ -62,20 +65,36 @@ namespace auto_creamapi.ViewModels public string ProgressPercent => _progress.ToString("P2"); - public override async Task Initialize() + public override void Prepare() { - await base.Initialize().ConfigureAwait(false); InfoLabel = "Please wait..."; FilenameLabel = ""; Progress = 0.0; - var download = _download.Download(Secrets.ForumUsername, Secrets.ForumPassword); - var filename = await download.ConfigureAwait(false); - /*var extract = _download.Extract(filename); - await extract;*/ - var extract = _download.Extract(filename); - await extract.ConfigureAwait(false); - _token.Dispose(); - await _navigationService.Close(this).ConfigureAwait(false); + } + + public override async Task Initialize() + { + try + { + await base.Initialize().ConfigureAwait(false); + var download = _download.Download(Secrets.ForumUsername, Secrets.ForumPassword); + var filename = await download.ConfigureAwait(false); + /*var extract = _download.Extract(filename); + await extract;*/ + var extract = _download.Extract(filename); + await extract.ConfigureAwait(false); + _token.Dispose(); + await _navigationService.Close(this).ConfigureAwait(false); + } + catch (Exception e) + { + MessageBox.Show("Could not download CreamAPI!\nPlease add CreamAPI DLLs manually!\nShutting down...", + "Error", MessageBoxButton.OK, MessageBoxImage.Error); + _token.Dispose(); + await _navigationService.Close(this).ConfigureAwait(false); + Console.WriteLine(e); + throw; + } } private void OnProgressMessage(ProgressMessage obj) diff --git a/auto-creamapi/ViewModels/MainViewModel.cs b/auto-creamapi/ViewModels/MainViewModel.cs index eed6b30..ac04a89 100644 --- a/auto-creamapi/ViewModels/MainViewModel.cs +++ b/auto-creamapi/ViewModels/MainViewModel.cs @@ -69,11 +69,6 @@ namespace auto_creamapi.ViewModels Status = "Ready."; } - public override Task Initialize() - { - return base.Initialize(); - } - // // COMMANDS // // public IMvxCommand OpenFileCommand => new MvxAsyncCommand(OpenFile); @@ -346,7 +341,7 @@ namespace auto_creamapi.ViewModels else { Status = $"Could not get DLC for AppID {AppId}"; - MyLogger.Log.Error($"GetListOfDlc: Invalid AppID {AppId}"); + MyLogger.Log.Error("GetListOfDlc: Invalid AppID {AppId}", AppId); } } @@ -397,7 +392,7 @@ namespace auto_creamapi.ViewModels } else { - MyLogger.Log.Error($"OpenURL: Invalid AppID {AppId}"); + MyLogger.Log.Error("OpenURL: Invalid AppID {AppId}", AppId); Status = $"Could not open URL: Invalid AppID {AppId}"; } } diff --git a/auto-creamapi/ViewModels/SearchResultViewModel.cs b/auto-creamapi/ViewModels/SearchResultViewModel.cs index 17804ca..361942e 100644 --- a/auto-creamapi/ViewModels/SearchResultViewModel.cs +++ b/auto-creamapi/ViewModels/SearchResultViewModel.cs @@ -66,7 +66,7 @@ namespace auto_creamapi.ViewModels { if (Selected != null) { - MyLogger.Log.Information($"Successfully got app {Selected}"); + MyLogger.Log.Information("Successfully got app {Selected}", Selected); await _navigationService.Close(this, Selected).ConfigureAwait(false); } } From 3c736674acff48559f6f2941c861ea4ad939739e Mon Sep 17 00:00:00 2001 From: Jeddunk Date: Sun, 14 Feb 2021 15:08:12 +0100 Subject: [PATCH 04/17] Removed automatically getting list of DLCs when selecting DLL file and looking for AppID --- auto-creamapi/ViewModels/MainViewModel.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/auto-creamapi/ViewModels/MainViewModel.cs b/auto-creamapi/ViewModels/MainViewModel.cs index ac04a89..2d5e9d6 100644 --- a/auto-creamapi/ViewModels/MainViewModel.cs +++ b/auto-creamapi/ViewModels/MainViewModel.cs @@ -270,7 +270,7 @@ namespace auto_creamapi.ViewModels var s = index > -1 ? strings[index] : null; if (s != null) GameName = s; await Search().ConfigureAwait(false); - await GetListOfDlc().ConfigureAwait(false); + // await GetListOfDlc().ConfigureAwait(false); } Status = "Ready."; @@ -306,7 +306,7 @@ namespace auto_creamapi.ViewModels } } - await GetListOfDlc().ConfigureAwait(false); + // await GetListOfDlc().ConfigureAwait(false); } else { From 67d289905cbf60f1f5e492f8f59fa13e70594986 Mon Sep 17 00:00:00 2001 From: Jeddunk Date: Sun, 14 Feb 2021 15:19:45 +0100 Subject: [PATCH 05/17] Throw exception if needed when trying to get DLCs. --- auto-creamapi/Services/CacheService.cs | 152 +++++++++++++------------ 1 file changed, 82 insertions(+), 70 deletions(-) diff --git a/auto-creamapi/Services/CacheService.cs b/auto-creamapi/Services/CacheService.cs index 85f2864..081c2c6 100644 --- a/auto-creamapi/Services/CacheService.cs +++ b/auto-creamapi/Services/CacheService.cs @@ -101,105 +101,117 @@ namespace auto_creamapi.Services public async Task> GetListOfDlc(SteamApp steamApp, bool useSteamDb, bool ignoreUnknown) { - MyLogger.Log.Information("Get DLC"); + MyLogger.Log.Debug("Start: GetListOfDlc"); var dlcList = new List(); - if (steamApp != null) + try { - var steamAppDetails = await AppDetails.GetAsync(steamApp.AppId).ConfigureAwait(false); - if (steamAppDetails != null) + if (steamApp != null) { - MyLogger.Log.Debug("Type for Steam App {Name}: \"{Type}\"", steamApp.Name, steamAppDetails.Type); - if (steamAppDetails.Type == "game" | steamAppDetails.Type == "demo") + var steamAppDetails = await AppDetails.GetAsync(steamApp.AppId).ConfigureAwait(false); + if (steamAppDetails != null) { - steamAppDetails.DLC.ForEach(x => + MyLogger.Log.Debug("Type for Steam App {Name}: \"{Type}\"", steamApp.Name, + steamAppDetails.Type); + if (steamAppDetails.Type == "game" | steamAppDetails.Type == "demo") { - var result = _cache.FirstOrDefault(y => y.AppId.Equals(x)); - if (result == null) return; - var dlcDetails = AppDetails.GetAsync(x).Result; - dlcList.Add(dlcDetails != null - ? new SteamApp { AppId = dlcDetails.SteamAppId, Name = dlcDetails.Name } - : new SteamApp { AppId = x, Name = $"Unknown DLC {x}" }); - }); - - dlcList.ForEach(x => MyLogger.Log.Debug("{AppId}={Name}", x.AppId, x.Name)); - MyLogger.Log.Information("Got DLC successfully..."); - - if (!useSteamDb) return dlcList; - - // Get DLC from SteamDB - // Get Cloudflare cookie - // Scrape and parse HTML page - // Add missing to DLC list - var steamDbUri = new Uri($"https://steamdb.info/app/{steamApp.AppId}/dlc/"); - - var client = new HttpClient(); - client.DefaultRequestHeaders.UserAgent.ParseAdd(UserAgent); - - MyLogger.Log.Information("Get SteamDB App"); - var httpCall = client.GetAsync(steamDbUri); - var response = await httpCall.ConfigureAwait(false); - MyLogger.Log.Debug("{Status}", httpCall.Status.ToString()); - MyLogger.Log.Debug("{Boolean}", response.EnsureSuccessStatusCode().ToString()); - - var readAsStringAsync = response.Content.ReadAsStringAsync(); - var responseBody = await readAsStringAsync.ConfigureAwait(false); - MyLogger.Log.Debug("{Status}", readAsStringAsync.Status.ToString()); - - var parser = new HtmlParser(); - var doc = parser.ParseDocument(responseBody); - // Console.WriteLine(doc.DocumentElement.OuterHtml); - - var query1 = doc.QuerySelector("#dlc"); - if (query1 != null) - { - var query2 = query1.QuerySelectorAll(".app"); - foreach (var element in query2) + steamAppDetails.DLC.ForEach(x => { - var dlcId = element.GetAttribute("data-appid"); - var query3 = element.QuerySelectorAll("td"); - var dlcName = query3 == null - ? $"Unknown DLC {dlcId}" - : query3[1].Text().Replace("\n", "").Trim(); + var result = _cache.FirstOrDefault(y => y.AppId.Equals(x)); + if (result == null) return; + var dlcDetails = AppDetails.GetAsync(x).Result; + dlcList.Add(dlcDetails != null + ? new SteamApp {AppId = dlcDetails.SteamAppId, Name = dlcDetails.Name} + : new SteamApp {AppId = x, Name = $"Unknown DLC {x}"}); + }); - if (ignoreUnknown && dlcName.Contains("SteamDB Unknown App")) + dlcList.ForEach(x => MyLogger.Log.Debug("{AppId}={Name}", x.AppId, x.Name)); + MyLogger.Log.Information("Got DLC successfully..."); + + if (!useSteamDb) return dlcList; + + // Get DLC from SteamDB + // Get Cloudflare cookie + // Scrape and parse HTML page + // Add missing to DLC list + var steamDbUri = new Uri($"https://steamdb.info/app/{steamApp.AppId}/dlc/"); + + var client = new HttpClient(); + client.DefaultRequestHeaders.UserAgent.ParseAdd(UserAgent); + + MyLogger.Log.Information("Get SteamDB App"); + var httpCall = client.GetAsync(steamDbUri); + var response = await httpCall.ConfigureAwait(false); + MyLogger.Log.Debug("{Status}", httpCall.Status.ToString()); + MyLogger.Log.Debug("{Boolean}", response.EnsureSuccessStatusCode().ToString()); + + var readAsStringAsync = response.Content.ReadAsStringAsync(); + var responseBody = await readAsStringAsync.ConfigureAwait(false); + MyLogger.Log.Debug("{Status}", readAsStringAsync.Status.ToString()); + + var parser = new HtmlParser(); + var doc = parser.ParseDocument(responseBody); + // Console.WriteLine(doc.DocumentElement.OuterHtml); + + var query1 = doc.QuerySelector("#dlc"); + if (query1 != null) + { + var query2 = query1.QuerySelectorAll(".app"); + foreach (var element in query2) { - MyLogger.Log.Information("Skipping SteamDB Unknown App {DlcId}", dlcId); - } - else - { - var dlcApp = new SteamApp {AppId = Convert.ToInt32(dlcId), Name = dlcName}; - var i = dlcList.FindIndex(x => x.AppId.Equals(dlcApp.AppId)); - if (i > -1) + var dlcId = element.GetAttribute("data-appid"); + var query3 = element.QuerySelectorAll("td"); + var dlcName = query3 == null + ? $"Unknown DLC {dlcId}" + : query3[1].Text().Replace("\n", "").Trim(); + + if (ignoreUnknown && dlcName.Contains("SteamDB Unknown App")) { - if (dlcList[i].Name.Contains("Unknown DLC")) dlcList[i] = dlcApp; + MyLogger.Log.Information("Skipping SteamDB Unknown App {DlcId}", dlcId); } else { - dlcList.Add(dlcApp); + var dlcApp = new SteamApp {AppId = Convert.ToInt32(dlcId), Name = dlcName}; + var i = dlcList.FindIndex(x => x.AppId.Equals(dlcApp.AppId)); + if (i > -1) + { + if (dlcList[i].Name.Contains("Unknown DLC")) dlcList[i] = dlcApp; + } + else + { + dlcList.Add(dlcApp); + } } } + + dlcList.ForEach(x => MyLogger.Log.Debug("{AppId}={Name}", x.AppId, x.Name)); + MyLogger.Log.Information("Got DLC from SteamDB successfully..."); + } + else + { + MyLogger.Log.Error("Could not get DLC from SteamDB!"); } - dlcList.ForEach(x => MyLogger.Log.Debug("{AppId}={Name}", x.AppId, x.Name)); - MyLogger.Log.Information("Got DLC from SteamDB successfully..."); } else { - MyLogger.Log.Error("Could not get DLC from SteamDB!"); + MyLogger.Log.Error("Could not get DLC: Steam App is not of type: \"Game\""); } } else { - MyLogger.Log.Error("Could not get DLC: Steam App is not of type: \"Game\""); + MyLogger.Log.Error("Could not get DLC: Could not get Steam App details"); } } else { - MyLogger.Log.Error("Could not get DLC..."); + MyLogger.Log.Error("Could not get DLC: Invalid Steam App"); } + + //return dlcList; } - else + catch (Exception e) { - MyLogger.Log.Error("Could not get DLC: Invalid Steam App"); + MyLogger.Log.Error("Could not get DLC!"); + Console.WriteLine(e); } return dlcList; From 0005f3d74b1d85f77cea0065cfd7331a2b25f856 Mon Sep 17 00:00:00 2001 From: Jeddunk Date: Sun, 14 Feb 2021 15:20:19 +0100 Subject: [PATCH 06/17] Set version to 2.1.7 --- auto-creamapi/auto-creamapi.csproj | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/auto-creamapi/auto-creamapi.csproj b/auto-creamapi/auto-creamapi.csproj index 07f982d..706b37f 100644 --- a/auto-creamapi/auto-creamapi.csproj +++ b/auto-creamapi/auto-creamapi.csproj @@ -5,12 +5,12 @@ netcoreapp3.1 auto_creamapi true - 2.1.6 + 2.1.7 auto-creamapi Jeddunk jeddunk.xyz - 2.1.6 - 2.1.6 + 2.1.7 + 2.1.7 From 23459ec79463afe81675702aa4656ad354d668cd Mon Sep 17 00:00:00 2001 From: Jeddunk Date: Mon, 15 Feb 2021 16:51:50 +0100 Subject: [PATCH 07/17] Fixed exception throwing stuff idunno --- auto-creamapi/Services/CacheService.cs | 3 ++- auto-creamapi/Utils/MyLogger.cs | 2 ++ auto-creamapi/auto-creamapi.csproj | 2 ++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/auto-creamapi/Services/CacheService.cs b/auto-creamapi/Services/CacheService.cs index 081c2c6..8d906a4 100644 --- a/auto-creamapi/Services/CacheService.cs +++ b/auto-creamapi/Services/CacheService.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.IO; using System.Linq; using System.Net.Http; @@ -211,7 +212,7 @@ namespace auto_creamapi.Services catch (Exception e) { MyLogger.Log.Error("Could not get DLC!"); - Console.WriteLine(e); + MyLogger.Log.Debug(e.Demystify(), "Exception thrown!"); } return dlcList; diff --git a/auto-creamapi/Utils/MyLogger.cs b/auto-creamapi/Utils/MyLogger.cs index 9e1b19a..a35a873 100644 --- a/auto-creamapi/Utils/MyLogger.cs +++ b/auto-creamapi/Utils/MyLogger.cs @@ -1,5 +1,6 @@ using Serilog; using Serilog.Core; +using Serilog.Exceptions; namespace auto_creamapi.Utils { @@ -7,6 +8,7 @@ namespace auto_creamapi.Utils { public static readonly Logger Log = new LoggerConfiguration() .MinimumLevel.Debug() + .Enrich.WithExceptionDetails() .WriteTo.Console() .WriteTo.File("autocreamapi.log", rollingInterval: RollingInterval.Day) .CreateLogger(); diff --git a/auto-creamapi/auto-creamapi.csproj b/auto-creamapi/auto-creamapi.csproj index 706b37f..38f78be 100644 --- a/auto-creamapi/auto-creamapi.csproj +++ b/auto-creamapi/auto-creamapi.csproj @@ -19,6 +19,7 @@ + @@ -27,6 +28,7 @@ + From 80b704cecbbb97209ff308f5257b26fc564ccf44 Mon Sep 17 00:00:00 2001 From: Jeddunk Date: Sat, 23 Dec 2023 19:23:14 +0100 Subject: [PATCH 08/17] Update to NET 8; Fix Secret class --- auto-creamapi/Utils/Secrets.EXAMPLE.cs | 6 +- auto-creamapi/auto-creamapi.csproj | 100 ++++++++++++------------- 2 files changed, 53 insertions(+), 53 deletions(-) diff --git a/auto-creamapi/Utils/Secrets.EXAMPLE.cs b/auto-creamapi/Utils/Secrets.EXAMPLE.cs index f885562..b25dd40 100644 --- a/auto-creamapi/Utils/Secrets.EXAMPLE.cs +++ b/auto-creamapi/Utils/Secrets.EXAMPLE.cs @@ -6,9 +6,9 @@ namespace auto_creamapi.Utils /// Rename class Secrets_REMOVETHIS to Secrets /// Enter the relevant info below /// - public class Secrets_REMOVETHIS + public static class Secrets_REMOVETHIS { - public const string Username = "Enter username here"; - public const string Password = "Enter password here"; + public const string ForumUsername = "Enter username here"; + public const string ForumPassword = "Enter password here"; } } \ No newline at end of file diff --git a/auto-creamapi/auto-creamapi.csproj b/auto-creamapi/auto-creamapi.csproj index 38f78be..d6cb71c 100644 --- a/auto-creamapi/auto-creamapi.csproj +++ b/auto-creamapi/auto-creamapi.csproj @@ -1,57 +1,57 @@  - - WinExe - netcoreapp3.1 - auto_creamapi - true - 2.1.7 - auto-creamapi - Jeddunk - jeddunk.xyz - 2.1.7 - 2.1.7 - + + WinExe + net8.0-windows + auto_creamapi + true + 2.2.0 + auto-creamapi + Jeddunk + jeddunk.xyz + 2.2.0 + 2.2.0 + - - none - + + none + - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + - - - - - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - + + + + + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + \ No newline at end of file From 1c66ff2684d21513bb3bbc89900a0d1e72b239b2 Mon Sep 17 00:00:00 2001 From: Jeddunk Date: Sat, 23 Dec 2023 19:47:11 +0100 Subject: [PATCH 09/17] Update Nuget Packages (except MvvmCross) --- auto-creamapi/auto-creamapi.csproj | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/auto-creamapi/auto-creamapi.csproj b/auto-creamapi/auto-creamapi.csproj index d6cb71c..02e54fb 100644 --- a/auto-creamapi/auto-creamapi.csproj +++ b/auto-creamapi/auto-creamapi.csproj @@ -18,8 +18,8 @@ - - + + @@ -27,11 +27,11 @@ - - - - - + + + + + From 991f52e87ed19e49e266e45a0ee8e7cfb4ff57d0 Mon Sep 17 00:00:00 2001 From: Jeddunk Date: Sat, 23 Dec 2023 20:51:30 +0100 Subject: [PATCH 10/17] Minor changes --- auto-creamapi/App.xaml.cs | 2 +- auto-creamapi/Core/{App.cs => MainApplication.cs} | 2 +- auto-creamapi/Utils/MyLogger.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) rename auto-creamapi/Core/{App.cs => MainApplication.cs} (90%) diff --git a/auto-creamapi/App.xaml.cs b/auto-creamapi/App.xaml.cs index 95e07c3..96ab732 100644 --- a/auto-creamapi/App.xaml.cs +++ b/auto-creamapi/App.xaml.cs @@ -10,7 +10,7 @@ namespace auto_creamapi { protected override void RegisterSetup() { - this.RegisterSetupType>(); + this.RegisterSetupType>(); } } } \ No newline at end of file diff --git a/auto-creamapi/Core/App.cs b/auto-creamapi/Core/MainApplication.cs similarity index 90% rename from auto-creamapi/Core/App.cs rename to auto-creamapi/Core/MainApplication.cs index f64d409..2201b8a 100644 --- a/auto-creamapi/Core/App.cs +++ b/auto-creamapi/Core/MainApplication.cs @@ -4,7 +4,7 @@ using MvvmCross.ViewModels; namespace auto_creamapi.Core { - public class App : MvxApplication + public class MainApplication : MvxApplication { public override void Initialize() { diff --git a/auto-creamapi/Utils/MyLogger.cs b/auto-creamapi/Utils/MyLogger.cs index a35a873..903e5a9 100644 --- a/auto-creamapi/Utils/MyLogger.cs +++ b/auto-creamapi/Utils/MyLogger.cs @@ -4,7 +4,7 @@ using Serilog.Exceptions; namespace auto_creamapi.Utils { - public class MyLogger + public static class MyLogger { public static readonly Logger Log = new LoggerConfiguration() .MinimumLevel.Debug() From 95361440f630ca4e8ba1775b8b2e07552b6dabe2 Mon Sep 17 00:00:00 2001 From: Jeddunk Date: Sat, 23 Dec 2023 22:55:26 +0100 Subject: [PATCH 11/17] Update to MvvmCross 8; Replace SteamfrontendAPI with fork to fix DLC issues; code refactoring --- .gitmodules | 3 ++ SteamStorefrontAPI | 1 + auto-creamapi.sln | 10 +++++-- auto-creamapi/App.xaml.cs | 2 +- .../Converters/ListOfDLcToStringConverter.cs | 6 ++-- auto-creamapi/Services/CacheService.cs | 18 +++++------- auto-creamapi/Setup.cs | 29 +++++++++++++++++++ auto-creamapi/Utils/Misc.cs | 4 +-- auto-creamapi/ViewModels/DownloadViewModel.cs | 11 ++++--- auto-creamapi/ViewModels/MainViewModel.cs | 15 ++++++---- .../ViewModels/SearchResultViewModel.cs | 13 ++++++--- auto-creamapi/auto-creamapi.csproj | 12 +++++--- 12 files changed, 89 insertions(+), 35 deletions(-) create mode 100644 .gitmodules create mode 160000 SteamStorefrontAPI create mode 100644 auto-creamapi/Setup.cs diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..bd149f0 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "SteamStorefrontAPI"] + path = SteamStorefrontAPI + url = https://git.jeddunk.xyz/jeddunk/SteamStorefrontAPI.git diff --git a/SteamStorefrontAPI b/SteamStorefrontAPI new file mode 160000 index 0000000..4560831 --- /dev/null +++ b/SteamStorefrontAPI @@ -0,0 +1 @@ +Subproject commit 45608312c692631476c3244e7e6560dd2935f895 diff --git a/auto-creamapi.sln b/auto-creamapi.sln index c220862..cc934dc 100644 --- a/auto-creamapi.sln +++ b/auto-creamapi.sln @@ -1,10 +1,12 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.30413.136 +# Visual Studio Version 17 +VisualStudioVersion = 17.8.34330.188 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "auto-creamapi", "auto-creamapi\auto-creamapi.csproj", "{26060B32-199E-4366-8FDE-6B1E10E0EF62}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SteamStorefrontAPI", "SteamStorefrontAPI\SteamStorefrontAPI\SteamStorefrontAPI.csproj", "{ECDB602D-4823-4F8E-8BAA-9554A08FA90F}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -15,6 +17,10 @@ Global {26060B32-199E-4366-8FDE-6B1E10E0EF62}.Debug|Any CPU.Build.0 = Debug|Any CPU {26060B32-199E-4366-8FDE-6B1E10E0EF62}.Release|Any CPU.ActiveCfg = Release|Any CPU {26060B32-199E-4366-8FDE-6B1E10E0EF62}.Release|Any CPU.Build.0 = Release|Any CPU + {ECDB602D-4823-4F8E-8BAA-9554A08FA90F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {ECDB602D-4823-4F8E-8BAA-9554A08FA90F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {ECDB602D-4823-4F8E-8BAA-9554A08FA90F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {ECDB602D-4823-4F8E-8BAA-9554A08FA90F}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/auto-creamapi/App.xaml.cs b/auto-creamapi/App.xaml.cs index 96ab732..d78cbe5 100644 --- a/auto-creamapi/App.xaml.cs +++ b/auto-creamapi/App.xaml.cs @@ -10,7 +10,7 @@ namespace auto_creamapi { protected override void RegisterSetup() { - this.RegisterSetupType>(); + this.RegisterSetupType(); } } } \ No newline at end of file diff --git a/auto-creamapi/Converters/ListOfDLcToStringConverter.cs b/auto-creamapi/Converters/ListOfDLcToStringConverter.cs index 9904374..5691ee6 100644 --- a/auto-creamapi/Converters/ListOfDLcToStringConverter.cs +++ b/auto-creamapi/Converters/ListOfDLcToStringConverter.cs @@ -31,24 +31,26 @@ namespace auto_creamapi.Converters { MyLogger.Log.Debug("ListOfDLcToStringConverter: ConvertBack"); var stringToDlcList = StringToDlcList(value); - return stringToDlcList.GetType() == targetType ? stringToDlcList : new ObservableCollection(); + return stringToDlcList.GetType() == targetType ? stringToDlcList : []; } private static ObservableCollection StringToDlcList(string value) { var result = new ObservableCollection(); - var expression = new Regex(@"(?.*) *= *(?.*)"); + var expression = new Regex("(?.*) *= *(?.*)"); using var reader = new StringReader(value); string line; while ((line = reader.ReadLine()) != null) { var match = expression.Match(line); if (match.Success) + { result.Add(new SteamApp { AppId = int.Parse(match.Groups["id"].Value), Name = match.Groups["name"].Value }); + } } return result; diff --git a/auto-creamapi/Services/CacheService.cs b/auto-creamapi/Services/CacheService.cs index 8d906a4..1d34765 100644 --- a/auto-creamapi/Services/CacheService.cs +++ b/auto-creamapi/Services/CacheService.cs @@ -37,7 +37,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 HashSet _cache = new HashSet(); + private HashSet _cache = []; public async Task Initialize() { @@ -113,7 +113,7 @@ namespace auto_creamapi.Services { MyLogger.Log.Debug("Type for Steam App {Name}: \"{Type}\"", steamApp.Name, steamAppDetails.Type); - if (steamAppDetails.Type == "game" | steamAppDetails.Type == "demo") + if (steamAppDetails.Type == "game" || steamAppDetails.Type == "demo") { steamAppDetails.DLC.ForEach(x => { @@ -121,8 +121,8 @@ namespace auto_creamapi.Services if (result == null) return; var dlcDetails = AppDetails.GetAsync(x).Result; dlcList.Add(dlcDetails != null - ? new SteamApp {AppId = dlcDetails.SteamAppId, Name = dlcDetails.Name} - : new SteamApp {AppId = x, Name = $"Unknown DLC {x}"}); + ? new SteamApp { AppId = dlcDetails.SteamAppId, Name = dlcDetails.Name } + : new SteamApp { AppId = x, Name = $"Unknown DLC {x}" }); }); dlcList.ForEach(x => MyLogger.Log.Debug("{AppId}={Name}", x.AppId, x.Name)); @@ -130,10 +130,6 @@ namespace auto_creamapi.Services if (!useSteamDb) return dlcList; - // Get DLC from SteamDB - // Get Cloudflare cookie - // Scrape and parse HTML page - // Add missing to DLC list var steamDbUri = new Uri($"https://steamdb.info/app/{steamApp.AppId}/dlc/"); var client = new HttpClient(); @@ -143,7 +139,9 @@ namespace auto_creamapi.Services var httpCall = client.GetAsync(steamDbUri); var response = await httpCall.ConfigureAwait(false); MyLogger.Log.Debug("{Status}", httpCall.Status.ToString()); - MyLogger.Log.Debug("{Boolean}", response.EnsureSuccessStatusCode().ToString()); + MyLogger.Log.Debug("{Boolean}", response.IsSuccessStatusCode.ToString()); + + response.EnsureSuccessStatusCode(); var readAsStringAsync = response.Content.ReadAsStringAsync(); var responseBody = await readAsStringAsync.ConfigureAwait(false); @@ -171,7 +169,7 @@ namespace auto_creamapi.Services } else { - var dlcApp = new SteamApp {AppId = Convert.ToInt32(dlcId), Name = dlcName}; + var dlcApp = new SteamApp { AppId = Convert.ToInt32(dlcId), Name = dlcName }; var i = dlcList.FindIndex(x => x.AppId.Equals(dlcApp.AppId)); if (i > -1) { diff --git a/auto-creamapi/Setup.cs b/auto-creamapi/Setup.cs new file mode 100644 index 0000000..9a5682a --- /dev/null +++ b/auto-creamapi/Setup.cs @@ -0,0 +1,29 @@ +using auto_creamapi.Core; +using auto_creamapi.Utils; +using Microsoft.Extensions.Logging; +using MvvmCross.Platforms.Wpf.Core; +using Serilog; +using Serilog.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace auto_creamapi +{ + public class Setup : MvxWpfSetup + { + protected override ILoggerFactory CreateLogFactory() + { + Log.Logger = MyLogger.Log; + + return new SerilogLoggerFactory(); + } + + protected override ILoggerProvider CreateLogProvider() + { + return new SerilogLoggerProvider(); + } + } +} diff --git a/auto-creamapi/Utils/Misc.cs b/auto-creamapi/Utils/Misc.cs index 3290f47..5e0883c 100644 --- a/auto-creamapi/Utils/Misc.cs +++ b/auto-creamapi/Utils/Misc.cs @@ -3,11 +3,11 @@ using System.Collections.ObjectModel; namespace auto_creamapi.Utils { - public class Misc + public static class Misc { public const string SpecialCharsRegex = "[^0-9a-zA-Z]+"; public const string DefaultLanguageSelection = "english"; - public static readonly ObservableCollection DefaultLanguages = new ObservableCollection(new[] + public static readonly ObservableCollection DefaultLanguages = new(new[] { "arabic", "bulgarian", diff --git a/auto-creamapi/ViewModels/DownloadViewModel.cs b/auto-creamapi/ViewModels/DownloadViewModel.cs index ba3230d..2ca63b5 100644 --- a/auto-creamapi/ViewModels/DownloadViewModel.cs +++ b/auto-creamapi/ViewModels/DownloadViewModel.cs @@ -5,6 +5,7 @@ using System.Windows; using auto_creamapi.Messenger; using auto_creamapi.Services; using auto_creamapi.Utils; +using Microsoft.Extensions.Logging; using MvvmCross.Logging; using MvvmCross.Navigation; using MvvmCross.Plugin.Messenger; @@ -12,24 +13,26 @@ using MvvmCross.ViewModels; namespace auto_creamapi.ViewModels { - + public class DownloadViewModel : MvxNavigationViewModel { private readonly IDownloadCreamApiService _download; private readonly IMvxNavigationService _navigationService; private readonly MvxSubscriptionToken _token; + private readonly ILogger _logger; private string _filename; private string _info; private double _progress; - public DownloadViewModel(IMvxLogProvider logProvider, IMvxNavigationService navigationService, - IDownloadCreamApiService download, IMvxMessenger messenger) : base(logProvider, navigationService) + public DownloadViewModel(ILoggerFactory loggerFactory, IMvxNavigationService navigationService, + IDownloadCreamApiService download, IMvxMessenger messenger) : base(loggerFactory, navigationService) { _navigationService = navigationService; + _logger = loggerFactory.CreateLogger(); _download = download; _token = messenger.Subscribe(OnProgressMessage); - MyLogger.Log.Debug("{Count}", messenger.CountSubscriptionsFor()); + _logger.LogDebug("{Count}", messenger.CountSubscriptionsFor()); } public string InfoLabel diff --git a/auto-creamapi/ViewModels/MainViewModel.cs b/auto-creamapi/ViewModels/MainViewModel.cs index 2d5e9d6..23bd933 100644 --- a/auto-creamapi/ViewModels/MainViewModel.cs +++ b/auto-creamapi/ViewModels/MainViewModel.cs @@ -7,6 +7,7 @@ using System.Threading.Tasks; using auto_creamapi.Models; using auto_creamapi.Services; using auto_creamapi.Utils; +using Microsoft.Extensions.Logging; using Microsoft.Win32; using MvvmCross.Commands; using MvvmCross.Navigation; @@ -19,6 +20,7 @@ namespace auto_creamapi.ViewModels private readonly ICacheService _cache; private readonly ICreamConfigService _config; + private readonly ILogger _logger; private readonly ICreamDllService _dll; private readonly IMvxNavigationService _navigationService; private int _appId; @@ -43,9 +45,10 @@ namespace auto_creamapi.ViewModels //private const string DlcRegexPattern = @"(?.*) *= *(?.*)"; public MainViewModel(ICacheService cache, ICreamConfigService config, ICreamDllService dll, - IMvxNavigationService navigationService) + IMvxNavigationService navigationService, ILoggerFactory loggerFactory) { _navigationService = navigationService; + _logger = loggerFactory.CreateLogger(); _cache = cache; _config = config; _dll = dll; @@ -56,7 +59,7 @@ namespace auto_creamapi.ViewModels { base.Prepare(); _config.Initialize(); - var tasks = new List {_cache.Initialize()}; + var tasks = new List { _cache.Initialize() }; if (!File.Exists("steam_api.dll") | !File.Exists("steam_api64.dll")) tasks.Add(_navigationService.Navigate()); //tasks.Add(_navigationService.Navigate()); @@ -310,7 +313,7 @@ namespace auto_creamapi.ViewModels } else { - MyLogger.Log.Warning("Empty game name, cannot initiate search!"); + _logger.LogWarning("Empty game name, cannot initiate search!"); } MainWindowEnabled = true; @@ -321,7 +324,7 @@ namespace auto_creamapi.ViewModels Status = "Trying to get DLC..."; if (AppId > 0) { - var app = new SteamApp {AppId = AppId, Name = GameName}; + var app = new SteamApp { AppId = AppId, Name = GameName }; var task = _cache.GetListOfDlc(app, UseSteamDb, IgnoreUnknown); MainWindowEnabled = false; var listOfDlc = await task.ConfigureAwait(false); @@ -341,7 +344,7 @@ namespace auto_creamapi.ViewModels else { Status = $"Could not get DLC for AppID {AppId}"; - MyLogger.Log.Error("GetListOfDlc: Invalid AppID {AppId}", AppId); + _logger.LogError("GetListOfDlc: Invalid AppID {AppId}", AppId); } } @@ -392,7 +395,7 @@ namespace auto_creamapi.ViewModels } else { - MyLogger.Log.Error("OpenURL: Invalid AppID {AppId}", AppId); + _logger.LogError("OpenURL: Invalid AppID {AppId}", AppId); Status = $"Could not open URL: Invalid AppID {AppId}"; } } diff --git a/auto-creamapi/ViewModels/SearchResultViewModel.cs b/auto-creamapi/ViewModels/SearchResultViewModel.cs index 361942e..82e401c 100644 --- a/auto-creamapi/ViewModels/SearchResultViewModel.cs +++ b/auto-creamapi/ViewModels/SearchResultViewModel.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Threading.Tasks; using auto_creamapi.Models; using auto_creamapi.Utils; +using Microsoft.Extensions.Logging; using MvvmCross.Commands; using MvvmCross.Logging; using MvvmCross.Navigation; @@ -13,16 +14,18 @@ namespace auto_creamapi.ViewModels IMvxViewModel, SteamApp> { private readonly IMvxNavigationService _navigationService; + private readonly ILogger _logger; private IEnumerable _steamApps; /*public override async Task Initialize() { await base.Initialize(); }*/ - public SearchResultViewModel(IMvxLogProvider logProvider, IMvxNavigationService navigationService) : base( - logProvider, navigationService) + public SearchResultViewModel(ILoggerFactory loggerFactory, IMvxNavigationService navigationService) : base( + loggerFactory, navigationService) { _navigationService = navigationService; + _logger = loggerFactory.CreateLogger(); } public IEnumerable Apps @@ -55,9 +58,11 @@ namespace auto_creamapi.ViewModels public override void ViewDestroy(bool viewFinishing = true) { - if (viewFinishing && CloseCompletionSource != null && !CloseCompletionSource.Task.IsCompleted && + if (viewFinishing && CloseCompletionSource?.Task.IsCompleted == false && !CloseCompletionSource.Task.IsFaulted) + { CloseCompletionSource?.TrySetCanceled(); + } base.ViewDestroy(viewFinishing); } @@ -66,7 +71,7 @@ namespace auto_creamapi.ViewModels { if (Selected != null) { - MyLogger.Log.Information("Successfully got app {Selected}", Selected); + _logger.LogInformation("Successfully got app {Selected}", Selected); await _navigationService.Close(this, Selected).ConfigureAwait(false); } } diff --git a/auto-creamapi/auto-creamapi.csproj b/auto-creamapi/auto-creamapi.csproj index 02e54fb..5830d4e 100644 --- a/auto-creamapi/auto-creamapi.csproj +++ b/auto-creamapi/auto-creamapi.csproj @@ -23,16 +23,16 @@ - - - + + + + - @@ -54,4 +54,8 @@ + + + + \ No newline at end of file From cfb9be69f7bfd0e07879cc8808cd03c8163524e8 Mon Sep 17 00:00:00 2001 From: Jeddunk Date: Sun, 24 Dec 2023 00:38:06 +0100 Subject: [PATCH 12/17] Add SteamDB link --- auto-creamapi/ViewModels/MainViewModel.cs | 28 ++++++++++++++++++++--- auto-creamapi/Views/MainView.xaml | 15 +++++++++--- 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/auto-creamapi/ViewModels/MainViewModel.cs b/auto-creamapi/ViewModels/MainViewModel.cs index 23bd933..ee5dcce 100644 --- a/auto-creamapi/ViewModels/MainViewModel.cs +++ b/auto-creamapi/ViewModels/MainViewModel.cs @@ -86,6 +86,8 @@ namespace auto_creamapi.ViewModels public IMvxCommand GoToForumThreadCommand => new MvxCommand(GoToForumThread); + public IMvxCommand GoToSteamdbCommand => new MvxCommand(GoToSteamdb); + // // ATTRIBUTES // // public bool MainWindowEnabled @@ -383,9 +385,29 @@ namespace auto_creamapi.ViewModels { var searchTerm = AppId; //$"{GameName.Replace(" ", "+")}+{appId}"; var destinationUrl = - "https://cs.rin.ru/forum/search.php?keywords=" + - searchTerm + - "&terms=any&fid[]=10&sf=firstpost&sr=topics&submit=Search"; + $"https://cs.rin.ru/forum/search.php?keywords={searchTerm}&terms=any&fid[]=10&sf=firstpost&sr=topics&submit=Search"; + var uri = new Uri(destinationUrl); + var process = new ProcessStartInfo(uri.AbsoluteUri) + { + UseShellExecute = true + }; + Process.Start(process); + } + else + { + _logger.LogError("OpenURL: Invalid AppID {AppId}", AppId); + Status = $"Could not open URL: Invalid AppID {AppId}"; + } + } + + private void GoToSteamdb() + { + Status = "Opening URL..."; + if (AppId > 0) + { + var searchTerm = AppId; //$"{GameName.Replace(" ", "+")}+{appId}"; + var destinationUrl = + $"https://steamdb.info/app/{searchTerm}/dlc/"; var uri = new Uri(destinationUrl); var process = new ProcessStartInfo(uri.AbsoluteUri) { diff --git a/auto-creamapi/Views/MainView.xaml b/auto-creamapi/Views/MainView.xaml index 154e9f4..719893e 100644 --- a/auto-creamapi/Views/MainView.xaml +++ b/auto-creamapi/Views/MainView.xaml @@ -56,9 +56,18 @@ - - Search for cs.rin.ru thread - + + + + + + + Search for cs.rin.ru thread... + + + Open SteamDB DLC page... + + Date: Sun, 24 Dec 2023 11:51:18 +0100 Subject: [PATCH 13/17] Try to use archived SteamDB page --- auto-creamapi/Services/CacheService.cs | 27 ++++++++++++----- auto-creamapi/Utils/AvailabeArchive.cs | 35 +++++++++++++++++++++++ auto-creamapi/ViewModels/MainViewModel.cs | 2 +- 3 files changed, 56 insertions(+), 8 deletions(-) create mode 100644 auto-creamapi/Utils/AvailabeArchive.cs diff --git a/auto-creamapi/Services/CacheService.cs b/auto-creamapi/Services/CacheService.cs index 1d34765..9cc0fa2 100644 --- a/auto-creamapi/Services/CacheService.cs +++ b/auto-creamapi/Services/CacheService.cs @@ -33,10 +33,6 @@ namespace auto_creamapi.Services private const string CachePath = "steamapps.json"; private const string SteamUri = "https://api.steampowered.com/ISteamApps/GetAppList/v2/"; - private const string UserAgent = - "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) " + - "Chrome/87.0.4280.88 Safari/537.36"; - private HashSet _cache = []; public async Task Initialize() @@ -128,15 +124,32 @@ namespace auto_creamapi.Services dlcList.ForEach(x => MyLogger.Log.Debug("{AppId}={Name}", x.AppId, x.Name)); MyLogger.Log.Information("Got DLC successfully..."); + // Return if Steam DB is deactivated if (!useSteamDb) return dlcList; - var steamDbUri = new Uri($"https://steamdb.info/app/{steamApp.AppId}/dlc/"); + string steamDbUrl = $"https://steamdb.info/app/{steamApp.AppId}/dlc/"; var client = new HttpClient(); - client.DefaultRequestHeaders.UserAgent.ParseAdd(UserAgent); + string archiveJson = await client.GetStringAsync($"https://archive.org/wayback/available?url={steamDbUrl}"); + var archiveResult = JsonSerializer.Deserialize(archiveJson); + + if (archiveResult == null || archiveResult.ArchivedSnapshots.Closest.Status != "200") + { + return dlcList; + } + + //language=regex + const string pattern = @"^(https?:\/\/web\.archive\.org\/web\/\d+)(\/.+)$"; + const string substitution = "$1id_$2"; + const RegexOptions options = RegexOptions.Multiline; + + Regex regex = new(pattern, options); + string newUrl = regex.Replace(archiveResult.ArchivedSnapshots.Closest.Url, substitution); + + //client.DefaultRequestHeaders.UserAgent.ParseAdd(UserAgent); MyLogger.Log.Information("Get SteamDB App"); - var httpCall = client.GetAsync(steamDbUri); + var httpCall = client.GetAsync(newUrl); var response = await httpCall.ConfigureAwait(false); MyLogger.Log.Debug("{Status}", httpCall.Status.ToString()); MyLogger.Log.Debug("{Boolean}", response.IsSuccessStatusCode.ToString()); diff --git a/auto-creamapi/Utils/AvailabeArchive.cs b/auto-creamapi/Utils/AvailabeArchive.cs new file mode 100644 index 0000000..f7561b1 --- /dev/null +++ b/auto-creamapi/Utils/AvailabeArchive.cs @@ -0,0 +1,35 @@ +using System.Text.Json.Serialization; + +namespace auto_creamapi.Utils +{ + + public class AvailableArchive + { + [JsonPropertyName("url")] + public string Url { get; set; } + + [JsonPropertyName("archived_snapshots")] + public ArchivedSnapshot ArchivedSnapshots { get; set; } + } + + public class ArchivedSnapshot + { + [JsonPropertyName("closest")] + public Closest Closest { get; set; } + } + + public class Closest + { + [JsonPropertyName("status")] + public string Status { get; set; } + + [JsonPropertyName("available")] + public bool Available { get; set; } + + [JsonPropertyName("url")] + public string Url { get; set; } + + [JsonPropertyName("timestamp")] + public string Timestamp { get; set; } + } +} diff --git a/auto-creamapi/ViewModels/MainViewModel.cs b/auto-creamapi/ViewModels/MainViewModel.cs index ee5dcce..296164d 100644 --- a/auto-creamapi/ViewModels/MainViewModel.cs +++ b/auto-creamapi/ViewModels/MainViewModel.cs @@ -323,7 +323,7 @@ namespace auto_creamapi.ViewModels private async Task GetListOfDlc() { - Status = "Trying to get DLC..."; + Status = "Trying to get DLC, please wait..."; if (AppId > 0) { var app = new SteamApp { AppId = AppId, Name = GameName }; From 5e2833e068413727d3a82ff8e196b7bb25db4eec Mon Sep 17 00:00:00 2001 From: Jeddunk Date: Sun, 24 Dec 2023 13:32:23 +0100 Subject: [PATCH 14/17] Overhaul Secrets implementation --- auto-creamapi/Utils/ISecrets.cs | 8 ++++++++ auto-creamapi/Utils/Secrets.EXAMPLE.cs | 14 -------------- auto-creamapi/ViewModels/DownloadViewModel.cs | 10 +++------- 3 files changed, 11 insertions(+), 21 deletions(-) create mode 100644 auto-creamapi/Utils/ISecrets.cs delete mode 100644 auto-creamapi/Utils/Secrets.EXAMPLE.cs diff --git a/auto-creamapi/Utils/ISecrets.cs b/auto-creamapi/Utils/ISecrets.cs new file mode 100644 index 0000000..01840ac --- /dev/null +++ b/auto-creamapi/Utils/ISecrets.cs @@ -0,0 +1,8 @@ +namespace auto_creamapi.Utils +{ + public interface ISecrets + { + public string ForumUsername(); + public string ForumPassword(); + } +} \ No newline at end of file diff --git a/auto-creamapi/Utils/Secrets.EXAMPLE.cs b/auto-creamapi/Utils/Secrets.EXAMPLE.cs deleted file mode 100644 index b25dd40..0000000 --- a/auto-creamapi/Utils/Secrets.EXAMPLE.cs +++ /dev/null @@ -1,14 +0,0 @@ -namespace auto_creamapi.Utils -{ - /// - /// To use this: - /// Rename file Secrets.EXAMPLE.cs to Secrets.cs - /// Rename class Secrets_REMOVETHIS to Secrets - /// Enter the relevant info below - /// - public static class Secrets_REMOVETHIS - { - public const string ForumUsername = "Enter username here"; - public const string ForumPassword = "Enter password here"; - } -} \ No newline at end of file diff --git a/auto-creamapi/ViewModels/DownloadViewModel.cs b/auto-creamapi/ViewModels/DownloadViewModel.cs index 2ca63b5..238509c 100644 --- a/auto-creamapi/ViewModels/DownloadViewModel.cs +++ b/auto-creamapi/ViewModels/DownloadViewModel.cs @@ -1,19 +1,16 @@ using System; -using System.Net.Http; using System.Threading.Tasks; using System.Windows; using auto_creamapi.Messenger; using auto_creamapi.Services; using auto_creamapi.Utils; using Microsoft.Extensions.Logging; -using MvvmCross.Logging; using MvvmCross.Navigation; using MvvmCross.Plugin.Messenger; using MvvmCross.ViewModels; namespace auto_creamapi.ViewModels { - public class DownloadViewModel : MvxNavigationViewModel { private readonly IDownloadCreamApiService _download; @@ -25,6 +22,8 @@ namespace auto_creamapi.ViewModels private string _info; private double _progress; + private readonly Secrets _secrets = new(); + public DownloadViewModel(ILoggerFactory loggerFactory, IMvxNavigationService navigationService, IDownloadCreamApiService download, IMvxMessenger messenger) : base(loggerFactory, navigationService) { @@ -80,10 +79,8 @@ namespace auto_creamapi.ViewModels try { await base.Initialize().ConfigureAwait(false); - var download = _download.Download(Secrets.ForumUsername, Secrets.ForumPassword); + var download = _download.Download(_secrets.ForumUsername(), _secrets.ForumPassword()); var filename = await download.ConfigureAwait(false); - /*var extract = _download.Extract(filename); - await extract;*/ var extract = _download.Extract(filename); await extract.ConfigureAwait(false); _token.Dispose(); @@ -102,7 +99,6 @@ namespace auto_creamapi.ViewModels private void OnProgressMessage(ProgressMessage obj) { - //MyLogger.Log.Debug($"{obj.Filename}: {obj.BytesTransferred}"); InfoLabel = obj.Info; FilenameLabel = obj.Filename; Progress = obj.PercentComplete; From d56e4802863981d7359d413eb4f6fe3da6a20876 Mon Sep 17 00:00:00 2001 From: Jeddunk Date: Mon, 25 Dec 2023 13:35:46 +0100 Subject: [PATCH 15/17] Update submodule --- SteamStorefrontAPI | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SteamStorefrontAPI b/SteamStorefrontAPI index 4560831..c1fc8a5 160000 --- a/SteamStorefrontAPI +++ b/SteamStorefrontAPI @@ -1 +1 @@ -Subproject commit 45608312c692631476c3244e7e6560dd2935f895 +Subproject commit c1fc8a5d6f4852c9430a66f7bc3c57c7076d2a39 From 956b5e669369e2388928286ed7dbf772909ff5ae Mon Sep 17 00:00:00 2001 From: Jeddunk Date: Mon, 25 Dec 2023 20:56:54 +0100 Subject: [PATCH 16/17] Use latest SteamStorefrontAPI version --- auto-creamapi.sln | 6 ------ auto-creamapi/Services/CacheService.cs | 2 +- auto-creamapi/auto-creamapi.csproj | 5 +---- 3 files changed, 2 insertions(+), 11 deletions(-) diff --git a/auto-creamapi.sln b/auto-creamapi.sln index cc934dc..78be129 100644 --- a/auto-creamapi.sln +++ b/auto-creamapi.sln @@ -5,8 +5,6 @@ VisualStudioVersion = 17.8.34330.188 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "auto-creamapi", "auto-creamapi\auto-creamapi.csproj", "{26060B32-199E-4366-8FDE-6B1E10E0EF62}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SteamStorefrontAPI", "SteamStorefrontAPI\SteamStorefrontAPI\SteamStorefrontAPI.csproj", "{ECDB602D-4823-4F8E-8BAA-9554A08FA90F}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -17,10 +15,6 @@ Global {26060B32-199E-4366-8FDE-6B1E10E0EF62}.Debug|Any CPU.Build.0 = Debug|Any CPU {26060B32-199E-4366-8FDE-6B1E10E0EF62}.Release|Any CPU.ActiveCfg = Release|Any CPU {26060B32-199E-4366-8FDE-6B1E10E0EF62}.Release|Any CPU.Build.0 = Release|Any CPU - {ECDB602D-4823-4F8E-8BAA-9554A08FA90F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {ECDB602D-4823-4F8E-8BAA-9554A08FA90F}.Debug|Any CPU.Build.0 = Debug|Any CPU - {ECDB602D-4823-4F8E-8BAA-9554A08FA90F}.Release|Any CPU.ActiveCfg = Release|Any CPU - {ECDB602D-4823-4F8E-8BAA-9554A08FA90F}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/auto-creamapi/Services/CacheService.cs b/auto-creamapi/Services/CacheService.cs index 9cc0fa2..223bbe5 100644 --- a/auto-creamapi/Services/CacheService.cs +++ b/auto-creamapi/Services/CacheService.cs @@ -133,7 +133,7 @@ namespace auto_creamapi.Services string archiveJson = await client.GetStringAsync($"https://archive.org/wayback/available?url={steamDbUrl}"); var archiveResult = JsonSerializer.Deserialize(archiveJson); - if (archiveResult == null || archiveResult.ArchivedSnapshots.Closest.Status != "200") + if (archiveResult == null || archiveResult.ArchivedSnapshots.Closest?.Status != "200") { return dlcList; } diff --git a/auto-creamapi/auto-creamapi.csproj b/auto-creamapi/auto-creamapi.csproj index 5830d4e..09956af 100644 --- a/auto-creamapi/auto-creamapi.csproj +++ b/auto-creamapi/auto-creamapi.csproj @@ -33,6 +33,7 @@ + @@ -54,8 +55,4 @@ - - - - \ No newline at end of file From 50308906eb0625d72d25d69685744e187f5c9956 Mon Sep 17 00:00:00 2001 From: Jeddunk Date: Mon, 25 Dec 2023 20:59:00 +0100 Subject: [PATCH 17/17] Remove old SteamStorefrontAPI fork --- SteamStorefrontAPI | 1 - 1 file changed, 1 deletion(-) delete mode 160000 SteamStorefrontAPI diff --git a/SteamStorefrontAPI b/SteamStorefrontAPI deleted file mode 160000 index c1fc8a5..0000000 --- a/SteamStorefrontAPI +++ /dev/null @@ -1 +0,0 @@ -Subproject commit c1fc8a5d6f4852c9430a66f7bc3c57c7076d2a39