-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
71 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using Ionic.Zip; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using SyncClipboard.Core.Interfaces; | ||
using SyncClipboard.Core.Utilities; | ||
using System.Text; | ||
|
||
namespace SyncClipboard.Core.Clipboard; | ||
|
||
public class GroupProfile : FileProfile | ||
{ | ||
private readonly string[] _files; | ||
|
||
protected override IClipboardSetter<Profile> ClipboardSetter | ||
=> ServiceProvider.GetRequiredService<IClipboardSetter<GroupProfile>>(); | ||
|
||
public GroupProfile(string[] files) : base() | ||
{ | ||
_files = files; | ||
} | ||
|
||
public override async Task UploadProfile(IWebDav webdav, CancellationToken token) | ||
{ | ||
await PrepareTransferFile(token); | ||
await base.UploadProfile(webdav, token); | ||
} | ||
|
||
protected async Task PrepareTransferFile(CancellationToken token) | ||
{ | ||
var filePath = Path.Combine(LocalTemplateFolder, $"{Path.GetRandomFileName()}.zip"); | ||
|
||
using ZipFile zip = new ZipFile(); | ||
zip.AlternateEncoding = Encoding.UTF8; | ||
zip.AlternateEncodingUsage = ZipOption.Always; | ||
_files.ForEach(path => | ||
{ | ||
if (Directory.Exists(path)) | ||
{ | ||
zip.AddDirectory(path, Path.GetFileName(path)); | ||
} | ||
else if (File.Exists(path)) | ||
{ | ||
zip.AddItem(path, ""); | ||
} | ||
}); | ||
|
||
await Task.Run(() => zip.Save(filePath), token).WaitAsync(token); | ||
FullPath = filePath; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters