Skip to content

Commit

Permalink
misc
Browse files Browse the repository at this point in the history
  • Loading branch information
chr233 committed Aug 3, 2024
1 parent 790a041 commit 5522ee7
Show file tree
Hide file tree
Showing 17 changed files with 30 additions and 41 deletions.
5 changes: 3 additions & 2 deletions ASFEnhance/ASFEnhance.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using ArchiSteamFarm.Core;
using ArchiSteamFarm.Helpers.Json;
using ArchiSteamFarm.Plugins.Interfaces;
using ArchiSteamFarm.Steam;
using ArchiSteamFarm.Web.GitHub.Data;
Expand Down Expand Up @@ -72,7 +73,7 @@ public Task OnASFInit(IReadOnlyDictionary<string, JsonElement>? additionalConfig
{
try
{
config = JsonSerializer.Deserialize<PluginConfig>(configValue);
config = configValue.ToJsonObject<PluginConfig>();
if (config != null)
{
break;
Expand Down Expand Up @@ -1154,7 +1155,7 @@ public Task OnLoaded()
}
catch (Exception ex) //错误日志
{
var cfg = JsonSerializer.Serialize(Config, DebugJsonOptions);
var cfg = Config.ToJsonText();

var sb = new StringBuilder();
sb.AppendLine(Langs.ErrorLogTitle);
Expand Down
5 changes: 5 additions & 0 deletions ASFEnhance/ASFEnhance.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@
<Static>True</Static>
</Using>
</ItemGroup>

<ItemGroup>
<Folder Include="WishList\新文件夹1\" />
<Folder Include="WishList\新文件夹\" />
</ItemGroup>

<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Copy SourceFiles="$(TargetPath)" DestinationFolder="..\ArchiSteamFarm\ArchiSteamFarm\bin\$(Configuration)\$(TargetFramework)\plugins\" SkipUnchangedFiles="true" />
Expand Down
6 changes: 3 additions & 3 deletions ASFEnhance/Account/HtmlParser.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using AngleSharp.Dom;
using ArchiSteamFarm.Core;
using ArchiSteamFarm.Helpers.Json;
using ArchiSteamFarm.Web.Responses;
using ASFEnhance.Data;
using ASFEnhance.Data.Plugin;
using System.Globalization;
using System.Text;
using System.Text.Json;
using static ASFEnhance.Account.CurrencyHelper;

namespace ASFEnhance.Account;
Expand Down Expand Up @@ -34,7 +34,7 @@ internal static class HtmlParser
content = match.Groups[1].Value;
try
{
var cursorData = JsonSerializer.Deserialize<AccountHistoryResponse.CursorData>(content, JsonOptions);
var cursorData = content.ToJsonObject<AccountHistoryResponse.CursorData>();
return cursorData;
}
catch
Expand Down Expand Up @@ -424,7 +424,7 @@ decimal ParseMoneyString(string strMoney)
}
try
{
var optionsList = JsonSerializer.Deserialize<List<NotificationPayload>>(payload, JsonOptions);
var optionsList = payload.ToJsonObject<List<NotificationPayload>>();
if (optionsList == null)
{
return null;
Expand Down
4 changes: 2 additions & 2 deletions ASFEnhance/Account/WebRequest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using ArchiSteamFarm.Core;
using ArchiSteamFarm.Helpers.Json;
using ArchiSteamFarm.Steam;
using ArchiSteamFarm.Web.Responses;
using ASFEnhance.Data;
Expand All @@ -7,7 +8,6 @@
using ASFEnhance.Data.Plugin;
using System.Net;
using System.Text;
using System.Text.Json;
using static ASFEnhance.Account.CurrencyHelper;

namespace ASFEnhance.Account;
Expand Down Expand Up @@ -301,7 +301,7 @@ internal static async Task<bool> RemoveLicense(Bot bot, uint subId)
new(NotificationType.SteamTurnNotification,option.SteamTurnNotification),
};

var json = JsonSerializer.Serialize(optionList, JsonOptions);
var json = optionList.ToJsonText();

var data = new Dictionary<string, string>(11) {
{ "notificationpreferences", json },
Expand Down
10 changes: 5 additions & 5 deletions ASFEnhance/Cart/WebRequest.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using ArchiSteamFarm.Core;
using ArchiSteamFarm.Helpers.Json;
using ArchiSteamFarm.Steam;
using ArchiSteamFarm.Steam.Integration;
using ArchiSteamFarm.Web.Responses;
using ASFEnhance.Data;
using ASFEnhance.Data.Common;
using ASFEnhance.Data.IAccountCartService;
using ASFEnhance.Data.Plugin;
using System.Text.Json;
namespace ASFEnhance.Cart;

internal static class WebRequest
Expand Down Expand Up @@ -73,7 +73,7 @@ internal static class WebRequest
},
};

var json = JsonSerializer.Serialize(payload, JsonOptions);
var json = payload.ToJsonText();
var token = bot.AccessToken ?? throw new AccessTokenNullException();
var request = new Uri(SteamApiURL, $"/IAccountCartService/AddItemsToCart/v1/?access_token={token}");
var data = new Dictionary<string, string>
Expand Down Expand Up @@ -119,7 +119,7 @@ internal static class WebRequest
},
};

var json = JsonSerializer.Serialize(payload, JsonOptions);
var json = payload.ToJsonText();
var token = bot.AccessToken ?? throw new AccessTokenNullException();
var request = new Uri(SteamApiURL, $"/IAccountCartService/AddItemsToCart/v1/?access_token={token}");
var data = new Dictionary<string, string>
Expand Down Expand Up @@ -155,7 +155,7 @@ internal static class WebRequest
},
};

