Skip to content

Code Quality: Remove manual interop definitions and add agent instructions for this#18449

Open
0x5bfa wants to merge 6 commits intofiles-community:mainfrom
0x5bfa:5bfa/CQ-RemoveVanara
Open

Code Quality: Remove manual interop definitions and add agent instructions for this#18449
0x5bfa wants to merge 6 commits intofiles-community:mainfrom
0x5bfa:5bfa/CQ-RemoveVanara

Conversation

@0x5bfa
Copy link
Copy Markdown
Member

@0x5bfa 0x5bfa commented May 1, 2026

Copilot AI review requested due to automatic review settings May 1, 2026 18:46
@0x5bfa
Copy link
Copy Markdown
Member Author

0x5bfa commented May 1, 2026

This is an experimental PR for writing agent instructions to remove aot-unsafe interop code to move things a lot faster.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.PInvoke calls 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 CsWin32 NativeMethods.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.

Comment thread src/Files.App/ViewModels/Dialogs/CreateShortcutDialogViewModel.cs
Comment thread src/Files.App/Utils/Shell/PreviewHandler.cs
Copy link
Copy Markdown
Member

@hez2010 hez2010 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
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.

3 participants