Skip to content

Commit

Permalink
Resolve some qodana warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
JustArchi committed Jan 5, 2025
1 parent 90ae809 commit ccec47c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
2 changes: 2 additions & 0 deletions ArchiSteamFarm/Helpers/SerializableFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ internal static async Task<bool> Write(string filePath, string json) {

try {
// We always want to write entire content to temporary file first, in order to never load corrupted data, also when target file doesn't exist
#pragma warning disable CA3003 // Ignored due to caller's intent
if (File.Exists(filePath)) {
string currentJson = await File.ReadAllTextAsync(filePath).ConfigureAwait(false);

Expand All @@ -169,6 +170,7 @@ internal static async Task<bool> Write(string filePath, string json) {

File.Move(newFilePath, filePath);
}
#pragma warning restore CA3003 // Ignored due to caller's intent

return true;
} catch (Exception e) {
Expand Down
8 changes: 4 additions & 4 deletions ArchiSteamFarm/Steam/Bot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ public EAccess GetAccess(ulong steamID) {

result.UnionWith(regexMatches);
} catch (RegexMatchTimeoutException e) {
ASF.ArchiLogger.LogGenericException(e);
ASF.ArchiLogger.LogGenericWarningException(e);
}

continue;
Expand Down Expand Up @@ -1811,13 +1811,13 @@ internal async Task<bool> Rename(string newBotName) {
string newFilePath = GetFilePath(newBotName, fileType);

if (string.IsNullOrEmpty(newFilePath)) {
ArchiLogger.LogNullError(newFilePath);

return false;
throw new InvalidOperationException(nameof(newFilePath));
}

try {
#pragma warning disable CA3003 // New file path derived from bot's name that was validated above
File.Move(filePath, newFilePath);
#pragma warning restore CA3003 // New file path derived from bot's name that was validated above
} catch (Exception e) {
ArchiLogger.LogGenericException(e);

Expand Down
19 changes: 14 additions & 5 deletions ArchiSteamFarm/Steam/Interaction/Commands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2054,7 +2054,9 @@ internal void OnNewLicenseList() {
Regex regex;

try {
regex = new Regex(game, RegexOptions.CultureInvariant);
#pragma warning disable CA3012 // We're aware of a potential denial of service here, this is why we limit maximum matching time to a sane value
regex = new Regex(game, RegexOptions.CultureInvariant, TimeSpan.FromSeconds(1));
#pragma warning restore CA3012 // We're aware of a potential denial of service here, this is why we limit maximum matching time to a sane value
} catch (ArgumentException e) {
Bot.ArchiLogger.LogGenericWarningException(e);
response.AppendLine(FormatBotResponse(Strings.FormatErrorIsInvalid(nameof(regex))));
Expand All @@ -2074,11 +2076,18 @@ internal void OnNewLicenseList() {

bool foundWithRegex = false;

foreach ((uint appID, string gameName) in gamesOwned.Where(gameOwned => regex.IsMatch(gameOwned.Value))) {
foundWithRegex = true;
try {
foreach ((uint appID, string gameName) in gamesOwned.Where(gameOwned => regex.IsMatch(gameOwned.Value))) {
foundWithRegex = true;

result[$"app/{appID}"] = gameName;
response.AppendLine(FormatBotResponse(Strings.FormatBotOwnedAlreadyWithName($"app/{appID}", gameName)));
result[$"app/{appID}"] = gameName;
response.AppendLine(FormatBotResponse(Strings.FormatBotOwnedAlreadyWithName($"app/{appID}", gameName)));
}
} catch (RegexMatchTimeoutException e) {
Bot.ArchiLogger.LogGenericWarningException(e);
response.AppendLine(FormatBotResponse(Strings.FormatWarningFailedWithError(nameof(regex))));

break;
}

if (!foundWithRegex) {
Expand Down

0 comments on commit ccec47c

Please sign in to comment.