Round 2 of nullable checks

This commit is contained in:
JustArchi 2020-08-23 20:45:24 +02:00
parent f99043db30
commit b3d476dea4
34 changed files with 187 additions and 338 deletions

View file

@ -48,7 +48,7 @@ namespace ArchiSteamFarm.CustomPlugins.ExamplePlugin {
throw new ArgumentNullException(nameof(response.Content.Link));
}
return Uri.EscapeUriString(response.Content.Link);
return Uri.EscapeUriString(response.Content!.Link!);
}
[SuppressMessage("ReSharper", "ClassCannotBeInstantiated")]

View file

@ -131,9 +131,7 @@ namespace ArchiSteamFarm {
internal static void InitGlobalConfig(GlobalConfig globalConfig) {
if (globalConfig == null) {
ArchiLogger.LogNullError(nameof(globalConfig));
return;
throw new ArgumentNullException(nameof(globalConfig));
}
if (GlobalConfig != null) {
@ -150,11 +148,11 @@ namespace ArchiSteamFarm {
if (!string.IsNullOrEmpty(Program.NetworkGroup)) {
using MD5 hashingAlgorithm = MD5.Create();
networkGroupText = "-" + BitConverter.ToString(hashingAlgorithm.ComputeHash(Encoding.UTF8.GetBytes(Program.NetworkGroup))).Replace("-", "");
networkGroupText = "-" + BitConverter.ToString(hashingAlgorithm.ComputeHash(Encoding.UTF8.GetBytes(Program.NetworkGroup!))).Replace("-", "");
} else if (!string.IsNullOrEmpty(globalConfig.WebProxyText)) {
using MD5 hashingAlgorithm = MD5.Create();
networkGroupText = "-" + BitConverter.ToString(hashingAlgorithm.ComputeHash(Encoding.UTF8.GetBytes(globalConfig.WebProxyText))).Replace("-", "");
networkGroupText = "-" + BitConverter.ToString(hashingAlgorithm.ComputeHash(Encoding.UTF8.GetBytes(globalConfig.WebProxyText!))).Replace("-", "");
}
ConfirmationsSemaphore ??= OS.CreateCrossProcessSemaphore(nameof(ConfirmationsSemaphore) + networkGroupText);
@ -174,9 +172,7 @@ namespace ArchiSteamFarm {
internal static void InitGlobalDatabase(GlobalDatabase globalDatabase) {
if (globalDatabase == null) {
ArchiLogger.LogNullError(nameof(globalDatabase));
return;
throw new ArgumentNullException(nameof(globalDatabase));
}
if (GlobalDatabase != null) {
@ -250,7 +246,7 @@ namespace ArchiSteamFarm {
return null;
}
Version newVersion = new Version(releaseResponse.Tag);
Version newVersion = new Version(releaseResponse.Tag!);
ArchiLogger.LogGenericInfo(string.Format(Strings.UpdateVersionInfo, SharedInfo.Version, newVersion));
@ -389,6 +385,10 @@ namespace ArchiSteamFarm {
return;
}
if (Bot.BotsComparer == null) {
throw new ArgumentNullException(nameof(Bot.BotsComparer));
}
FileSystemWatcher = new FileSystemWatcher(SharedInfo.ConfigDirectory) { NotifyFilter = NotifyFilters.FileName | NotifyFilters.LastWrite };
FileSystemWatcher.Changed += OnChanged;
@ -858,7 +858,7 @@ namespace ArchiSteamFarm {
}
if (!Directory.Exists(directory)) {
Directory.CreateDirectory(directory);
Directory.CreateDirectory(directory!);
}
// We're not interested in extracting placeholder files (but we still want directories created for them, done above)

View file

@ -63,9 +63,7 @@ namespace ArchiSteamFarm {
public override void HandleMsg(IPacketMsg packetMsg) {
if ((packetMsg == null) || (Client == null)) {
ArchiLogger.LogNullError(nameof(packetMsg) + " || " + nameof(Client));
return;
throw new ArgumentNullException(nameof(packetMsg) + " || " + nameof(Client));
}
LastPacketReceived = DateTime.UtcNow;
@ -119,12 +117,6 @@ namespace ArchiSteamFarm {
throw new ArgumentNullException(nameof(chatGroupID) + " || " + nameof(chatID) + " || " + nameof(timestamp));
}
if (Client == null) {
ArchiLogger.LogNullError(nameof(Client));
return;
}
if (!Client.IsConnected) {
return;
}
@ -143,12 +135,6 @@ namespace ArchiSteamFarm {
throw new ArgumentNullException(nameof(steamID) + " || " + nameof(timestamp));
}
if (Client == null) {
ArchiLogger.LogNullError(nameof(Client));
return;
}
if (!Client.IsConnected) {
return;
}
@ -166,12 +152,6 @@ namespace ArchiSteamFarm {
throw new ArgumentNullException(nameof(steamID));
}
if (Client == null) {
ArchiLogger.LogNullError(nameof(Client));
return;
}
if (!Client.IsConnected) {
return;
}
@ -191,12 +171,6 @@ namespace ArchiSteamFarm {
throw new ArgumentNullException(nameof(steamID));
}
if (Client == null) {
ArchiLogger.LogNullError(nameof(Client));
return false;
}
if (!Client.IsConnected) {
return false;
}
@ -221,12 +195,6 @@ namespace ArchiSteamFarm {
throw new ArgumentNullException(nameof(steamID));
}
if (Client == null) {
ArchiLogger.LogNullError(nameof(Client));
return 0;
}
if (!Client.IsConnected) {
return 0;
}
@ -256,12 +224,6 @@ namespace ArchiSteamFarm {
}
internal async Task<uint?> GetLevel() {
if (Client == null) {
ArchiLogger.LogNullError(nameof(Client));
return null;
}
if (!Client.IsConnected) {
return null;
}
@ -287,12 +249,6 @@ namespace ArchiSteamFarm {
}
internal async Task<HashSet<ulong>?> GetMyChatGroupIDs() {
if (Client == null) {
ArchiLogger.LogNullError(nameof(Client));
return null;
}
if (!Client.IsConnected) {
return null;
}
@ -319,12 +275,6 @@ namespace ArchiSteamFarm {
}
internal async Task<CPrivacySettings?> GetPrivacySettings() {
if (Client == null) {
ArchiLogger.LogNullError(nameof(Client));
return null;
}
if (!Client.IsConnected) {
return null;
}
@ -351,12 +301,6 @@ namespace ArchiSteamFarm {
}
internal async Task<string?> GetTradeToken() {
if (Client == null) {
ArchiLogger.LogNullError(nameof(Client));
return null;
}
if (!Client.IsConnected) {
return null;
}
@ -387,12 +331,6 @@ namespace ArchiSteamFarm {
throw new ArgumentNullException(nameof(steamID));
}
if (Client == null) {
ArchiLogger.LogNullError(nameof(Client));
return null;
}
if (!Client.IsConnected) {
return null;
}
@ -425,12 +363,6 @@ namespace ArchiSteamFarm {
throw new ArgumentNullException(nameof(chatGroupID));
}
if (Client == null) {
ArchiLogger.LogNullError(nameof(Client));
return false;
}
if (!Client.IsConnected) {
return false;
}
@ -455,12 +387,6 @@ namespace ArchiSteamFarm {
throw new ArgumentNullException(nameof(gameIDs));
}
if (Client == null) {
ArchiLogger.LogNullError(nameof(Client));
return;
}
if (!Client.IsConnected) {
return;
}
@ -509,12 +435,6 @@ namespace ArchiSteamFarm {
throw new ArgumentNullException(nameof(guestPassID));
}
if (Client == null) {
ArchiLogger.LogNullError(nameof(Client));
return null;
}
if (!Client.IsConnected) {
return null;
}
@ -540,12 +460,6 @@ namespace ArchiSteamFarm {
throw new ArgumentNullException(nameof(key));
}
if (Client == null) {
ArchiLogger.LogNullError(nameof(Client));
return null;
}
if (!Client.IsConnected) {
return null;
}
@ -571,12 +485,6 @@ namespace ArchiSteamFarm {
throw new ArgumentNullException(nameof(steamID));
}
if (Client == null) {
ArchiLogger.LogNullError(nameof(Client));
return false;
}
if (!Client.IsConnected) {
return false;
}
@ -597,12 +505,6 @@ namespace ArchiSteamFarm {
}
internal void RequestItemAnnouncements() {
if (Client == null) {
ArchiLogger.LogNullError(nameof(Client));
return;
}
if (!Client.IsConnected) {
return;
}
@ -616,12 +518,6 @@ namespace ArchiSteamFarm {
throw new ArgumentNullException(nameof(steamID) + " || " + nameof(message));
}
if (Client == null) {
ArchiLogger.LogNullError(nameof(Client));
return EResult.Invalid;
}
if (!Client.IsConnected) {
return EResult.NoConnection;
}
@ -651,12 +547,6 @@ namespace ArchiSteamFarm {
throw new ArgumentNullException(nameof(chatGroupID) + " || " + nameof(chatID) + " || " + nameof(message));
}
if (Client == null) {
ArchiLogger.LogNullError(nameof(Client));
return EResult.Invalid;
}
if (!Client.IsConnected) {
return EResult.NoConnection;
}
@ -685,12 +575,6 @@ namespace ArchiSteamFarm {
throw new ArgumentNullException(nameof(steamID));
}
if (Client == null) {
ArchiLogger.LogNullError(nameof(Client));
return EResult.Invalid;
}
if (!Client.IsConnected) {
return EResult.NoConnection;
}
@ -718,12 +602,6 @@ namespace ArchiSteamFarm {
throw new ArgumentNullException(nameof(chatMode));
}
if (Client == null) {
ArchiLogger.LogNullError(nameof(Client));
return;
}
if (!Client.IsConnected) {
return;
}

View file

@ -245,7 +245,7 @@ namespace ArchiSteamFarm {
return null;
}
XmlNode appNode = xmlNode.SelectSingleNode("appID");
XmlNode? appNode = xmlNode.SelectSingleNode("appID");
if (appNode == null) {
Bot.ArchiLogger.LogNullError(nameof(appNode));
@ -259,7 +259,7 @@ namespace ArchiSteamFarm {
return null;
}
XmlNode nameNode = xmlNode.SelectSingleNode("name");
XmlNode? nameNode = xmlNode.SelectSingleNode("name");
if (nameNode == null) {
Bot.ArchiLogger.LogNullError(nameof(nameNode));

View file

@ -102,15 +102,15 @@ namespace ArchiSteamFarm {
[JsonProperty]
[PublicAPI]
public uint GamesToRedeemInBackgroundCount => BotDatabase?.GamesToRedeemInBackgroundCount ?? 0;
public uint GamesToRedeemInBackgroundCount => BotDatabase.GamesToRedeemInBackgroundCount;
[JsonProperty]
[PublicAPI]
public bool HasMobileAuthenticator => BotDatabase?.MobileAuthenticator != null;
public bool HasMobileAuthenticator => BotDatabase.MobileAuthenticator != null;
[JsonProperty]
[PublicAPI]
public bool IsConnectedAndLoggedOn => SteamClient?.SteamID != null;
public bool IsConnectedAndLoggedOn => SteamClient.SteamID != null;
[JsonProperty]
[PublicAPI]
@ -140,14 +140,11 @@ namespace ArchiSteamFarm {
private readonly SteamUser SteamUser;
private readonly Trading Trading;
#pragma warning disable CS8605
private IEnumerable<(string FilePath, EFileType FileType)> RelatedFiles {
get {
foreach (EFileType? fileType in Enum.GetValues(typeof(EFileType))) {
if (fileType == null) {
continue;
}
string filePath = GetFilePath(fileType.Value);
foreach (EFileType fileType in Enum.GetValues(typeof(EFileType))) {
string filePath = GetFilePath(fileType);
if (string.IsNullOrEmpty(filePath)) {
ArchiLogger.LogNullError(nameof(filePath));
@ -155,10 +152,11 @@ namespace ArchiSteamFarm {
yield break;
}
yield return (filePath, fileType.Value);
yield return (filePath, fileType);
}
}
}
#pragma warning restore CS8605
#pragma warning disable IDE0051
[JsonProperty(PropertyName = SharedInfo.UlongCompatibilityStringPrefix + nameof(SteamID))]
@ -364,8 +362,8 @@ namespace ArchiSteamFarm {
[PublicAPI]
public static HashSet<Bot>? GetBots(string args) {
if (string.IsNullOrEmpty(args)) {
throw new ArgumentNullException(nameof(args));
if (string.IsNullOrEmpty(args) || (Bots == null)) {
throw new ArgumentNullException(nameof(args) + " || " + nameof(Bots));
}
string[] botNames = args.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
@ -905,7 +903,7 @@ namespace ArchiSteamFarm {
string? gameName = null;
if (!string.IsNullOrEmpty(BotConfig.CustomGamePlayedWhileFarming)) {
gameName = string.Format(BotConfig.CustomGamePlayedWhileFarming, game.AppID, game.GameName);
gameName = string.Format(BotConfig.CustomGamePlayedWhileFarming!, game.AppID, game.GameName);
}
await ArchiHandler.PlayGames(game.PlayableAppID.ToEnumerable(), gameName).ConfigureAwait(false);
@ -919,7 +917,7 @@ namespace ArchiSteamFarm {
string? gameName = null;
if (!string.IsNullOrEmpty(BotConfig.CustomGamePlayedWhileFarming)) {
gameName = string.Format(BotConfig.CustomGamePlayedWhileFarming, string.Join(", ", games.Select(game => game.AppID)), string.Join(", ", games.Select(game => game.GameName)));
gameName = string.Format(BotConfig.CustomGamePlayedWhileFarming!, string.Join(", ", games.Select(game => game.AppID)), string.Join(", ", games.Select(game => game.GameName)));
}
await ArchiHandler.PlayGames(games.Select(game => game.PlayableAppID), gameName).ConfigureAwait(false);
@ -963,7 +961,7 @@ namespace ArchiSteamFarm {
if (gamesToRedeemInBackground.Count > 0) {
IOrderedDictionary validGamesToRedeemInBackground = ValidateGamesToRedeemInBackground(gamesToRedeemInBackground);
if ((validGamesToRedeemInBackground != null) && (validGamesToRedeemInBackground.Count > 0)) {
if (validGamesToRedeemInBackground.Count > 0) {
AddGamesToRedeemInBackground(validGamesToRedeemInBackground);
}
}
@ -1249,7 +1247,7 @@ namespace ArchiSteamFarm {
ArchiLogger.LogChatMessage(true, message, steamID: steamID);
string? steamMessagePrefix = ASF.GlobalConfig?.SteamMessagePrefix ?? GlobalConfig.DefaultSteamMessagePrefix;
string? steamMessagePrefix = ASF.GlobalConfig != null ? ASF.GlobalConfig.SteamMessagePrefix : GlobalConfig.DefaultSteamMessagePrefix;
ushort maxMessageLength = (ushort) (MaxMessageLength - ReservedMessageLength - (steamMessagePrefix?.Length ?? 0));
// We must escape our message prior to sending it
@ -1344,7 +1342,7 @@ namespace ArchiSteamFarm {
ArchiLogger.LogChatMessage(true, message, chatGroupID, chatID);
string? steamMessagePrefix = ASF.GlobalConfig?.SteamMessagePrefix ?? GlobalConfig.DefaultSteamMessagePrefix;
string? steamMessagePrefix = ASF.GlobalConfig != null ? ASF.GlobalConfig.SteamMessagePrefix : GlobalConfig.DefaultSteamMessagePrefix;
ushort maxMessageLength = (ushort) (MaxMessageLength - ReservedMessageLength - (steamMessagePrefix?.Length ?? 0));
// We must escape our message prior to sending it
@ -1492,6 +1490,7 @@ namespace ArchiSteamFarm {
}
}
#pragma warning disable CS8605
internal static IOrderedDictionary ValidateGamesToRedeemInBackground(IOrderedDictionary gamesToRedeemInBackground) {
if ((gamesToRedeemInBackground == null) || (gamesToRedeemInBackground.Count == 0)) {
throw new ArgumentNullException(nameof(gamesToRedeemInBackground));
@ -1499,10 +1498,10 @@ namespace ArchiSteamFarm {
HashSet<object> invalidKeys = new HashSet<object>();
foreach (DictionaryEntry? game in gamesToRedeemInBackground) {
foreach (DictionaryEntry game in gamesToRedeemInBackground) {
bool invalid = false;
string? key = game?.Key as string;
string? key = game.Key as string;
if (string.IsNullOrEmpty(key)) {
invalid = true;
@ -1512,7 +1511,7 @@ namespace ArchiSteamFarm {
ASF.ArchiLogger.LogGenericWarning(string.Format(Strings.ErrorIsInvalid, key));
}
string? name = game?.Value as string;
string? name = game.Value as string;
if (string.IsNullOrEmpty(name)) {
invalid = true;
@ -1532,6 +1531,7 @@ namespace ArchiSteamFarm {
return gamesToRedeemInBackground;
}
#pragma warning restore CS8605
private async Task CheckOccupationStatus() {
StopPlayingWasBlockedTimer();
@ -1730,8 +1730,9 @@ namespace ArchiSteamFarm {
return;
}
MobileAuthenticator authenticator = JsonConvert.DeserializeObject<MobileAuthenticator>(json);
MobileAuthenticator? authenticator = JsonConvert.DeserializeObject<MobileAuthenticator>(json);
// ReSharper disable once ConditionIsAlwaysTrueOrFalse - wrong, "null" json serializes into null object
if (authenticator == null) {
ArchiLogger.LogNullError(nameof(authenticator));
@ -1962,9 +1963,7 @@ namespace ArchiSteamFarm {
private async void OnConnected(SteamClient.ConnectedCallback callback) {
if (callback == null) {
ArchiLogger.LogNullError(nameof(callback));
return;
throw new ArgumentNullException(nameof(callback));
}
HeartBeatFailures = 0;
@ -2028,14 +2027,18 @@ namespace ArchiSteamFarm {
return;
}
if (string.IsNullOrEmpty(BotConfig.SteamLogin)) {
throw new ArgumentNullException(nameof(BotConfig.SteamLogin));
}
// Steam login and password fields can contain ASCII characters only, including spaces
const string nonAsciiPattern = @"[^\u0000-\u007F]+";
string username = Regex.Replace(BotConfig.SteamLogin, nonAsciiPattern, "", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);
string username = Regex.Replace(BotConfig.SteamLogin!, nonAsciiPattern, "", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);
string? password = BotConfig.DecryptedSteamPassword;
if (!string.IsNullOrEmpty(password)) {
password = Regex.Replace(password, nonAsciiPattern, "", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);
password = Regex.Replace(password!, nonAsciiPattern, "", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);
}
ArchiLogger.LogGenericInfo(Strings.BotLoggingIn);
@ -2067,16 +2070,8 @@ namespace ArchiSteamFarm {
}
private async void OnDisconnected(SteamClient.DisconnectedCallback callback) {
if (ASF.LoginRateLimitingSemaphore == null) {
ASF.ArchiLogger.LogNullError(nameof(ASF.LoginRateLimitingSemaphore));
return;
}
if (callback == null) {
ArchiLogger.LogNullError(nameof(callback));
return;
if ((callback == null) || (ASF.LoginRateLimitingSemaphore == null)) {
throw new ArgumentNullException(nameof(callback) + " || " + nameof(ASF.LoginRateLimitingSemaphore));
}
EResult lastLogOnResult = LastLogOnResult;
@ -2147,10 +2142,12 @@ namespace ArchiSteamFarm {
}
private async void OnFriendsList(SteamFriends.FriendsListCallback callback) {
if (callback?.FriendList == null) {
ArchiLogger.LogNullError(nameof(callback) + " || " + nameof(callback.FriendList));
if (callback == null) {
throw new ArgumentNullException(nameof(callback));
}
return;
if (callback.FriendList == null) {
throw new ArgumentNullException(nameof(callback.FriendList));
}
foreach (SteamFriends.FriendsListCallback.Friend friend in callback.FriendList.Where(friend => friend.Relationship == EFriendRelationship.RequestRecipient)) {
@ -2206,10 +2203,12 @@ namespace ArchiSteamFarm {
}
private async void OnGuestPassList(SteamApps.GuestPassListCallback callback) {
if (callback?.GuestPasses == null) {
ArchiLogger.LogNullError(nameof(callback) + " || " + nameof(callback.GuestPasses));
if (callback == null) {
throw new ArgumentNullException(nameof(callback));
}
return;
if (callback.GuestPasses == null) {
throw new ArgumentNullException(nameof(callback.GuestPasses));
}
if ((callback.CountGuestPassesToRedeem == 0) || (callback.GuestPasses.Count == 0) || !BotConfig.AcceptGifts) {
@ -2227,9 +2226,7 @@ namespace ArchiSteamFarm {
private async Task OnIncomingChatMessage(CChatRoom_IncomingChatMessage_Notification notification) {
if (notification == null) {
ArchiLogger.LogNullError(nameof(notification));
return;
throw new ArgumentNullException(nameof(notification));
}
// Under normal circumstances, timestamp must always be greater than 0, but Steam already proved that it's capable of going against the logic
@ -2265,9 +2262,7 @@ namespace ArchiSteamFarm {
private async Task OnIncomingMessage(CFriendMessages_IncomingMessage_Notification notification) {
if (notification == null) {
ArchiLogger.LogNullError(nameof(notification));
return;
throw new ArgumentNullException(nameof(notification));
}
if ((EChatEntryType) notification.chat_entry_type != EChatEntryType.ChatMsg) {
@ -2306,14 +2301,16 @@ namespace ArchiSteamFarm {
}
private async void OnLicenseList(SteamApps.LicenseListCallback callback) {
if (ASF.GlobalDatabase == null) {
throw new ArgumentNullException(nameof(ASF.GlobalDatabase));
if (callback == null) {
throw new ArgumentNullException(nameof(callback));
}
if (callback?.LicenseList == null) {
ArchiLogger.LogNullError(nameof(callback) + " || " + nameof(callback.LicenseList));
if (callback.LicenseList == null) {
throw new ArgumentNullException(nameof(callback.LicenseList));
}
return;
if (ASF.GlobalDatabase == null) {
throw new ArgumentNullException(nameof(ASF.GlobalDatabase));
}
if (callback.LicenseList.Count == 0) {
@ -2359,9 +2356,7 @@ namespace ArchiSteamFarm {
private void OnLoggedOff(SteamUser.LoggedOffCallback callback) {
if (callback == null) {
ArchiLogger.LogNullError(nameof(callback));
return;
throw new ArgumentNullException(nameof(callback));
}
LastLogOnResult = callback.Result;
@ -2395,9 +2390,7 @@ namespace ArchiSteamFarm {
private async void OnLoggedOn(SteamUser.LoggedOnCallback callback) {
if (callback == null) {
ArchiLogger.LogNullError(nameof(callback));
return;
throw new ArgumentNullException(nameof(callback));
}
// Always reset one-time-only access tokens when we get OnLoggedOn() response
@ -2613,17 +2606,19 @@ namespace ArchiSteamFarm {
}
private void OnLoginKey(SteamUser.LoginKeyCallback callback) {
if (string.IsNullOrEmpty(callback?.LoginKey)) {
ArchiLogger.LogNullError(nameof(callback) + " || " + nameof(callback.LoginKey));
if (callback == null) {
throw new ArgumentNullException(nameof(callback));
}
return;
if (string.IsNullOrEmpty(callback.LoginKey)) {
throw new ArgumentNullException(nameof(callback.LoginKey));
}
if (!BotConfig.UseLoginKeys) {
return;
}
string? loginKey = callback!.LoginKey;
string? loginKey = callback.LoginKey;
if (BotConfig.PasswordFormat != ArchiCryptoHelper.ECryptoMethod.PlainText) {
loginKey = ArchiCryptoHelper.Encrypt(BotConfig.PasswordFormat, loginKey);
@ -2635,9 +2630,7 @@ namespace ArchiSteamFarm {
private async void OnMachineAuth(SteamUser.UpdateMachineAuthCallback callback) {
if (callback == null) {
ArchiLogger.LogNullError(nameof(callback));
return;
throw new ArgumentNullException(nameof(callback));
}
string sentryFilePath = GetFilePath(EFileType.SentryFile);
@ -2698,9 +2691,7 @@ namespace ArchiSteamFarm {
private void OnPersonaState(SteamFriends.PersonaStateCallback callback) {
if (callback == null) {
ArchiLogger.LogNullError(nameof(callback));
return;
throw new ArgumentNullException(nameof(callback));
}
if (callback.FriendID != SteamID) {
@ -2727,9 +2718,7 @@ namespace ArchiSteamFarm {
private async void OnPlayingSessionState(ArchiHandler.PlayingSessionStateCallback callback) {
if (callback == null) {
ArchiLogger.LogNullError(nameof(callback));
return;
throw new ArgumentNullException(nameof(callback));
}
if (callback.PlayingBlocked == PlayingBlocked) {
@ -2742,9 +2731,7 @@ namespace ArchiSteamFarm {
private async void OnServiceMethod(SteamUnifiedMessages.ServiceMethodNotification notification) {
if (notification == null) {
ArchiLogger.LogNullError(nameof(notification));
return;
throw new ArgumentNullException(nameof(notification));
}
switch (notification.MethodName) {
@ -2761,9 +2748,7 @@ namespace ArchiSteamFarm {
private async void OnSharedLibraryLockStatus(ArchiHandler.SharedLibraryLockStatusCallback callback) {
if (callback == null) {
ArchiLogger.LogNullError(nameof(callback));
return;
throw new ArgumentNullException(nameof(callback));
}
// Ignore no status updates
@ -2786,12 +2771,14 @@ namespace ArchiSteamFarm {
private void OnUserNotifications(ArchiHandler.UserNotificationsCallback callback) {
if (callback == null) {
ArchiLogger.LogNullError(nameof(callback));
return;
throw new ArgumentNullException(nameof(callback));
}
if ((callback.Notifications == null) || (callback.Notifications.Count == 0)) {
if (callback.Notifications == null) {
throw new ArgumentNullException(nameof(callback));
}
if (callback.Notifications.Count == 0) {
return;
}
@ -2841,9 +2828,7 @@ namespace ArchiSteamFarm {
private void OnVanityURLChangedCallback(ArchiHandler.VanityURLChangedCallback callback) {
if (callback == null) {
ArchiLogger.LogNullError(nameof(callback));
return;
throw new ArgumentNullException(nameof(callback));
}
ArchiWebHandler.OnVanityURLChanged(callback.VanityURL);
@ -2851,9 +2836,7 @@ namespace ArchiSteamFarm {
private void OnWalletUpdate(SteamUser.WalletInfoCallback callback) {
if (callback == null) {
ArchiLogger.LogNullError(nameof(callback));
return;
throw new ArgumentNullException(nameof(callback));
}
WalletBalance = callback.LongBalance;

View file

@ -333,6 +333,7 @@ namespace ArchiSteamFarm {
return null;
}
// ReSharper disable once ConditionIsAlwaysTrueOrFalse - wrong, "null" json serializes into null object
if (botConfig == null) {
ASF.ArchiLogger.LogNullError(nameof(botConfig));

View file

@ -182,6 +182,7 @@ namespace ArchiSteamFarm {
return null;
}
// ReSharper disable once ConditionIsAlwaysTrueOrFalse - wrong, "null" json serializes into null object
if (botDatabase == null) {
ASF.ArchiLogger.LogNullError(nameof(botDatabase));
@ -195,15 +196,17 @@ namespace ArchiSteamFarm {
internal IReadOnlyCollection<ulong> GetBlacklistedFromTradesSteamIDs() => BlacklistedFromTradesSteamIDs;
#pragma warning disable CS8605
internal (string? Key, string? Name) GetGameToRedeemInBackground() {
lock (GamesToRedeemInBackground) {
foreach (DictionaryEntry? game in GamesToRedeemInBackground) {
return (game?.Key as string, game?.Value as string);
foreach (DictionaryEntry game in GamesToRedeemInBackground) {
return (game.Key as string, game.Value as string);
}
}
return (null, null);
}
#pragma warning restore CS8605
internal IReadOnlyCollection<uint> GetIdlingBlacklistedAppIDs() => IdlingBlacklistedAppIDs;
internal IReadOnlyCollection<uint> GetIdlingPriorityAppIDs() => IdlingPriorityAppIDs;

View file

@ -19,6 +19,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
using System;
using System.IO;
using System.Text;
using SteamKit2;
@ -31,9 +32,7 @@ namespace ArchiSteamFarm.CMsgs {
void ISteamSerializable.Deserialize(Stream stream) {
if (stream == null) {
ASF.ArchiLogger.LogNullError(nameof(stream));
return;
throw new ArgumentNullException(nameof(stream));
}
using BinaryReader binaryReader = new BinaryReader(stream, Encoding.UTF8, true);
@ -46,9 +45,7 @@ namespace ArchiSteamFarm.CMsgs {
void ISteamSerializable.Serialize(Stream stream) {
if (stream == null) {
ASF.ArchiLogger.LogNullError(nameof(stream));
return;
throw new ArgumentNullException(nameof(stream));
}
using BinaryWriter binaryWriter = new BinaryWriter(stream, Encoding.UTF8, true);

View file

@ -289,10 +289,10 @@ namespace ArchiSteamFarm {
throw new ArgumentNullException(nameof(steamID) + " || " + nameof(message));
}
string commandPrefix = ASF.GlobalConfig?.CommandPrefix ?? GlobalConfig.DefaultCommandPrefix;
string? commandPrefix = ASF.GlobalConfig != null ? ASF.GlobalConfig.CommandPrefix : GlobalConfig.DefaultCommandPrefix;
if (!string.IsNullOrEmpty(commandPrefix)) {
if (!message.StartsWith(commandPrefix, StringComparison.OrdinalIgnoreCase)) {
if (!message.StartsWith(commandPrefix!, StringComparison.OrdinalIgnoreCase)) {
string? pluginsResponse = await PluginsCore.OnBotMessage(Bot, steamID, message).ConfigureAwait(false);
if (!string.IsNullOrEmpty(pluginsResponse)) {
@ -305,7 +305,7 @@ namespace ArchiSteamFarm {
return;
}
message = message.Substring(commandPrefix.Length);
message = message.Substring(commandPrefix!.Length);
}
Task<string?> responseTask = Response(steamID, message);
@ -346,10 +346,10 @@ namespace ArchiSteamFarm {
throw new ArgumentNullException(nameof(chatGroupID) + " || " + nameof(chatID) + " || " + nameof(steamID) + " || " + nameof(message));
}
string commandPrefix = ASF.GlobalConfig?.CommandPrefix ?? GlobalConfig.DefaultCommandPrefix;
string? commandPrefix = ASF.GlobalConfig != null ? ASF.GlobalConfig.CommandPrefix : GlobalConfig.DefaultCommandPrefix;
if (!string.IsNullOrEmpty(commandPrefix)) {
if (!message.StartsWith(commandPrefix, StringComparison.OrdinalIgnoreCase)) {
if (!message.StartsWith(commandPrefix!, StringComparison.OrdinalIgnoreCase)) {
string? pluginsResponse = await PluginsCore.OnBotMessage(Bot, steamID, message).ConfigureAwait(false);
if (!string.IsNullOrEmpty(pluginsResponse)) {
@ -362,7 +362,7 @@ namespace ArchiSteamFarm {
return;
}
message = message.Substring(commandPrefix.Length);
message = message.Substring(commandPrefix!.Length);
}
Task<string?> responseTask = Response(steamID, message);
@ -1680,7 +1680,7 @@ namespace ArchiSteamFarm {
Dictionary<string, (ushort Count, string GameName)> ownedGamesStats = new Dictionary<string, (ushort Count, string GameName)>();
foreach ((string gameID, string gameName) in validResults.Where(validResult => (validResult.OwnedGames != null) && (validResult.OwnedGames.Count > 0)).SelectMany(validResult => validResult.OwnedGames)) {
foreach ((string gameID, string gameName) in validResults.Where(validResult => validResult.OwnedGames.Count > 0).SelectMany(validResult => validResult.OwnedGames)) {
if (ownedGamesStats.TryGetValue(gameID, out (ushort Count, string GameName) ownedGameStats)) {
ownedGameStats.Count++;
} else {
@ -2003,8 +2003,8 @@ namespace ArchiSteamFarm {
}
private async Task<string?> ResponseRedeem(ulong steamID, string keysText, ERedeemFlags redeemFlags = ERedeemFlags.None) {
if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount || string.IsNullOrEmpty(keysText)) {
throw new ArgumentNullException(nameof(steamID) + " || " + nameof(keysText));
if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount || string.IsNullOrEmpty(keysText) || (Bot.Bots == null)) {
throw new ArgumentNullException(nameof(steamID) + " || " + nameof(keysText) + " || " + nameof(Bot.Bots));
}
if (!Bot.HasPermission(steamID, BotConfig.EPermission.Operator)) {

View file

@ -53,7 +53,7 @@ namespace ArchiSteamFarm {
return await GetReleaseFromURL(SharedInfo.GithubReleaseURL + "/tags/" + version).ConfigureAwait(false);
}
private static MarkdownDocument? ExtractChangelogFromBody(string markdownText) {
private static MarkdownDocument ExtractChangelogFromBody(string markdownText) {
if (string.IsNullOrEmpty(markdownText)) {
throw new ArgumentNullException(nameof(markdownText));
}

View file

@ -158,7 +158,7 @@ namespace ArchiSteamFarm {
Uri uri;
try {
uri = new Uri(WebProxyText);
uri = new Uri(WebProxyText!);
} catch (UriFormatException e) {
ASF.ArchiLogger.LogGenericException(e);
@ -299,6 +299,7 @@ namespace ArchiSteamFarm {
return null;
}
// ReSharper disable once ConditionIsAlwaysTrueOrFalse - wrong, "null" json serializes into null object
if (globalConfig == null) {
ASF.ArchiLogger.LogNullError(nameof(globalConfig));

View file

@ -122,6 +122,7 @@ namespace ArchiSteamFarm {
return null;
}
// ReSharper disable once ConditionIsAlwaysTrueOrFalse - wrong, "null" json serializes into null object
if (globalDatabase == null) {
ASF.ArchiLogger.LogNullError(nameof(globalDatabase));

View file

@ -159,15 +159,15 @@ namespace ArchiSteamFarm.Helpers {
}
if (!Directory.Exists(directoryPath)) {
Directory.CreateDirectory(directoryPath);
Directory.CreateDirectory(directoryPath!);
if (OS.IsUnix) {
OS.UnixSetFileAccess(directoryPath, OS.EUnixPermission.Combined777);
OS.UnixSetFileAccess(directoryPath!, OS.EUnixPermission.Combined777);
} else {
DirectoryInfo directoryInfo = new DirectoryInfo(directoryPath);
DirectoryInfo directoryInfo = new DirectoryInfo(directoryPath!);
try {
DirectorySecurity directorySecurity = new DirectorySecurity(directoryPath, AccessControlSections.All);
DirectorySecurity directorySecurity = new DirectorySecurity(directoryPath!, AccessControlSections.All);
directoryInfo.SetAccessControl(directorySecurity);
} catch (PrivilegeNotHeldException e) {

View file

@ -78,9 +78,9 @@ namespace ArchiSteamFarm.Helpers {
await RuntimeCompatibility.File.WriteAllTextAsync(newFilePath, json).ConfigureAwait(false);
if (File.Exists(FilePath)) {
File.Replace(newFilePath, FilePath, null);
File.Replace(newFilePath, FilePath!, null);
} else {
File.Move(newFilePath, FilePath);
File.Move(newFilePath, FilePath!);
}
} catch (Exception e) {
ASF.ArchiLogger.LogGenericException(e);

View file

@ -31,9 +31,9 @@ using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using NLog.Web;
#if !NETFRAMEWORK
using Microsoft.Extensions.Hosting;
#endif
namespace ArchiSteamFarm.IPC {

View file

@ -220,7 +220,7 @@ namespace ArchiSteamFarm.IPC.Controllers.Api {
IOrderedDictionary validGamesToRedeemInBackground = Bot.ValidateGamesToRedeemInBackground(request.GamesToRedeemInBackground);
if ((validGamesToRedeemInBackground == null) || (validGamesToRedeemInBackground.Count == 0)) {
if (validGamesToRedeemInBackground.Count == 0) {
return BadRequest(new GenericResponse(false, string.Format(Strings.ErrorIsEmpty, nameof(validGamesToRedeemInBackground))));
}

View file

@ -57,16 +57,16 @@ namespace ArchiSteamFarm.IPC.Controllers.Api {
return BadRequest(new GenericResponse(false, string.Format(Strings.ErrorIsInvalid, nameof(ASF.GlobalConfig.SteamOwnerID))));
}
Bot? targetBot = Bot.Bots.OrderBy(bot => bot.Key, Bot.BotsComparer).Select(bot => bot.Value).FirstOrDefault();
Bot? targetBot = Bot.Bots?.OrderBy(bot => bot.Key, Bot.BotsComparer).Select(bot => bot.Value).FirstOrDefault();
if (targetBot == null) {
return BadRequest(new GenericResponse(false, Strings.ErrorNoBotsDefined));
}
string command = request.Command!;
string? commandPrefix = ASF.GlobalConfig?.CommandPrefix ?? GlobalConfig.DefaultCommandPrefix;
string? commandPrefix = ASF.GlobalConfig != null ? ASF.GlobalConfig.CommandPrefix : GlobalConfig.DefaultCommandPrefix;
if (!string.IsNullOrEmpty(commandPrefix) && command.StartsWith(commandPrefix, StringComparison.Ordinal)) {
if (!string.IsNullOrEmpty(commandPrefix) && command.StartsWith(commandPrefix!, StringComparison.Ordinal)) {
command = command.Substring(commandPrefix!.Length);
if (string.IsNullOrEmpty(command)) {

View file

@ -87,11 +87,7 @@ namespace ArchiSteamFarm.IPC.Controllers.Api {
underlyingType = enumType.GetUnifiedName();
foreach (object? value in Enum.GetValues(targetType)) {
if (value == null) {
continue;
}
string? valueText = value.ToString();
string? valueText = value?.ToString();
if (string.IsNullOrEmpty(valueText)) {
ASF.ArchiLogger.LogNullError(nameof(valueText));
@ -105,7 +101,7 @@ namespace ArchiSteamFarm.IPC.Controllers.Api {
continue;
}
body[valueText] = valueObjText!;
body[valueText!] = valueObjText!;
}
}

View file

@ -80,7 +80,7 @@ namespace ArchiSteamFarm.IPC.Integration {
throw new ArgumentNullException(nameof(context) + " || " + nameof(ClearFailedAuthorizationsTimer));
}
string? ipcPassword = ASF.GlobalConfig?.IPCPassword ?? GlobalConfig.DefaultIPCPassword;
string? ipcPassword = ASF.GlobalConfig != null ? ASF.GlobalConfig.IPCPassword : GlobalConfig.DefaultIPCPassword;
if (string.IsNullOrEmpty(ipcPassword)) {
return HttpStatusCode.OK;

View file

@ -31,9 +31,7 @@ namespace ArchiSteamFarm.IPC.Integration {
internal sealed class EnumSchemaFilter : ISchemaFilter {
public void Apply(OpenApiSchema schema, SchemaFilterContext context) {
if ((schema == null) || (context == null)) {
ASF.ArchiLogger.LogNullError(nameof(schema) + " || " + nameof(context));
return;
throw new ArgumentNullException(nameof(schema) + " || " + nameof(context));
}
if (!context.Type.IsEnum) {
@ -74,7 +72,7 @@ namespace ArchiSteamFarm.IPC.Integration {
throw new ArgumentOutOfRangeException(nameof(enumValue));
}
definition.Add(enumName, enumObject);
definition.Add(enumName!, enumObject);
}
schema.AddExtension("x-definition", definition);

View file

@ -19,6 +19,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics.CodeAnalysis;
@ -59,9 +60,7 @@ namespace ArchiSteamFarm.IPC.Requests {
public ImmutableHashSet<string> SAcceptedCreatorIDs {
set {
if (value == null) {
ASF.ArchiLogger.LogNullError(nameof(value));
return;
throw new ArgumentNullException(nameof(value));
}
HashSet<ulong> acceptedCreatorIDs = new HashSet<ulong>(value.Count);

View file

@ -39,7 +39,6 @@ using Newtonsoft.Json.Serialization;
#if NETFRAMEWORK
using Newtonsoft.Json.Converters;
#endif
namespace ArchiSteamFarm.IPC {
@ -92,7 +91,7 @@ namespace ArchiSteamFarm.IPC {
app.UseRouting();
#endif
string? ipcPassword = ASF.GlobalConfig?.IPCPassword ?? GlobalConfig.DefaultIPCPassword;
string? ipcPassword = ASF.GlobalConfig != null ? ASF.GlobalConfig.IPCPassword : GlobalConfig.DefaultIPCPassword;
if (!string.IsNullOrEmpty(ipcPassword)) {
// We need ApiAuthenticationMiddleware for IPCPassword
@ -137,7 +136,7 @@ namespace ArchiSteamFarm.IPC {
// Add support for response compression
services.AddResponseCompression();
string? ipcPassword = ASF.GlobalConfig?.IPCPassword ?? GlobalConfig.DefaultIPCPassword;
string? ipcPassword = ASF.GlobalConfig != null ? ASF.GlobalConfig.IPCPassword : GlobalConfig.DefaultIPCPassword;
// Add CORS to allow userscripts and third-party apps
if (!string.IsNullOrEmpty(ipcPassword)) {

View file

@ -335,9 +335,7 @@ namespace ArchiSteamFarm.Json {
[PublicAPI]
public bool IsValidSteamItemsRequest(IReadOnlyCollection<Asset.EType> acceptedTypes) {
if ((acceptedTypes == null) || (acceptedTypes.Count == 0)) {
ASF.ArchiLogger.LogNullError(nameof(acceptedTypes));
return false;
throw new ArgumentNullException(nameof(acceptedTypes));
}
return ItemsToGive.All(item => (item.AppID == Asset.SteamAppID) && (item.ContextID == Asset.SteamCommunityContextID) && acceptedTypes.Contains(item.Type));

View file

@ -257,7 +257,7 @@ namespace ArchiSteamFarm {
byte[] identitySecret;
try {
identitySecret = Convert.FromBase64String(IdentitySecret);
identitySecret = Convert.FromBase64String(IdentitySecret!);
} catch (FormatException e) {
Bot.ArchiLogger.LogGenericException(e);
Bot.ArchiLogger.LogGenericError(string.Format(Strings.ErrorIsInvalid, nameof(IdentitySecret)));
@ -282,7 +282,7 @@ namespace ArchiSteamFarm {
Array.Copy(timeArray, buffer, 8);
if (!string.IsNullOrEmpty(tag)) {
Array.Copy(Encoding.UTF8.GetBytes(tag), 0, buffer, 8, bufferSize - 8);
Array.Copy(Encoding.UTF8.GetBytes(tag!), 0, buffer, 8, bufferSize - 8);
}
using HMACSHA1 hmac = new HMACSHA1(identitySecret);
@ -300,7 +300,7 @@ namespace ArchiSteamFarm {
byte[] sharedSecret;
try {
sharedSecret = Convert.FromBase64String(SharedSecret);
sharedSecret = Convert.FromBase64String(SharedSecret!);
} catch (FormatException e) {
Bot.ArchiLogger.LogGenericException(e);
Bot.ArchiLogger.LogGenericError(string.Format(Strings.ErrorIsInvalid, nameof(SharedSecret)));

View file

@ -62,9 +62,7 @@ namespace ArchiSteamFarm.NLog {
protected override void Write(LogEventInfo logEvent) {
if (logEvent == null) {
ASF.ArchiLogger.LogNullError(nameof(logEvent));
return;
throw new ArgumentNullException(nameof(logEvent));
}
base.Write(logEvent);

View file

@ -76,7 +76,7 @@ namespace ArchiSteamFarm.NLog {
await ConsoleSemaphore.WaitAsync().ConfigureAwait(false);
string result;
string? result;
try {
OnUserInputStart();
@ -131,7 +131,7 @@ namespace ArchiSteamFarm.NLog {
ConsoleSemaphore.Release();
}
return !string.IsNullOrEmpty(result) ? result.Trim() : null;
return !string.IsNullOrEmpty(result) ? result!.Trim() : null;
}
internal static void InitCoreLoggers(bool uniqueInstance) {
@ -221,7 +221,7 @@ namespace ArchiSteamFarm.NLog {
ASF.ArchiLogger.LogGenericInfo(Strings.InteractiveConsoleEnabled);
}
private static string ConsoleReadLine() {
private static string? ConsoleReadLine() {
Console.Beep();
return Console.ReadLine();
@ -277,23 +277,23 @@ namespace ArchiSteamFarm.NLog {
try {
Console.Write(@">> " + Strings.EnterCommand);
string command = ConsoleReadLine();
string? command = ConsoleReadLine();
if (string.IsNullOrEmpty(command)) {
continue;
}
string commandPrefix = ASF.GlobalConfig?.CommandPrefix ?? GlobalConfig.DefaultCommandPrefix;
string? commandPrefix = ASF.GlobalConfig != null ? ASF.GlobalConfig.CommandPrefix : GlobalConfig.DefaultCommandPrefix;
if (!string.IsNullOrEmpty(commandPrefix) && command.StartsWith(commandPrefix, StringComparison.Ordinal)) {
command = command.Substring(commandPrefix.Length);
if (!string.IsNullOrEmpty(commandPrefix) && command!.StartsWith(commandPrefix!, StringComparison.Ordinal)) {
command = command.Substring(commandPrefix!.Length);
if (string.IsNullOrEmpty(command)) {
continue;
}
}
Bot? targetBot = Bot.Bots.OrderBy(bot => bot.Key, Bot.BotsComparer).Select(bot => bot.Value).FirstOrDefault();
Bot? targetBot = Bot.Bots?.OrderBy(bot => bot.Key, Bot.BotsComparer).Select(bot => bot.Value).FirstOrDefault();
if (targetBot == null) {
Console.WriteLine(@"<< " + Strings.ErrorNoBotsDefined);
@ -305,7 +305,7 @@ namespace ArchiSteamFarm.NLog {
ulong steamOwnerID = ASF.GlobalConfig?.SteamOwnerID ?? GlobalConfig.DefaultSteamOwnerID;
string? response = await targetBot.Commands.Response(steamOwnerID, command).ConfigureAwait(false);
string? response = await targetBot.Commands.Response(steamOwnerID, command!).ConfigureAwait(false);
if (string.IsNullOrEmpty(response)) {
ASF.ArchiLogger.LogNullError(nameof(response));
@ -341,9 +341,7 @@ namespace ArchiSteamFarm.NLog {
private static void OnConfigurationChanged(object? sender, LoggingConfigurationChangedEventArgs e) {
if (e == null) {
ASF.ArchiLogger.LogNullError(nameof(e));
return;
throw new ArgumentNullException(nameof(e));
}
InitConsoleLoggers();

View file

@ -55,9 +55,7 @@ namespace ArchiSteamFarm.NLog {
protected override async void Write(LogEventInfo logEvent) {
if (logEvent == null) {
ASF.ArchiLogger.LogNullError(nameof(logEvent));
return;
throw new ArgumentNullException(nameof(logEvent));
}
base.Write(logEvent);

View file

@ -36,15 +36,13 @@ using SteamKit2;
namespace ArchiSteamFarm.Plugins {
internal static class PluginsCore {
internal static bool HasCustomPluginsLoaded => HasActivePluginsLoaded && ActivePlugins.Any(plugin => !(plugin is OfficialPlugin officialPlugin) || !officialPlugin.HasSameVersion());
internal static bool HasCustomPluginsLoaded => ActivePlugins?.Any(plugin => !(plugin is OfficialPlugin officialPlugin) || !officialPlugin.HasSameVersion()) == true;
[ImportMany]
internal static ImmutableHashSet<IPlugin>? ActivePlugins { get; private set; }
private static bool HasActivePluginsLoaded => ActivePlugins?.Count > 0;
internal static async Task<StringComparer> GetBotsComparer() {
if (!HasActivePluginsLoaded) {
if (ActivePlugins == null) {
return StringComparer.Ordinal;
}
@ -64,7 +62,7 @@ namespace ArchiSteamFarm.Plugins {
}
internal static async Task<uint> GetChangeNumberToStartFrom() {
if (!HasActivePluginsLoaded) {
if (ActivePlugins == null) {
return 0;
}
@ -88,7 +86,7 @@ namespace ArchiSteamFarm.Plugins {
}
internal static bool InitPlugins() {
if (HasActivePluginsLoaded) {
if (ActivePlugins != null) {
return false;
}
@ -189,7 +187,7 @@ namespace ArchiSteamFarm.Plugins {
}
internal static async Task OnASFInitModules(IReadOnlyDictionary<string, JToken>? additionalConfigProperties = null) {
if (!HasActivePluginsLoaded) {
if ((ActivePlugins == null) || (ActivePlugins.Count == 0)) {
return;
}
@ -205,7 +203,7 @@ namespace ArchiSteamFarm.Plugins {
throw new ArgumentNullException(nameof(bot) + " || " + nameof(steamID) + " || " + nameof(message) + " || " + nameof(args));
}
if (!HasActivePluginsLoaded) {
if ((ActivePlugins == null) || (ActivePlugins.Count == 0)) {
return null;
}
@ -227,7 +225,7 @@ namespace ArchiSteamFarm.Plugins {
throw new ArgumentNullException(nameof(bot));
}
if (!HasActivePluginsLoaded) {
if ((ActivePlugins == null) || (ActivePlugins.Count == 0)) {
return;
}
@ -243,7 +241,7 @@ namespace ArchiSteamFarm.Plugins {
throw new ArgumentNullException(nameof(bot));
}
if (!HasActivePluginsLoaded) {
if ((ActivePlugins == null) || (ActivePlugins.Count == 0)) {
return;
}
@ -259,7 +257,7 @@ namespace ArchiSteamFarm.Plugins {
throw new ArgumentNullException(nameof(bot));
}
if (!HasActivePluginsLoaded) {
if ((ActivePlugins == null) || (ActivePlugins.Count == 0)) {
return;
}
@ -275,7 +273,7 @@ namespace ArchiSteamFarm.Plugins {
throw new ArgumentNullException(nameof(bot));
}
if (!HasActivePluginsLoaded) {
if ((ActivePlugins == null) || (ActivePlugins.Count == 0)) {
return;
}
@ -291,7 +289,7 @@ namespace ArchiSteamFarm.Plugins {
throw new ArgumentNullException(nameof(bot));
}
if (!HasActivePluginsLoaded) {
if ((ActivePlugins == null) || (ActivePlugins.Count == 0)) {
return;
}
@ -307,7 +305,7 @@ namespace ArchiSteamFarm.Plugins {
throw new ArgumentNullException(nameof(bot) + " || " + nameof(steamID));
}
if (!HasActivePluginsLoaded) {
if ((ActivePlugins == null) || (ActivePlugins.Count == 0)) {
return false;
}
@ -329,7 +327,7 @@ namespace ArchiSteamFarm.Plugins {
throw new ArgumentNullException(nameof(bot));
}
if (!HasActivePluginsLoaded) {
if ((ActivePlugins == null) || (ActivePlugins.Count == 0)) {
return;
}
@ -345,7 +343,7 @@ namespace ArchiSteamFarm.Plugins {
throw new ArgumentNullException(nameof(bot));
}
if (!HasActivePluginsLoaded) {
if ((ActivePlugins == null) || (ActivePlugins.Count == 0)) {
return;
}
@ -361,7 +359,7 @@ namespace ArchiSteamFarm.Plugins {
throw new ArgumentNullException(nameof(bot));
}
if (!HasActivePluginsLoaded) {
if ((ActivePlugins == null) || (ActivePlugins.Count == 0)) {
return;
}
@ -377,7 +375,7 @@ namespace ArchiSteamFarm.Plugins {
throw new ArgumentNullException(nameof(bot) + " || " + nameof(steamID) + " || " + nameof(message));
}
if (!HasActivePluginsLoaded) {
if ((ActivePlugins == null) || (ActivePlugins.Count == 0)) {
return null;
}
@ -399,7 +397,7 @@ namespace ArchiSteamFarm.Plugins {
throw new ArgumentNullException(nameof(bot) + " || " + nameof(callbackManager));
}
if (!HasActivePluginsLoaded) {
if ((ActivePlugins == null) || (ActivePlugins.Count == 0)) {
return;
}
@ -415,7 +413,7 @@ namespace ArchiSteamFarm.Plugins {
throw new ArgumentNullException(nameof(bot));
}
if (!HasActivePluginsLoaded) {
if ((ActivePlugins == null) || (ActivePlugins.Count == 0)) {
return null;
}
@ -437,7 +435,7 @@ namespace ArchiSteamFarm.Plugins {
throw new ArgumentNullException(nameof(bot) + " || " + nameof(tradeOffer));
}
if (!HasActivePluginsLoaded) {
if ((ActivePlugins == null) || (ActivePlugins.Count == 0)) {
return false;
}
@ -459,7 +457,7 @@ namespace ArchiSteamFarm.Plugins {
throw new ArgumentNullException(nameof(bot) + " || " + nameof(tradeResults));
}
if (!HasActivePluginsLoaded) {
if ((ActivePlugins == null) || (ActivePlugins.Count == 0)) {
return;
}
@ -475,7 +473,7 @@ namespace ArchiSteamFarm.Plugins {
throw new ArgumentNullException(nameof(bot) + " || " + nameof(newNotifications));
}
if (!HasActivePluginsLoaded) {
if ((ActivePlugins == null) || (ActivePlugins.Count == 0)) {
return;
}
@ -491,7 +489,7 @@ namespace ArchiSteamFarm.Plugins {
throw new ArgumentNullException(nameof(currentChangeNumber) + " || " + nameof(appChanges) + " || " + nameof(packageChanges));
}
if (!HasActivePluginsLoaded) {
if ((ActivePlugins == null) || (ActivePlugins.Count == 0)) {
return;
}
@ -507,7 +505,7 @@ namespace ArchiSteamFarm.Plugins {
throw new ArgumentNullException(nameof(currentChangeNumber));
}
if (!HasActivePluginsLoaded) {
if ((ActivePlugins == null) || (ActivePlugins.Count == 0)) {
return;
}

View file

@ -61,7 +61,7 @@ namespace ArchiSteamFarm {
return;
}
string? executableName = Path.GetFileNameWithoutExtension(OS.ProcessFileName);
string executableName = Path.GetFileNameWithoutExtension(OS.ProcessFileName);
if (string.IsNullOrEmpty(executableName)) {
throw new ArgumentNullException(nameof(executableName));
@ -223,7 +223,7 @@ namespace ArchiSteamFarm {
if (!string.IsNullOrEmpty(ASF.GlobalConfig?.CurrentCulture)) {
try {
// GetCultureInfo() would be better but we can't use it for specifying neutral cultures such as "en"
CultureInfo culture = CultureInfo.CreateSpecificCulture(ASF.GlobalConfig!.CurrentCulture);
CultureInfo culture = CultureInfo.CreateSpecificCulture(ASF.GlobalConfig!.CurrentCulture!);
CultureInfo.DefaultThreadCurrentCulture = CultureInfo.DefaultThreadCurrentUICulture = culture;
} catch (Exception e) {
ASF.ArchiLogger.LogGenericWarningException(e);
@ -385,8 +385,12 @@ namespace ArchiSteamFarm {
private static async void OnProcessExit(object? sender, EventArgs e) => await Shutdown().ConfigureAwait(false);
private static async void OnUnhandledException(object? sender, UnhandledExceptionEventArgs e) {
if (e?.ExceptionObject == null) {
throw new ArgumentNullException(nameof(e) + " || " + nameof(e.ExceptionObject));
if (e == null) {
throw new ArgumentNullException(nameof(e));
}
if (e.ExceptionObject == null) {
throw new ArgumentNullException(nameof(e.ExceptionObject));
}
await ASF.ArchiLogger.LogFatalException((Exception) e.ExceptionObject).ConfigureAwait(false);
@ -394,8 +398,12 @@ namespace ArchiSteamFarm {
}
private static async void OnUnobservedTaskException(object? sender, UnobservedTaskExceptionEventArgs e) {
if (e?.Exception == null) {
throw new ArgumentNullException(nameof(e) + " || " + nameof(e.Exception));
if (e == null) {
throw new ArgumentNullException(nameof(e));
}
if (e.Exception == null) {
throw new ArgumentNullException(nameof(e.Exception));
}
await ASF.ArchiLogger.LogFatalException(e.Exception).ConfigureAwait(false);
@ -414,7 +422,7 @@ namespace ArchiSteamFarm {
string? envCryptKey = Environment.GetEnvironmentVariable(SharedInfo.EnvironmentVariableCryptKey);
if (!string.IsNullOrEmpty(envCryptKey)) {
HandleCryptKeyArgument(envCryptKey);
HandleCryptKeyArgument(envCryptKey!);
}
} catch (Exception e) {
ASF.ArchiLogger.LogGenericException(e);
@ -462,13 +470,13 @@ namespace ArchiSteamFarm {
string? envNetworkGroup = Environment.GetEnvironmentVariable(SharedInfo.EnvironmentVariableNetworkGroup);
if (!string.IsNullOrEmpty(envNetworkGroup)) {
HandleNetworkGroupArgument(envNetworkGroup);
HandleNetworkGroupArgument(envNetworkGroup!);
}
string? envPath = Environment.GetEnvironmentVariable(SharedInfo.EnvironmentVariablePath);
if (!string.IsNullOrEmpty(envPath)) {
HandlePathArgument(envPath);
HandlePathArgument(envPath!);
}
} catch (Exception e) {
ASF.ArchiLogger.LogGenericException(e);

View file

@ -29,7 +29,6 @@ using Microsoft.AspNetCore.Hosting;
using System.Collections.Generic;
using System.Net.WebSockets;
using System.Threading;
#endif
namespace ArchiSteamFarm {

View file

@ -355,9 +355,7 @@ namespace ArchiSteamFarm {
private async Task<(bool ShouldContinueMatching, bool TradedSomething)> MatchActivelyRound(IReadOnlyCollection<Steam.Asset.EType> acceptedMatchableTypes, IDictionary<ulong, (byte Tries, ISet<ulong>? GivenAssetIDs, ISet<ulong>? ReceivedAssetIDs)> triedSteamIDs) {
if ((acceptedMatchableTypes == null) || (acceptedMatchableTypes.Count == 0) || (triedSteamIDs == null)) {
Bot.ArchiLogger.LogNullError(nameof(acceptedMatchableTypes) + " || " + nameof(triedSteamIDs));
return (false, false);
throw new ArgumentNullException(nameof(acceptedMatchableTypes) + " || " + nameof(triedSteamIDs));
}
HashSet<Steam.Asset> ourInventory;

View file

@ -36,9 +36,7 @@ namespace ArchiSteamFarm.SteamKit2 {
public Task UpdateServerListAsync(IEnumerable<ServerRecord> endpoints) {
if (endpoints == null) {
ASF.ArchiLogger.LogNullError(nameof(endpoints));
return Task.CompletedTask;
throw new ArgumentNullException(nameof(endpoints));
}
HashSet<ServerRecordEndPoint> newServerRecords = endpoints.Select(ep => new ServerRecordEndPoint(ep.GetHost(), (ushort) ep.GetPort(), ep.ProtocolTypes)).ToHashSet();

View file

@ -265,7 +265,7 @@ namespace ArchiSteamFarm {
}
foreach (((uint RealAppID, Steam.Asset.EType Type, Steam.Asset.ERarity Rarity) set, Dictionary<ulong, uint> state) in tradableState) {
if (!fullState.TryGetValue(set, out Dictionary<ulong, uint>? fullSet) || (fullSet == null) || (fullSet.Count == 0)) {
if (!fullState.TryGetValue(set, out Dictionary<ulong, uint>? fullSet) || (fullSet.Count == 0)) {
throw new ArgumentNullException(nameof(fullSet));
}

View file

@ -671,7 +671,7 @@ namespace ArchiSteamFarm {
}
if (!string.IsNullOrEmpty(referer)) {
request.Headers.Referrer = new Uri(referer);
request.Headers.Referrer = new Uri(referer!);
}
if (Debugging.IsUserDebugging) {