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