@@ -54,7 +54,7 @@ public FilesystemOperations(IShellPage associatedInstance)
54
54
55
55
public async Task < ( IStorageHistory , IStorageItem ) > CreateAsync ( IStorageItemWithPath source , IProgress < FileSystemStatusCode > errorCode , CancellationToken cancellationToken )
56
56
{
57
- IStorageItem item = null ;
57
+ IStorageItemWithPath item = null ;
58
58
try
59
59
{
60
60
switch ( source . ItemType )
@@ -64,22 +64,82 @@ public FilesystemOperations(IShellPage associatedInstance)
64
64
var newEntryInfo = await RegistryHelper . GetNewContextMenuEntryForType ( Path . GetExtension ( source . Path ) ) ;
65
65
if ( newEntryInfo == null )
66
66
{
67
- BaseStorageFolder folder = await associatedInstance . FilesystemViewModel . GetFolderFromPathAsync ( PathNormalization . GetParentDir ( source . Path ) ) ;
68
- item = await folder . CreateFileAsync ( Path . GetFileName ( source . Path ) ) ;
67
+ var fsFolderResult = await associatedInstance . FilesystemViewModel . GetFolderFromPathAsync ( PathNormalization . GetParentDir ( source . Path ) ) ;
68
+ var fsResult = ( FilesystemResult ) false ;
69
+ if ( fsFolderResult )
70
+ {
71
+ var fsCreateResult = await FilesystemTasks . Wrap ( ( ) => fsFolderResult . Result . CreateFileAsync ( Path . GetFileName ( source . Path ) , CreationCollisionOption . GenerateUniqueName ) . AsTask ( ) ) ;
72
+ fsResult = fsCreateResult ;
73
+ item = fsCreateResult . Result . FromStorageItem ( ) ;
74
+ }
75
+ if ( fsResult == FileSystemStatusCode . Unauthorized )
76
+ {
77
+ ( var fsAdminResult , var shellOpRes ) = await PerformAdminOperation ( new ValueSet ( )
78
+ {
79
+ { "Arguments" , "FileOperation" } ,
80
+ { "fileop" , "CreateFile" } ,
81
+ { "filepath" , source . Path }
82
+ } ) ;
83
+ if ( fsAdminResult )
84
+ {
85
+ fsResult = fsAdminResult ;
86
+ item = StorageItemHelpers . FromPathAndType ( shellOpRes . Items . SingleOrDefault ( ) ? . Destination , FilesystemItemType . File ) ;
87
+ }
88
+ }
69
89
}
70
90
else
71
91
{
72
- item = ( await newEntryInfo . Create ( source . Path , associatedInstance ) ) . Result ;
92
+ var fsCreateResult = await newEntryInfo . Create ( source . Path , associatedInstance ) ;
93
+ if ( fsCreateResult )
94
+ {
95
+ item = fsCreateResult . Result . FromStorageItem ( ) ;
96
+ }
97
+ var fsResult = ( FilesystemResult ) fsCreateResult . ErrorCode ;
98
+ if ( fsResult == FileSystemStatusCode . Unauthorized )
99
+ {
100
+ ( var fsAdminResult , var shellOpRes ) = await PerformAdminOperation ( new ValueSet ( )
101
+ {
102
+ { "Arguments" , "FileOperation" } ,
103
+ { "fileop" , "CreateFile" } ,
104
+ { "filepath" , source . Path } ,
105
+ { "template" , newEntryInfo . Template } ,
106
+ { "data" , newEntryInfo . Data }
107
+ } ) ;
108
+ if ( fsAdminResult && shellOpRes . Items . Count == 1 )
109
+ {
110
+ fsResult = fsAdminResult ;
111
+ item = StorageItemHelpers . FromPathAndType ( shellOpRes . Items . Single ( ) . Destination , FilesystemItemType . File ) ;
112
+ }
113
+ }
73
114
}
74
115
75
116
break ;
76
117
}
77
118
78
119
case FilesystemItemType . Directory :
79
120
{
80
- BaseStorageFolder folder = await associatedInstance . FilesystemViewModel . GetFolderFromPathAsync ( PathNormalization . GetParentDir ( source . Path ) ) ;
81
- item = await folder . CreateFolderAsync ( Path . GetFileName ( source . Path ) ) ;
82
-
121
+ var fsFolderResult = await associatedInstance . FilesystemViewModel . GetFolderFromPathAsync ( PathNormalization . GetParentDir ( source . Path ) ) ;
122
+ var fsResult = ( FilesystemResult ) false ;
123
+ if ( fsFolderResult )
124
+ {
125
+ var fsCreateResult = await FilesystemTasks . Wrap ( ( ) => fsFolderResult . Result . CreateFolderAsync ( Path . GetFileName ( source . Path ) , CreationCollisionOption . GenerateUniqueName ) . AsTask ( ) ) ;
126
+ fsResult = fsCreateResult ;
127
+ item = fsCreateResult . Result . FromStorageItem ( ) ;
128
+ }
129
+ if ( fsResult == FileSystemStatusCode . Unauthorized )
130
+ {
131
+ ( var fsAdminResult , var shellOpRes ) = await PerformAdminOperation ( new ValueSet ( )
132
+ {
133
+ { "Arguments" , "FileOperation" } ,
134
+ { "fileop" , "CreateFolder" } ,
135
+ { "filepath" , source . Path }
136
+ } ) ;
137
+ if ( fsAdminResult && shellOpRes . Items . Count == 1 )
138
+ {
139
+ fsResult = fsAdminResult ;
140
+ item = StorageItemHelpers . FromPathAndType ( shellOpRes . Items . Single ( ) . Destination , FilesystemItemType . Directory ) ;
141
+ }
142
+ }
83
143
break ;
84
144
}
85
145
@@ -89,7 +149,11 @@ public FilesystemOperations(IShellPage associatedInstance)
89
149
}
90
150
91
151
errorCode ? . Report ( FileSystemStatusCode . Success ) ;
92
- return ( new StorageHistory ( FileOperationType . CreateNew , source . CreateEnumerable ( ) , null ) , item ) ;
152
+ if ( item != null )
153
+ {
154
+ return ( new StorageHistory ( FileOperationType . CreateNew , item . CreateEnumerable ( ) , null ) , item . Item ) ;
155
+ }
156
+ return ( null , null ) ;
93
157
}
94
158
catch ( Exception e )
95
159
{
@@ -195,7 +259,7 @@ await DialogDisplayHelper.ShowDialogAsync(
195
259
}
196
260
if ( fsResult == FileSystemStatusCode . Unauthorized )
197
261
{
198
- fsResult = await PerformAdminOperation ( new ValueSet ( )
262
+ ( fsResult , _ ) = await PerformAdminOperation ( new ValueSet ( )
199
263
{
200
264
{ "Arguments" , "FileOperation" } ,
201
265
{ "fileop" , "CopyItem" } ,
@@ -253,7 +317,7 @@ await DialogDisplayHelper.ShowDialogAsync(
253
317
}
254
318
if ( fsResult == FileSystemStatusCode . Unauthorized )
255
319
{
256
- fsResult = await PerformAdminOperation ( new ValueSet ( )
320
+ ( fsResult , _ ) = await PerformAdminOperation ( new ValueSet ( )
257
321
{
258
322
{ "Arguments" , "FileOperation" } ,
259
323
{ "fileop" , "CopyItem" } ,
@@ -418,7 +482,7 @@ await DialogDisplayHelper.ShowDialogAsync(
418
482
}
419
483
if ( fsResult == FileSystemStatusCode . Unauthorized || fsResult == FileSystemStatusCode . ReadOnly )
420
484
{
421
- fsResult = await PerformAdminOperation ( new ValueSet ( )
485
+ ( fsResult , _ ) = await PerformAdminOperation ( new ValueSet ( )
422
486
{
423
487
{ "Arguments" , "FileOperation" } ,
424
488
{ "fileop" , "MoveItem" } ,
@@ -464,7 +528,7 @@ await DialogDisplayHelper.ShowDialogAsync(
464
528
}
465
529
if ( fsResult == FileSystemStatusCode . Unauthorized || fsResult == FileSystemStatusCode . ReadOnly )
466
530
{
467
- fsResult = await PerformAdminOperation ( new ValueSet ( )
531
+ ( fsResult , _ ) = await PerformAdminOperation ( new ValueSet ( )
468
532
{
469
533
{ "Arguments" , "FileOperation" } ,
470
534
{ "fileop" , "MoveItem" } ,
@@ -558,7 +622,7 @@ public async Task<IStorageHistory> DeleteAsync(IStorageItemWithPath source,
558
622
// not neeeded if called after trying with ShellFilesystemOperations
559
623
if ( ! fsResult )
560
624
{
561
- fsResult = await PerformAdminOperation ( new ValueSet ( )
625
+ ( fsResult , _ ) = await PerformAdminOperation ( new ValueSet ( )
562
626
{
563
627
{ "Arguments" , "FileOperation" } ,
564
628
{ "fileop" , "DeleteItem" } ,
@@ -674,7 +738,7 @@ public async Task<IStorageHistory> RenameAsync(IStorageItemWithPath source,
674
738
}
675
739
else
676
740
{
677
- var fsResult = await PerformAdminOperation ( new ValueSet ( )
741
+ var ( fsResult , _ ) = await PerformAdminOperation ( new ValueSet ( )
678
742
{
679
743
{ "Arguments" , "FileOperation" } ,
680
744
{ "fileop" , "RenameItem" } ,
@@ -785,7 +849,7 @@ public async Task<IStorageHistory> RestoreFromTrashAsync(IStorageItemWithPath so
785
849
}
786
850
if ( fsResult == FileSystemStatusCode . Unauthorized || fsResult == FileSystemStatusCode . ReadOnly )
787
851
{
788
- fsResult = await PerformAdminOperation ( new ValueSet ( )
852
+ ( fsResult , _ ) = await PerformAdminOperation ( new ValueSet ( )
789
853
{
790
854
{ "Arguments" , "FileOperation" } ,
791
855
{ "fileop" , "MoveItem" } ,
@@ -870,7 +934,7 @@ private static async Task<BaseStorageFolder> MoveDirectoryAsync(BaseStorageFolde
870
934
return createdRoot ;
871
935
}
872
936
873
- private async Task < FilesystemResult > PerformAdminOperation ( ValueSet operation )
937
+ private async Task < ( FilesystemResult , ShellOperationResult ) > PerformAdminOperation ( ValueSet operation )
874
938
{
875
939
var elevateConfirmDialog = new Files . Dialogs . ElevateConfirmDialog ( ) ;
876
940
var elevateConfirmResult = await elevateConfirmDialog . ShowAsync ( ) ;
@@ -888,11 +952,11 @@ private async Task<FilesystemResult> PerformAdminOperation(ValueSet operation)
888
952
&& response . Get ( "Success" , false ) ) ;
889
953
var shellOpResult = JsonConvert . DeserializeObject < ShellOperationResult > ( response . Get ( "Result" , "{\" Items\" : []}" ) ) ;
890
954
fsResult &= ( FilesystemResult ) shellOpResult . Items . All ( x => x . Succeeded ) ;
891
- return fsResult ;
955
+ return ( fsResult , shellOpResult ) ;
892
956
}
893
957
}
894
958
}
895
- return ( FilesystemResult ) false ;
959
+ return ( ( FilesystemResult ) false , null ) ;
896
960
}
897
961
898
962
#endregion Helpers
0 commit comments