var json = JsonSerializer.Serialize(payload, JsonOptions);
var json = payload.ToJsonText();
var token = bot.AccessToken ?? throw new AccessTokenNullException();
var request = new Uri(SteamApiURL, $"/IAccountCartService/ModifyLineItem/v1/?access_token={token}");
var data = new Dictionary<string, string>
Expand All @@ -182,7 +182,7 @@ internal static class WebRequest
UserCountry = WalletCurrency2UserCountry(bot.WalletCurrency),
};

var json = JsonSerializer.Serialize(payload, JsonOptions);
var json = payload.ToJsonText();
var token = bot.AccessToken ?? throw new AccessTokenNullException();
var request = new Uri(SteamApiURL, $"/IAccountCartService/RemoveItemFromCart/v1/?access_token={token}");
var data = new Dictionary<string, string>
Expand Down
4 changes: 2 additions & 2 deletions ASFEnhance/Curator/HtmlParser.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using ArchiSteamFarm.Helpers.Json;
using ASFEnhance.Data;
using System.Text.Json;
using System.Text.RegularExpressions;

namespace ASFEnhance.Curator;
Expand All @@ -25,7 +25,7 @@ internal static class HtmlParser
try
{
string jsonStr = match.Groups[1].Value;
var data = JsonSerializer.Deserialize<HashSet<CuratorItem>>(jsonStr, JsonOptions);
var data = jsonStr.ToJsonObject<HashSet<CuratorItem>>();
return data;
}
catch (Exception ex)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using ASFEnhance.Data.Common;
using System.Text.Json.Serialization;

namespace ASFEnhance.Data.IAccountCartService;
Expand Down
1 change: 0 additions & 1 deletion ASFEnhance/Data/WebApi/AJaxFollowResponse.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using ArchiSteamFarm.Steam.Data;
using ASFEnhance.Data.Common;
using System.Text.Json.Serialization;

Expand Down
4 changes: 2 additions & 2 deletions ASFEnhance/Event/WebRequest.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using AngleSharp.Dom;
using ArchiSteamFarm.Core;
using ArchiSteamFarm.Helpers.Json;
using ArchiSteamFarm.Steam;
using ASFEnhance.Data;
using System.Text;
using System.Text.Json;

namespace ASFEnhance.Event;

