Code Quality: Remove manual interop definitions and add agent instructions for this#18449
Open
0x5bfa wants to merge 6 commits intofiles-community:mainfrom
Open
Code Quality: Remove manual interop definitions and add agent instructions for this#184490x5bfa wants to merge 6 commits intofiles-community:mainfrom
0x5bfa wants to merge 6 commits intofiles-community:mainfrom
Conversation
Member
Author
|
This is an experimental PR for writing agent instructions to remove aot-unsafe interop code to move things a lot faster. |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR continues the repo’s migration away from trim-unsafe/manual Win32 interop (and some Vanara-wrapped usage) toward CsWin32 source-generated interop, and adds documentation/instructions for both interop conversions and AI agent tooling.
Changes:
- Replace several manual P/Invoke definitions/usages with CsWin32-generated
Windows.Win32.PInvokecalls and generated types (RM_PROCESS_INFO,BROWSEINFOW,WIN32_ERROR, etc.). - Remove now-unneeded manual interop structs/enums/consts/method declarations from
Win32PInvoke.*. - Add repo guidance docs (
docs/interop-unmarshaled-conversion.md) and agent-facing instructions (AGENTS.md), plus expand CsWin32NativeMethods.txt.
Reviewed changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Files.App/ViewModels/ShellViewModel.cs | Switch directory watcher event creation to CsWin32 CreateEvent with a disposable handle. |
| src/Files.App/ViewModels/Dialogs/CreateShortcutDialogViewModel.cs | Convert folder browsing interop to CsWin32 (BROWSEINFOW, SHBrowseForFolder, SHGetPathFromIDList). |
| src/Files.App/Utils/Shell/PreviewHandler.cs | Convert COM activation to CsWin32 CoCreateInstance/HRESULT patterns. |
| src/Files.App/Utils/Shell/ItemStreamHelper.cs | Convert shell item/stream creation helpers to CsWin32 APIs. |
| src/Files.App/Services/Storage/StorageNetworkService.cs | Replace WNetGetConnection DllImport with CsWin32 PInvoke.WNetGetConnection. |
| src/Files.App/Services/App/AppUpdateSideloadService.cs | Use CsWin32 RegisterApplicationRestart. |
| src/Files.App/Helpers/Win32/Win32PInvoke.Structs.cs | Remove manual interop struct definitions now provided by CsWin32. |
| src/Files.App/Helpers/Win32/Win32PInvoke.Methods.cs | Remove manual DllImports now replaced by CsWin32-generated interop. |
| src/Files.App/Helpers/Win32/Win32PInvoke.Enums.cs | Remove Restart Manager enum now sourced from CsWin32 projections. |
| src/Files.App/Helpers/Win32/Win32PInvoke.Consts.cs | Remove Restart Manager constants now handled via CsWin32 usage. |
| src/Files.App/Helpers/Win32/Win32Helper.Storage.cs | Convert DLL string extraction from Vanara wrappers to CsWin32 (LoadLibrary, LoadString). |
| src/Files.App/Helpers/Win32/Win32Helper.Shell.cs | Convert known-folder path lookup to CsWin32 SHGetKnownFolderPath. |
| src/Files.App/Helpers/Win32/Win32Helper.Process.cs | Convert Restart Manager usage (Rm*) to CsWin32 types/APIs. |
| src/Files.App/App.xaml.cs | Convert named event creation/signaling to CsWin32 safe-handle usage. |
| src/Files.App.CsWin32/NativeMethods.txt | Add required APIs/types so CsWin32 generates the needed interop. |
| src/Files.App.CsWin32/Extras.cs | Replace manual DllImport with LibraryImport for helper interop not generated by CsWin32. |
| docs/interop-unmarshaled-conversion.md | Add documented workflow for converting marshaled/manual interop to CsWin32-generated interop. |
| AGENTS.md | Add repo overview and agent instructions, including interop conversion guidance link. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
hez2010
approved these changes
May 3, 2026
Member
hez2010
left a comment
There was a problem hiding this comment.
The copilot review feedback about SHBrowseForFolder is valid and should be addressed. Otherwise LGTM.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: terat <62196528+0x5bfa@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolved / Related Issues
Steps used to test these changes