Skip to content

Refactor: use COM API for windows firewall rules#21

Merged
FN-FAL113 merged 6 commits into
FN-FAL113:mainfrom
JanitorialMess:refactor/windows-firewall-com-api
Mar 31, 2026
Merged

Refactor: use COM API for windows firewall rules#21
FN-FAL113 merged 6 commits into
FN-FAL113:mainfrom
JanitorialMess:refactor/windows-firewall-com-api

Conversation

@JanitorialMess

@JanitorialMess JanitorialMess commented Mar 29, 2026

Copy link
Copy Markdown
Contributor

As discussed in #17, this PR replaces the Windows firewall block/unblock path with direct HNetCfg.FwPolicy2 / HNetCfg.FWRule COM calls instead of spawning cmd.exe -> netsh.exe once per rule.

The previous implementation handled each rule change by launching a separate shell process and waiting for it to finish. That makes block/unblock operations unnecessarily slow, especially when switching games or applying many rule changes in a row. See #17 (comment) for the comparison numbers.

Changes

  • replace Windows firewall rule add/delete operations with direct COM calls
  • keep ResetFirewallAsync() on netsh advfirewall reset (I wasn't able to find an alternative in the COM API)
  • enable built-in COM interop in the project file

Notes

  • this change only affects the Windows firewall implementation
  • Linux firewall behavior is unchanged
  • I tested this locally, but only on my own Windows machine

@FN-FAL113

Copy link
Copy Markdown
Owner

I'll take a look at this later, thanks.

Comment thread ServerPickerX/Services/SystemFirewalls/WindowsFirewallService.cs Outdated
Comment thread ServerPickerX/Services/SystemFirewalls/WindowsFirewallService.cs Outdated
@FN-FAL113

FN-FAL113 commented Mar 31, 2026

Copy link
Copy Markdown
Owner

Did you try publishing the app and running it?

command: dotnet publish ServerPickerX.slnx -c Release -r win-x64
output directory: ServerPickerX/bin/Release/net10.0/<runtime>/publish/

Seems to be not working, crashes. Might not be trim-compatible.

@FN-FAL113

FN-FAL113 commented Mar 31, 2026

Copy link
Copy Markdown
Owner

Tested it without trimming and it worked, so its not trim-compatible due to usage of reflection. Without trim, file size is 101 mb. Wondering if there's a way to support COM interop with trim-enabled apps by directly adding COM packages as dependencies

@FN-FAL113

FN-FAL113 commented Mar 31, 2026

Copy link
Copy Markdown
Owner

ServerPickerX-Windows.zip

Can you test this release (v1.0.4) before I merge this PR? Thanks. It references Interop.NetFwTypeLib.dll COM as a regular assembly and used for static types rather than using dynamic types. This allows the app to be trim-compatible

@JanitorialMess

JanitorialMess commented Mar 31, 2026

Copy link
Copy Markdown
Contributor Author

Seems to work just fine!

Unrelated but I noticed on that build (and probably on the main app) that the "New version available! Go to releases?" window is showing again every time I change the game from the dropdown and it doesn't get dismissed for the session. It spawns again. Unticking the box in the setting makes it completely disappear.

@FN-FAL113

FN-FAL113 commented Mar 31, 2026

Copy link
Copy Markdown
Owner

Seems to work just fine!

Unrelated but I noticed on that build (and probably on the main app) that the "New version available! Go to releases?" window is showing again every time I change the game, it's not just on startup. Unticking the box in the setting makes it completely disappear.

Thanks! Yeah the version checker relies on Github API. I haven't created a new release so it will check against v1,0,3.

@FN-FAL113 FN-FAL113 merged commit e2f0030 into FN-FAL113:main Mar 31, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants