Skip to content

Commit

Permalink
Add demo to default IgnoredTypes filter
Browse files Browse the repository at this point in the history
  • Loading branch information
Citrinate committed Jan 26, 2025
1 parent e8e0ae4 commit ca2c3fb
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 35 deletions.
21 changes: 7 additions & 14 deletions FreePackages.Tests/Filters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ public void InitializePackageFilter () {
PackageFilter = new PackageFilter(new BotCache(), new List<FilterConfig>());
PackageFilter.UpdateUserData(File.ReadAllText("userdata_empty.json").ToJsonObject<Steam.UserData>());
Filter = new FilterConfig();
Filter.IgnoredTypes.Remove("Demo");
}

[TestCleanup]
public void CleanupPackageFilter() {
PackageFilter.UpdateUserData(File.ReadAllText("userdata_empty.json").ToJsonObject<Steam.UserData>());
Filter = new FilterConfig();
Filter.IgnoredTypes.Remove("Demo");
}

[TestMethod]
Expand Down Expand Up @@ -435,23 +437,14 @@ public void CanFilterByReleaseDate() {

[TestMethod]
public void CanFilterDemos() {
var defaultFilter = new FilterConfig();
var app = new FilterableApp(KeyValue.LoadAsText("demo_which_will_be_removed.txt"));

Assert.IsFalse(PackageFilter.IsWantedApp(app));
Assert.IsFalse(PackageFilter.IsAppWantedByFilter(app, Filter));

Filter.Types.Add("Demo");
var packageFilterWhichAllowsDemos = new PackageFilter(new BotCache(), new List<FilterConfig>() { Filter });
packageFilterWhichAllowsDemos.UpdateUserData(File.ReadAllText("userdata_empty.json").ToJsonObject<Steam.UserData>());
Assert.IsTrue(PackageFilter.IsAppIgnoredByFilter(app, defaultFilter));

Assert.IsTrue(packageFilterWhichAllowsDemos.IsWantedApp(app));
Assert.IsTrue(PackageFilter.IsAppWantedByFilter(app, Filter));

var package = new FilterablePackage(KeyValue.LoadAsText("package_with_demo_which_will_be_removed.txt"));
var package_app_1 = KeyValue.LoadAsText("demo_which_will_be_removed.txt");
package.AddPackageContents(new List<KeyValue>() { package_app_1 });
defaultFilter.IgnoredTypes.Remove("Demo");

Assert.IsTrue(packageFilterWhichAllowsDemos.IsWantedPackage(package));
Assert.IsFalse(PackageFilter.IsWantedPackage(package));
Assert.IsTrue(PackageFilter.IsAppWantedByFilter(app, defaultFilter));
Assert.IsFalse(PackageFilter.IsAppIgnoredByFilter(app, defaultFilter));
}
}
11 changes: 11 additions & 0 deletions FreePackages/FreePackages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ public async Task OnBotInitModules(Bot bot, IReadOnlyDictionary<string, JsonElem
case "FreePackagesFilter": {
FilterConfig? filter = configProperty.Value.ToJsonObject<FilterConfig>();
if (filter != null) {
// Handles filter config changes made in V1.6.0
if (filter.Types.Contains("Demo") && filter.IgnoredTypes.Contains("Demo")) {
filter.IgnoredTypes.Remove("Demo");
}

bot.ArchiLogger.LogGenericInfo("Free Packages Filter : " + filter.ToJsonText());
filterConfigs.Add(filter);
}
Expand All @@ -78,6 +83,12 @@ public async Task OnBotInitModules(Bot bot, IReadOnlyDictionary<string, JsonElem
case "FreePackagesFilters": {
List<FilterConfig>? filters = configProperty.Value.ToJsonObject<List<FilterConfig>>();
if (filters != null) {
// Handles filter config changes made in V1.6.0
foreach (FilterConfig filter in filters) {
if (filter.Types.Contains("Demo") && filter.IgnoredTypes.Contains("Demo")) {
filter.IgnoredTypes.Remove("Demo");
}
}
bot.ArchiLogger.LogGenericInfo("Free Packages Filters : " + filters.ToJsonText());
filterConfigs.AddRange(filters);
}
Expand Down
2 changes: 1 addition & 1 deletion FreePackages/PackageFilter/FilterConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ internal sealed class FilterConfig {
internal HashSet<uint> Tags { get; set; } = new();

[JsonInclude]
internal HashSet<string> IgnoredTypes { get; set; } = new();
internal HashSet<string> IgnoredTypes { get; set; } = new() {"Demo"};

[JsonInclude]
internal HashSet<uint> IgnoredTags { get; set; } = new();
Expand Down
15 changes: 0 additions & 15 deletions FreePackages/PackageFilter/PackageFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,6 @@ internal bool IsAppWantedByFilter(FilterableApp app, FilterConfig filter) {
return false;
}

if (app.Type == EAppType.Demo && !app.HasType(filter.Types)) {
// Demos are unwanted by default unless the filter explicitly applies to them
return false;
}

if (filter.Categories.Count > 0 && !app.HasCategory(filter.Categories, filter.RequireAllCategories)) {
// Unwanted due to missing categories
return false;
Expand Down Expand Up @@ -339,11 +334,6 @@ internal bool FilterOnlyAllowsPackages(FilterConfig filter) {

internal bool IsWantedApp(FilterableApp app) {
if (FilterConfigs.Count == 0) {
if (app.Type == EAppType.Demo) {
// Demos are unwanted by default
return false;
}

return true;
}

Expand All @@ -352,11 +342,6 @@ internal bool IsWantedApp(FilterableApp app) {

internal bool IsWantedPackage(FilterablePackage package) {
if (FilterConfigs.Count == 0) {
if (package.PackageContents.All(app => app.Type == EAppType.Demo)) {
// Demos are unwanted by default
return false;
}

return true;
}

Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ By default, the plugin will attempt to activate all free non-demo and non-playte
"MinReviewScore": 0,
"MinDaysOld": 0,
"IgnoredContentDescriptors": [],
"IgnoredTypes": [],
"IgnoredTypes": ["Demo"],
"IgnoredTags": [],
"IgnoredCategories": [],
"IgnoredAppIDs": [],
Expand All @@ -91,9 +91,6 @@ All filter options are explained below:

`HashSet<string>` type with default value of `[]`. Packages must contain an app with one of the `TypeNames` specified here or they will not be added to your account. You can leave this empty to allow for all types. The available `TypeNames` for filtering are: `"Game"`, `"Application"`, `"Tool"`, `"Demo"`, `"DLC"`, `"Music"`, `"Video"`

> [!NOTE]
> Demos are filtered out by default. This is because Steam will automatically remove all uninstalled demos from your account eventually. However if you specify in your `Types` that you do want demos, then they will be included for that filter.
---

#### Tags
Expand Down Expand Up @@ -340,7 +337,10 @@ All filter options are explained below:

#### IgnoredTypes

`HashSet<string>` type with default value of `[]`. Packages containing apps with any of the `TypeNames` specified here will not be added to your account. Refer to [Types](#types) for more information about `TypeNames`.
`HashSet<string>` type with default value of `["Demo"]`. Packages containing apps with any of the `TypeNames` specified here will not be added to your account. Refer to [Types](#types) for more information about `TypeNames`.

> [!NOTE]
> Demos are filtered out by default. This is because Steam has at times removed all uninstalled demos from accounts. If you'd like the plugin to activate demos, you can do so by setting `IgnoredTypes` to `[]`, or some other value that doesn't include `"Demo"`.
---

Expand Down

0 comments on commit ca2c3fb

Please sign in to comment.