|
7 | 7 | using System.Threading.Tasks;
|
8 | 8 | using Windows.ApplicationModel.DataTransfer;
|
9 | 9 | using Windows.Storage;
|
| 10 | +using System.Collections.Generic; |
| 11 | +using Windows.ApplicationModel.AppService; |
| 12 | +using Windows.Foundation.Collections; |
| 13 | +using System.Linq; |
10 | 14 |
|
11 | 15 | namespace Files.Helpers
|
12 | 16 | {
|
13 | 17 | public static class UIFilesystemHelpers
|
14 | 18 | {
|
| 19 | + public static async void CutItem(IShellPage associatedInstance) |
| 20 | + { |
| 21 | + DataPackage dataPackage = new DataPackage |
| 22 | + { |
| 23 | + RequestedOperation = DataPackageOperation.Move |
| 24 | + }; |
| 25 | + List<IStorageItem> items = new List<IStorageItem>(); |
| 26 | + FilesystemResult result = (FilesystemResult)false; |
| 27 | + |
| 28 | + if (associatedInstance.SlimContentPage.IsItemSelected) |
| 29 | + { |
| 30 | + // First, reset DataGrid Rows that may be in "cut" command mode |
| 31 | + associatedInstance.SlimContentPage.ResetItemOpacity(); |
| 32 | + |
| 33 | + foreach (ListedItem listedItem in associatedInstance.SlimContentPage.SelectedItems) |
| 34 | + { |
| 35 | + // Dim opacities accordingly |
| 36 | + associatedInstance.SlimContentPage.SetItemOpacity(listedItem); |
| 37 | + |
| 38 | + if (listedItem.PrimaryItemAttribute == StorageItemTypes.File) |
| 39 | + { |
| 40 | + result = await associatedInstance.FilesystemViewModel.GetFileFromPathAsync(listedItem.ItemPath) |
| 41 | + .OnSuccess(t => items.Add(t)); |
| 42 | + if (!result) |
| 43 | + { |
| 44 | + break; |
| 45 | + } |
| 46 | + } |
| 47 | + else |
| 48 | + { |
| 49 | + result = await associatedInstance.FilesystemViewModel.GetFolderFromPathAsync(listedItem.ItemPath) |
| 50 | + .OnSuccess(t => items.Add(t)); |
| 51 | + if (!result) |
| 52 | + { |
| 53 | + break; |
| 54 | + } |
| 55 | + } |
| 56 | + } |
| 57 | + if (result.ErrorCode == FileSystemStatusCode.NotFound) |
| 58 | + { |
| 59 | + associatedInstance.SlimContentPage.ResetItemOpacity(); |
| 60 | + return; |
| 61 | + } |
| 62 | + else if (result.ErrorCode == FileSystemStatusCode.Unauthorized) |
| 63 | + { |
| 64 | + // Try again with fulltrust process |
| 65 | + if (associatedInstance.ServiceConnection != null) |
| 66 | + { |
| 67 | + string filePaths = string.Join('|', associatedInstance.SlimContentPage.SelectedItems.Select(x => x.ItemPath)); |
| 68 | + AppServiceResponseStatus status = await associatedInstance.ServiceConnection.SendMessageAsync(new ValueSet() |
| 69 | + { |
| 70 | + { "Arguments", "FileOperation" }, |
| 71 | + { "fileop", "Clipboard" }, |
| 72 | + { "filepath", filePaths }, |
| 73 | + { "operation", (int)DataPackageOperation.Move } |
| 74 | + }); |
| 75 | + if (status == AppServiceResponseStatus.Success) |
| 76 | + { |
| 77 | + return; |
| 78 | + } |
| 79 | + } |
| 80 | + associatedInstance.SlimContentPage.ResetItemOpacity(); |
| 81 | + return; |
| 82 | + } |
| 83 | + } |
| 84 | + |
| 85 | + if (!items.Any()) |
| 86 | + { |
| 87 | + return; |
| 88 | + } |
| 89 | + dataPackage.SetStorageItems(items); |
| 90 | + try |
| 91 | + { |
| 92 | + Clipboard.SetContent(dataPackage); |
| 93 | + Clipboard.Flush(); |
| 94 | + } |
| 95 | + catch |
| 96 | + { |
| 97 | + dataPackage = null; |
| 98 | + } |
| 99 | + } |
| 100 | + |
| 101 | + public static async void CopyItem(IShellPage associatedInstance) |
| 102 | + { |
| 103 | + DataPackage dataPackage = new DataPackage() |
| 104 | + { |
| 105 | + RequestedOperation = DataPackageOperation.Copy |
| 106 | + }; |
| 107 | + List<IStorageItem> items = new List<IStorageItem>(); |
| 108 | + |
| 109 | + string copySourcePath = associatedInstance.FilesystemViewModel.WorkingDirectory; |
| 110 | + FilesystemResult result = (FilesystemResult)false; |
| 111 | + |
| 112 | + if (associatedInstance.SlimContentPage.IsItemSelected) |
| 113 | + { |
| 114 | + foreach (ListedItem listedItem in associatedInstance.SlimContentPage.SelectedItems) |
| 115 | + { |
| 116 | + if (listedItem.PrimaryItemAttribute == StorageItemTypes.File) |
| 117 | + { |
| 118 | + result = await associatedInstance.FilesystemViewModel.GetFileFromPathAsync(listedItem.ItemPath) |
| 119 | + .OnSuccess(t => items.Add(t)); |
| 120 | + if (!result) |
| 121 | + { |
| 122 | + break; |
| 123 | + } |
| 124 | + } |
| 125 | + else |
| 126 | + { |
| 127 | + result = await associatedInstance.FilesystemViewModel.GetFolderFromPathAsync(listedItem.ItemPath) |
| 128 | + .OnSuccess(t => items.Add(t)); |
| 129 | + if (!result) |
| 130 | + { |
| 131 | + break; |
| 132 | + } |
| 133 | + } |
| 134 | + } |
| 135 | + if (result.ErrorCode == FileSystemStatusCode.Unauthorized) |
| 136 | + { |
| 137 | + // Try again with fulltrust process |
| 138 | + if (associatedInstance.ServiceConnection != null) |
| 139 | + { |
| 140 | + string filePaths = string.Join('|', associatedInstance.SlimContentPage.SelectedItems.Select(x => x.ItemPath)); |
| 141 | + await associatedInstance.ServiceConnection.SendMessageAsync(new ValueSet() |
| 142 | + { |
| 143 | + { "Arguments", "FileOperation" }, |
| 144 | + { "fileop", "Clipboard" }, |
| 145 | + { "filepath", filePaths }, |
| 146 | + { "operation", (int)DataPackageOperation.Copy } |
| 147 | + }); |
| 148 | + } |
| 149 | + return; |
| 150 | + } |
| 151 | + } |
| 152 | + |
| 153 | + if (items?.Count > 0) |
| 154 | + { |
| 155 | + dataPackage.SetStorageItems(items); |
| 156 | + try |
| 157 | + { |
| 158 | + Clipboard.SetContent(dataPackage); |
| 159 | + Clipboard.Flush(); |
| 160 | + } |
| 161 | + catch |
| 162 | + { |
| 163 | + dataPackage = null; |
| 164 | + } |
| 165 | + } |
| 166 | + } |
| 167 | + |
15 | 168 | public static async Task PasteItemAsync(string destinationPath, IShellPage associatedInstance)
|
16 | 169 | {
|
17 | 170 | DataPackageView packageView = await FilesystemTasks.Wrap(() => Task.FromResult(Clipboard.GetContent()));
|
|
0 commit comments