Skip to content

Commit

Permalink
GroupProfile
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeric-X committed May 6, 2024
1 parent eda0c34 commit 43bedec
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
7 changes: 6 additions & 1 deletion src/SyncClipboard.Core/Clipboard/Profile/GroupProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ private static string CaclHash(string[] files)
if (Directory.Exists(file))
{
var directoryInfo = new DirectoryInfo(file);
hash += (hash * -1521134295) + directoryInfo.Name.GetHashCode();
foreach (var subFile in directoryInfo.GetFiles("*", SearchOption.AllDirectories))
{
sumSize += subFile.Length;
Expand Down Expand Up @@ -115,7 +116,11 @@ public override async Task BeforeSetLocal(CancellationToken token, IProgress<Htt
using ZipFile zip = ZipFile.Read(FullPath);

await Task.Run(() => zip.ExtractAll(extractPath, ExtractExistingFileAction.DoNotOverwrite), token).WaitAsync(token);
_files = zip.EntryFileNames.Select(fileName => Path.Combine(extractPath, fileName.TrimEnd('\\', '/'))).ToArray();
_files = zip.EntryFileNames
.Select(file => file.TrimEnd('/'))
.Where(file => !file.Contains('/'))
.Select(file => Path.Combine(extractPath, file))
.ToArray();
}

protected override ClipboardMetaInfomation CreateMetaInformation()
Expand Down
17 changes: 15 additions & 2 deletions src/SyncClipboard.Core/Clipboard/Profile/ImageProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,21 @@ public ImageProfile(ClipboardProfileDTO profileDTO) : base(profileDTO)

public static async Task<ImageProfile> Create(IClipboardImage image, CancellationToken token)
{
var fullPath = await Task.Run(() => SaveImageToFile(image)).WaitAsync(token);
return await Create(fullPath, token);
for (int i = 0; ; i++)
{
try
{
var fullPath = await Task.Run(() => SaveImageToFile(image)).WaitAsync(token);
return await Create(fullPath, token);
}
catch when (!token.IsCancellationRequested)
{
Logger.Write($"SaveImageToFile wrong time {i + 1}");
if (i > 5)
throw;
}
await Task.Delay(100, token);
}
}

public static new async Task<ImageProfile> Create(string fullPath, CancellationToken token)
Expand Down
14 changes: 13 additions & 1 deletion src/SyncClipboard.Core/Models/ClipboardMetaInfomation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,19 @@ public record class ClipboardMetaInfomation
public string? Text;
public string? Html;
public IClipboardImage? Image;
public string[]? Files;
public string[]? _files;
public string[]? Files
{
get => _files;
set
{
_files = (string[]?)value?.Clone();
if (_files != null)
{
Array.Sort(_files);
}
}
}
public DragDropEffects? Effects;
public string? OriginalType;

Expand Down

0 comments on commit 43bedec

Please sign in to comment.