mirror of
https://github.com/Caraxi/mare.client.git
synced 2025-12-12 16:57:22 +01:00
add more debugging info
This commit is contained in:
parent
eb42079e85
commit
8c2f17b75f
2 changed files with 23 additions and 16 deletions
|
|
@ -66,7 +66,7 @@ public class CachedPlayer
|
||||||
Logger.Debug("Received data for " + this);
|
Logger.Debug("Received data for " + this);
|
||||||
|
|
||||||
Logger.Debug("Checking for files to download for player " + PlayerName);
|
Logger.Debug("Checking for files to download for player " + PlayerName);
|
||||||
Logger.Debug("Hash for data is " + characterData.GetHashCode());
|
Logger.Debug("Hash for data is " + characterData.GetHashCode() + ", current cache hash is " + _cachedData.GetHashCode());
|
||||||
|
|
||||||
if (characterData.GetHashCode() == _cachedData.GetHashCode()) return;
|
if (characterData.GetHashCode() == _cachedData.GetHashCode()) return;
|
||||||
|
|
||||||
|
|
@ -434,9 +434,11 @@ public class CachedPlayer
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
_cachedData = new();
|
_cachedData = new();
|
||||||
|
var tempPlayerName = PlayerName;
|
||||||
PlayerName = string.Empty;
|
PlayerName = string.Empty;
|
||||||
PlayerCharacter = IntPtr.Zero;
|
PlayerCharacter = IntPtr.Zero;
|
||||||
IsVisible = false;
|
IsVisible = false;
|
||||||
|
Logger.Debug("Disposing " + tempPlayerName + " complete");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -98,7 +98,7 @@ public partial class ApiController
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<string> DownloadFileHttpClient(DownloadFileTransfer fileTransfer, IProgress<long> progress, CancellationToken ct)
|
private async Task DownloadFileHttpClient(DownloadFileTransfer fileTransfer, string tempPath, IProgress<long> progress, CancellationToken ct)
|
||||||
{
|
{
|
||||||
var requestId = await GetQueueRequest(fileTransfer, ct).ConfigureAwait(false);
|
var requestId = await GetQueueRequest(fileTransfer, ct).ConfigureAwait(false);
|
||||||
|
|
||||||
|
|
@ -124,12 +124,9 @@ public partial class ApiController
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var fileName = "";
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
fileName = Path.GetTempFileName();
|
var fileStream = File.Create(tempPath);
|
||||||
|
|
||||||
var fileStream = File.Create(fileName);
|
|
||||||
await using (fileStream.ConfigureAwait(false))
|
await using (fileStream.ConfigureAwait(false))
|
||||||
{
|
{
|
||||||
var bufferSize = response.Content.Headers.ContentLength > 1024 * 1024 ? 4096 : 1024;
|
var bufferSize = response.Content.Headers.ContentLength > 1024 * 1024 ? 4096 : 1024;
|
||||||
|
|
@ -145,8 +142,7 @@ public partial class ApiController
|
||||||
progress.Report(bytesRead);
|
progress.Report(bytesRead);
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger.Debug($"{requestUrl} downloaded to {fileName}");
|
Logger.Debug($"{requestUrl} downloaded to {tempPath}");
|
||||||
return fileName;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
|
@ -154,8 +150,8 @@ public partial class ApiController
|
||||||
Logger.Warn($"Error during file download of {requestUrl}", ex);
|
Logger.Warn($"Error during file download of {requestUrl}", ex);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (!fileName.IsNullOrEmpty())
|
if (!tempPath.IsNullOrEmpty())
|
||||||
File.Delete(fileName);
|
File.Delete(tempPath);
|
||||||
}
|
}
|
||||||
catch { }
|
catch { }
|
||||||
throw;
|
throw;
|
||||||
|
|
@ -246,18 +242,27 @@ public partial class ApiController
|
||||||
file.Transferred += bytesDownloaded;
|
file.Transferred += bytesDownloaded;
|
||||||
});
|
});
|
||||||
|
|
||||||
var tempFile = await DownloadFileHttpClient(file, progress, token).ConfigureAwait(false);
|
var tempPath = Path.Combine(_pluginConfiguration.CacheFolder, file.Hash + ".tmp");
|
||||||
if (token.IsCancellationRequested)
|
try
|
||||||
{
|
{
|
||||||
File.Delete(tempFile);
|
await DownloadFileHttpClient(file, tempPath, progress, token).ConfigureAwait(false);
|
||||||
Logger.Debug("Detetokened cancellation, removing " + currentDownloadId);
|
}
|
||||||
|
catch (OperationCanceledException)
|
||||||
|
{
|
||||||
|
File.Delete(tempPath);
|
||||||
|
Logger.Debug("Detected cancellation, removing " + currentDownloadId);
|
||||||
CancelDownload(currentDownloadId);
|
CancelDownload(currentDownloadId);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Logger.Error("Error during download of " + file.Hash, ex);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var tempFileData = await File.ReadAllBytesAsync(tempFile, token).ConfigureAwait(false);
|
var tempFileData = await File.ReadAllBytesAsync(tempPath, token).ConfigureAwait(false);
|
||||||
var extratokenedFile = LZ4Codec.Unwrap(tempFileData);
|
var extratokenedFile = LZ4Codec.Unwrap(tempFileData);
|
||||||
File.Delete(tempFile);
|
File.Delete(tempPath);
|
||||||
var filePath = Path.Combine(_pluginConfiguration.CacheFolder, file.Hash);
|
var filePath = Path.Combine(_pluginConfiguration.CacheFolder, file.Hash);
|
||||||
await File.WriteAllBytesAsync(filePath, extratokenedFile, token).ConfigureAwait(false);
|
await File.WriteAllBytesAsync(filePath, extratokenedFile, token).ConfigureAwait(false);
|
||||||
var fi = new FileInfo(filePath);
|
var fi = new FileInfo(filePath);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue