Fix a lot of the analyzer warnings too
This commit is contained in:
@@ -323,7 +323,7 @@ public partial class FileDownloadManager : DisposableMediatorSubscriberBase
|
||||
fileBlockStream.Position += fileLengthBytes;
|
||||
|
||||
while (tasks.Count > threadCount && tasks.Where(t => !t.IsCompleted).Count() > 4)
|
||||
await Task.Delay(10, CancellationToken.None);
|
||||
await Task.Delay(10, CancellationToken.None).ConfigureAwait(false);
|
||||
|
||||
var fileExtension = fileReplacement.First(f => string.Equals(f.Hash, fileHash, StringComparison.OrdinalIgnoreCase)).GamePaths[0].Split(".")[^1];
|
||||
var tmpPath = _fileDbManager.GetCacheFilePath(Guid.NewGuid().ToString(), "tmp");
|
||||
@@ -362,7 +362,7 @@ public partial class FileDownloadManager : DisposableMediatorSubscriberBase
|
||||
|
||||
string calculatedHash = BitConverter.ToString(tmpFileStream.Finish()).Replace("-", "", StringComparison.Ordinal);
|
||||
|
||||
if (calculatedHash != fileHash)
|
||||
if (!calculatedHash.Equals(fileHash, StringComparison.Ordinal))
|
||||
{
|
||||
Logger.LogError("Hash mismatch after extracting, got {hash}, expected {expectedHash}, deleting file", calculatedHash, fileHash);
|
||||
return;
|
||||
@@ -388,7 +388,7 @@ public partial class FileDownloadManager : DisposableMediatorSubscriberBase
|
||||
if (File.Exists(tmpPath))
|
||||
File.Delete(tmpPath);
|
||||
}
|
||||
}));
|
||||
}, CancellationToken.None));
|
||||
}
|
||||
|
||||
Task.WaitAll([..tasks], CancellationToken.None);
|
||||
|
||||
@@ -15,7 +15,7 @@ public class FileTransferOrchestrator : DisposableMediatorSubscriberBase
|
||||
private readonly ConcurrentDictionary<Guid, bool> _downloadReady = new();
|
||||
private readonly HttpClient _httpClient;
|
||||
private readonly MareConfigService _mareConfig;
|
||||
private readonly object _semaphoreModificationLock = new();
|
||||
private readonly Lock _semaphoreModificationLock = new();
|
||||
private readonly TokenProvider _tokenProvider;
|
||||
private int _availableDownloadSlots;
|
||||
private SemaphoreSlim _downloadSemaphore;
|
||||
|
||||
@@ -182,27 +182,19 @@ public sealed class FileUploadManager : DisposableMediatorSubscriberBase
|
||||
|
||||
try
|
||||
{
|
||||
await UploadFileStream(compressedFile, fileHash, false, postProgress, uploadToken).ConfigureAwait(false);
|
||||
await UploadFileStream(compressedFile, fileHash, munged: false, postProgress, uploadToken).ConfigureAwait(false);
|
||||
_verifiedUploadedHashes[fileHash] = DateTime.UtcNow;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (false && ex is not OperationCanceledException)
|
||||
{
|
||||
Logger.LogWarning(ex, "[{hash}] Error during file upload, trying alternative file upload", fileHash);
|
||||
await UploadFileStream(compressedFile, fileHash, munged: true, postProgress, uploadToken).ConfigureAwait(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.LogWarning(ex, "[{hash}] File upload cancelled", fileHash);
|
||||
}
|
||||
Logger.LogWarning(ex, "[{hash}] File upload cancelled", fileHash);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task UploadFileStream(byte[] compressedFile, string fileHash, bool munged, bool postProgress, CancellationToken uploadToken)
|
||||
{
|
||||
if (munged)
|
||||
throw new NotImplementedException();
|
||||
throw new InvalidOperationException();
|
||||
|
||||
using var ms = new MemoryStream(compressedFile);
|
||||
|
||||
|
||||
@@ -102,7 +102,7 @@
|
||||
#pragma warning restore CA1835
|
||||
}
|
||||
|
||||
public override async ValueTask<int> ReadAsync(Memory<byte> buffer, CancellationToken cancellationToken)
|
||||
public override async ValueTask<int> ReadAsync(Memory<byte> buffer, CancellationToken cancellationToken = default)
|
||||
{
|
||||
await Throttle(buffer.Length, cancellationToken).ConfigureAwait(false);
|
||||
return await _baseStream.ReadAsync(buffer, cancellationToken).ConfigureAwait(false);
|
||||
@@ -125,7 +125,7 @@
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override async ValueTask WriteAsync(ReadOnlyMemory<byte> buffer, CancellationToken cancellationToken)
|
||||
public override async ValueTask WriteAsync(ReadOnlyMemory<byte> buffer, CancellationToken cancellationToken = default)
|
||||
{
|
||||
await Throttle(buffer.Length, cancellationToken).ConfigureAwait(false);
|
||||
await _baseStream.WriteAsync(buffer, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
@@ -179,7 +179,7 @@ public sealed partial class ApiController : DisposableMediatorSubscriberBase, IM
|
||||
|
||||
if (token.IsCancellationRequested) break;
|
||||
|
||||
_mareHub = await _hubFactory.GetOrCreate(token);
|
||||
_mareHub = await _hubFactory.GetOrCreate(token).ConfigureAwait(false);
|
||||
InitializeApiHooks();
|
||||
|
||||
await _mareHub.StartAsync(token).ConfigureAwait(false);
|
||||
|
||||
@@ -57,7 +57,7 @@ public class HubFactory : MediatorSubscriberBase
|
||||
{
|
||||
if (!_isDisposed && _instance != null) return _instance;
|
||||
|
||||
_cachedConfig = await ResolveHubConfig();
|
||||
_cachedConfig = await ResolveHubConfig().ConfigureAwait(false);
|
||||
_cachedConfigFor = _serverConfigurationManager.CurrentApiUrl;
|
||||
|
||||
return BuildHubConnection(_cachedConfig, ct);
|
||||
@@ -71,7 +71,7 @@ public class HubFactory : MediatorSubscriberBase
|
||||
|
||||
HubConnectionConfig defaultConfig;
|
||||
|
||||
if (_cachedConfig != null && _serverConfigurationManager.CurrentApiUrl == _cachedConfigFor)
|
||||
if (_cachedConfig != null && _serverConfigurationManager.CurrentApiUrl.Equals(_cachedConfigFor, StringComparison.Ordinal))
|
||||
{
|
||||
defaultConfig = _cachedConfig;
|
||||
}
|
||||
@@ -84,7 +84,7 @@ public class HubFactory : MediatorSubscriberBase
|
||||
};
|
||||
}
|
||||
|
||||
if (_serverConfigurationManager.CurrentApiUrl == ApiController.LoporritServiceUri)
|
||||
if (_serverConfigurationManager.CurrentApiUrl.Equals(ApiController.LoporritServiceUri, StringComparison.Ordinal))
|
||||
defaultConfig.HubUrl = ApiController.LoporritServiceHubUri;
|
||||
|
||||
string jsonResponse;
|
||||
@@ -126,7 +126,7 @@ public class HubFactory : MediatorSubscriberBase
|
||||
|
||||
var contentType = response.Content.Headers.ContentType?.MediaType;
|
||||
|
||||
if (contentType == null || contentType != "application/json")
|
||||
if (contentType == null || !contentType.Equals("application/json", StringComparison.Ordinal))
|
||||
return defaultConfig;
|
||||
|
||||
jsonResponse = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
|
||||
|
||||
@@ -21,7 +21,7 @@ public sealed class TokenProvider : IDisposable, IMediatorSubscriber
|
||||
private readonly ILogger<TokenProvider> _logger;
|
||||
private readonly ServerConfigurationManager _serverManager;
|
||||
private readonly ConcurrentDictionary<JwtIdentifier, string> _tokenCache = new();
|
||||
private readonly ConcurrentDictionary<string, string?> _wellKnownCache = new();
|
||||
private readonly ConcurrentDictionary<string, string?> _wellKnownCache = new(StringComparer.Ordinal);
|
||||
|
||||
public TokenProvider(ILogger<TokenProvider> logger, ServerConfigurationManager serverManager, DalamudUtilService dalamudUtil, MareMediator mareMediator)
|
||||
{
|
||||
@@ -70,22 +70,20 @@ public sealed class TokenProvider : IDisposable, IMediatorSubscriber
|
||||
.Replace("ws://", "http://", StringComparison.OrdinalIgnoreCase)));
|
||||
var secretKey = _serverManager.GetSecretKey(out _)!;
|
||||
var auth = secretKey.GetHash256();
|
||||
result = await _httpClient.PostAsync(tokenUri, new FormUrlEncodedContent(new[]
|
||||
{
|
||||
new KeyValuePair<string, string>("auth", auth),
|
||||
new KeyValuePair<string, string>("charaIdent", await _dalamudUtil.GetPlayerNameHashedAsync().ConfigureAwait(false)),
|
||||
}), token).ConfigureAwait(false);
|
||||
result = await _httpClient.PostAsync(tokenUri, new FormUrlEncodedContent([
|
||||
new("auth", auth),
|
||||
new("charaIdent", await _dalamudUtil.GetPlayerNameHashedAsync().ConfigureAwait(false)),
|
||||
]), token).ConfigureAwait(false);
|
||||
|
||||
if (result.StatusCode == HttpStatusCode.NotFound)
|
||||
{
|
||||
tokenUri = MareAuth.AuthFullPath(new Uri(_serverManager.CurrentApiUrl
|
||||
.Replace("wss://", "https://", StringComparison.OrdinalIgnoreCase)
|
||||
.Replace("ws://", "http://", StringComparison.OrdinalIgnoreCase)));
|
||||
result = await _httpClient.PostAsync(tokenUri, new FormUrlEncodedContent(new[]
|
||||
{
|
||||
new KeyValuePair<string, string>("auth", auth),
|
||||
new KeyValuePair<string, string>("charaIdent", await _dalamudUtil.GetPlayerNameHashedAsync().ConfigureAwait(false)),
|
||||
}), token).ConfigureAwait(false);
|
||||
result = await _httpClient.PostAsync(tokenUri, new FormUrlEncodedContent([
|
||||
new("auth", auth),
|
||||
new("charaIdent", await _dalamudUtil.GetPlayerNameHashedAsync().ConfigureAwait(false)),
|
||||
]), token).ConfigureAwait(false);
|
||||
|
||||
var textResponse = await result.Content.ReadAsStringAsync(token).ConfigureAwait(false) ?? string.Empty;
|
||||
result.EnsureSuccessStatusCode();
|
||||
|
||||
Reference in New Issue
Block a user