Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix broken Open dialog when launching Dn by opening a file #76

Merged
merged 1 commit into from
Aug 3, 2021

Conversation

nyanpasu64
Copy link
Collaborator

@nyanpasu64 nyanpasu64 commented Aug 2, 2021

On Windows Vista and up, RegOverridePredefKey is necessary for Dn's RegisterShellFileTypes() to create .0cc file associations without running as admin. Unfortunately that function also screws with the program's view of the registry. When opening a file from the command line, Dn later runs ProcessShellCommand, which indirectly calls SHGetFileInfo and SHParseDisplayName, which queries the registry. With RegOverridePredefKey in place, these registry queries load and cache incorrect data, causing file dialogs to see incorrect special folders (like the home directory being called "UsersFiles", and "This PC" disappearing from the sidebar, and sometimes the "Downloads" folder being unclickable).

This commit fixes the bug by replacing RegOverridePredefKey() with AfxSetPerUserRegistration(TRUE) (discovered in a 2007 forum post and having literally 9 Google results). This function only affects MFC RegisterShellFileTypes() and doesn't break special folders. Just to be safe, run AfxSetPerUserRegistration(FALSE) before calling ProcessShellCommand afterwards. It's safe to omit this call (the bug is still fixed), but I prefer avoiding persistent changes to global state.

I tested that .0cc file associations were being created properly using a clean non-admin user account. A build of Dn-FT with RegOverridePredefKey() removed was unable to create a .0cc file association. Replacing it with AfxSetPerUserRegistration(TRUE) fixed the ability to create per-user file associations. However both programs can update the .0cc file association on a user account which already has a per-user .0cc file type/association.

Fixes #74.

RegOverridePredefKey is necessary to create .0cc file associations on
new user accounts, but screws with the program's view of the registry.
When opening a file from the command line,
Dn later runs ProcessShellCommand, which indirectly calls
SHGetFileInfo and SHParseDisplayName, which queries the registry.
With RegOverridePredefKey in place, these registry queries load
and cache incorrect data,
causing file dialogs to see incorrect special folders.

This commit fixes the bug by replacing RegOverridePredefKey()
with AfxSetPerUserRegistration(TRUE)
(discovered in a 2007 forum post at https://social.msdn.microsoft.com/Forums/vstudio/en-US/1f90d106-6cc2-4fd3-a31d-13e742386b5c/calling-cwinappregistershellfiletypes-in-vista?forum=vcgeneral
and having literally 9 Google results),
which only affects MFC RegisterShellFileTypes().
Just to be safe, run AfxSetPerUserRegistration(FALSE)
before calling ProcessShellCommand afterwards.
It's safe to omit this call (the bug is still fixed),
but I prefer avoiding persistent changes to global state.
@nyanpasu64 nyanpasu64 changed the base branch from master to dev August 2, 2021 08:08
@Gumball2415 Gumball2415 merged commit 485bc7d into dev Aug 3, 2021
@nyanpasu64 nyanpasu64 deleted the fix-association-file-dialog branch August 14, 2021 05:12
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.

Open dialogs malfunction if .exe invoked with module in command line
2 participants