#33 Use default settings from HKLM in registry

open
Kimmo Varis
None
6
2015-01-13
2006-03-29
Kimmo Varis
No

This has been discussed in several items, so it is time
to create new item.

Currently we just use HKCU almost everywhere for
settings, including installer. This causes we really
don't support multi-users. And at worst WinMerge
properly works only for user who runs the installer.

What we need to do is:
- create default settings to HKLM
- write user's modified settings to HKCU
- installer installs default settings to HKLM
- WinMerge stores settings to HKCU
- when WinMerge reads some setting, it first checks if
it exists in HKCU. If not found, it reads default
setting from HKLM

Discussion

  • Kimmo Varis
    Kimmo Varis
    2008-06-16

    Logged In: YES
    user_id=631874
    Originator: YES

    I'll start some work with this item. See development wiki about my ideas how to implement this:
    http://winmerge.org/Wiki/Options_system

     
  • Kimmo Varis
    Kimmo Varis
    2008-06-16

    • assigned_to: nobody --> kimmov
     
  • Kimmo Varis
    Kimmo Varis
    2008-06-16

    Logged In: YES
    user_id=631874
    Originator: YES

    This is also requirement that WinMerge can be successfully installed in corporate environments by administrators. So increasin priority now that I'm doing some work with this.

    Attaching first patch to convert installer script correctly use {common*} values instead of {user*} values. This makes installer to write values to all users, not only currently logged in user.

    Also convert registry values from HKCU to HKLM where appropriate.

    File Added: Installer_HKLM.zip

     
  • Kimmo Varis
    Kimmo Varis
    2008-06-16

    Installer to use all users and HKLM

     
    Attachments
  • Kimmo Varis
    Kimmo Varis
    2008-06-16

    • priority: 5 --> 6
     
  • Kimmo Varis
    Kimmo Varis
    2008-06-16

    Logged In: YES
    user_id=631874
    Originator: YES

    Committed a patch to split CRegOptions class to own files from OptionsMgr.h/cpp.
    Completed: At revision: 5489

    Committed a patch to move new files to correct folder..
    Completed: At revision: 5490

     
  • Kimmo Varis
    Kimmo Varis
    2008-06-17

    Logged In: YES
    user_id=631874
    Originator: YES

    Committed the installer patch install WinMerge for all users:
    Completed: At revision: 5498

     
  • Kimmo Varis
    Kimmo Varis
    2008-06-17

    Copy some values from HKLM to HKCU

     
    Attachments
  • Kimmo Varis
    Kimmo Varis
    2008-06-17

    Logged In: YES
    user_id=631874
    Originator: YES

    Attaching a patch that copies some values installer sets to HKLM to HKCU when WinMerge starts. The value is copied only if it is missing from HKCU, so existing value is not overwritten.

    File Added: CopyRegValues.zip

     
  • Kimmo Varis
    Kimmo Varis
    2008-06-18

    Logged In: YES
    user_id=631874
    Originator: YES

    Committed the patch to copy values from HKLM to HKCU to SVN trunk:
    Completed: At revision: 5500

     
  • A Japanese user reported the following problems to me.

    1) After installing WinMerge, WinMerge's interface language is not Japanese but English.

    2) WinMerge icon is not shown on Quick Launch bar.

    3) After uninstalling WinMerge, the registry key 'HKEY_CURRENT_USER/Software/Thingamahoochie/WinMerge' is not deleted.

    4) and I also noticed that TortoiseCVS and TortoiseSVN integrations have not been worked now.

    The problem 1) is caused by the registry key 'Locale/LanguageId' in HKLM being not copied to HKCU.
    The other problems are installer script's problems.

    Here is the fix:

    Index: OptionsInit.cpp

    --- OptionsInit.cpp (revision 5970)
    +++ OptionsInit.cpp (working copy)
    @@ -16,8 +16,8 @@

    // Functions to copy values set by installer from HKLM to HKCU.
    static void CopyHKLMValues();
    -static bool OpenHKLM(HKEY *key);
    -static bool OpenHKCU(HKEY *key);
    +static bool OpenHKLM(HKEY *key, LPCTSTR relpath = NULL);
    +static bool OpenHKCU(HKEY *key, LPCTSTR relpath = NULL);
    static bool IsFirstRun(HKEY key);
    static void CopyFromLMtoCU(HKEY lmKey, HKEY cuKey, LPCTSTR valname);
    static void ResetFirstRun(HKEY key);
    @@ -235,23 +235,34 @@
    {
    CopyFromLMtoCU(LMKey, CUKey, _T("ContextMenuEnabled"));
    CopyFromLMtoCU(LMKey, CUKey, _T("Executable"));
    - CopyFromLMtoCU(LMKey, CUKey, _T("Locale\\LanguageId"));
    RegCloseKey(CUKey);
    }
    RegCloseKey(LMKey);
    }
    + if (OpenHKLM(&LMKey, _T("Locale")))
    + {
    + if (OpenHKCU(&CUKey, _T("Locale")))
    + {
    + CopyFromLMtoCU(LMKey, CUKey, _T("LanguageId"));
    + RegCloseKey(CUKey);
    + }
    + RegCloseKey(LMKey);
    + }
    }

    /**
    * @brief Open HKLM registry key.
    * @param [out] key Pointer to open HKLM key.
    + * @param [in] relative registry path to open.
    * @return true if opening succeeded.
    */
    -static bool OpenHKLM(HKEY *key)
    +static bool OpenHKLM(HKEY *key, LPCTSTR relpath)
    {
    + TCHAR valuename[256] = _T("Software\\Thingamahoochie\\WinMerge\\");
    + if (relpath)
    + lstrcat(valuename, relpath);
    LONG retval = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
    - _T("Software\\Thingamahoochie\\WinMerge\\"),
    - 0, KEY_READ, key);
    + valuename, 0, KEY_READ, key);
    if (retval == ERROR_SUCCESS)
    {
    return true;
    @@ -263,13 +274,16 @@
    * @brief Open HKCU registry key.
    * Opens the HKCU key for WinMerge. If the key does not exist, creates one.
    * @param [out] key Pointer to open HKCU key.
    + * @param [in] relative registry path to open.
    * @return true if opening succeeded.
    */
    -static bool OpenHKCU(HKEY *key)
    +static bool OpenHKCU(HKEY *key, LPCTSTR relpath)
    {
    + TCHAR valuename[256] = _T("Software\\Thingamahoochie\\WinMerge\\");
    + if (relpath)
    + lstrcat(valuename, relpath);
    LONG retval = RegOpenKeyEx(HKEY_CURRENT_USER,
    - _T("Software\\Thingamahoochie\\WinMerge\\"),
    - 0, KEY_ALL_ACCESS, key);
    + valuename, 0, KEY_ALL_ACCESS, key);
    if (retval == ERROR_SUCCESS)
    {
    return true;
    @@ -277,8 +291,7 @@
    else if (retval == ERROR_FILE_NOT_FOUND)
    {
    retval = RegCreateKeyEx(HKEY_CURRENT_USER,
    - _T("Software\\Thingamahoochie\\WinMerge\\"),
    - 0, NULL, 0, KEY_ALL_ACCESS, NULL, key, NULL);
    + valuename, 0, NULL, 0, KEY_ALL_ACCESS, NULL, key, NULL);
    if (retval == ERROR_SUCCESS)
    return true;
    }

    Index: WinMerge.iss

    --- WinMerge.iss (revision 5970)
    +++ WinMerge.iss (working copy)
    @@ -300,6 +300,7 @@
    Name: {group}\{cm:UsersGuide}.lnk; Type: files; Check: not IsComponentSelected('Docs')

    ;This removes the quick launch icon in case the user chooses not to install it after previously having it installed
    +Name: {userappdata}\Microsoft\Internet Explorer\Quick Launch\WinMerge.lnk; Type: files; Check: not IsTaskSelected('QuickLauchIcon')
    Name: {commonappdata}\Microsoft\Internet Explorer\Quick Launch\WinMerge.lnk; Type: files; Check: not IsTaskSelected('QuickLauchIcon')

    ;This removes the desktop icon in case the user chooses not to install it after previously having it installed
    @@ -445,9 +446,11 @@
    Name: {commondesktop}\WinMerge; Filename: {app}\{code:ExeName}; Tasks: desktopicon

    ;Quick Launch Icon
    -Name: {commonappdata}\Microsoft\Internet Explorer\Quick Launch\WinMerge; Filename: {app}\{code:ExeName}; Tasks: quicklaunchicon
    +Name: {userappdata}\Microsoft\Internet Explorer\Quick Launch\WinMerge; Filename: {app}\{code:ExeName}; Tasks: quicklaunchicon

    [Registry]
    +Root: HKCU; Subkey: Software\Thingamahoochie; Flags: uninsdeletekeyifempty
    +Root: HKCU; Subkey: Software\Thingamahoochie\WinMerge; Flags: uninsdeletekey
    Root: HKLM; Subkey: Software\Thingamahoochie; Flags: uninsdeletekeyifempty
    Root: HKLM; Subkey: Software\Thingamahoochie\WinMerge; Flags: uninsdeletekey

    @@ -491,20 +494,20 @@
    Root: HKLM; SubKey: Software\Thingamahoochie\WinMerge; ValueType: dword; ValueName: ContextMenuEnabled; ValueData: 1; Tasks: ShellExtension; Check: not ShellMenuEnabled()

    ;If WinMerge.exe is installed then we'll automatically configure WinMerge as the differencing application
    -Root: HKLM; SubKey: Software\TortoiseCVS; ValueType: string; ValueName: External Diff Application; ValueData: {app}\{code:ExeName}; Flags: uninsdeletevalue; Tasks: TortoiseCVS
    -Root: HKLM; SubKey: Software\TortoiseCVS; ValueType: dword; ValueName: DiffAsUnicode; ValueData: $00000001; Flags: uninsdeletevalue; Tasks: TortoiseCVS
    -Root: HKLM; SubKey: Software\TortoiseCVS\Prefs\External Diff Application; ValueType: string; ValueName: _; ValueData: {app}\{code:ExeName}; Flags: uninsdeletevalue dontcreatekey; Tasks: TortoiseCVS
    -Root: HKLM; SubKey: Software\TortoiseCVS\Prefs\External Diff2 Params; ValueType: string; ValueName: _; ValueData: """%1"" ""%2"""; Flags: uninsdeletevalue dontcreatekey; Tasks: TortoiseCVS
    +Root: HKCU; SubKey: Software\TortoiseCVS; ValueType: string; ValueName: External Diff Application; ValueData: {app}\{code:ExeName}; Flags: uninsdeletevalue; Tasks: TortoiseCVS
    +Root: HKCU; SubKey: Software\TortoiseCVS; ValueType: dword; ValueName: DiffAsUnicode; ValueData: $00000001; Flags: uninsdeletevalue; Tasks: TortoiseCVS
    +Root: HKCU; SubKey: Software\TortoiseCVS\Prefs\External Diff Application; ValueType: string; ValueName: _; ValueData: {app}\{code:ExeName}; Flags: uninsdeletevalue dontcreatekey; Tasks: TortoiseCVS
    +Root: HKCU; SubKey: Software\TortoiseCVS\Prefs\External Diff2 Params; ValueType: string; ValueName: _; ValueData: """%1"" ""%2"""; Flags: uninsdeletevalue dontcreatekey; Tasks: TortoiseCVS

    ;Tells TortoiseCVS to use WinMerge as its differencing application (this happens whether or not Tortoise is current installed, that way
    ;if it is installed at a later date this will automatically support it)
    -Root: HKLM; SubKey: Software\TortoiseCVS; ValueType: string; ValueName: External Merge Application; ValueData: {app}\{code:ExeName}; Flags: uninsdeletevalue; Tasks: TortoiseCVS
    -Root: HKLM; SubKey: Software\TortoiseCVS; ValueType: dword; ValueName: MergeAsUnicode; ValueData: $00000001; Flags: uninsdeletevalue; Tasks: TortoiseCVS
    -Root: HKLM; SubKey: Software\TortoiseCVS\Prefs\External Merge Application; ValueType: string; ValueName: _; ValueData: {app}\{code:ExeName}; Flags: uninsdeletevalue dontcreatekey; Tasks: TortoiseCVS
    -Root: HKLM; SubKey: Software\TortoiseCVS\Prefs\External Merge2 Params; ValueType: string; ValueName: _; ValueData: """%mine"" ""%yours"""; Flags: uninsdeletevalue dontcreatekey; Tasks: TortoiseCVS
    +Root: HKCU; SubKey: Software\TortoiseCVS; ValueType: string; ValueName: External Merge Application; ValueData: {app}\{code:ExeName}; Flags: uninsdeletevalue; Tasks: TortoiseCVS
    +Root: HKCU; SubKey: Software\TortoiseCVS; ValueType: dword; ValueName: MergeAsUnicode; ValueData: $00000001; Flags: uninsdeletevalue; Tasks: TortoiseCVS
    +Root: HKCU; SubKey: Software\TortoiseCVS\Prefs\External Merge Application; ValueType: string; ValueName: _; ValueData: {app}\{code:ExeName}; Flags: uninsdeletevalue dontcreatekey; Tasks: TortoiseCVS
    +Root: HKCU; SubKey: Software\TortoiseCVS\Prefs\External Merge2 Params; ValueType: string; ValueName: _; ValueData: """%mine"" ""%yours"""; Flags: uninsdeletevalue dontcreatekey; Tasks: TortoiseCVS

    ;Set WinMerge as TortoiseSVN diff tool
    -Root: HKLM; SubKey: Software\TortoiseSVN; ValueType: string; ValueName: Diff; ValueData: {app}\{code:ExeName} -e -x -u -dl %bname -dr %yname %base %mine; Flags: uninsdeletevalue; Tasks: TortoiseSVN
    +Root: HKCU; SubKey: Software\TortoiseSVN; ValueType: string; ValueName: Diff; ValueData: {app}\{code:ExeName} -e -x -ub -dl %bname -dr %yname %base %mine; Flags: uninsdeletevalue; Tasks: TortoiseSVN

    ;Whatever the user chooses at the [Select Setup Language] dialog should also determine what language WinMerge will start up in
    ;(unless the user already has a startup language specified)

     
  • Kimmo Varis
    Kimmo Varis
    2008-09-23

    A bit sad these problems were reported three months after the patch got in.. :( And these changes look riskier than I'd like in current stable series. But the bugs are serious too. This really should not have happened.

    #1 fix looks ok.

    But InnoSetup.iss fixes need to be separated one for each bug.

    #2 Is is really so that quick launch icon must be in per-user setting? That does not work for installing for every user.

    #3 I'm not sure this is bug at all. Most Windows programs don't delete user settings. Its a bug WinMerge did.

    #4 Ok, this is a problem. But I think we should handle it by copying settings from HKLM to HKCU so that all users get the integration.

     
  • Here is the separated fixes.

    #2 WinMerge icon is not shown on Quick Launch bar.

    Index: WinMerge.iss

    --- WinMerge.iss (revision 5970)
    +++ WinMerge.iss (working copy)
    @@ -300,6 +300,7 @@
    Name: {group}\{cm:UsersGuide}.lnk; Type: files; Check: not
    IsComponentSelected('Docs')

    ;This removes the quick launch icon in case the user chooses not to
    install it after previously having it installed
    +Name: {userappdata}\Microsoft\Internet Explorer\Quick
    Launch\WinMerge.lnk; Type: files; Check: not
    IsTaskSelected('QuickLauchIcon')
    Name: {commonappdata}\Microsoft\Internet Explorer\Quick
    Launch\WinMerge.lnk; Type: files; Check: not
    IsTaskSelected('QuickLauchIcon')

    ;This removes the desktop icon in case the user chooses not to install it
    after previously having it installed
    @@ -445,9 +446,11 @@
    Name: {commondesktop}\WinMerge; Filename: {app}\{code:ExeName}; Tasks:
    desktopicon

    ;Quick Launch Icon
    -Name: {commonappdata}\Microsoft\Internet Explorer\Quick Launch\WinMerge;
    Filename: {app}\{code:ExeName}; Tasks: quicklaunchicon
    +Name: {userappdata}\Microsoft\Internet Explorer\Quick Launch\WinMerge;
    Filename: {app}\{code:ExeName}; Tasks: quicklaunchicon

    #3 After uninstalling WinMerge, the registry key
    'HKEY_CURRENT_USER/Software/Thingamahoochie/WinMerge' is not deleted.

    Index: WinMerge.iss

    --- WinMerge.iss (revision 5970)
    +++ WinMerge.iss (working copy)
    @@ -448,6 +448,8 @@
    Name: {commonappdata}\Microsoft\Internet Explorer\Quick Launch\WinMerge; Filename: {app}\{code:ExeName}; Tasks: quicklaunchicon

    [Registry]
    +Root: HKCU; Subkey: Software\Thingamahoochie; Flags: uninsdeletekeyifempty
    +Root: HKCU; Subkey: Software\Thingamahoochie\WinMerge; Flags: uninsdeletekey
    Root: HKLM; Subkey: Software\Thingamahoochie; Flags: uninsdeletekeyifempty
    Root: HKLM; Subkey: Software\Thingamahoochie\WinMerge; Flags: uninsdeletekey

    #4 TortoiseCVS and TortoiseSVN integrations have
    not been worked now.

    Index: WinMerge.iss

    --- WinMerge.iss (revision 5970)
    +++ WinMerge.iss (working copy)
    @@ -491,20 +494,20 @@
    Root: HKLM; SubKey: Software\Thingamahoochie\WinMerge; ValueType: dword;
    ValueName: ContextMenuEnabled; ValueData: 1; Tasks: ShellExtension; Check:
    not ShellMenuEnabled()

    ;If WinMerge.exe is installed then we'll automatically configure WinMerge
    as the differencing application
    -Root: HKLM; SubKey: Software\TortoiseCVS; ValueType: string; ValueName:
    External Diff Application; ValueData: {app}\{code:ExeName}; Flags:
    uninsdeletevalue; Tasks: TortoiseCVS
    -Root: HKLM; SubKey: Software\TortoiseCVS; ValueType: dword; ValueName:
    DiffAsUnicode; ValueData: $00000001; Flags: uninsdeletevalue; Tasks:
    TortoiseCVS
    -Root: HKLM; SubKey: Software\TortoiseCVS\Prefs\External Diff Application;
    ValueType: string; ValueName: _; ValueData: {app}\{code:ExeName}; Flags:
    uninsdeletevalue dontcreatekey; Tasks: TortoiseCVS
    -Root: HKLM; SubKey: Software\TortoiseCVS\Prefs\External Diff2 Params;
    ValueType: string; ValueName: _; ValueData: """%1"" ""%2"""; Flags:
    uninsdeletevalue dontcreatekey; Tasks: TortoiseCVS
    +Root: HKCU; SubKey: Software\TortoiseCVS; ValueType: string; ValueName:
    External Diff Application; ValueData: {app}\{code:ExeName}; Flags:
    uninsdeletevalue; Tasks: TortoiseCVS
    +Root: HKCU; SubKey: Software\TortoiseCVS; ValueType: dword; ValueName:
    DiffAsUnicode; ValueData: $00000001; Flags: uninsdeletevalue; Tasks:
    TortoiseCVS
    +Root: HKCU; SubKey: Software\TortoiseCVS\Prefs\External Diff Application;
    ValueType: string; ValueName: _; ValueData: {app}\{code:ExeName}; Flags:
    uninsdeletevalue dontcreatekey; Tasks: TortoiseCVS
    +Root: HKCU; SubKey: Software\TortoiseCVS\Prefs\External Diff2 Params;
    ValueType: string; ValueName: _; ValueData: """%1"" ""%2"""; Flags:
    uninsdeletevalue dontcreatekey; Tasks: TortoiseCVS

    ;Tells TortoiseCVS to use WinMerge as its differencing application (this
    happens whether or not Tortoise is current installed, that way
    ;if it is installed at a later date this will automatically support it)
    -Root: HKLM; SubKey: Software\TortoiseCVS; ValueType: string; ValueName:
    External Merge Application; ValueData: {app}\{code:ExeName}; Flags:
    uninsdeletevalue; Tasks: TortoiseCVS
    -Root: HKLM; SubKey: Software\TortoiseCVS; ValueType: dword; ValueName:
    MergeAsUnicode; ValueData: $00000001; Flags: uninsdeletevalue; Tasks:
    TortoiseCVS
    -Root: HKLM; SubKey: Software\TortoiseCVS\Prefs\External Merge
    Application; ValueType: string; ValueName: _; ValueData:
    {app}\{code:ExeName}; Flags: uninsdeletevalue dontcreatekey; Tasks:
    TortoiseCVS
    -Root: HKLM; SubKey: Software\TortoiseCVS\Prefs\External Merge2 Params;
    ValueType: string; ValueName: _; ValueData: """%mine"" ""%yours"""; Flags:
    uninsdeletevalue dontcreatekey; Tasks: TortoiseCVS
    +Root: HKCU; SubKey: Software\TortoiseCVS; ValueType: string; ValueName:
    External Merge Application; ValueData: {app}\{code:ExeName}; Flags:
    uninsdeletevalue; Tasks: TortoiseCVS
    +Root: HKCU; SubKey: Software\TortoiseCVS; ValueType: dword; ValueName:
    MergeAsUnicode; ValueData: $00000001; Flags: uninsdeletevalue; Tasks:
    TortoiseCVS
    +Root: HKCU; SubKey: Software\TortoiseCVS\Prefs\External Merge
    Application; ValueType: string; ValueName: _; ValueData:
    {app}\{code:ExeName}; Flags: uninsdeletevalue dontcreatekey; Tasks:
    TortoiseCVS
    +Root: HKCU; SubKey: Software\TortoiseCVS\Prefs\External Merge2 Params;
    ValueType: string; ValueName: _; ValueData: """%mine"" ""%yours"""; Flags:
    uninsdeletevalue dontcreatekey; Tasks: TortoiseCVS

    ;Set WinMerge as TortoiseSVN diff tool
    -Root: HKLM; SubKey: Software\TortoiseSVN; ValueType: string; ValueName:
    Diff; ValueData: {app}\{code:ExeName} -e -x -u -dl %bname -dr %yname %base
    %mine; Flags: uninsdeletevalue; Tasks: TortoiseSVN
    +Root: HKCU; SubKey: Software\TortoiseSVN; ValueType: string; ValueName:
    Diff; ValueData: {app}\{code:ExeName} -e -x -ub -dl %bname -dr %yname %base
    %mine; Flags: uninsdeletevalue; Tasks: TortoiseSVN

    ;Whatever the user chooses at the [Select Setup Language] dialog should
    also determine what language WinMerge will start up in
    ;(unless the user already has a startup language specified)

     
  • >http://www.innosetup.com/isfaq.php#quicklaunch
    >seems to imply that quick launch needs to be user setting.

    I think so, too.

    It is possible to copy quick launch icon from {commonappdata} to {userappdata} like copying LocaleId. But I think we should not do it.
    For example, although a user deletes WinMerge quick launch icon, WinMerge will restore unexpectedly the icon on startup.

    The same can be said for Tortoise* integration.

    >#3 I'm not sure this is bug at all. Most Windows programs don't delete
    >user settings. Its a bug WinMerge did.

    There are pros and cons to delete user settings.

    Pros
    It is easy for user to recover from situation like '[ winmerge-Bugs-1882699 ] Corrupted font settings in registry'.
    just uninstall and reinstall.

    Cons
    It cannot delete all user settings when uninstalling.

    I have no preference.

     
  • Kimmo Varis
    Kimmo Varis
    2008-09-24

    InnoSetup.iss changes:
    #2 looks good
    #3 looks good
    #4 looks good as a bug fix. But this really needs more studying. As there is both HKLM and HKCU keys for TortoiseSVN. And currently it seems to use HKCU for merge program settings. But this needs to be checked what it really supports.

    So these patches can go into trunk now.

     
  • Committed to SVN trunk. Completed: At revision: 5975

     
  • Kimmo Varis
    Kimmo Varis
    2008-10-22

    Can you commit the fixes into 2.10 branch?

     
  • Committed to 2.10 branch. Completed: At revision: 6035