From 1d69b7b45a57fc26d33b8e6f2d139af887bdc8ab Mon Sep 17 00:00:00 2001 From: Jeddunk Date: Mon, 4 Jan 2021 16:14:10 +0100 Subject: [PATCH] Add option to ignore unknown DLC from SteamDB. Show amount of DLCs after getting list of DLCs successfully. --- auto-creamapi/MainWindow.xaml | 2 +- auto-creamapi/Services/CacheService.cs | 21 +++++++++++++------- auto-creamapi/ViewModels/MainViewModel.cs | 24 ++++++++++++++++++++--- auto-creamapi/Views/MainView.xaml | 8 ++++++-- 4 files changed, 42 insertions(+), 13 deletions(-) diff --git a/auto-creamapi/MainWindow.xaml b/auto-creamapi/MainWindow.xaml index ffcc975..7212a0c 100644 --- a/auto-creamapi/MainWindow.xaml +++ b/auto-creamapi/MainWindow.xaml @@ -6,6 +6,6 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" mc:Ignorable="d" - Title="Auto-CreamAPI 2" MinWidth="420" MinHeight="600" Width="420" Height="600"> + Title="Auto-CreamAPI 2" MinWidth="420" MinHeight="640" Width="560" Height="720"> \ No newline at end of file diff --git a/auto-creamapi/Services/CacheService.cs b/auto-creamapi/Services/CacheService.cs index 486a08a..61c7ee2 100644 --- a/auto-creamapi/Services/CacheService.cs +++ b/auto-creamapi/Services/CacheService.cs @@ -24,7 +24,7 @@ namespace auto_creamapi.Services public IEnumerable GetListOfAppsByName(string name); public SteamApp GetAppByName(string name); public SteamApp GetAppById(int appid); - public Task> GetListOfDlc(SteamApp steamApp, bool useSteamDb); + public Task> GetListOfDlc(SteamApp steamApp, bool useSteamDb, bool ignoreUnknown); } public class CacheService : ICacheService @@ -99,7 +99,7 @@ namespace auto_creamapi.Services return app; } - public async Task> GetListOfDlc(SteamApp steamApp, bool useSteamDb) + public async Task> GetListOfDlc(SteamApp steamApp, bool useSteamDb, bool ignoreUnknown) { MyLogger.Log.Information("Get DLC"); var dlcList = new List(); @@ -164,15 +164,22 @@ namespace auto_creamapi.Services var query3 = element.QuerySelectorAll("td"); 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.AppId.Equals(dlcApp.AppId)); - if (i > -1) + 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}"); } 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); + } } } diff --git a/auto-creamapi/ViewModels/MainViewModel.cs b/auto-creamapi/ViewModels/MainViewModel.cs index 074c476..3bda2a7 100644 --- a/auto-creamapi/ViewModels/MainViewModel.cs +++ b/auto-creamapi/ViewModels/MainViewModel.cs @@ -38,6 +38,8 @@ namespace auto_creamapi.ViewModels private bool _unlockAll; private bool _useSteamDb; + + private bool _ignoreUnknown; //private const string DlcRegexPattern = @"(?.*) *= *(?.*)"; public MainViewModel(ICacheService cache, ICreamConfigService config, ICreamDllService dll, @@ -224,6 +226,16 @@ namespace auto_creamapi.ViewModels } } + public bool IgnoreUnknown + { + get => _ignoreUnknown; + set + { + _ignoreUnknown = value; + RaisePropertyChanged(() => IgnoreUnknown); + } + } + private async Task OpenFile() { Status = "Waiting for file..."; @@ -251,12 +263,16 @@ namespace auto_creamapi.ViewModels var separator = Path.DirectorySeparatorChar; var strings = new List(dirPath.Split(separator)); var index = strings.Contains("common") ? strings.FindIndex(x => x.Equals("common")) + 1 : -1; - if (index == -1) index = strings.Contains("steamapps") ? strings.FindIndex(x => x.Equals("steamapps")) + 2 : -1; + if (index == -1) + index = strings.Contains("steamapps") + ? strings.FindIndex(x => x.Equals("steamapps")) + 2 + : -1; var s = index > -1 ? strings[index] : null; if (s != null) GameName = s; await Search(); await GetListOfDlc(); } + Status = "Ready."; } } @@ -289,12 +305,14 @@ namespace auto_creamapi.ViewModels AppId = navigateResult.AppId; } } + await GetListOfDlc(); } else { MyLogger.Log.Warning("Empty game name, cannot initiate search!"); } + MainWindowEnabled = true; } @@ -304,14 +322,14 @@ namespace auto_creamapi.ViewModels if (AppId > 0) { var app = new SteamApp {AppId = AppId, Name = GameName}; - var task = _cache.GetListOfDlc(app, UseSteamDb); + var task = _cache.GetListOfDlc(app, UseSteamDb, IgnoreUnknown); MainWindowEnabled = false; var listOfDlc = await task; if (task.IsCompletedSuccessfully) { listOfDlc.Sort((app1, app2) => app1.AppId.CompareTo(app2.AppId)); Dlcs = new ObservableCollection(listOfDlc); - Status = $"Got DLC for AppID {AppId}"; + Status = $"Got DLC for AppID {AppId} (Count: {Dlcs.Count})"; } else { diff --git a/auto-creamapi/Views/MainView.xaml b/auto-creamapi/Views/MainView.xaml index 021d61b..1686e0c 100644 --- a/auto-creamapi/Views/MainView.xaml +++ b/auto-creamapi/Views/MainView.xaml @@ -74,6 +74,7 @@ + @@ -85,6 +86,9 @@ + + FontFamily="../resources/#Courier Prime" Grid.Row="3" />