diff --git a/CHANGELOG.md b/CHANGELOG.md index b38ff07..7161979 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [2.0.49] - 2023-11-24 +### Changed +- Fixed memory issue in internal downloader +- Changed unpack process to handle cancels + ## [2.0.48] - 2023-11-15 ### Changed - Reverted dockerfile again as the packagemanager still doesn't have .net 8. diff --git a/client/src/app/navbar/navbar.component.html b/client/src/app/navbar/navbar.component.html index 1621838..32d854e 100644 --- a/client/src/app/navbar/navbar.component.html +++ b/client/src/app/navbar/navbar.component.html @@ -55,7 +55,7 @@ Profile Logout - Version 2.0.48 + Version 2.0.49 diff --git a/package.json b/package.json index 57425c8..cb3c2b1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rdt-client", - "version": "2.0.48", + "version": "2.0.49", "description": "This is a web interface to manage your torrents on Real-Debrid.", "main": "index.js", "dependencies": { diff --git a/server/RdtClient.Service/RdtClient.Service.csproj b/server/RdtClient.Service/RdtClient.Service.csproj index c4f25b3..f5b569a 100644 --- a/server/RdtClient.Service/RdtClient.Service.csproj +++ b/server/RdtClient.Service/RdtClient.Service.csproj @@ -11,7 +11,7 @@ - + diff --git a/server/RdtClient.Service/Services/Downloaders/InternalDownloader.cs b/server/RdtClient.Service/Services/Downloaders/InternalDownloader.cs index 0b95a07..c3f011a 100644 --- a/server/RdtClient.Service/Services/Downloaders/InternalDownloader.cs +++ b/server/RdtClient.Service/Services/Downloaders/InternalDownloader.cs @@ -1,5 +1,4 @@ -using System.Diagnostics; -using DownloaderNET; +using DownloaderNET; using Serilog; namespace RdtClient.Service.Services.Downloaders; @@ -34,7 +33,7 @@ public class InternalDownloader : IDownloader _downloadService = new Downloader(_uri, _filePath, _downloadConfiguration); - _downloadService.OnLog += message => Debug.WriteLine(message.Message); + //_downloadService.OnLog += message => Debug.WriteLine(message.Message); _downloadService.OnProgress += (chunks, _) => { diff --git a/server/RdtClient.Service/Services/Torrents.cs b/server/RdtClient.Service/Services/Torrents.cs index 569d336..fa475c9 100644 --- a/server/RdtClient.Service/Services/Torrents.cs +++ b/server/RdtClient.Service/Services/Torrents.cs @@ -76,8 +76,8 @@ public class Torrents if (TorrentRunner.ActiveUnpackClients.TryGetValue(download.DownloadId, out var unpackClient)) { - download.BytesTotal = unpackClient.BytesTotal; - download.BytesDone = unpackClient.BytesDone; + download.BytesTotal = 100; + download.BytesDone = unpackClient.Progess; } } } @@ -580,8 +580,8 @@ public class Torrents if (TorrentRunner.ActiveUnpackClients.TryGetValue(download.DownloadId, out var unpackClient)) { - download.BytesTotal = unpackClient.BytesTotal; - download.BytesDone = unpackClient.BytesDone; + download.BytesTotal = 100; + download.BytesDone = unpackClient.Progess; } } diff --git a/server/RdtClient.Service/Services/UnpackClient.cs b/server/RdtClient.Service/Services/UnpackClient.cs index f24f592..b7ea06f 100644 --- a/server/RdtClient.Service/Services/UnpackClient.cs +++ b/server/RdtClient.Service/Services/UnpackClient.cs @@ -1,9 +1,9 @@ -using RdtClient.Data.Models.Data; +using System.Diagnostics; +using RdtClient.Data.Models.Data; using RdtClient.Service.Helpers; using SharpCompress.Archives; using SharpCompress.Archives.Rar; using SharpCompress.Archives.Zip; -using SharpCompress.Common; namespace RdtClient.Service.Services; @@ -13,17 +13,13 @@ public class UnpackClient public String? Error { get; private set; } - public Int64 BytesTotal { get; private set; } - public Int64 BytesDone { get; private set; } + public Int32 Progess { get; private set; } private readonly Download _download; private readonly String _destinationPath; private readonly Torrent _torrent; - - private Boolean _cancelled; - - private IArchiveEntry? _rarCurrentEntry; - private Dictionary? _rarfileStatus; + + private readonly CancellationTokenSource _cancellationTokenSource = new CancellationTokenSource(); public UnpackClient(Download download, String destinationPath) { @@ -34,8 +30,7 @@ public class UnpackClient public void Start() { - BytesDone = 0; - BytesTotal = 0; + Progess = 0; try { @@ -48,9 +43,9 @@ public class UnpackClient Task.Run(async delegate { - if (!_cancelled) + if (!_cancellationTokenSource.IsCancellationRequested) { - await Unpack(filePath); + await Unpack(filePath, _cancellationTokenSource.Token); } }); } @@ -63,10 +58,10 @@ public class UnpackClient public void Cancel() { - _cancelled = true; + _cancellationTokenSource.Cancel(); } - private async Task Unpack(String filePath) + private async Task Unpack(String filePath, CancellationToken cancellationToken) { try { @@ -80,7 +75,7 @@ public class UnpackClient var archiveEntries = await GetArchiveFiles(filePath); - if (!archiveEntries.Any(m => m.StartsWith(_torrent.RdName + @"\")) && !archiveEntries.Any(m => m.StartsWith(_torrent.RdName + @"/"))) + if (!archiveEntries.Any(m => m.StartsWith(_torrent.RdName + @"\")) && !archiveEntries.Any(m => m.StartsWith(_torrent.RdName + "/"))) { extractPath = Path.Combine(_destinationPath, _torrent.RdName!); } @@ -97,7 +92,7 @@ public class UnpackClient if (extractPathTemp != null) { - Extract(filePath, extractPathTemp); + Extract(filePath, extractPathTemp, cancellationToken); await FileHelper.Delete(filePath); @@ -109,7 +104,7 @@ public class UnpackClient if (File.Exists(mainRarFile)) { - Extract(mainRarFile, extractPath); + Extract(mainRarFile, extractPath, cancellationToken); } await FileHelper.DeleteDirectory(extractPathTemp); @@ -117,7 +112,7 @@ public class UnpackClient } else { - Extract(filePath, extractPath); + Extract(filePath, extractPath, cancellationToken); await FileHelper.Delete(filePath); } @@ -132,7 +127,7 @@ public class UnpackClient } } - private async Task> GetArchiveFiles(String filePath) + private static async Task> GetArchiveFiles(String filePath) { await using Stream stream = File.OpenRead(filePath); @@ -148,8 +143,6 @@ public class UnpackClient archive = RarArchive.Open(stream); } - BytesTotal = archive.TotalSize; - var entries = archive.Entries .Where(entry => !entry.IsDirectory) .Select(m => m.Key) @@ -160,7 +153,7 @@ public class UnpackClient return entries; } - private void Extract(String filePath, String extractPath) + private void Extract(String filePath, String extractPath, CancellationToken cancellationToken) { var parts = ArchiveFactory.GetFileParts(filePath); @@ -177,48 +170,17 @@ public class UnpackClient { archive = RarArchive.Open(fi); } - - if (archive.IsComplete) - { - BytesTotal = archive.TotalSize; - } - var entries = archive.Entries.Where(entry => !entry.IsDirectory) - .ToList(); - - _rarfileStatus = entries.ToDictionary(entry => entry.Key, _ => 0L); - _rarCurrentEntry = null; - archive.CompressedBytesRead += ArchiveOnCompressedBytesRead; - - foreach (var entry in entries) - { - if (_cancelled) - { - throw new Exception("Task was cancelled"); - } - - _rarCurrentEntry = entry; - - entry.WriteToDirectory(extractPath, - new ExtractionOptions + archive.ExtractToDirectory(extractPath, + d => { - ExtractFullPath = true, - Overwrite = true - }); - } - + Debug.WriteLine(d); + Progess = (Int32) Math.Round(d); + }, + cancellationToken: cancellationToken); + archive.Dispose(); - } - private void ArchiveOnCompressedBytesRead(Object? sender, CompressedBytesReadEventArgs e) - { - if (_rarCurrentEntry == null) - { - return; - } - - _rarfileStatus![_rarCurrentEntry.Key] = e.CompressedBytesRead; - - BytesDone = _rarfileStatus.Sum(m => m.Value); + GC.Collect(); } } \ No newline at end of file diff --git a/server/RdtClient.Web/RdtClient.Web.csproj b/server/RdtClient.Web/RdtClient.Web.csproj index f6f7413..af1b746 100644 --- a/server/RdtClient.Web/RdtClient.Web.csproj +++ b/server/RdtClient.Web/RdtClient.Web.csproj @@ -4,7 +4,7 @@ net8.0 Exe 94c24cba-f03f-4453-a671-3640b517c573 - 2.0.48 + 2.0.49 enable enable latest diff --git a/server/RdtClient.sln b/server/RdtClient.sln index 1b5b53e..58f8ccd 100644 --- a/server/RdtClient.sln +++ b/server/RdtClient.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.29911.84 +# Visual Studio Version 17 +VisualStudioVersion = 17.8.34316.72 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RdtClient.Web", "RdtClient.Web\RdtClient.Web.csproj", "{A8C7F095-89C6-4CD1-AFB2-27106F470D62}" EndProject