4
4
using Files . App . Utils . Storage . Operations ;
5
5
using Files . Shared . Helpers ;
6
6
using Microsoft . Extensions . Logging ;
7
- using Microsoft . Win32 ;
8
7
using System . Collections . Concurrent ;
9
8
using System . IO ;
10
9
using System . Runtime . InteropServices ;
@@ -492,7 +491,7 @@ public static Task SetClipboard(string[] filesToCopy, DataPackageOperation opera
492
491
Destination = e . DestFolder . GetParsingPath ( ) is not null && ! string . IsNullOrEmpty ( e . Name ) ? Path . Combine ( e . DestFolder . GetParsingPath ( ) , e . Name ) : null ,
493
492
HResult = ( int ) e . Result
494
493
} ) ;
495
-
494
+
496
495
UpdateFileTagsDb ( e , "move" ) ;
497
496
} ;
498
497
@@ -580,10 +579,10 @@ public static Task SetClipboard(string[] filesToCopy, DataPackageOperation opera
580
579
{
581
580
using ShellItem shi = new ( fileToCopyPath [ i ] ) ;
582
581
using ShellFolder shd = new ( Path . GetDirectoryName ( copyDestination [ i ] ) ) ;
583
-
582
+
584
583
var fileName = GetIncrementalName ( overwriteOnCopy , copyDestination [ i ] , fileToCopyPath [ i ] ) ;
585
584
// Perform a copy operation
586
- op . QueueCopyOperation ( shi , shd , fileName ) ;
585
+ op . QueueCopyOperation ( shi , shd , fileName ) ;
587
586
} ) )
588
587
{
589
588
shellOperationResult . Items . Add ( new ShellOperationItemResult ( )
@@ -623,7 +622,7 @@ public static Task SetClipboard(string[] filesToCopy, DataPackageOperation opera
623
622
Destination = e . DestFolder . GetParsingPath ( ) is not null && ! string . IsNullOrEmpty ( e . Name ) ? Path . Combine ( e . DestFolder . GetParsingPath ( ) , e . Name ) : null ,
624
623
HResult = ( int ) e . Result
625
624
} ) ;
626
-
625
+
627
626
UpdateFileTagsDb ( e , "copy" ) ;
628
627
} ;
629
628
@@ -774,6 +773,38 @@ public static bool SetLinkIcon(string filePath, string iconFile, int iconIndex)
774
773
link . SaveAs ( filePath ) ; // Overwrite if exists
775
774
return true ;
776
775
}
776
+ catch ( UnauthorizedAccessException )
777
+ {
778
+ string psScript = $@ "
779
+ $FilePath = '{ filePath } '
780
+ $IconFile = '{ iconFile } '
781
+ $IconIndex = '{ iconIndex } '
782
+
783
+ $Shell = New-Object -ComObject WScript.Shell
784
+ $Shortcut = $Shell.CreateShortcut($FilePath)
785
+ $Shortcut.IconLocation = ""$IconFile, $IconIndex""
786
+ $Shortcut.Save()
787
+ " ;
788
+
789
+ var base64EncodedScript = Convert . ToBase64String ( System . Text . Encoding . Unicode . GetBytes ( psScript ) ) ;
790
+
791
+ ProcessStartInfo startInfo = new ProcessStartInfo ( )
792
+ {
793
+ FileName = "powershell.exe" ,
794
+ Arguments = $ "-NoProfile -EncodedCommand { base64EncodedScript } ",
795
+ Verb = "runas" ,
796
+ CreateNoWindow = true ,
797
+ WindowStyle = ProcessWindowStyle . Hidden ,
798
+ UseShellExecute = true
799
+ } ;
800
+
801
+ // Start the process
802
+ Process process = new Process ( ) { StartInfo = startInfo } ;
803
+ process . Start ( ) ;
804
+ process . WaitForExit ( ) ;
805
+
806
+ return true ;
807
+ }
777
808
catch ( Exception ex )
778
809
{
779
810
// Could not create shortcut
@@ -1023,7 +1054,7 @@ protected override void Dispose(bool disposing)
1023
1054
private static string GetIncrementalName ( bool overWriteOnCopy , string ? filePathToCheck , string ? filePathToCopy )
1024
1055
{
1025
1056
if ( filePathToCheck == null )
1026
- return null ;
1057
+ return null ;
1027
1058
1028
1059
if ( ( ! Path . Exists ( filePathToCheck ) ) || overWriteOnCopy || filePathToCheck == filePathToCopy )
1029
1060
return Path . GetFileName ( filePathToCheck ) ;
@@ -1039,6 +1070,6 @@ private static string GetIncrementalName(bool overWriteOnCopy, string? filePathT
1039
1070
index ++ ;
1040
1071
1041
1072
return Path . GetFileName ( genFilePath ( index ) ) ;
1042
- }
1073
+ }
1043
1074
}
1044
1075
}
0 commit comments