Skip to content
This repository has been archived by the owner on Mar 3, 2023. It is now read-only.

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
erri120 committed Jan 3, 2022
1 parent 0201d9d commit 308f9a2
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 14 deletions.
Binary file modified CHANGELOG.md
Binary file not shown.
21 changes: 11 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`

Expand Down
2 changes: 1 addition & 1 deletion src/F95ZoneMetadata/F95ZoneMetadataPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 6 additions & 1 deletion src/F95ZoneMetadata/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -94,6 +96,7 @@ public Settings(Plugin plugin, IPlayniteAPI playniteAPI)
TagProperty = savedSettings.TagProperty;
CheckForUpdates = savedSettings.CheckForUpdates;
DaysBetweenUpdate = savedSettings.DaysBetweenUpdate;
UpdateCompletedGames = savedSettings.UpdateCompletedGames;
}
}

Expand Down Expand Up @@ -155,7 +158,8 @@ public void BeginEdit()
LabelProperty = LabelProperty,
TagProperty = TagProperty,
CheckForUpdates = CheckForUpdates,
DaysBetweenUpdate = DaysBetweenUpdate
DaysBetweenUpdate = DaysBetweenUpdate,
UpdateCompletedGames = UpdateCompletedGames
};
}

Expand All @@ -176,6 +180,7 @@ public void CancelEdit()
TagProperty = _previousSettings.TagProperty;
CheckForUpdates = _previousSettings.CheckForUpdates;
DaysBetweenUpdate = _previousSettings.DaysBetweenUpdate;
UpdateCompletedGames = _previousSettings.UpdateCompletedGames;
}

public bool VerifySettings(out List<string> errors)
Expand Down
3 changes: 3 additions & 0 deletions src/F95ZoneMetadata/SettingsView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,8 @@

<TextBlock Text="Update Interval in Days:"/>
<TextBox TextChanged="TextBoxBase_OnTextChanged" Text="{Binding Mode=TwoWay, Path=DaysBetweenUpdate, Converter={StaticResource IntToStringConverter}}"/>

<TextBlock Text="Look for Updates of Completed Games:"/>
<CheckBox IsChecked="{Binding Mode=TwoWay, Path=UpdateCompletedGames}"/>
</StackPanel>
</UserControl>
17 changes: 15 additions & 2 deletions src/F95ZoneMetadata/UpdateTracking.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Extensions.Common;
using Playnite.SDK.Models;

namespace F95ZoneMetadata;
Expand Down Expand Up @@ -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<DatabaseObject> 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));
}
}

0 comments on commit 308f9a2

Please sign in to comment.