Skip to content

Commit 16747b2

Browse files
committed
CR feedback
1 parent 3022018 commit 16747b2

File tree

1 file changed

+23
-34
lines changed

1 file changed

+23
-34
lines changed

src/Files.App/Shell/Win32API.cs

Lines changed: 23 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,18 @@ internal class Win32API
3030
{
3131
public static Task StartSTATask(Func<Task> func)
3232
{
33-
var tcs = new TaskCompletionSource();
33+
var taskCompletionSource = new TaskCompletionSource();
3434
Thread thread = new Thread(async () =>
3535
{
3636
Ole32.OleInitialize();
3737
try
3838
{
3939
await func();
40-
tcs.SetResult();
40+
taskCompletionSource.SetResult();
4141
}
4242
catch (Exception ex)
4343
{
44-
tcs.SetResult();
44+
taskCompletionSource.SetResult();
4545
App.Logger.Warn(ex, ex.Message);
4646
}
4747
finally
@@ -55,23 +55,23 @@ public static Task StartSTATask(Func<Task> func)
5555
};
5656
thread.SetApartmentState(ApartmentState.STA);
5757
thread.Start();
58-
return tcs.Task;
58+
return taskCompletionSource.Task;
5959
}
6060

6161
public static Task StartSTATask(Action action)
6262
{
63-
var tcs = new TaskCompletionSource();
63+
var taskCompletionSource = new TaskCompletionSource();
6464
Thread thread = new Thread(() =>
6565
{
6666
Ole32.OleInitialize();
6767
try
6868
{
6969
action();
70-
tcs.SetResult();
70+
taskCompletionSource.SetResult();
7171
}
7272
catch (Exception ex)
7373
{
74-
tcs.SetResult();
74+
taskCompletionSource.SetResult();
7575
App.Logger.Warn(ex, ex.Message);
7676
}
7777
finally
@@ -85,22 +85,22 @@ public static Task StartSTATask(Action action)
8585
};
8686
thread.SetApartmentState(ApartmentState.STA);
8787
thread.Start();
88-
return tcs.Task;
88+
return taskCompletionSource.Task;
8989
}
9090

9191
public static Task<T> StartSTATask<T>(Func<T> func)
9292
{
93-
var tcs = new TaskCompletionSource<T>();
93+
var taskCompletionSource = new TaskCompletionSource<T>();
9494
Thread thread = new Thread(() =>
9595
{
9696
Ole32.OleInitialize();
9797
try
9898
{
99-
tcs.SetResult(func());
99+
taskCompletionSource.SetResult(func());
100100
}
101101
catch (Exception ex)
102102
{
103-
tcs.SetResult(default);
103+
taskCompletionSource.SetResult(default);
104104
App.Logger.Warn(ex, ex.Message);
105105
//tcs.SetException(e);
106106
}
@@ -115,22 +115,22 @@ public static Task<T> StartSTATask<T>(Func<T> func)
115115
};
116116
thread.SetApartmentState(ApartmentState.STA);
117117
thread.Start();
118-
return tcs.Task;
118+
return taskCompletionSource.Task;
119119
}
120120

121121
public static Task<T> StartSTATask<T>(Func<Task<T>> func)
122122
{
123-
var tcs = new TaskCompletionSource<T>();
123+
var taskCompletionSource = new TaskCompletionSource<T>();
124124
Thread thread = new Thread(async () =>
125125
{
126126
Ole32.OleInitialize();
127127
try
128128
{
129-
tcs.SetResult(await func());
129+
taskCompletionSource.SetResult(await func());
130130
}
131131
catch (Exception ex)
132132
{
133-
tcs.SetResult(default);
133+
taskCompletionSource.SetResult(default);
134134
App.Logger.Info(ex, ex.Message);
135135
//tcs.SetException(e);
136136
}
@@ -145,7 +145,7 @@ public static Task<T> StartSTATask<T>(Func<Task<T>> func)
145145
};
146146
thread.SetApartmentState(ApartmentState.STA);
147147
thread.Start();
148-
return tcs.Task;
148+
return taskCompletionSource.Task;
149149
}
150150

151151
public static async Task<string> GetFileAssociationAsync(string filename, bool checkDesktopFirst = false)
@@ -428,16 +428,10 @@ public static IList<IconFileInfo> ExtractIconsFromDLL(string file)
428428
var iconsList = new List<IconFileInfo>();
429429
using var currentProc = Process.GetCurrentProcess();
430430
using var icoCnt = Shell32.ExtractIcon(currentProc.Handle, file, -1);
431-
if (icoCnt == null)
432-
{
433-
return null;
434-
}
431+
if (icoCnt == null) return null;
435432

436433
int count = icoCnt.DangerousGetHandle().ToInt32();
437-
if (count <= 0)
438-
{
439-
return null;
440-
}
434+
if (count <= 0) return null;
441435

442436
for (int i = 0; i < count; i++)
443437
{
@@ -480,23 +474,18 @@ public static bool SetCustomDirectoryIcon(string folderPath, string iconFile, in
480474
public static async Task<bool> SetCustomFileIconAsync(string filePath, string iconFile, int iconIndex = 0)
481475
{
482476
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()
486479
{
487480
{"Arguments", "FileOperation" },
488481
{"fileop", "SetLinkIcon" },
489482
{"iconIndex", iconIndex },
490483
{"filepath", filePath },
491484
{"iconFile", iconFile }
492485
});
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;
500489
}
501490

502491
public static void UnlockBitlockerDrive(string drive, string password)

0 commit comments

Comments
 (0)