Read selection from the active Explorer tab and use email feedback
This commit is contained in:
1 parent
3f9541c1b9
commit
0e84a1c452
15 files changed
+185
-53
No files matched your search
+1
-36
@@ -5,7 +5,6 @@ using Windows.ApplicationModel;
|
||||
|
||||
internal static class Program
|
||||
{
|
||||
[DllImport("user32.dll")] static extern IntPtr GetForegroundWindow();
|
||||
[DllImport("user32.dll")] static extern short GetAsyncKeyState(int key);
|
||||
[DllImport("user32.dll")] static extern bool GetCursorPos(out Point point);
|
||||
[DllImport("user32.dll")] static extern bool SetProcessDpiAwarenessContext(IntPtr context);
|
||||
@@ -80,39 +79,5 @@ internal static class Program
|
||||
Application.Run();
|
||||
}
|
||||
|
||||
static string[] Selection()
|
||||
{
|
||||
var files = new List<string>();
|
||||
object? shell = null, windows = null;
|
||||
try {
|
||||
shell = Activator.CreateInstance(Type.GetTypeFromProgID("Shell.Application")!);
|
||||
windows = ((dynamic)shell!).Windows();
|
||||
IntPtr foreground = GetForegroundWindow();
|
||||
foreach (object window in (dynamic)windows) {
|
||||
object? document = null, items = null;
|
||||
try {
|
||||
if (new IntPtr((long)((dynamic)window).HWND) != foreground) continue;
|
||||
document = ((dynamic)window).Document;
|
||||
items = ((dynamic)document).SelectedItems();
|
||||
foreach (object item in (dynamic)items) {
|
||||
try {
|
||||
string file = ((dynamic)item).Path;
|
||||
if (File.Exists(file)) files.Add(file);
|
||||
} finally { Marshal.ReleaseComObject(item); }
|
||||
}
|
||||
break;
|
||||
} catch (COMException) { }
|
||||
finally {
|
||||
if (items != null) Marshal.ReleaseComObject(items);
|
||||
if (document != null) Marshal.ReleaseComObject(document);
|
||||
Marshal.ReleaseComObject(window);
|
||||
}
|
||||
}
|
||||
} catch { }
|
||||
finally {
|
||||
if (windows != null) Marshal.ReleaseComObject(windows);
|
||||
if (shell != null) Marshal.ReleaseComObject(shell);
|
||||
}
|
||||
return files.Distinct(StringComparer.OrdinalIgnoreCase).ToArray();
|
||||
}
|
||||
static string[] Selection() => ExplorerSelection.Read();
|
||||
}
|
||||
Reference in new issue
Block a user