From 308f9a2e48b7e639955eb0cb2d8673999648158e Mon Sep 17 00:00:00 2001 From: erri120 Date: Mon, 3 Jan 2022 12:04:36 +0100 Subject: [PATCH] Update --- CHANGELOG.md | Bin 3292 -> 3580 bytes README.md | 21 ++++++++++--------- src/F95ZoneMetadata/F95ZoneMetadataPlugin.cs | 2 +- src/F95ZoneMetadata/Settings.cs | 7 ++++++- src/F95ZoneMetadata/SettingsView.xaml | 3 +++ src/F95ZoneMetadata/UpdateTracking.cs | 17 +++++++++++++-- 6 files changed, 36 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5f58f4d4139c0867baecec3b968b54d9b9c516d5..2f3a63ef7751e0d859768d26319127e814cb6092 100644 GIT binary patch delta 276 zcmYk1PY%IA6o-GT8sPw9)39Mb`r|abt432i@8#SE)o+2ZeYRn_{i@cw4kUE3%AM{6{+e@f|Gtu~Mbvytcmjs6Z diff --git a/README.md b/README.md index 64ec130..42a04fb 100644 --- a/README.md +++ b/README.md @@ -66,16 +66,17 @@ The search function is only available if you logged into your account in the set The following settings can be adjusted in _Add-ons..._ -> _Extensions settings_ -> _Metadata Sources_ -> _F95zone_: -| Name | Default Value | Description | -|---------------------------------------------------------------------|---------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| Login | - | Use this Login Button to log into F95zone with your account. If this does not work you can copy the required cookies from your browser into the text fields below. | -| Cookie `xf_csrf` | - | Cookie used for authentication. | -| Cookie `xf_user` | - | Cookie used for authentication. | -| Cookie `xf_tfa_trust` | - | Cookie used for authentication if the user has Two-Factor authentication enabled. If you do not have TFA enabled you don't need to set this value. | -| Which property should the F95zone labels be assigned to in Playnite | Features | You can decide whether the "Categories" from DLsite should go into the "Features", "Genres" or "Tags" field in Playnite | -| Which property should the F95zone tags be assigned to in Playnite | Tags | You can decide whether the "Genres" from DLsite should go into the "Features", "Genres" or "Tags" field in Playnite | -| Check for Updates on Startup | false | This Plugin will check for updates on startup if you want. You can also specify the minimum wait time between updates per game. | -| Update Interval in Days | 7 | This is the minimum wait time between update checking **per game**. This value must be a positive number. | +| Name | Default Value | Description | +|---------------------------------------------------------------------|---------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| Login | - | Use this Login Button to log into F95zone with your account. If this does not work you can copy the required cookies from your browser into the text fields below. | +| Cookie `xf_csrf` | - | Cookie used for authentication. | +| Cookie `xf_user` | - | Cookie used for authentication. | +| Cookie `xf_tfa_trust` | - | Cookie used for authentication if the user has Two-Factor authentication enabled. If you do not have TFA enabled you don't need to set this value. | +| Which property should the F95zone labels be assigned to in Playnite | Features | You can decide whether the "Categories" from DLsite should go into the "Features", "Genres" or "Tags" field in Playnite | +| Which property should the F95zone tags be assigned to in Playnite | Tags | You can decide whether the "Genres" from DLsite should go into the "Features", "Genres" or "Tags" field in Playnite | +| Check for Updates on Startup | false | This Plugin will check for updates on startup if you want. You can also specify the minimum wait time between updates per game. | +| Update Interval in Days | 7 | This is the minimum wait time between update checking **per game**. This value must be a positive number. | +| Look for Updates of Completed Games | false | Setting this to true will make the Plugin look for updates for games that have the F95zone "Completed" label. I don't recommend setting this to true because it is very unlikely that a game will receive an update once it is marked as "Completed" and will only put strain on the F95zone servers. | **Config location**: `3af84c02-7825-4cd6-b0bd-d0800d26ffc5/config.json` diff --git a/src/F95ZoneMetadata/F95ZoneMetadataPlugin.cs b/src/F95ZoneMetadata/F95ZoneMetadataPlugin.cs index 28daaff..a11919d 100644 --- a/src/F95ZoneMetadata/F95ZoneMetadataPlugin.cs +++ b/src/F95ZoneMetadata/F95ZoneMetadataPlugin.cs @@ -51,7 +51,7 @@ public override void OnApplicationStarted(OnApplicationStartedEventArgs args) var f95Games = _playniteAPI.Database.Games .Where(game => game.Links is not null && game.Links.Any(link => link.Name is not null && link.Name.Equals("F95zone", StringComparison.OrdinalIgnoreCase))) .Select(game => (game, tracking: _updateTracking.GetOrAdd(game))) - .Where(tuple => tuple.tracking.NeedsUpdate(_settings.UpdateDistance)) + .Where(tuple => tuple.tracking.NeedsUpdate(tuple.game, _settings)) .ToList(); _logger.LogInformation("Looking for updates for {Count} games", f95Games.Count); diff --git a/src/F95ZoneMetadata/Settings.cs b/src/F95ZoneMetadata/Settings.cs index 5bf5b4c..d9198ad 100644 --- a/src/F95ZoneMetadata/Settings.cs +++ b/src/F95ZoneMetadata/Settings.cs @@ -44,6 +44,8 @@ public class Settings : ISettings [DontSerialize] public TimeSpan UpdateDistance => TimeSpan.FromDays(DaysBetweenUpdate); + public bool UpdateCompletedGames { get; set; } = false; + public CookieContainer? CreateCookieContainer() { if (CookieUser is null || CookieCsrf is null) return null; @@ -94,6 +96,7 @@ public Settings(Plugin plugin, IPlayniteAPI playniteAPI) TagProperty = savedSettings.TagProperty; CheckForUpdates = savedSettings.CheckForUpdates; DaysBetweenUpdate = savedSettings.DaysBetweenUpdate; + UpdateCompletedGames = savedSettings.UpdateCompletedGames; } } @@ -155,7 +158,8 @@ public void BeginEdit() LabelProperty = LabelProperty, TagProperty = TagProperty, CheckForUpdates = CheckForUpdates, - DaysBetweenUpdate = DaysBetweenUpdate + DaysBetweenUpdate = DaysBetweenUpdate, + UpdateCompletedGames = UpdateCompletedGames }; } @@ -176,6 +180,7 @@ public void CancelEdit() TagProperty = _previousSettings.TagProperty; CheckForUpdates = _previousSettings.CheckForUpdates; DaysBetweenUpdate = _previousSettings.DaysBetweenUpdate; + UpdateCompletedGames = _previousSettings.UpdateCompletedGames; } public bool VerifySettings(out List errors) diff --git a/src/F95ZoneMetadata/SettingsView.xaml b/src/F95ZoneMetadata/SettingsView.xaml index 65cf6e9..90fdf0e 100644 --- a/src/F95ZoneMetadata/SettingsView.xaml +++ b/src/F95ZoneMetadata/SettingsView.xaml @@ -45,5 +45,8 @@ + + + diff --git a/src/F95ZoneMetadata/UpdateTracking.cs b/src/F95ZoneMetadata/UpdateTracking.cs index f64fecc..5585b0c 100644 --- a/src/F95ZoneMetadata/UpdateTracking.cs +++ b/src/F95ZoneMetadata/UpdateTracking.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using Extensions.Common; using Playnite.SDK.Models; namespace F95ZoneMetadata; @@ -30,8 +31,20 @@ public class GameTracking public DateTime LastChecked { get; set; } = DateTime.MinValue; - public bool NeedsUpdate(TimeSpan minDistance) + public bool NeedsUpdate(Game game, Settings settings) { - return DateTime.UtcNow - LastChecked > minDistance; + if (!settings.CheckForUpdates) return false; + if (DateTime.UtcNow - LastChecked < settings.UpdateDistance) return false; + if (settings.UpdateCompletedGames) return true; + + IEnumerable enumerable = settings.LabelProperty switch + { + PlayniteProperty.Features => game.Features, + PlayniteProperty.Genres => game.Genres, + PlayniteProperty.Tags => game.Tags, + _ => throw new ArgumentOutOfRangeException() + }; + + return !enumerable.Any(item => item.Name is not null && item.Name.Equals("Completed", StringComparison.OrdinalIgnoreCase)); } }