dev2.0
洁 任 2025-07-07 15:33:30 +08:00
commit 04ef99dcc0
4 changed files with 45 additions and 18 deletions

View File

@ -269,10 +269,12 @@ public class MinioDownloadTask : NotifyPropertyChangedBase
{
// 验证文件是否存在
if (File.Exists(Path.Combine(FilePath, item.Key))) continue;
// 1 文件夹 2 存储桶
var localDir = Type == 1 ? FilePath : Path.Combine(FilePath, BucketName);
try
{
await Minio.DownLoadObject(BucketName, item.Key, localDir, item.ETag, StopDownTs.Token);
// 修改
await Minio.DownLoadObject(BucketName, item.Key, localDir, item.ETag,FileName, StopDownTs.Token);
}
catch (Exception e)
{

View File

@ -2,6 +2,7 @@
using System.IO;
using System.Security.Cryptography;
using System.Threading.Channels;
using System.Windows.Forms.VisualStyles;
using Hopetry.Provider;
using Microsoft.Extensions.Configuration;
using Minio;
@ -285,17 +286,37 @@ namespace Hopetry.Services
public async Task DownLoadObject(string bucketName, string objectKey, string localDir, string objectETag,
CancellationToken token = default)
{
var index = objectKey.LastIndexOf("/", StringComparison.Ordinal);
await DownLoadObject(bucketName, objectKey, localDir, objectETag, objectKey, token);
}
public async Task DownLoadObject(string bucketName, string objectKey, string localDir, string objectETag,
string name, CancellationToken token = default)
{
var dir = Path.Combine(localDir);
string temp;
if (name.Equals(bucketName))
{
// todo 桶下载
temp = Path.Combine(localDir, objectKey);
}
else
{
temp = objectKey.Substring(objectKey.IndexOf(name, StringComparison.Ordinal));
}
temp = temp.Replace("\\","/" );
var index = temp.LastIndexOf("/", StringComparison.Ordinal);
if (index > 0)
{
var dir = Path.Combine(localDir, objectKey.Substring(0, index));
dir = Path.Combine(localDir, temp.Substring(0, index));
if (!Directory.Exists(dir))
{
Directory.CreateDirectory(dir);
}
}
var localPath = Path.Combine(localDir, objectKey.Replace('/', Path.DirectorySeparatorChar));
var localPath = Path.Combine(dir, Path.GetFileName(objectKey));
var getArgs = new GetObjectArgs()
.WithBucket(string.IsNullOrEmpty(bucketName) ? _bucketName : bucketName)
.WithObject(objectKey)
@ -347,7 +368,8 @@ namespace Hopetry.Services
}
// 实时监听方法
public async Task RealTimeListen(string bucketName, string localDir,Action<string> action, string prefix = "", string suffix = "",
public async Task RealTimeListen(string bucketName, string localDir, Action<string> action, string prefix = "",
string suffix = "",
CancellationToken cancellationToken = default)
{
Console.WriteLine("开启实时监听");
@ -438,15 +460,6 @@ namespace Hopetry.Services
};
var token = downTask.StopDownTs.Token;
long totalBytes = 0;
var index = objectKey.LastIndexOf("/", StringComparison.Ordinal);
if (index > 0)
{
var dir = Path.Combine(filePath, objectKey.Substring(0, index));
if (!Directory.Exists(dir))
{
Directory.CreateDirectory(dir);
}
}
var args = new StatObjectArgs()
.WithBucket(string.IsNullOrEmpty(bucketName) ? _bucketName : bucketName)
@ -455,7 +468,18 @@ namespace Hopetry.Services
totalBytes = stat.Size;
//var localPath = Path.Combine(filePath, objectKey.Replace('/', Path.DirectorySeparatorChar));
var localPath = Path.Combine(filePath,
objectKey);
objectKey[(objectKey.LastIndexOf('/') + 1)..]);
var index = localPath.LastIndexOf("/", StringComparison.Ordinal);
if (index > 0)
{
var dir = localPath.Substring(0, index);
if (!Directory.Exists(dir))
{
Directory.CreateDirectory(dir);
}
}
var getObjectArgs = new GetObjectArgs()
.WithBucket(string.IsNullOrEmpty(bucketName) ? _bucketName : bucketName)
.WithObject(objectKey)

View File

@ -449,7 +449,7 @@ namespace HeBianGu.App.Disk
var temp = (MinIODirectoryInfo)dir.Model;
//Console.WriteLine($"bucket: {temp.BucketName} objectKey {temp.FullName}");
var objectKey = temp.FullName.Replace(temp.BucketName + "/", "");
ViewModelLocator.DownViewModel.AddDirTask(temp.BucketName, objectKey, downDir);
ViewModelLocator.DownViewModel.AddDirTask(temp.BucketName, objectKey,temp.Name, downDir);
}
MessageProxy.Snacker.Show("已加入下载队列");

View File

@ -428,6 +428,7 @@ public class DownViewModel : MvcViewModelBase
// 异常释放信号源
//_semaphore.Release();
Console.WriteLine($"下载失败或取消:{ex.Message}");
Console.WriteLine(ex.StackTrace);
}
finally
{
@ -549,7 +550,7 @@ public class DownViewModel : MvcViewModelBase
{
}
public async void AddDirTask(string bucketName, string objectKey, string downDir)
public async void AddDirTask(string bucketName, string objectKey, string name,string downDir)
{
// 情景1 只选了一个文件夹
// 情景2 只选了一个存储桶
@ -559,7 +560,7 @@ public class DownViewModel : MvcViewModelBase
FilePath = downDir,
ObjectKey = objectKey,
BucketName = bucketName,
FileName = objectKey,
FileName = name, // todo 确定修改这里是否有影响
Status = "等待中",
FileIcon = "\xe87a",
//DownloadInfo = "0/na",