mirror of
https://github.com/JustArchiNET/ArchiSteamFarm
synced 2024-11-10 07:04:27 +00:00
Resolve CA1307
This commit is contained in:
parent
a3d352c64d
commit
04ff460d69
9 changed files with 72 additions and 15 deletions
|
@ -111,7 +111,6 @@ dotnet_diagnostic.ca1028.severity = silent
|
|||
dotnet_diagnostic.ca1031.severity = silent
|
||||
|
||||
# TODO - one at a time
|
||||
dotnet_diagnostic.ca1307.severity = silent
|
||||
dotnet_diagnostic.ca1308.severity = silent
|
||||
dotnet_diagnostic.ca1508.severity = silent
|
||||
dotnet_diagnostic.ca1819.severity = silent
|
||||
|
|
|
@ -220,7 +220,7 @@ namespace ArchiSteamFarm.OfficialPlugins.SteamTokenDumper {
|
|||
continue;
|
||||
}
|
||||
|
||||
string depotKey = BitConverter.ToString(depotKeyResult.DepotKey).Replace("-", "");
|
||||
string depotKey = BitConverter.ToString(depotKeyResult.DepotKey).Replace("-", "", StringComparison.Ordinal);
|
||||
|
||||
if (DepotKeys.TryGetValue(depotKeyResult.DepotID, out string? previousDepotKey) && (previousDepotKey == depotKey)) {
|
||||
continue;
|
||||
|
|
|
@ -19,6 +19,11 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#if NETFRAMEWORK
|
||||
using ArchiSteamFarm.RuntimeCompatibility;
|
||||
using File = System.IO.File;
|
||||
using Path = System.IO.Path;
|
||||
#endif
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
|
@ -156,11 +161,11 @@ namespace ArchiSteamFarm {
|
|||
if (!string.IsNullOrEmpty(Program.NetworkGroup)) {
|
||||
using SHA256CryptoServiceProvider hashingAlgorithm = new();
|
||||
|
||||
networkGroupText = "-" + BitConverter.ToString(hashingAlgorithm.ComputeHash(Encoding.UTF8.GetBytes(Program.NetworkGroup!))).Replace("-", "");
|
||||
networkGroupText = "-" + BitConverter.ToString(hashingAlgorithm.ComputeHash(Encoding.UTF8.GetBytes(Program.NetworkGroup!))).Replace("-", "", StringComparison.Ordinal);
|
||||
} else if (!string.IsNullOrEmpty(globalConfig.WebProxyText)) {
|
||||
using SHA256CryptoServiceProvider hashingAlgorithm = new();
|
||||
|
||||
networkGroupText = "-" + BitConverter.ToString(hashingAlgorithm.ComputeHash(Encoding.UTF8.GetBytes(globalConfig.WebProxyText!))).Replace("-", "");
|
||||
networkGroupText = "-" + BitConverter.ToString(hashingAlgorithm.ComputeHash(Encoding.UTF8.GetBytes(globalConfig.WebProxyText!))).Replace("-", "", StringComparison.Ordinal);
|
||||
}
|
||||
|
||||
ConfirmationsSemaphore ??= await PluginsCore.GetCrossProcessSemaphore(nameof(ConfirmationsSemaphore) + networkGroupText).ConfigureAwait(false);
|
||||
|
|
|
@ -19,6 +19,9 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#if NETFRAMEWORK
|
||||
using ArchiSteamFarm.RuntimeCompatibility;
|
||||
#endif
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
|
@ -1925,7 +1928,7 @@ namespace ArchiSteamFarm {
|
|||
index += daysTheirVariableName.Length;
|
||||
text = text[index..];
|
||||
|
||||
index = text.IndexOf(';');
|
||||
index = text.IndexOf(';', StringComparison.Ordinal);
|
||||
|
||||
if (index < 0) {
|
||||
Bot.ArchiLogger.LogNullError(nameof(index));
|
||||
|
@ -2362,7 +2365,7 @@ namespace ArchiSteamFarm {
|
|||
return (ESteamApiKeyState.Error, null);
|
||||
}
|
||||
|
||||
if (title.Contains("Access Denied") || title.Contains("Validated email address required")) {
|
||||
if (title.Contains("Access Denied", StringComparison.OrdinalIgnoreCase) || title.Contains("Validated email address required", StringComparison.OrdinalIgnoreCase)) {
|
||||
return (ESteamApiKeyState.AccessDenied, null);
|
||||
}
|
||||
|
||||
|
@ -2382,7 +2385,7 @@ namespace ArchiSteamFarm {
|
|||
return (ESteamApiKeyState.Error, null);
|
||||
}
|
||||
|
||||
if (text.Contains("Registering for a Steam Web API Key")) {
|
||||
if (text.Contains("Registering for a Steam Web API Key", StringComparison.OrdinalIgnoreCase)) {
|
||||
return (ESteamApiKeyState.NotRegisteredYet, null);
|
||||
}
|
||||
|
||||
|
|
|
@ -423,7 +423,7 @@ namespace ArchiSteamFarm {
|
|||
return result;
|
||||
}
|
||||
|
||||
if (botName.Contains("..")) {
|
||||
if (botName.Contains("..", StringComparison.Ordinal)) {
|
||||
string[] botRange = botName.Split(new[] { ".." }, StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
if (botRange.Length == 2) {
|
||||
|
@ -1859,7 +1859,7 @@ namespace ArchiSteamFarm {
|
|||
throw new ArgumentNullException(nameof(message));
|
||||
}
|
||||
|
||||
return message.Replace("\\", "\\\\").Replace("[", "\\[");
|
||||
return message.Replace("\\", "\\\\", StringComparison.Ordinal).Replace("[", "\\[", StringComparison.Ordinal);
|
||||
}
|
||||
|
||||
private async Task<Dictionary<string, string>?> GetKeysFromFile(string filePath) {
|
||||
|
@ -3087,7 +3087,7 @@ namespace ArchiSteamFarm {
|
|||
string? avatarHash = null;
|
||||
|
||||
if ((callback.AvatarHash.Length > 0) && callback.AvatarHash.Any(singleByte => singleByte != 0)) {
|
||||
avatarHash = BitConverter.ToString(callback.AvatarHash).Replace("-", "").ToLowerInvariant();
|
||||
avatarHash = BitConverter.ToString(callback.AvatarHash).Replace("-", "", StringComparison.Ordinal).ToLowerInvariant();
|
||||
|
||||
if (string.IsNullOrEmpty(avatarHash) || avatarHash.All(singleChar => singleChar == '0')) {
|
||||
avatarHash = null;
|
||||
|
@ -3489,7 +3489,7 @@ namespace ArchiSteamFarm {
|
|||
throw new ArgumentNullException(nameof(message));
|
||||
}
|
||||
|
||||
return message.Replace("\\[", "[").Replace("\\\\", "\\");
|
||||
return message.Replace("\\[", "[", StringComparison.Ordinal).Replace("\\\\", "\\", StringComparison.Ordinal);
|
||||
}
|
||||
|
||||
private (bool IsSteamParentalEnabled, string? SteamParentalCode) ValidateSteamParental(ParentalSettings settings, string? steamParentalCode = null) {
|
||||
|
|
|
@ -595,7 +595,7 @@ namespace ArchiSteamFarm {
|
|||
uint gameID;
|
||||
string type;
|
||||
|
||||
int index = entry.IndexOf('/');
|
||||
int index = entry.IndexOf('/', StringComparison.Ordinal);
|
||||
|
||||
if ((index > 0) && (entry.Length > index + 1)) {
|
||||
if (!uint.TryParse(entry[(index + 1)..], out gameID) || (gameID == 0)) {
|
||||
|
@ -2049,7 +2049,7 @@ namespace ArchiSteamFarm {
|
|||
string game;
|
||||
string type;
|
||||
|
||||
int index = entry.IndexOf('/');
|
||||
int index = entry.IndexOf('/', StringComparison.Ordinal);
|
||||
|
||||
if ((index > 0) && (entry.Length > index + 1)) {
|
||||
game = entry[(index + 1)..];
|
||||
|
|
|
@ -19,6 +19,9 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#if NETFRAMEWORK
|
||||
using ArchiSteamFarm.RuntimeCompatibility;
|
||||
#endif
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
|
@ -58,7 +61,7 @@ namespace ArchiSteamFarm.IPC {
|
|||
}
|
||||
|
||||
// We can try one more time by trying to smartly guess the assembly name from the namespace, this will work for custom libraries like SteamKit2
|
||||
int index = typeText.IndexOf('.');
|
||||
int index = typeText.IndexOf('.', StringComparison.Ordinal);
|
||||
|
||||
if ((index <= 0) || (index >= typeText.Length - 1)) {
|
||||
return null;
|
||||
|
|
|
@ -106,7 +106,7 @@ namespace ArchiSteamFarm {
|
|||
// At the same time it'd be the best if we avoided all special characters, such as '/' found e.g. in base64, as we can't be sure that it's not a prohibited character in regards to native OS implementation
|
||||
// Because of that, SHA256 is sufficient for our case, as it generates alphanumeric characters only, and is barely 256-bit long. We don't need any kind of complex cryptography or collision detection here, any hashing algorithm will do, and the shorter the better
|
||||
using (SHA256CryptoServiceProvider hashingAlgorithm = new()) {
|
||||
uniqueName = "Global\\" + GetOsResourceName(nameof(SingleInstance)) + "-" + BitConverter.ToString(hashingAlgorithm.ComputeHash(Encoding.UTF8.GetBytes(Directory.GetCurrentDirectory()))).Replace("-", "");
|
||||
uniqueName = "Global\\" + GetOsResourceName(nameof(SingleInstance)) + "-" + BitConverter.ToString(hashingAlgorithm.ComputeHash(Encoding.UTF8.GetBytes(Directory.GetCurrentDirectory()))).Replace("-", "", StringComparison.Ordinal);
|
||||
}
|
||||
|
||||
Mutex? singleInstance = null;
|
||||
|
|
|
@ -21,11 +21,13 @@
|
|||
|
||||
#if NETFRAMEWORK
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Net.WebSockets;
|
||||
using System.Security.Cryptography;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using ArchiSteamFarm.Localization;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
#endif
|
||||
using System;
|
||||
|
@ -102,6 +104,14 @@ namespace ArchiSteamFarm.RuntimeCompatibility {
|
|||
return default(ValueTask);
|
||||
}
|
||||
|
||||
public static int IndexOf(this string source, char value, StringComparison comparisonType) {
|
||||
if (source == null) {
|
||||
throw new ArgumentNullException(nameof(source));
|
||||
}
|
||||
|
||||
return source.IndexOf(value.ToString(), comparisonType);
|
||||
}
|
||||
|
||||
public static async Task<WebSocketReceiveResult> ReceiveAsync(this WebSocket webSocket, byte[] buffer, CancellationToken cancellationToken) {
|
||||
if (webSocket == null) {
|
||||
throw new ArgumentNullException(nameof(webSocket));
|
||||
|
@ -110,6 +120,43 @@ namespace ArchiSteamFarm.RuntimeCompatibility {
|
|||
return await webSocket.ReceiveAsync(new ArraySegment<byte>(buffer), cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public static string Replace(this string source, string oldValue, string? newValue, StringComparison comparisonType) {
|
||||
if (source == null) {
|
||||
throw new ArgumentNullException(nameof(source));
|
||||
}
|
||||
|
||||
if (oldValue == null) {
|
||||
throw new ArgumentNullException(nameof(oldValue));
|
||||
}
|
||||
|
||||
if (oldValue.Length == 0) {
|
||||
throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Strings.ErrorIsEmpty, nameof(oldValue)), nameof(oldValue));
|
||||
}
|
||||
|
||||
int startIndex = 0;
|
||||
|
||||
while (true) {
|
||||
if (source.Length == 0) {
|
||||
return source;
|
||||
}
|
||||
|
||||
int index = source.IndexOf(oldValue, startIndex, comparisonType);
|
||||
|
||||
if (index < 0) {
|
||||
return source;
|
||||
}
|
||||
|
||||
startIndex = index;
|
||||
|
||||
source = source.Remove(index, oldValue.Length);
|
||||
|
||||
if (!string.IsNullOrEmpty(newValue)) {
|
||||
source = source.Insert(index, newValue!);
|
||||
startIndex += newValue!.Length;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static async Task SendAsync(this WebSocket webSocket, byte[] buffer, WebSocketMessageType messageType, bool endOfMessage, CancellationToken cancellationToken) {
|
||||
if (webSocket == null) {
|
||||
throw new ArgumentNullException(nameof(webSocket));
|
||||
|
|
Loading…
Reference in a new issue