@@ -498,9 +498,9 @@ await Win32API.StartSTATask(() =>
498498 break ;
499499
500500 case "ParseLink" :
501- var linkPath = ( string ) message [ "filepath" ] ;
502501 try
503502 {
503+ var linkPath = ( string ) message [ "filepath" ] ;
504504 if ( linkPath . EndsWith ( ".lnk" ) )
505505 {
506506 using var link = new ShellLink ( linkPath , LinkResolution . NoUIWithMsgPump , null , TimeSpan . FromMilliseconds ( 100 ) ) ;
@@ -537,22 +537,23 @@ await Win32API.StartSTATask(() =>
537537 // Could not parse shortcut
538538 Program . Logger . Warn ( ex , ex . Message ) ;
539539 await Win32API . SendMessageAsync ( connection , new ValueSet ( )
540- {
541- { "TargetPath" , null } ,
542- { "Arguments" , null } ,
543- { "WorkingDirectory" , null } ,
544- { "RunAsAdmin" , false } ,
545- { "IsFolder" , false }
546- } , message . Get ( "RequestID" , ( string ) null ) ) ;
540+ {
541+ { "TargetPath" , null } ,
542+ { "Arguments" , null } ,
543+ { "WorkingDirectory" , null } ,
544+ { "RunAsAdmin" , false } ,
545+ { "IsFolder" , false }
546+ } , message . Get ( "RequestID" , ( string ) null ) ) ;
547547 }
548548 break ;
549549
550550 case "CreateLink" :
551551 case "UpdateLink" :
552- var linkSavePath = ( string ) message [ "filepath" ] ;
553- var targetPath = ( string ) message [ "targetpath" ] ;
554552 try
555553 {
554+ var linkSavePath = ( string ) message [ "filepath" ] ;
555+ var targetPath = ( string ) message [ "targetpath" ] ;
556+
556557 bool success = false ;
557558 if ( linkSavePath . EndsWith ( ".lnk" ) )
558559 {
@@ -584,6 +585,23 @@ await Win32API.StartSTATask(() =>
584585 }
585586 break ;
586587
588+ case "SetLinkIcon" :
589+ try
590+ {
591+ var linkPath = ( string ) message [ "filepath" ] ;
592+ using var link = new ShellLink ( linkPath , LinkResolution . NoUIWithMsgPump , null , TimeSpan . FromMilliseconds ( 100 ) ) ;
593+ link . IconLocation = new IconLocation ( ( string ) message [ "iconFile" ] , ( int ) message . Get ( "iconIndex" , 0L ) ) ;
594+ link . SaveAs ( linkPath ) ; // Overwrite if exists
595+ await Win32API . SendMessageAsync ( connection , new ValueSet ( ) { { "Success" , true } } , message . Get ( "RequestID" , ( string ) null ) ) ;
596+ }
597+ catch ( Exception ex )
598+ {
599+ // Could not create shortcut
600+ Program . Logger . Warn ( ex , ex . Message ) ;
601+ await Win32API . SendMessageAsync ( connection , new ValueSet ( ) { { "Success" , false } } , message . Get ( "RequestID" , ( string ) null ) ) ;
602+ }
603+ break ;
604+
587605 case "GetFilePermissions" :
588606 {
589607 var filePathForPerm = ( string ) message [ "filepath" ] ;
0 commit comments