Skip to content

Commit

Permalink
Merge pull request #26 from Citrinate/asf6
Browse files Browse the repository at this point in the history
Update to ASF 6
  • Loading branch information
Citrinate authored Mar 9, 2024
2 parents aa431f2 + acd1595 commit a1c1d49
Show file tree
Hide file tree
Showing 22 changed files with 287 additions and 211 deletions.
2 changes: 1 addition & 1 deletion ArchiSteamFarm
Submodule ArchiSteamFarm updated 177 files
8 changes: 4 additions & 4 deletions FreePackages.Tests/Apps.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System.Collections.Generic;
using System.IO;
using ArchiSteamFarm.Helpers.Json;
using Microsoft.IdentityModel.Tokens;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json;
using SteamKit2;

namespace FreePackages.Tests;
Expand All @@ -15,13 +15,13 @@ public class Apps {
[TestInitialize]
public void InitializePackageFilter () {
PackageFilter = new PackageFilter(new BotCache(), new List<FilterConfig>());
PackageFilter.UpdateUserData(JsonConvert.DeserializeObject<UserData>(File.ReadAllText("userdata_empty.json")));
PackageFilter.UpdateUserData(File.ReadAllText("userdata_empty.json").ToJsonObject<UserData>());
PackageFilter.Country = "FOO";
}

[TestCleanup]
public void CleanupPackageFilter() {
PackageFilter.UpdateUserData(JsonConvert.DeserializeObject<UserData>(File.ReadAllText("userdata_empty.json")));
PackageFilter.UpdateUserData(File.ReadAllText("userdata_empty.json").ToJsonObject<UserData>());
PackageFilter.Country = "FOO";
}

Expand Down Expand Up @@ -51,7 +51,7 @@ public void CanDetectAvailableAppByState() {
[TestMethod]
public void CanDetectRedeemableAppWithAppRequirement() {
var app = new FilterableApp(KeyValue.LoadAsText("app_with_required_app.txt"));
var userData = JsonConvert.DeserializeObject<UserData>(File.ReadAllText("userdata_empty.json"));
var userData = File.ReadAllText("userdata_empty.json").ToJsonObject<UserData>();
userData.OwnedApps.Add(1086940);
PackageFilter.UpdateUserData(userData);

Expand Down
18 changes: 9 additions & 9 deletions FreePackages.Tests/Filters.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Collections.Generic;
using System.IO;
using ArchiSteamFarm.Helpers.Json;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json;
using SteamKit2;

namespace FreePackages.Tests;
Expand All @@ -15,13 +15,13 @@ public class Filters {
[TestInitialize]
public void InitializePackageFilter () {
PackageFilter = new PackageFilter(new BotCache(), new List<FilterConfig>());
PackageFilter.UpdateUserData(JsonConvert.DeserializeObject<UserData>(File.ReadAllText("userdata_empty.json")));
PackageFilter.UpdateUserData(File.ReadAllText("userdata_empty.json").ToJsonObject<UserData>());
Filter = new FilterConfig();
}

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

Expand Down Expand Up @@ -308,15 +308,15 @@ public void CanFilterByStoreData() {

Assert.IsFalse(PackageFilter.IsAppIgnoredByFilter(app, Filter));

PackageFilter.UpdateUserData(JsonConvert.DeserializeObject<UserData>(File.ReadAllText("userdata_with_ignored_apps.json")));
PackageFilter.UpdateUserData(File.ReadAllText("userdata_with_ignored_apps.json").ToJsonObject<UserData>());

Assert.IsTrue(PackageFilter.IsAppIgnoredByFilter(app, Filter));

PackageFilter.UpdateUserData(JsonConvert.DeserializeObject<UserData>(File.ReadAllText("userdata_with_excluded_tags.json")));
PackageFilter.UpdateUserData(File.ReadAllText("userdata_with_excluded_tags.json").ToJsonObject<UserData>());

Assert.IsTrue(PackageFilter.IsAppIgnoredByFilter(app, Filter));

PackageFilter.UpdateUserData(JsonConvert.DeserializeObject<UserData>(File.ReadAllText("userdata_with_excluded_content_descriptors.json")));
PackageFilter.UpdateUserData(File.ReadAllText("userdata_with_excluded_content_descriptors.json").ToJsonObject<UserData>());

Assert.IsTrue(PackageFilter.IsAppIgnoredByFilter(app, Filter));
}
Expand All @@ -333,7 +333,7 @@ public void CanUseMultipleFilters() {
filterB.Types.Add("Game");

var packageFilter = new PackageFilter(new BotCache(), new List<FilterConfig>() { filterA, filterB });
packageFilter.UpdateUserData(JsonConvert.DeserializeObject<UserData>(File.ReadAllText("userdata_empty.json")));
packageFilter.UpdateUserData(File.ReadAllText("userdata_empty.json").ToJsonObject<UserData>());

Assert.IsFalse(packageFilter.IsAppWantedByFilter(app, filterA));
Assert.IsTrue(packageFilter.IsAppIgnoredByFilter(app, filterA));
Expand Down Expand Up @@ -406,11 +406,11 @@ public void CanFilterByWishlist() {

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

PackageFilter.UpdateUserData(JsonConvert.DeserializeObject<UserData>(File.ReadAllText("userdata_with_wishlist_apps.json")));
PackageFilter.UpdateUserData(File.ReadAllText("userdata_with_wishlist_apps.json").ToJsonObject<UserData>());

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

PackageFilter.UpdateUserData(JsonConvert.DeserializeObject<UserData>(File.ReadAllText("userdata_with_followed_apps.json")));
PackageFilter.UpdateUserData(File.ReadAllText("userdata_with_followed_apps.json").ToJsonObject<UserData>());

Assert.IsTrue(PackageFilter.IsAppWantedByFilter(app, Filter));
}
Expand Down
6 changes: 3 additions & 3 deletions FreePackages.Tests/Packages.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Collections.Generic;
using System.IO;
using ArchiSteamFarm.Helpers.Json;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json;
using SteamKit2;

namespace FreePackages.Tests;
Expand All @@ -14,13 +14,13 @@ public class Packages {
[TestInitialize]
public void InitializePackageFilter () {
PackageFilter = new PackageFilter(new BotCache(), new List<FilterConfig>());
PackageFilter.UpdateUserData(JsonConvert.DeserializeObject<UserData>(File.ReadAllText("userdata_empty.json")));
PackageFilter.UpdateUserData(File.ReadAllText("userdata_empty.json").ToJsonObject<UserData>());
PackageFilter.Country = "FOO";
}

[TestCleanup]
public void CleanupPackageFilter() {
PackageFilter.UpdateUserData(JsonConvert.DeserializeObject<UserData>(File.ReadAllText("userdata_empty.json")));
PackageFilter.UpdateUserData(File.ReadAllText("userdata_empty.json").ToJsonObject<UserData>());
PackageFilter.Country = "FOO";
}

Expand Down
32 changes: 32 additions & 0 deletions FreePackages/AdapterBridge.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;
using System.Reflection;
using ArchiSteamFarm.Core;

// ASFEnhanced Adapter https://github.com/chr233/ASFEnhanceAdapterDemoPlugin

namespace FreePackages;
internal static class AdapterBridge {
public static bool InitAdapter(string pluginName, string pluginId, string? cmdPrefix, string? repoName, MethodInfo? cmdHandler) {
try {
var adapterEndpoint = Assembly.Load("ASFEnhance").GetType("ASFEnhance._Adapter_.Endpoint");
var registerModule = adapterEndpoint?.GetMethod("RegisterModule", BindingFlags.Static | BindingFlags.Public);
var pluinVersion = Assembly.GetExecutingAssembly().GetName().Version;

if (registerModule != null && adapterEndpoint != null) {
var result = registerModule?.Invoke(null, new object?[] { pluginName, pluginId, cmdPrefix, repoName, pluinVersion, cmdHandler });

if (result is string str) {
if (str == pluginName) {
return true;
} else {
ASF.ArchiLogger.LogGenericWarning(str);
}
}
}
} catch (Exception ex) {
ASF.ArchiLogger.LogGenericException(ex, "Community with ASFEnhance failed");
}

return false;
}
}
3 changes: 3 additions & 0 deletions FreePackages/Commands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ internal static class Commands {
switch (args.Length) {
case 1:
switch (args[0].ToUpperInvariant()) {
case "FREEPACKAGES" when access >= EAccess.FamilySharing:
return String.Format("{0} {1}", nameof(FreePackages), (typeof(FreePackages).Assembly.GetName().Version ?? new Version("0")).ToString());

case "CLEARFREEPACKAGESQUEUE":
return ResponseClearQueue(bot, access);

Expand Down
41 changes: 25 additions & 16 deletions FreePackages/Data/AppDetails.cs
Original file line number Diff line number Diff line change
@@ -1,42 +1,51 @@
using System.Collections.Generic;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace FreePackages {
internal sealed class AppDetails {
[JsonProperty(PropertyName = "success", Required = Required.Always)]
internal bool Success = false;
[JsonInclude]
[JsonPropertyName("success")]
[JsonRequired]
internal bool Success { get; private init; } = false;

[JsonProperty(PropertyName = "data", Required = Required.Default)]
internal AppDetailsData? Data = null;
[JsonInclude]
[JsonPropertyName("data")]
internal AppDetailsData? Data { get; private init; } = null;

[JsonConstructor]
internal AppDetails() {}
}

internal sealed class AppDetailsData {
[JsonProperty(PropertyName = "is_free", Required = Required.Default)]
internal bool IsFree = false;
[JsonInclude]
[JsonPropertyName("is_free")]
internal bool IsFree { get; private init; } = false;

[JsonProperty(PropertyName = "packages", Required = Required.Default)]
internal HashSet<uint> Packages = new();
[JsonInclude]
[JsonPropertyName("packages")]
internal HashSet<uint> Packages { get; private init; } = new();

[JsonProperty(PropertyName = "release_date", Required = Required.Default)]
internal AppDetailsReleaseDate? ReleaseDate = null;
[JsonInclude]
[JsonPropertyName("release_date")]
internal AppDetailsReleaseDate? ReleaseDate { get; private init; } = null;

[JsonInclude]
[JsonExtensionData]
internal Dictionary<string, JToken> AdditionalData = new();
internal Dictionary<string, JsonElement> AdditionalData { get; private init; } = new();

[JsonConstructor]
internal AppDetailsData() {}
}

internal sealed class AppDetailsReleaseDate {
[JsonProperty(PropertyName = "coming_soon", Required = Required.Default)]
internal bool ComingSoon = true;
[JsonInclude]
[JsonPropertyName("coming_soon")]
internal bool ComingSoon { get; private init; } = true;

[JsonInclude]
[JsonExtensionData]
internal Dictionary<string, JToken> AdditionalData = new();
internal Dictionary<string, JsonElement> AdditionalData { get; private init; } = new();

[JsonConstructor]
internal AppDetailsReleaseDate() {}
Expand Down
42 changes: 26 additions & 16 deletions FreePackages/Data/BotCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,44 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
using ArchiSteamFarm.Collections;
using ArchiSteamFarm.Core;
using ArchiSteamFarm.Helpers;
using ArchiSteamFarm.Helpers.Json;
using ArchiSteamFarm.Localization;
using Newtonsoft.Json;
using SteamKit2;

namespace FreePackages {
internal sealed class BotCache : SerializableFile {
[JsonProperty(Required = Required.DisallowNull)]
internal ConcurrentHashSet<Package> Packages { get; } = new(new PackageComparer());
[JsonInclude]
[JsonDisallowNull]
internal ConcurrentHashSet<Package> Packages { get; private set; } = new(new PackageComparer());

[JsonProperty(Required = Required.DisallowNull)]
internal ConcurrentHashSet<DateTime> Activations = new();
[JsonInclude]
[JsonDisallowNull]
internal ConcurrentHashSet<DateTime> Activations { get; private set; } = new();

[JsonProperty(Required = Required.DisallowNull)]
internal ConcurrentHashSet<uint> ChangedApps = new();
[JsonInclude]
[JsonDisallowNull]
internal ConcurrentHashSet<uint> ChangedApps { get; private set; } = new();

[JsonProperty(Required = Required.DisallowNull)]
internal ConcurrentHashSet<uint> ChangedPackages = new();
[JsonInclude]
[JsonDisallowNull]
internal ConcurrentHashSet<uint> ChangedPackages { get; private set; } = new();

[JsonProperty(Required = Required.DisallowNull)]
internal ConcurrentHashSet<uint> NewOwnedPackages = new();
[JsonInclude]
[JsonDisallowNull]
internal ConcurrentHashSet<uint> NewOwnedPackages { get; private set; } = new();

[JsonProperty(Required = Required.DisallowNull)]
internal ConcurrentHashSet<uint> SeenPackages = new();
[JsonInclude]
[JsonDisallowNull]
internal ConcurrentHashSet<uint> SeenPackages { get; private set; } = new();

[JsonProperty(Required = Required.DisallowNull)]
internal ConcurrentHashSet<uint> WaitlistedPlaytests = new();
[JsonInclude]
[JsonDisallowNull]
internal ConcurrentHashSet<uint> WaitlistedPlaytests { get; private set; } = new();

[JsonConstructor]
internal BotCache() { }
Expand All @@ -44,6 +52,8 @@ internal BotCache(string filePath) : this() {
FilePath = filePath;
}

protected override Task Save() => Save(this);

internal static async Task<BotCache?> CreateOrLoad(string filePath) {
if (string.IsNullOrEmpty(filePath)) {
throw new ArgumentNullException(nameof(filePath));
Expand All @@ -63,7 +73,7 @@ internal BotCache(string filePath) : this() {
return null;
}

botCache = JsonConvert.DeserializeObject<BotCache>(json);
botCache = json.ToJsonObject<BotCache>();
} catch (Exception e) {
ASF.ArchiLogger.LogGenericException(e);

Expand Down
7 changes: 4 additions & 3 deletions FreePackages/Data/CardApps.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Threading;
using System.Threading.Tasks;
using ArchiSteamFarm.Core;
using ArchiSteamFarm.Web.Responses;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace FreePackages {
internal static class CardApps {
Expand Down Expand Up @@ -46,7 +46,8 @@ private static async Task DoUpdate() {

private sealed class Badges {
[JsonExtensionData]
internal Dictionary<string, JToken> Data = new();
[JsonInclude]
internal Dictionary<string, JsonElement> Data { get; private init; } = new();
}
}
}
Loading

0 comments on commit a1c1d49

Please sign in to comment.