Expand Down Expand Up @@ -269,7 +269,7 @@ internal static async Task MakeWinterSteamAwardVote(Bot bot, int gameID, int cat
var configEle = response?.Content?.QuerySelector<IElement>("#application_config");
var config = configEle?.GetAttribute("data-steam_awards_config") ?? "";

var data = JsonSerializer.Deserialize<SteamAwardVoteData>(config, JsonOptions);
var data = config.ToJsonObject<SteamAwardVoteData>();

if (data == null)
{
Expand Down
5 changes: 2 additions & 3 deletions ASFEnhance/Explorer/Command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using ArchiSteamFarm.Localization;
using ArchiSteamFarm.Steam;
using ArchiSteamFarm.Steam.Storage;
using System.Text.Json;

namespace ASFEnhance.Explorer;

Expand Down Expand Up @@ -139,7 +138,7 @@ internal static class Command

var newValue = bot.BotConfig.FarmingPreferences | BotConfig.EFarmingPreferences.AutoSteamSaleEvent;

var jsonObject = JsonSerializer.Deserialize<Dictionary<string, object>>(currentJson, JsonUtilities.DefaultJsonSerialierOptions);
var jsonObject = currentJson.ToJsonObject<Dictionary<string, object>>();
if (jsonObject != null)
{
if (jsonObject.ContainsKey("FarmingPreferences"))
Expand All @@ -151,7 +150,7 @@ internal static class Command
jsonObject.Add("FarmingPreferences", newValue);
}

currentJson = JsonSerializer.Serialize(jsonObject, JsonUtilities.IndentedJsonSerialierOptions);
currentJson = jsonObject.ToJsonText();
}

await File.WriteAllTextAsync(filePath, currentJson).ConfigureAwait(false);
Expand Down
1 change: 0 additions & 1 deletion ASFEnhance/Inventory/WebRequest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using ArchiSteamFarm.Steam;
using ASFEnhance.Data;
using ASFEnhance.Data.Common;


namespace ASFEnhance.Inventory;
Expand Down
4 changes: 2 additions & 2 deletions ASFEnhance/Profile/WebRequest.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using ArchiSteamFarm.Helpers.Json;
using ArchiSteamFarm.Steam;
using ArchiSteamFarm.Steam.Integration;
using ArchiSteamFarm.Web;
Expand All @@ -8,7 +9,6 @@
using System.Net;
using System.Net.Http.Headers;
using System.Text;
using System.Text.Json;

namespace ASFEnhance.Profile;

Expand Down Expand Up @@ -294,7 +294,7 @@ internal static async Task<bool> CraftBadge(Bot bot, int appId, bool foil, int l

try
{
var payload = JsonSerializer.Deserialize<EditProfilePayload>(json, JsonOptions);
var payload = json.ToJsonObject<EditProfilePayload>();
return payload;
}
catch (Exception ex)
Expand Down
5 changes: 2 additions & 3 deletions ASFEnhance/Store/WebRequest.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
using ArchiSteamFarm.Core;
using ArchiSteamFarm.Helpers.Json;
using ArchiSteamFarm.Steam;
using ASFEnhance.Data;
using ASFEnhance.Data.Common;
using ASFEnhance.Data.IStoreBrowseService;
using ASFEnhance.Data.Plugin;
using System.Text;
using System.Text.Json;

namespace ASFEnhance.Store;

Expand Down Expand Up @@ -247,7 +246,7 @@ internal static async Task<string> RedeemPoints(this Bot bot, uint defId)
},
};

var json = JsonSerializer.Serialize(payload, JsonOptions);
var json = payload.ToJsonText();
var encJson = UrlEncode(json);
var token = bot.AccessToken ?? throw new AccessTokenNullException();
var request = new Uri(SteamApiURL, $"/IStoreBrowseService/GetItems/v1/?access_token={token}&input_json={encJson}");
Expand Down
4 changes: 0 additions & 4 deletions ASFEnhance/Update/WebRequest.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
using ArchiSteamFarm.Core;
using ArchiSteamFarm.Web.GitHub;
using ArchiSteamFarm.Web.GitHub.Data;
using ArchiSteamFarm.Web.Responses;
using ASFEnhance.Data;
using System.IO.Compression;

namespace ASFEnhance.Update;

Expand Down
9 changes: 0 additions & 9 deletions ASFEnhance/Utils.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using ArchiSteamFarm.Core;
using ArchiSteamFarm.Helpers.Json;
using ArchiSteamFarm.NLog;
using ArchiSteamFarm.Steam;
using ArchiSteamFarm.Steam.Integration;
Expand All @@ -11,7 +10,6 @@
using System.Collections.ObjectModel;
using System.Reflection;
using System.Text;
using System.Text.Json;
using static ArchiSteamFarm.Steam.Integration.ArchiWebHandler;

namespace ASFEnhance;
Expand Down Expand Up @@ -353,13 +351,6 @@ public static Task<bool> UrlPost(this ArchiWebHandler handler,
bool allowSessionRefresh = true,
CancellationToken cancellationToken = default) => handler.UrlPostWithSession(request, null, data, referer, requestOptions, ESession.None, checkSessionPreemptively, maxTries, rateLimitingDelay, allowSessionRefresh, cancellationToken);

/// <summary>
/// Json序列化设置
/// </summary>
public static JsonSerializerOptions JsonOptions => JsonUtilities.DefaultJsonSerialierOptions;

public static JsonSerializerOptions DebugJsonOptions => JsonUtilities.IndentedJsonSerialierOptions;

internal static string GetGifteeProfile(ulong accountId)
{
ulong steam32;
Expand Down
1 change: 1 addition & 0 deletions ASFEnhance/WishList/WebRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ internal static class WebRequest
/// </summary>
/// <param name="bot"></param>
/// <param name="gameId"></param>
/// <param name="isAddWishlist"></param>
/// <returns></returns>
internal static async Task<IgnoreGameResponse?> AddWishlist(this Bot bot, uint gameId, bool isAddWishlist)
{
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<Version>2.2.0.0</Version>
<Version>2.2.0.1</Version>
</PropertyGroup>

<PropertyGroup>
Expand Down

0 comments on commit 5522ee7

Please sign in to comment.