|
13 | 13 | using System.Threading;
|
14 | 14 | using System.Threading.Tasks;
|
15 | 15 | using Windows.ApplicationModel.DataTransfer;
|
| 16 | +using Windows.Graphics.Imaging; |
16 | 17 | using Windows.Storage;
|
| 18 | +using Windows.Storage.Streams; |
17 | 19 | using static Files.Helpers.NativeFindStorageItemHelper;
|
18 | 20 | using FileAttributes = System.IO.FileAttributes;
|
19 | 21 |
|
@@ -505,33 +507,53 @@ public async Task<ReturnResult> CopyItemAsync(IStorageItemWithPath source, strin
|
505 | 507 |
|
506 | 508 | public async Task<ReturnResult> CopyItemsFromClipboard(DataPackageView packageView, string destination, bool registerHistory)
|
507 | 509 | {
|
508 |
| - if (!packageView.Contains(StandardDataFormats.StorageItems)) |
| 510 | + if (packageView.Contains(StandardDataFormats.StorageItems)) |
509 | 511 | {
|
510 |
| - // Happens if you copy some text and then you Ctrl+V in Files |
511 |
| - // Should this be done in ModernShellPage? |
512 |
| - return ReturnResult.BadArgumentException; |
513 |
| - } |
| 512 | + IReadOnlyList<IStorageItem> source; |
| 513 | + try |
| 514 | + { |
| 515 | + source = await packageView.GetStorageItemsAsync(); |
| 516 | + } |
| 517 | + catch (Exception ex) when ((uint)ex.HResult == 0x80040064 || (uint)ex.HResult == 0x8004006A) |
| 518 | + { |
| 519 | + return ReturnResult.UnknownException; |
| 520 | + } |
| 521 | + ReturnResult returnStatus = ReturnResult.InProgress; |
514 | 522 |
|
515 |
| - IReadOnlyList<IStorageItem> source; |
516 |
| - try |
517 |
| - { |
518 |
| - source = await packageView.GetStorageItemsAsync(); |
519 |
| - } |
520 |
| - catch (Exception ex) when ((uint)ex.HResult == 0x80040064 || (uint)ex.HResult == 0x8004006A) |
521 |
| - { |
522 |
| - return ReturnResult.UnknownException; |
| 523 | + List<string> destinations = new List<string>(); |
| 524 | + foreach (IStorageItem item in source) |
| 525 | + { |
| 526 | + destinations.Add(Path.Combine(destination, item.Name)); |
| 527 | + } |
| 528 | + |
| 529 | + returnStatus = await CopyItemsAsync(source, destinations, registerHistory); |
| 530 | + |
| 531 | + return returnStatus; |
523 | 532 | }
|
524 |
| - ReturnResult returnStatus = ReturnResult.InProgress; |
525 | 533 |
|
526 |
| - List<string> destinations = new List<string>(); |
527 |
| - foreach (IStorageItem item in source) |
| 534 | + if (packageView.Contains(StandardDataFormats.Bitmap)) |
528 | 535 | {
|
529 |
| - destinations.Add(Path.Combine(destination, item.Name)); |
| 536 | + try |
| 537 | + { |
| 538 | + var imgSource = await packageView.GetBitmapAsync(); |
| 539 | + using var imageStream = await imgSource.OpenReadAsync(); |
| 540 | + var folder = await StorageFolder.GetFolderFromPathAsync(destination); |
| 541 | + // Set the name of the file to be the current time and date |
| 542 | + var file = await folder.CreateFileAsync($"{DateTime.Now:mm-dd-yy-HHmmss}.png", CreationCollisionOption.GenerateUniqueName); |
| 543 | + |
| 544 | + using var stream = await file.OpenAsync(FileAccessMode.ReadWrite); |
| 545 | + await imageStream.AsStreamForRead().CopyToAsync(stream.AsStreamForWrite()); |
| 546 | + return ReturnResult.Success; |
| 547 | + } |
| 548 | + catch (Exception) |
| 549 | + { |
| 550 | + return ReturnResult.UnknownException; |
| 551 | + } |
530 | 552 | }
|
531 | 553 |
|
532 |
| - returnStatus = await CopyItemsAsync(source, destinations, registerHistory); |
533 |
| - |
534 |
| - return returnStatus; |
| 554 | + // Happens if you copy some text and then you Ctrl+V in Files |
| 555 | + // Should this be done in ModernShellPage? |
| 556 | + return ReturnResult.BadArgumentException; |
535 | 557 | }
|
536 | 558 |
|
537 | 559 | #endregion Copy
|
|
0 commit comments