Misc code improvements

This commit is contained in:
JustArchi 2020-12-05 20:27:10 +01:00
parent f66d5e6116
commit 6265aa7271
23 changed files with 38 additions and 60 deletions

View file

@ -287,7 +287,7 @@ namespace ArchiSteamFarm {
}
// Auto update logic starts here
if (releaseResponse.Assets == null) {
if (releaseResponse.Assets.IsEmpty) {
ArchiLogger.LogGenericWarning(Strings.ErrorUpdateNoAssets);
return null;

View file

@ -170,7 +170,7 @@ namespace ArchiSteamFarm {
yield break;
}
if ((response.Content.Assets == null) || (response.Content.Assets.Count == 0) || (response.Content.Descriptions == null) || (response.Content.Descriptions.Count == 0)) {
if ((response.Content.Assets.Count == 0) || (response.Content.Descriptions.Count == 0)) {
throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, Strings.ErrorObjectIsNull, nameof(response.Content.Assets) + " || " + nameof(response.Content.Descriptions)));
}

View file

@ -297,7 +297,6 @@ namespace ArchiSteamFarm {
private string? BackingSteamPassword = DefaultSteamPassword;
[JsonProperty(PropertyName = SharedInfo.UlongCompatibilityStringPrefix + nameof(SteamMasterClanID), Required = Required.DisallowNull)]
private string SSteamMasterClanID {
get => SteamMasterClanID.ToString(CultureInfo.InvariantCulture);
@ -313,7 +312,7 @@ namespace ArchiSteamFarm {
}
[JsonConstructor]
private BotConfig() { }
internal BotConfig() { }
internal (bool Valid, string? ErrorMessage) CheckValidation() {
if (BotBehaviour > EBotBehaviour.All) {

View file

@ -101,7 +101,7 @@ namespace ArchiSteamFarm {
[SuppressMessage("ReSharper", "ClassCannotBeInstantiated")]
internal sealed class ReleaseResponse {
[JsonProperty(PropertyName = "assets", Required = Required.Always)]
internal readonly ImmutableHashSet<Asset>? Assets;
internal readonly ImmutableHashSet<Asset> Assets = ImmutableHashSet<Asset>.Empty;
[JsonProperty(PropertyName = "prerelease", Required = Required.Always)]
internal readonly bool IsPreRelease;
@ -110,7 +110,7 @@ namespace ArchiSteamFarm {
internal readonly DateTime PublishedAt;
[JsonProperty(PropertyName = "tag_name", Required = Required.Always)]
internal readonly string? Tag;
internal readonly string Tag = "";
internal string? ChangelogHTML {
get {

View file

@ -283,7 +283,6 @@ namespace ArchiSteamFarm {
private string? BackingWebProxyPassword = DefaultWebProxyPassword;
[JsonProperty(PropertyName = SharedInfo.UlongCompatibilityStringPrefix + nameof(SteamOwnerID), Required = Required.DisallowNull)]
private string SSteamOwnerID {
get => SteamOwnerID.ToString(CultureInfo.InvariantCulture);

View file

@ -109,10 +109,6 @@ namespace ArchiSteamFarm.IPC.Controllers.Api {
throw new InvalidOperationException(nameof(ASF.GlobalConfig));
}
if (request.GlobalConfig == null) {
return BadRequest(new GenericResponse(false, string.Format(CultureInfo.CurrentCulture, Strings.ErrorIsEmpty, nameof(request.GlobalConfig))));
}
(bool valid, string? errorMessage) = request.GlobalConfig.CheckValidation();
if (!valid) {

View file

@ -97,10 +97,6 @@ namespace ArchiSteamFarm.IPC.Controllers.Api {
throw new InvalidOperationException(nameof(Bot.Bots));
}
if (request.BotConfig == null) {
return BadRequest(new GenericResponse(false, string.Format(CultureInfo.CurrentCulture, Strings.ErrorIsEmpty, nameof(request.BotConfig))));
}
(bool valid, string? errorMessage) = request.BotConfig.CheckValidation();
if (!valid) {
@ -225,7 +221,7 @@ namespace ArchiSteamFarm.IPC.Controllers.Api {
throw new ArgumentNullException(nameof(request));
}
if ((request.GamesToRedeemInBackground == null) || (request.GamesToRedeemInBackground.Count == 0)) {
if (request.GamesToRedeemInBackground.Count == 0) {
return BadRequest(new GenericResponse(false, string.Format(CultureInfo.CurrentCulture, Strings.ErrorIsEmpty, nameof(request.GamesToRedeemInBackground))));
}
@ -330,7 +326,7 @@ namespace ArchiSteamFarm.IPC.Controllers.Api {
throw new ArgumentNullException(nameof(request));
}
if ((request.KeysToRedeem == null) || (request.KeysToRedeem.Count == 0)) {
if (request.KeysToRedeem.Count == 0) {
return BadRequest(new GenericResponse(false, string.Format(CultureInfo.CurrentCulture, Strings.ErrorIsEmpty, nameof(request.KeysToRedeem))));
}
@ -482,7 +478,7 @@ namespace ArchiSteamFarm.IPC.Controllers.Api {
return BadRequest(new GenericResponse<IReadOnlyDictionary<string, GenericResponse>>(false, string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)));
}
IList<(bool Success, string Message)> results = await Utilities.InParallel(bots.Select(bot => bot.Actions.HandleTwoFactorAuthenticationConfirmations(request.Accept, request.AcceptedType, request.AcceptedCreatorIDs?.Count > 0 ? request.AcceptedCreatorIDs : null, request.WaitIfNeeded))).ConfigureAwait(false);
IList<(bool Success, string Message)> results = await Utilities.InParallel(bots.Select(bot => bot.Actions.HandleTwoFactorAuthenticationConfirmations(request.Accept, request.AcceptedType, request.AcceptedCreatorIDs.Count > 0 ? request.AcceptedCreatorIDs : null, request.WaitIfNeeded))).ConfigureAwait(false);
Dictionary<string, GenericResponse> result = new(bots.Count, Bot.BotsComparer);

View file

@ -38,7 +38,7 @@ namespace ArchiSteamFarm.IPC.Requests {
/// </summary>
[JsonProperty(Required = Required.Always)]
[Required]
public string? StringToEncrypt { get; private set; }
public string StringToEncrypt { get; private set; } = "";
[JsonConstructor]
private ASFEncryptRequest() { }

View file

@ -38,7 +38,7 @@ namespace ArchiSteamFarm.IPC.Requests {
/// </summary>
[JsonProperty(Required = Required.Always)]
[Required]
public string? StringToHash { get; private set; }
public string StringToHash { get; private set; } = "";
[JsonConstructor]
private ASFHashRequest() { }

View file

@ -31,7 +31,7 @@ namespace ArchiSteamFarm.IPC.Requests {
/// </summary>
[JsonProperty(Required = Required.Always)]
[Required]
public GlobalConfig? GlobalConfig { get; private set; }
public GlobalConfig GlobalConfig { get; private set; } = new();
[JsonConstructor]
private ASFRequest() { }

View file

@ -36,7 +36,7 @@ namespace ArchiSteamFarm.IPC.Requests {
/// </remarks>
[JsonProperty(Required = Required.Always)]
[Required]
public OrderedDictionary? GamesToRedeemInBackground { get; private set; }
public OrderedDictionary GamesToRedeemInBackground { get; private set; } = new();
[JsonConstructor]
private BotGamesToRedeemInBackgroundRequest() { }

View file

@ -35,7 +35,7 @@ namespace ArchiSteamFarm.IPC.Requests {
/// Specifies the value for given input type (declared in <see cref="Type" />)
/// </summary>
[JsonProperty(Required = Required.Always)]
public string? Value { get; private set; }
public string Value { get; private set; } = "";
[JsonConstructor]
private BotInputRequest() { }

View file

@ -32,7 +32,7 @@ namespace ArchiSteamFarm.IPC.Requests {
/// </summary>
[JsonProperty(Required = Required.Always)]
[Required]
public ImmutableHashSet<string>? KeysToRedeem { get; private set; }
public ImmutableHashSet<string> KeysToRedeem { get; private set; } = ImmutableHashSet<string>.Empty;
[JsonConstructor]
private BotRedeemRequest() { }

View file

@ -31,7 +31,7 @@ namespace ArchiSteamFarm.IPC.Requests {
/// </summary>
[JsonProperty(Required = Required.Always)]
[Required]
public string? NewName { get; private set; }
public string NewName { get; private set; } = "";
[JsonConstructor]
private BotRenameRequest() { }

View file

@ -31,7 +31,7 @@ namespace ArchiSteamFarm.IPC.Requests {
/// </summary>
[JsonProperty(Required = Required.Always)]
[Required]
public BotConfig? BotConfig { get; private set; }
public BotConfig BotConfig { get; private set; } = new();
[JsonConstructor]
private BotRequest() { }

View file

@ -32,7 +32,7 @@ namespace ArchiSteamFarm.IPC.Requests {
/// </summary>
[JsonProperty(Required = Required.Always)]
[Required]
public string? Command { get; private set; }
public string Command { get; private set; } = "";
internal CommandRequest(string command) {
if (string.IsNullOrEmpty(command)) {

View file

@ -40,12 +40,12 @@ namespace ArchiSteamFarm.IPC.Requests {
/// Specifies IDs of the confirmations that we're supposed to handle. CreatorID of the confirmation is equal to ID of the object that triggered it - e.g. ID of the trade offer, or ID of the market listing. If not provided, or empty array, all confirmation IDs are considered for an action.
/// </summary>
[JsonProperty(Required = Required.DisallowNull)]
public ImmutableHashSet<ulong>? AcceptedCreatorIDs { get; private set; }
public ImmutableHashSet<ulong> AcceptedCreatorIDs { get; private set; } = ImmutableHashSet<ulong>.Empty;
/// <summary>
/// Specifies the type of confirmations to handle. If not provided, all confirmation types are considered for an action.
/// </summary>
[JsonProperty(Required = Required.DisallowNull)]
[JsonProperty]
public MobileAuthenticator.Confirmation.EType? AcceptedType { get; private set; }
/// <summary>

View file

@ -34,7 +34,7 @@ namespace ArchiSteamFarm.IPC.Requests {
/// </remarks>
[Required]
[JsonProperty(Required = Required.Always)]
public string? URL { get; private set; }
public string URL { get; private set; } = "";
[JsonConstructor]
private WWWSendRequest() { }

View file

@ -30,7 +30,7 @@ namespace ArchiSteamFarm.IPC.Responses {
/// </summary>
[JsonProperty(Required = Required.Always)]
[Required]
public string? ChangelogHTML { get; private set; }
public string ChangelogHTML { get; private set; }
/// <summary>
/// Date of the release.
@ -51,14 +51,14 @@ namespace ArchiSteamFarm.IPC.Responses {
/// </summary>
[JsonProperty(Required = Required.Always)]
[Required]
public string? Version { get; private set; }
public string Version { get; private set; }
internal GitHubReleaseResponse(GitHub.ReleaseResponse releaseResponse) {
if (releaseResponse == null) {
throw new ArgumentNullException(nameof(releaseResponse));
}
ChangelogHTML = releaseResponse.ChangelogHTML;
ChangelogHTML = releaseResponse.ChangelogHTML ?? "";
ReleasedAt = releaseResponse.PublishedAt;
Stable = !releaseResponse.IsPreRelease;
Version = releaseResponse.Tag;

View file

@ -253,11 +253,11 @@ namespace ArchiSteamFarm.Json {
public sealed class Tag {
[JsonProperty(PropertyName = "category", Required = Required.Always)]
[PublicAPI]
public string? Identifier { get; private set; }
public string Identifier { get; private set; } = "";
[JsonProperty(PropertyName = "internal_name", Required = Required.Always)]
[PublicAPI]
public string? Value { get; private set; }
public string Value { get; private set; } = "";
internal Tag(string identifier, string value) {
Identifier = !string.IsNullOrEmpty(identifier) ? identifier : throw new ArgumentNullException(nameof(identifier));
@ -366,13 +366,13 @@ namespace ArchiSteamFarm.Json {
[SuppressMessage("ReSharper", "ClassCannotBeInstantiated")]
internal sealed class InventoryResponse : EResultResponse {
[JsonProperty(PropertyName = "assets", Required = Required.DisallowNull)]
internal readonly ImmutableHashSet<Asset>? Assets;
internal readonly ImmutableHashSet<Asset> Assets = ImmutableHashSet<Asset>.Empty;
[JsonProperty(PropertyName = "descriptions", Required = Required.DisallowNull)]
internal readonly ImmutableHashSet<Description>? Descriptions;
internal readonly ImmutableHashSet<Description> Descriptions = ImmutableHashSet<Description>.Empty;
[JsonProperty(PropertyName = "error", Required = Required.DisallowNull)]
internal readonly string? Error;
internal readonly string Error = "";
[JsonProperty(PropertyName = "total_inventory_count", Required = Required.DisallowNull)]
internal readonly uint TotalInventoryCount;
@ -414,10 +414,6 @@ namespace ArchiSteamFarm.Json {
internal sealed class Description {
internal Asset.ERarity Rarity {
get {
if (Tags == null) {
return Asset.ERarity.Unknown;
}
foreach (Asset.Tag tag in Tags) {
switch (tag.Identifier) {
case "droprate":
@ -444,10 +440,6 @@ namespace ArchiSteamFarm.Json {
internal uint RealAppID {
get {
if (Tags == null) {
return 0;
}
foreach (Asset.Tag tag in Tags) {
switch (tag.Identifier) {
case "Game":
@ -475,10 +467,6 @@ namespace ArchiSteamFarm.Json {
internal Asset.EType Type {
get {
if (Tags == null) {
return Asset.EType.Unknown;
}
Asset.EType type = Asset.EType.Unknown;
foreach (Asset.Tag tag in Tags) {
@ -554,7 +542,7 @@ namespace ArchiSteamFarm.Json {
internal bool Marketable { get; set; }
[JsonProperty(PropertyName = "tags", Required = Required.DisallowNull)]
internal ImmutableHashSet<Asset.Tag>? Tags { get; set; }
internal ImmutableHashSet<Asset.Tag> Tags { get; set; } = ImmutableHashSet<Asset.Tag>.Empty;
internal bool Tradable { get; set; }
@ -620,7 +608,7 @@ namespace ArchiSteamFarm.Json {
[SuppressMessage("ReSharper", "ClassCannotBeInstantiated")]
internal sealed class NewDiscoveryQueueResponse {
[JsonProperty(PropertyName = "queue", Required = Required.Always)]
internal readonly ImmutableHashSet<uint>? Queue;
internal readonly ImmutableHashSet<uint> Queue = ImmutableHashSet<uint>.Empty;
[JsonConstructor]
private NewDiscoveryQueueResponse() { }
@ -629,7 +617,7 @@ namespace ArchiSteamFarm.Json {
[SuppressMessage("ReSharper", "ClassCannotBeInstantiated")]
internal sealed class RedeemWalletResponse : EResultResponse {
[JsonProperty(PropertyName = "detail", Required = Required.DisallowNull)]
internal readonly EPurchaseResultDetail? PurchaseResultDetail;
internal readonly EPurchaseResultDetail PurchaseResultDetail;
[JsonConstructor]
private RedeemWalletResponse() { }
@ -638,7 +626,7 @@ namespace ArchiSteamFarm.Json {
[SuppressMessage("ReSharper", "ClassCannotBeInstantiated")]
internal sealed class TradeOfferAcceptResponse {
[JsonProperty(PropertyName = "strError", Required = Required.DisallowNull)]
internal readonly string? ErrorText;
internal readonly string ErrorText = "";
[JsonProperty(PropertyName = "needs_mobile_confirmation", Required = Required.DisallowNull)]
internal readonly bool RequiresMobileConfirmation;
@ -698,7 +686,7 @@ namespace ArchiSteamFarm.Json {
internal readonly ECommentPermission CommentPermission;
[JsonProperty(PropertyName = "PrivacySettings", Required = Required.Always)]
internal readonly PrivacySettings? Settings;
internal readonly PrivacySettings Settings = new();
// Constructed from privacy change request
internal UserPrivacy(PrivacySettings settings, ECommentPermission commentPermission) {
@ -763,7 +751,7 @@ namespace ArchiSteamFarm.Json {
}
[JsonConstructor]
private PrivacySettings() { }
internal PrivacySettings() { }
}
internal enum ECommentPermission : byte {

View file

@ -57,12 +57,12 @@ namespace ArchiSteamFarm {
#pragma warning disable 649
[JsonProperty(PropertyName = "identity_secret", Required = Required.Always)]
private readonly string? IdentitySecret;
private readonly string IdentitySecret = "";
#pragma warning restore 649
#pragma warning disable 649
[JsonProperty(PropertyName = "shared_secret", Required = Required.Always)]
private readonly string? SharedSecret;
private readonly string SharedSecret = "";
#pragma warning restore 649
private Bot? Bot;

View file

@ -716,7 +716,7 @@ namespace ArchiSteamFarm {
#pragma warning disable 649
[JsonProperty(PropertyName = "trade_token", Required = Required.Always)]
internal readonly string? TradeToken;
internal readonly string TradeToken = "";
#pragma warning restore 649
internal float Score => GamesCount / (float) ItemsCount;

View file

@ -27,7 +27,7 @@ using SteamKit2;
namespace ArchiSteamFarm.SteamKit2 {
internal sealed class ServerRecordEndPoint : IEquatable<ServerRecordEndPoint> {
[JsonProperty(Required = Required.Always)]
internal readonly string? Host;
internal readonly string Host = "";
[JsonProperty(Required = Required.Always)]
internal readonly ushort Port;