Add FileBow Windows app, Store identity and optional Ko-fi link

This commit is contained in:
nordik committed 2026-10-27 01:13:56 +01:00
commit 65cebb31ca
139 files changed
+375057

No files matched your search

+17
View File
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0-windows10.0.19041.0</TargetFramework>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AssemblyName>FileBow.Windows</AssemblyName>
<ApplicationIcon>../assets/icon.ico</ApplicationIcon>
<PublishSingleFile>true</PublishSingleFile>
<SelfContained>true</SelfContained>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
</PropertyGroup>
<ItemGroup><PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.26100.8249" PrivateAssets="all" /></ItemGroup>
</Project>
+118
View File
@@ -0,0 +1,118 @@
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Text.Json;
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);
static readonly object OutputLock = new();
static void Write(object data) { lock (OutputLock) { Console.WriteLine(JsonSerializer.Serialize(data)); Console.Out.Flush(); } }
[STAThread]
static void Main(string[] args)
{
SetProcessDpiAwarenessContext(new IntPtr(-4));
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
using var dispatch = new Control();
dispatch.CreateControl();
var timer = new System.Windows.Forms.Timer { Interval = 35 };
bool monitor = false, wasDown = false, dragging = false;
Point origin = default;
string[] dragFiles = [];
timer.Tick += (_, _) => {
bool down = (GetAsyncKeyState(1) & 0x8000) != 0;
GetCursorPos(out var point);
if (monitor && down && !wasDown) { origin = point; dragFiles = Selection(); }
if (monitor && down && !dragging &&
Math.Abs(point.X - origin.X) + Math.Abs(point.Y - origin.Y) > 24) {
var currentSelection = Selection();
if (currentSelection.Length > 0) dragFiles = currentSelection;
if (dragFiles.Length == 0) { wasDown = down; return; }
dragging = true;
Write(new { type = "drag", phase = "start", x = point.X, y = point.Y, files = dragFiles,
tools = (GetAsyncKeyState(18) & 0x8000) != 0 });
}
if (!down && wasDown && dragging) {
Write(new { type = "drag", phase = "drop", x = point.X, y = point.Y, files = dragFiles });
dragging = false; dragFiles = [];
}
wasDown = down;
};
timer.Start();
_ = Task.Run(() => {
string? line;
while ((line = Console.ReadLine()) != null) {
string request = line;
dispatch.BeginInvoke(new Action(async () => {
int id = 0;
try {
using var doc = JsonDocument.Parse(request);
var value = doc.RootElement;
id = value.GetProperty("id").GetInt32();
string command = value.GetProperty("command").GetString() ?? "";
object result;
switch (command) {
case "selection": result = Selection(); break;
case "monitor": monitor = value.GetProperty("enabled").GetBoolean(); result = monitor; break;
case "identity":
try { result = new { packaged = true, family = Package.Current.Id.FamilyName }; }
catch { result = new { packaged = false, family = "" }; }
break;
case "startup":
var task = await StartupTask.GetAsync("FileBowStartup");
if (value.TryGetProperty("enabled", out var enabled)) {
if (enabled.GetBoolean()) await task.RequestEnableAsync(); else task.Disable();
}
result = task.State.ToString(); break;
default: throw new InvalidOperationException("Unknown command.");
}
Write(new { id, result });
} catch (Exception ex) { Write(new { id, error = ex.Message }); }
}));
}
dispatch.BeginInvoke(new Action(Application.Exit));
});
Write(new { type = "ready" });
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();
}
}
+20
View File
@@ -0,0 +1,20 @@
{
"version": 1,
"dependencies": {
"net8.0-windows10.0.19041": {
"Microsoft.NET.ILLink.Tasks": {
"type": "Direct",
"requested": "[8.0.31, )",
"resolved": "8.0.31",
"contentHash": "OJdAGATV2QoVWL11zlDLEluA06q8rK+cgZR47ohrO8V+Qj5z9dlvN7bG9/0e5t0IOe+yD8tREC0bpsEgDGrzIQ=="
},
"Microsoft.Windows.SDK.BuildTools": {
"type": "Direct",
"requested": "[10.0.26100.8249, )",
"resolved": "10.0.26100.8249",
"contentHash": "WJ+X+fVbBcZFc5q1MufkqBNjeMqWUblbG6PmijNG0tMVt+VXdE5cdaD30dbZ90RwUTidbjxv/tmgovl5czLlrg=="
}
},
"net8.0-windows10.0.19041/win-x64": {}
}
}