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 };