Skip to content

Conversation

@GurliGebis
Copy link
Contributor

This optimizes the registry work the installer does.
All the registry work has been refactored into a separate RegistryKey class, which both abstracts alot away, and handles the cleanup of handles.

This has been included in the last few DLL's I have built for the notepad-plus-plus/notepad-plus-plus#13399 issue - just didn't tell anyone.
So it has been tested a lot actually.

Now the installer code is way easier to understand, since it now is like this all the way:

HRESULT NppShell::Installer::RegisterOldContextMenu()
{
    const wstring contextMenuFullName = GetContextMenuFullName();
    const wstring guid = GetCLSIDString();

    // First we set the shell extension values.
    RegistryKey regKeyExtension(HKEY_LOCAL_MACHINE, ShellKey, KEY_READ | KEY_WRITE, true);
    regKeyExtension.SetStringValue(L"", L"Notepad++ Context menu");
    regKeyExtension.SetStringValue(L"ExplorerCommandHandler", guid);
    regKeyExtension.SetStringValue(L"NeverDefault", L"");

    // Then we create the CLSID for the handler with it's values.
    RegistryKey regKeyClsid(HKEY_LOCAL_MACHINE, L"Software\\Classes\\CLSID\\" + guid, KEY_READ | KEY_WRITE, true);
    regKeyClsid.SetStringValue(L"", L"notepad++");

    RegistryKey regKeyInProc = regKeyClsid.GetSubKey(L"InProcServer32", true);
    regKeyInProc.SetStringValue(L"", contextMenuFullName);
    regKeyInProc.SetStringValue(L"ThreadingModel", L"Apartment");

    return S_OK;
}

@GurliGebis
Copy link
Contributor Author

@donho this would make it a lot easier for other people get use as a base for their implementation, since it cleans up the installer A LOT 😀

@GurliGebis
Copy link
Contributor Author

from a functional point of view, it does exactly the same as the current code, but it is way cleaner and easier to read.

@donho
Copy link
Member

donho commented Apr 5, 2023

@GurliGebis
So it's just a refactoring right?

@GurliGebis
Copy link
Contributor Author

@donho yep, refactoring and cleanup, does exactly the same as the existing code - just a lot cleaner and more readable, since all the registry logic has been refactored into a class, and then we just call it instead, making it cleaner and more readable.

@donho donho self-assigned this Apr 6, 2023
@donho donho added the accepted Extra attention is needed label Apr 6, 2023
@donho donho closed this in 4f05154 Apr 6, 2023
@GurliGebis GurliGebis deleted the registry-optimization branch April 6, 2023 14:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

accepted Extra attention is needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants