Skip to content

Commit 2c6e2a5

Browse files
committed
CodeQA
Co-authored-by: Kemal Setya Adhi <[email protected]>
1 parent 2af2e27 commit 2c6e2a5

6 files changed

+33
-30
lines changed

ChunkSession.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ internal static async IAsyncEnumerable<ChunkSession> EnumerateMultipleChunks(
4141
// Enumerate previous chunks inside the metadata first
4242
FileInfo outputFileInfo = new FileInfo(outputFilePath);
4343

44-
// If the overwrite is toggled and the file exist, delete them.
44+
// If overwrite is toggled and the file exist, delete them.
4545
// Or if the file overflow, then delete the file and start from scratch
4646
if ((outputFileInfo.Exists && outputFileInfo.Length > contentLength)
4747
|| outputFileInfo.Exists && overwrite)

DownloadClient.cs

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
using System;
22
using System.IO;
3-
using System.Linq;
43
using System.Net;
54
using System.Net.Http;
65
using System.Threading;
76
using System.Threading.Tasks;
87
using System.Threading.Tasks.Dataflow;
8+
// ReSharper disable MemberCanBePrivate.Global
99

1010
// ReSharper disable AutoPropertyCanBeMadeGetOnly.Local
1111
// ReSharper disable UnusedMember.Global
@@ -325,7 +325,7 @@ await IO.WriteStreamToFileChunkSessionAsync(
325325
/// </summary>
326326
/// <param name="url">The URL to check</param>
327327
/// <param name="cancelToken">The cancellation token</param>
328-
/// <returns>A tuple contains a <seealso cref="HttpResponseMessage.StatusCode"/> and a <seealso cref="bool"/> of the status code (true = success, false = failed)</returns>
328+
/// <returns>A tuple contains a <seealso cref="HttpResponseMessage.StatusCode"/> and an <seealso cref="bool"/> of the status code (true = success, false = failed)</returns>
329329
public async ValueTask<(HttpStatusCode, bool)> GetURLStatus(string url, CancellationToken cancelToken)
330330
=> await GetURLStatus(CurrentHttpClientInstance, url, cancelToken);
331331

@@ -334,27 +334,27 @@ await IO.WriteStreamToFileChunkSessionAsync(
334334
/// </summary>
335335
/// <param name="url">The URL to check</param>
336336
/// <param name="cancelToken">The cancellation token</param>
337-
/// <returns>A tuple contains a <seealso cref="HttpResponseMessage.StatusCode"/> and a <seealso cref="bool"/> of the status code (true = success, false = failed)</returns>
337+
/// <returns>A tuple contains a <seealso cref="HttpResponseMessage.StatusCode"/> and an <seealso cref="bool"/> of the status code (true = success, false = failed)</returns>
338338
public async ValueTask<(HttpStatusCode, bool)> GetURLStatus(Uri url, CancellationToken cancelToken)
339339
=> await GetURLStatus(CurrentHttpClientInstance, url, cancelToken);
340340

341341
/// <summary>
342-
/// Get the Http's <seealso cref="HttpResponseMessage.StatusCode"/> of the URL from a <seealso cref="HttpClient"/> instance.
342+
/// Get the Http's <seealso cref="HttpResponseMessage.StatusCode"/> of the URL from an <seealso cref="HttpClient"/> instance.
343343
/// </summary>
344344
/// <param name="httpClient">The <seealso cref="HttpClient"/> instance to be used for URL checking</param>
345345
/// <param name="url">The URL to check</param>
346346
/// <param name="cancelToken">The cancellation token</param>
347-
/// <returns>A tuple contains a <seealso cref="HttpResponseMessage.StatusCode"/> and a <seealso cref="bool"/> of the status code (true = success, false = failed)</returns>
347+
/// <returns>A tuple contains a <seealso cref="HttpResponseMessage.StatusCode"/> and an <seealso cref="bool"/> of the status code (true = success, false = failed)</returns>
348348
public static async ValueTask<(HttpStatusCode, bool)> GetURLStatus(HttpClient httpClient, string url, CancellationToken cancelToken)
349349
=> await GetURLStatus(httpClient, url.ToUri(), cancelToken);
350350

351351
/// <summary>
352-
/// Get the Http's <seealso cref="HttpResponseMessage.StatusCode"/> of the URL from a <seealso cref="HttpClient"/> instance.
352+
/// Get the Http's <seealso cref="HttpResponseMessage.StatusCode"/> of the URL from an <seealso cref="HttpClient"/> instance.
353353
/// </summary>
354354
/// <param name="httpClient">The <seealso cref="HttpClient"/> instance to be used for URL checking</param>
355355
/// <param name="url">The URL to check</param>
356356
/// <param name="cancelToken">The cancellation token</param>
357-
/// <returns>A tuple contains a <seealso cref="HttpResponseMessage.StatusCode"/> and a <seealso cref="bool"/> of the status code (true = success, false = failed)</returns>
357+
/// <returns>A tuple contains a <seealso cref="HttpResponseMessage.StatusCode"/> and an <seealso cref="bool"/> of the status code (true = success, false = failed)</returns>
358358
public static async ValueTask<(HttpStatusCode, bool)> GetURLStatus(HttpClient httpClient, Uri url, CancellationToken cancelToken)
359359
{
360360
using (HttpResponseMessage response = await httpClient.SendAsync(
@@ -482,7 +482,7 @@ public static async ValueTask<long> GetDownloadedFileSize(
482482
throw new InvalidOperationException($"You cannot set {nameof(httpClient)} to null while {nameof(expectedLength)} is set to 0!");
483483

484484
// Get the file size from the URL or expected value
485-
long contentLength = expectedLength > 0 ? expectedLength : await fileUrl.GetUrlContentLengthAsync(httpClient!, retryCountMax ?? DefaultRetryCountMax,
485+
long contentLength = expectedLength > 0 ? expectedLength : await fileUrl.GetUrlContentLengthAsync(httpClient!, (int)retryCountMax,
486486
retryAttemptInterval.Value, timeoutAfterInterval.Value, cancelToken);
487487

488488
// Get the last session metadata info
@@ -504,9 +504,9 @@ public static async ValueTask<long> GetDownloadedFileSize(
504504
}
505505

506506
// Enumerate last ranges
507-
long lastEndOffset = currentSessionMetadata.Ranges.Count > 0
508-
? currentSessionMetadata.Ranges.Max(x => x?.End ?? 0) + 1
509-
: 0;
507+
// long lastEndOffset = currentSessionMetadata.Ranges.Count > 0
508+
// ? currentSessionMetadata.Ranges.Max(x => x?.End ?? 0) + 1
509+
// : 0;
510510

511511
// If the metadata is not exist, but it has an uncompleted file with size > DefaultSessionChunkSize,
512512
// then try to resume the download and advance the lastEndOffset from the file last position.

DownloadSpeedLimiter.cs

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
// ReSharper disable UnusedType.Global
23

34
namespace Hi3Helper.Http
45
{
@@ -11,6 +12,7 @@ namespace Hi3Helper.Http
1112
public class DownloadSpeedLimiter
1213
{
1314
internal event EventHandler<long>? DownloadSpeedChangedEvent;
15+
// ReSharper disable once MemberCanBePrivate.Global
1416
internal long? InitialRequestedSpeed { get; set; }
1517
private EventHandler<long>? InnerListener { get; set; }
1618

@@ -30,8 +32,9 @@ public static DownloadSpeedLimiter CreateInstance(long initialSpeed)
3032
/// <summary>
3133
/// Get the listener for the parent event
3234
/// </summary>
33-
/// <returns>The <seealso cref="EventHandler{long}"/> of the listener.</returns>
34-
public EventHandler<long> GetListener() => InnerListener ??= new EventHandler<long>(DownloadSpeedChangeListener);
35+
/// <returns>The EventHandler of the listener.</returns>
36+
/// <seealso cref="EventHandler"/>
37+
public EventHandler<long> GetListener() => InnerListener ??= DownloadSpeedChangeListener;
3538

3639
private void DownloadSpeedChangeListener(object? sender, long newRequestedSpeed)
3740
{

HttpResponseInputStream.cs

+14-15
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ namespace Hi3Helper.Http
1818
public class HttpResponseInputStream : Stream
1919
{
2020
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable.
21-
private protected HttpRequestMessage _networkRequest;
22-
private protected HttpResponseMessage _networkResponse;
23-
private protected Stream _networkStream;
21+
private HttpRequestMessage _networkRequest;
22+
private HttpResponseMessage _networkResponse;
23+
private Stream _networkStream;
2424
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable.
2525

26-
private protected long _networkLength;
27-
private protected long _currentPosition;
28-
public HttpStatusCode _statusCode;
29-
public bool _isSuccessStatusCode;
26+
private long _networkLength;
27+
private long _currentPosition;
28+
private HttpStatusCode _statusCode;
29+
private bool _isSuccessStatusCode;
3030

3131
public static async Task<HttpResponseInputStream?> CreateStreamAsync(
3232
HttpClient client,
@@ -232,9 +232,9 @@ protected override void Dispose(bool disposing)
232232
{
233233
if (disposing)
234234
{
235-
_networkRequest?.Dispose();
236-
_networkResponse?.Dispose();
237-
_networkStream?.Dispose();
235+
_networkRequest.Dispose();
236+
_networkResponse.Dispose();
237+
_networkStream.Dispose();
238238
}
239239

240240
GC.SuppressFinalize(this);
@@ -243,11 +243,10 @@ protected override void Dispose(bool disposing)
243243
#if NET6_0_OR_GREATER
244244
public override async ValueTask DisposeAsync()
245245
{
246-
_networkRequest?.Dispose();
247-
_networkResponse?.Dispose();
248-
if (_networkStream != null)
249-
await _networkStream.DisposeAsync();
250-
246+
_networkRequest.Dispose();
247+
_networkResponse.Dispose();
248+
await _networkStream.DisposeAsync();
249+
251250
GC.SuppressFinalize(this);
252251
}
253252
#endif

LogEvent.cs

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
// ReSharper disable UnusedAutoPropertyAccessor.Global
23

34
// ReSharper disable UnusedMember.Global
45

Utility.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ internal static bool IsStreamCanSeeLength(this Stream stream)
6767
{
6868
try
6969
{
70-
long len = stream.Length;
70+
_ = stream.Length;
7171
return true;
7272
}
7373
catch { return false; }

0 commit comments

Comments
 (0)