[TB] fix: move MoveHashDirectoryUpTB to TorBoxTorrentClient

This commit is contained in:
Sam Heinz 2025-03-16 19:09:30 +10:00
parent bf023b333b
commit fd7bc529c8
2 changed files with 26 additions and 25 deletions

View file

@ -345,6 +345,29 @@ public class TorBoxTorrentClient(ILogger<TorBoxTorrentClient> logger, IHttpClien
return Map(result!); return Map(result!);
} }
public static void MoveHashDirectoryUpTB(String extractPath, Torrent _torrent)
{
var hashDir = Path.Combine(extractPath, _torrent.Hash);
if (Directory.Exists(hashDir))
{
var innerFolder = Directory.GetDirectories(hashDir)[0];
foreach (var file in Directory.GetFiles(innerFolder))
{
var destFile = Path.Combine(extractPath, Path.GetFileName(file));
File.Move(file, destFile);
}
foreach (var dir in Directory.GetDirectories(innerFolder))
{
var destDir = Path.Combine(extractPath, Path.GetFileName(dir));
Directory.Move(dir, destDir);
}
Directory.Delete(hashDir, true);
}
}
private void Log(String message, Torrent? torrent = null) private void Log(String message, Torrent? torrent = null)
{ {
if (torrent != null) if (torrent != null)

View file

@ -1,6 +1,7 @@
using System.Diagnostics; using System.Diagnostics;
using RdtClient.Data.Models.Data; using RdtClient.Data.Models.Data;
using RdtClient.Service.Helpers; using RdtClient.Service.Helpers;
using RdtClient.Service.Services.TorrentClients;
using SharpCompress.Archives; using SharpCompress.Archives;
using SharpCompress.Archives.Rar; using SharpCompress.Archives.Rar;
using SharpCompress.Archives.Zip; using SharpCompress.Archives.Zip;
@ -105,7 +106,7 @@ public class UnpackClient(Download download, String destinationPath)
if (Settings.Get.Provider.Provider == Data.Enums.Provider.TorBox) if (Settings.Get.Provider.Provider == Data.Enums.Provider.TorBox)
{ {
MoveHashDirectoryUpTB(extractPath); TorBoxTorrentClient.MoveHashDirectoryUpTB(extractPath, _torrent);
} }
} }
catch (Exception ex) catch (Exception ex)
@ -119,29 +120,6 @@ public class UnpackClient(Download download, String destinationPath)
} }
private void MoveHashDirectoryUpTB(String extractPath)
{
var hashDir = Path.Combine(extractPath, _torrent.Hash);
if (Directory.Exists(hashDir))
{
var innerFolder = Directory.GetDirectories(hashDir)[0];
foreach (var file in Directory.GetFiles(innerFolder))
{
var destFile = Path.Combine(extractPath, Path.GetFileName(file));
File.Move(file, destFile);
}
foreach (var dir in Directory.GetDirectories(innerFolder))
{
var destDir = Path.Combine(extractPath, Path.GetFileName(dir));
Directory.Move(dir, destDir);
}
Directory.Delete(hashDir, true);
}
}
private static async Task<IList<String>> GetArchiveFiles(String filePath) private static async Task<IList<String>> GetArchiveFiles(String filePath)
{ {
await using Stream stream = File.OpenRead(filePath); await using Stream stream = File.OpenRead(filePath);