@@ -30,18 +30,18 @@ internal class Win32API
30
30
{
31
31
public static Task StartSTATask ( Func < Task > func )
32
32
{
33
- var tcs = new TaskCompletionSource ( ) ;
33
+ var taskCompletionSource = new TaskCompletionSource ( ) ;
34
34
Thread thread = new Thread ( async ( ) =>
35
35
{
36
36
Ole32 . OleInitialize ( ) ;
37
37
try
38
38
{
39
39
await func ( ) ;
40
- tcs . SetResult ( ) ;
40
+ taskCompletionSource . SetResult ( ) ;
41
41
}
42
42
catch ( Exception ex )
43
43
{
44
- tcs . SetResult ( ) ;
44
+ taskCompletionSource . SetResult ( ) ;
45
45
App . Logger . Warn ( ex , ex . Message ) ;
46
46
}
47
47
finally
@@ -55,23 +55,23 @@ public static Task StartSTATask(Func<Task> func)
55
55
} ;
56
56
thread . SetApartmentState ( ApartmentState . STA ) ;
57
57
thread . Start ( ) ;
58
- return tcs . Task ;
58
+ return taskCompletionSource . Task ;
59
59
}
60
60
61
61
public static Task StartSTATask ( Action action )
62
62
{
63
- var tcs = new TaskCompletionSource ( ) ;
63
+ var taskCompletionSource = new TaskCompletionSource ( ) ;
64
64
Thread thread = new Thread ( ( ) =>
65
65
{
66
66
Ole32 . OleInitialize ( ) ;
67
67
try
68
68
{
69
69
action ( ) ;
70
- tcs . SetResult ( ) ;
70
+ taskCompletionSource . SetResult ( ) ;
71
71
}
72
72
catch ( Exception ex )
73
73
{
74
- tcs . SetResult ( ) ;
74
+ taskCompletionSource . SetResult ( ) ;
75
75
App . Logger . Warn ( ex , ex . Message ) ;
76
76
}
77
77
finally
@@ -85,22 +85,22 @@ public static Task StartSTATask(Action action)
85
85
} ;
86
86
thread . SetApartmentState ( ApartmentState . STA ) ;
87
87
thread . Start ( ) ;
88
- return tcs . Task ;
88
+ return taskCompletionSource . Task ;
89
89
}
90
90
91
91
public static Task < T > StartSTATask < T > ( Func < T > func )
92
92
{
93
- var tcs = new TaskCompletionSource < T > ( ) ;
93
+ var taskCompletionSource = new TaskCompletionSource < T > ( ) ;
94
94
Thread thread = new Thread ( ( ) =>
95
95
{
96
96
Ole32 . OleInitialize ( ) ;
97
97
try
98
98
{
99
- tcs . SetResult ( func ( ) ) ;
99
+ taskCompletionSource . SetResult ( func ( ) ) ;
100
100
}
101
101
catch ( Exception ex )
102
102
{
103
- tcs . SetResult ( default ) ;
103
+ taskCompletionSource . SetResult ( default ) ;
104
104
App . Logger . Warn ( ex , ex . Message ) ;
105
105
//tcs.SetException(e);
106
106
}
@@ -115,22 +115,22 @@ public static Task<T> StartSTATask<T>(Func<T> func)
115
115
} ;
116
116
thread . SetApartmentState ( ApartmentState . STA ) ;
117
117
thread . Start ( ) ;
118
- return tcs . Task ;
118
+ return taskCompletionSource . Task ;
119
119
}
120
120
121
121
public static Task < T > StartSTATask < T > ( Func < Task < T > > func )
122
122
{
123
- var tcs = new TaskCompletionSource < T > ( ) ;
123
+ var taskCompletionSource = new TaskCompletionSource < T > ( ) ;
124
124
Thread thread = new Thread ( async ( ) =>
125
125
{
126
126
Ole32 . OleInitialize ( ) ;
127
127
try
128
128
{
129
- tcs . SetResult ( await func ( ) ) ;
129
+ taskCompletionSource . SetResult ( await func ( ) ) ;
130
130
}
131
131
catch ( Exception ex )
132
132
{
133
- tcs . SetResult ( default ) ;
133
+ taskCompletionSource . SetResult ( default ) ;
134
134
App . Logger . Info ( ex , ex . Message ) ;
135
135
//tcs.SetException(e);
136
136
}
@@ -145,7 +145,7 @@ public static Task<T> StartSTATask<T>(Func<Task<T>> func)
145
145
} ;
146
146
thread . SetApartmentState ( ApartmentState . STA ) ;
147
147
thread . Start ( ) ;
148
- return tcs . Task ;
148
+ return taskCompletionSource . Task ;
149
149
}
150
150
151
151
public static async Task < string > GetFileAssociationAsync ( string filename , bool checkDesktopFirst = false )
@@ -428,16 +428,10 @@ public static IList<IconFileInfo> ExtractIconsFromDLL(string file)
428
428
var iconsList = new List < IconFileInfo > ( ) ;
429
429
using var currentProc = Process . GetCurrentProcess ( ) ;
430
430
using var icoCnt = Shell32 . ExtractIcon ( currentProc . Handle , file , - 1 ) ;
431
- if ( icoCnt == null )
432
- {
433
- return null ;
434
- }
431
+ if ( icoCnt == null ) return null ;
435
432
436
433
int count = icoCnt . DangerousGetHandle ( ) . ToInt32 ( ) ;
437
- if ( count <= 0 )
438
- {
439
- return null ;
440
- }
434
+ if ( count <= 0 ) return null ;
441
435
442
436
for ( int i = 0 ; i < count ; i ++ )
443
437
{
@@ -480,23 +474,18 @@ public static bool SetCustomDirectoryIcon(string folderPath, string iconFile, in
480
474
public static async Task < bool > SetCustomFileIconAsync ( string filePath , string iconFile , int iconIndex = 0 )
481
475
{
482
476
var connection = await AppServiceConnectionHelper . Instance ;
483
- if ( connection != null )
484
- {
485
- var ( status , response ) = await connection . SendMessageForResponseAsync ( new ValueSet ( )
477
+ if ( connection == null ) return false ;
478
+ var ( status , response ) = await connection . SendMessageForResponseAsync ( new ValueSet ( )
486
479
{
487
480
{ "Arguments" , "FileOperation" } ,
488
481
{ "fileop" , "SetLinkIcon" } ,
489
482
{ "iconIndex" , iconIndex } ,
490
483
{ "filepath" , filePath } ,
491
484
{ "iconFile" , iconFile }
492
485
} ) ;
493
- var success = status == AppServiceResponseStatus . Success && response . Get ( "Success" , false ) ;
494
- if ( success )
495
- {
496
- _iconAndOverlayCache [ filePath ] = new ( ) ;
497
- }
498
- }
499
- return false ;
486
+ var success = status == AppServiceResponseStatus . Success && response . Get ( "Success" , false ) ;
487
+ if ( success ) _iconAndOverlayCache [ filePath ] = new ( ) ;
488
+ return success ;
500
489
}
501
490
502
491
public static void UnlockBitlockerDrive ( string drive , string password )
0 commit comments