Skip to content

Commit 3f4000a

Browse files
committed
Enable nullable for project
1 parent 9122f7d commit 3f4000a

File tree

11 files changed

+26
-26
lines changed

11 files changed

+26
-26
lines changed

.editorconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
[*.cs]
22
csharp_style_namespace_declarations = file_scoped:warning
33
csharp_style_unused_value_expression_statement_preference = false
4+
dotnet_diagnostic.CA1031.severity = none

ApiClient.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
using System.Threading.Tasks;
1313
using Spectre.Console;
1414

15-
#pragma warning disable CA1031 // Do not catch general exception types
1615
namespace SteamTokenDumper;
1716

1817
internal sealed class ApiClient : IDisposable
@@ -34,8 +33,7 @@ public ApiClient()
3433

3534
public void Dispose()
3635
{
37-
HttpClient?.Dispose();
38-
HttpClient = null;
36+
HttpClient.Dispose();
3937
}
4038

4139
public async Task<bool> SendTokens(Payload payload, Configuration config)
@@ -207,7 +205,7 @@ public async Task<ImmutableHashSet<uint>> GetBackendKnownDepotIds()
207205

208206
using var reader = new StreamReader(await result.Content.ReadAsStreamAsync());
209207

210-
var count = await reader.ReadLineAsync();
208+
var count = await reader.ReadLineAsync() ?? string.Empty;
211209
var countInt = int.Parse(count, CultureInfo.InvariantCulture);
212210
var list = new HashSet<uint>(countInt);
213211

ConsoleAuthenticator.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,29 @@ namespace SteamTokenDumper;
77
internal sealed class ConsoleAuthenticator : IAuthenticator
88
{
99
/// <inheritdoc />
10-
public Task<string> GetDeviceCodeAsync(bool previousCodeWasIncorrect)
10+
public async Task<string> GetDeviceCodeAsync(bool previousCodeWasIncorrect)
1111
{
1212
if (previousCodeWasIncorrect)
1313
{
1414
AnsiConsole.MarkupLine("[red]The previous two-factor auth code you have provided is incorrect.[/]");
1515
}
1616

17-
var code = AnsiConsole.Ask<string>("[green][bold]STEAM GUARD![/][/] Enter your two-factor code from your authenticator app:").Trim();
17+
var code = await AnsiConsole.AskAsync<string>("[green][bold]STEAM GUARD![/][/] Enter your two-factor code from your authenticator app:");
1818

19-
return Task.FromResult(code);
19+
return code.Trim();
2020
}
2121

2222
/// <inheritdoc />
23-
public Task<string> GetEmailCodeAsync(string email, bool previousCodeWasIncorrect)
23+
public async Task<string> GetEmailCodeAsync(string email, bool previousCodeWasIncorrect)
2424
{
2525
if (previousCodeWasIncorrect)
2626
{
2727
AnsiConsole.MarkupLine("[red]The previous two-factor auth code you have provided is incorrect.[/]");
2828
}
2929

30-
var code = AnsiConsole.Ask<string>($"[green][bold]STEAM GUARD![/][/] Please enter the auth code sent to the email at {Markup.Escape(email)}:").Trim();
30+
var code = await AnsiConsole.AskAsync<string>($"[green][bold]STEAM GUARD![/][/] Please enter the auth code sent to the email at {Markup.Escape(email)}:");
3131

32-
return Task.FromResult(code);
32+
return code.Trim();
3333
}
3434

3535
/// <inheritdoc />

CryptoHelper.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,13 @@ public static byte[] SymmetricDecrypt(ReadOnlySpan<byte> input)
4848
return aes.DecryptCbc(input[iv.Length..], iv, PaddingMode.PKCS7);
4949
}
5050

51-
private static string GetMachineGuid()
51+
private static string? GetMachineGuid()
5252
{
5353
if (!OperatingSystem.IsWindows())
5454
{
5555
return null;
5656
}
5757

58-
#pragma warning disable CA1031 // Do not catch general exception types
5958
try
6059
{
6160
using var baseKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64);
@@ -73,6 +72,5 @@ private static string GetMachineGuid()
7372
{
7473
return null;
7574
}
76-
#pragma warning restore CA1031
7775
}
7876
}

KnownDepotIds.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,12 @@
88
using System.Threading.Tasks;
99
using Spectre.Console;
1010

11-
#pragma warning disable CA1031 // Do not catch general exception types
1211
namespace SteamTokenDumper;
1312

