Skip to content

Commit 1606908

Browse files
committed
Move to dynamic
1 parent ab306d9 commit 1606908

File tree

2 files changed

+14
-38
lines changed

2 files changed

+14
-38
lines changed

Flow.Launcher/Flow.Launcher.csproj

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -77,24 +77,6 @@
7777
<SubType>Designer</SubType>
7878
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
7979
</Content>
80-
<COMReference Include="SHDocVw">
81-
<VersionMinor>1</VersionMinor>
82-
<VersionMajor>1</VersionMajor>
83-
<Guid>eab22ac0-30c1-11cf-a7eb-0000c05bae0b</Guid>
84-
<Lcid>0</Lcid>
85-
<WrapperTool>tlbimp</WrapperTool>
86-
<Isolated>false</Isolated>
87-
<EmbedInteropTypes>true</EmbedInteropTypes>
88-
</COMReference>
89-
<COMReference Include="Shell32">
90-
<VersionMinor>0</VersionMinor>
91-
<VersionMajor>1</VersionMajor>
92-
<Guid>50a7e9b0-70ef-11d1-b75a-00a0c90564fe</Guid>
93-
<Lcid>0</Lcid>
94-
<WrapperTool>tlbimp</WrapperTool>
95-
<Isolated>false</Isolated>
96-
<EmbedInteropTypes>true</EmbedInteropTypes>
97-
</COMReference>
9880
<Content Include="Resources\Segoe Fluent Icons.ttf">
9981
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
10082
</Content>

Flow.Launcher/Helper/FileExplorerHelper.cs

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class FileExplorerHelper
1414
public static string GetActiveExplorerPath()
1515
{
1616
var explorerWindow = GetActiveExplorer();
17-
string locationUrl = explorerWindow.LocationURL;
17+
string locationUrl = explorerWindow?.LocationURL;
1818
if (!string.IsNullOrEmpty(locationUrl))
1919
{
2020
return new Uri(locationUrl).LocalPath;
@@ -28,31 +28,25 @@ public static string GetActiveExplorerPath()
2828
/// <summary>
2929
/// Gets the file explorer that is currently in the foreground
3030
/// </summary>
31-
private static SHDocVw.InternetExplorer GetActiveExplorer()
31+
private static dynamic GetActiveExplorer()
3232
{
3333
// get the active window
3434
IntPtr handle = GetForegroundWindow();
3535

36-
// Required ref: SHDocVw (Microsoft Internet Controls COM Object) - C:\Windows\system32\ShDocVw.dll
37-
var shellWindows = new SHDocVw.ShellWindows();
38-
39-
// loop through all windows
40-
foreach (var window in shellWindows)
36+
Type type = Type.GetTypeFromProgID("Shell.Application");
37+
if (type == null) return null;
38+
dynamic shell = Activator.CreateInstance(type);
39+
var openWindows = shell.Windows();
40+
for (int i = 0; i < openWindows.Count; i++)
4141
{
42-
if (window is SHDocVw.InternetExplorer explorerWindow && new IntPtr(explorerWindow.HWND) == handle)
43-
{
44-
// we have found the desired window, now let's make sure that it is indeed a file explorer
45-
// we don't want the Internet Explorer or the classic control panel
46-
if (explorerWindow.Document is not Shell32.IShellFolderViewDual2)
47-
{
48-
return null;
49-
}
50-
if (Path.GetFileName(explorerWindow.FullName) != "explorer.exe")
51-
{
52-
return null;
53-
}
42+
var window = openWindows.Item(i);
43+
if (window == null) continue;
5444

55-
return explorerWindow;
45+
// find the desired window and make sure that it is indeed a file explorer
46+
// we don't want the Internet Explorer or the classic control panel
47+
if (Path.GetFileName((string)window.FullName) == "explorer.exe" && new IntPtr(window.HWND) == handle)
48+
{
49+
return window;
5650
}
5751
}
5852

0 commit comments

Comments
 (0)