1413
internal sealed class KnownDepotIds
1514
{
1615
public readonly HashSet<uint> PreviouslySent = [];
17-
public ImmutableHashSet<uint> Server;
16+
public ImmutableHashSet<uint> Server = [];
1817
private readonly string KnownDepotIdsPath = Path.Combine(Program.AppPath, "SteamTokenDumper.depots.txt");
1918

2019
public async Task Load(ApiClient apiClient)

Payload.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ internal sealed class Payload
1414
public string Token { get; } = ApiClient.Token;
1515

1616
[JsonPropertyName("steamid")]
17-
public string SteamID { get; set; }
17+
public string SteamID { get; set; } = string.Empty;
1818

1919
[JsonPropertyName("apps")]
2020
public Dictionary<string, string> Apps { get; } = [];

Program.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
using SteamKit2;
1313
using SteamKit2.Authentication;
1414

15-
#pragma warning disable CA1031 // Do not catch general exception types
15+
#nullable disable
16+
1617
[assembly: CLSCompliant(false)]
1718
namespace SteamTokenDumper;
1819

Requester.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
using SteamKit2;
1111
using static SteamKit2.SteamApps;
1212

13-
#pragma warning disable CA1031 // Do not catch general exception types
1413
namespace SteamTokenDumper;
1514

1615
internal sealed class Requester(Payload payload, SteamApps steamApps, KnownDepotIds knownDepotIds, Configuration config)
@@ -152,7 +151,7 @@ await AnsiConsole.Progress()
152151

153152
foreach (var chunk in subInfoRequests.Chunk(ItemsPerRequest))
154153
{
155-
AsyncJobMultiple<PICSProductInfoCallback>.ResultSet info = null;
154+
AsyncJobMultiple<PICSProductInfoCallback>.ResultSet? info = null;
156155

157156
for (var retry = 3; retry > 0; retry--)
158157
{
@@ -259,7 +258,7 @@ private async Task Request(ProgressTask progress, ProgressTask progressTokens, P
259258

260259
foreach (var chunk in ownedApps.Chunk(ItemsPerRequest))
261260
{
262-
PICSTokensCallback tokens = null;
261+
PICSTokensCallback? tokens = null;
263262

264263
for (var retry = 3; retry > 0; retry--)
265264
{
@@ -354,7 +353,7 @@ async Task CheckFinishedDepotKeyRequests()
354353

355354
foreach (var chunk in appInfoRequests.AsEnumerable().Reverse().Chunk(ItemsPerRequest))
356355
{
357-
AsyncJobMultiple<PICSProductInfoCallback>.ResultSet appInfo = null;
356+
AsyncJobMultiple<PICSProductInfoCallback>.ResultSet? appInfo = null;
358357

359358
for (var retry = 3; retry > 0; retry--)
360359
{
@@ -517,20 +516,25 @@ public static async Task<List<uint>> GetOwnedFromStore(SteamClient steamClient,
517516

518517
try
519518
{
520-
var newToken = await steamClient.Authentication.GenerateAccessTokenForAppAsync(steamClient.SteamID, refreshToken, allowRenewal: false);
519+
var steamid = steamClient.SteamID;
520+
ArgumentNullException.ThrowIfNull(steamid);
521+
522+
var newToken = await steamClient.Authentication.GenerateAccessTokenForAppAsync(steamid, refreshToken, allowRenewal: false);
521523

522524
ArgumentNullException.ThrowIfNullOrEmpty(newToken.AccessToken);
523525

524526
using var requestMessage = new HttpRequestMessage(HttpMethod.Get, "https://store.steampowered.com/dynamicstore/userdata");
525527

526-
var cookie = string.Concat(steamClient.SteamID.ConvertToUInt64().ToString(), "||", newToken.AccessToken);
528+
var cookie = string.Concat(steamid.ConvertToUInt64().ToString(), "||", newToken.AccessToken);
527529
requestMessage.Headers.Add("Cookie", string.Concat("steamLoginSecure=", WebUtility.UrlEncode(cookie)));
528530

529531
var response = await httpClient.SendAsync(requestMessage);
530532
response.EnsureSuccessStatusCode();
531533

532534
var data = await response.Content.ReadFromJsonAsync(StoreUserDataJsonContext.Default.StoreUserData);
533535

536+
ArgumentNullException.ThrowIfNull(data);
537+
534538
AnsiConsole.WriteLine($"Store says you own {data.OwnedPackages.Count} licenses.");
535539

536540
return data.OwnedPackages;

SavedCredentials.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace SteamTokenDumper;
44

5-
#nullable enable
65
internal sealed class SavedCredentials
76
{
87
public const uint CurrentVersion = 1679580480; // 2023-03-24

SteamClientData.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
using Spectre.Console;
77
using ValveKeyValue;
88

9-
#pragma warning disable CA1031 // Do not catch general exception types
109
namespace SteamTokenDumper;
1110

1211
internal static class SteamClientData
@@ -197,7 +196,7 @@ private static void ReadDepotKeys(Table table, Payload payload, KnownDepotIds kn
197196
table.AddRow($"Got {depots.Count()} depot keys from config.vdf");
198197
}
199198

200-
private static string GetSteamPath()
199+
private static string? GetSteamPath()
201200
{
202201
if (OperatingSystem.IsWindows())
203202
{

0 commit comments

Comments
 (0)