1 // UserRegistrar.cpp: Implementierung der Klasse UserRegistrar.
3 //////////////////////////////////////////////////////////////////////
5 #include "userregistrar.hxx"
6 #include "registryvalueimpl.hxx"
7 #include "windowsregistry.hxx"
8 #include "registryexception.hxx"
11 #pragma warning(disable : 4350)
14 //--------------------------------------
17 UserRegistrar::UserRegistrar(const RegistrationContextInformation
& RegContext
) :
20 RegistryKey RegKey
= WindowsRegistry().GetCurrentUserKey();
21 m_RootKey
= RegKey
->OpenSubKey(L
"Software\\Classes");
24 //###################################
26 //###################################
28 //--------------------------------------
31 void UserRegistrar::UnregisterAsHtmlEditorForInternetExplorer() const
33 Registrar::UnregisterAsHtmlEditorForInternetExplorer();
35 DeleteHtmFileAssociationKeys();
39 RegistryKey RegKey
= m_RootKey
->OpenSubKey(L
"Applications");
40 if ((0 == RegKey
->GetSubValueCount()) && (0 == RegKey
->GetSubKeyCount()))
43 m_RootKey
->DeleteSubKey(L
"Applications");
46 catch(RegistryKeyNotFoundException
&)
51 //--------------------------------------
54 void UserRegistrar::RegisterAsDefaultShellHtmlEditor() const
56 RegistryKey LocalHtmKey
= m_RootKey
->CreateSubKey(L
".htm");
58 if (!LocalHtmKey
->HasValue(DEFAULT_VALUE_NAME
))
60 RegistryKey HKCRKey
= WindowsRegistry().GetClassesRootKey();
62 if (HKCRKey
->HasSubKey(L
".htm"))
64 RegistryKey RootHtmKey
= HKCRKey
->OpenSubKey(L
".htm", false);
66 if (RootHtmKey
->HasValue(DEFAULT_VALUE_NAME
))
68 RegistryValue RegVal
= RootHtmKey
->GetValue(DEFAULT_VALUE_NAME
);
70 std::wstring RootHtmFwdKey
= RegVal
->GetDataAsUniString();
72 if (HKCRKey
->HasSubKey(RootHtmFwdKey
))
74 m_RootKey
->CreateSubKey(RootHtmFwdKey
);
75 LocalHtmKey
->CopyValue(RootHtmKey
, DEFAULT_VALUE_NAME
);
81 // calling base class method
82 Registrar::RegisterAsDefaultShellHtmlEditor();
85 //--------------------------------------
88 void UserRegistrar::UnregisterAsDefaultShellHtmlEditor() const
90 // calling base class method
91 Registrar::UnregisterAsDefaultShellHtmlEditor();
92 DeleteHtmFileAssociationKeys();
95 //--------------------------------------
98 void UserRegistrar::UnregisterForMsOfficeApplication(
99 const std::wstring
& FileExtension
) const
101 /// calling base class method
102 Registrar::UnregisterForMsOfficeApplication(FileExtension
);
104 if (m_RootKey
->HasSubKey(FileExtension
))
106 RegistryKey RegKey
= m_RootKey
->OpenSubKey(FileExtension
);
108 if ((0 == RegKey
->GetSubKeyCount()) && (0 == RegKey
->GetSubValueCount()))
111 m_RootKey
->DeleteSubKey(FileExtension
);
116 //--------------------------------------
119 RegistryKey
UserRegistrar::GetRootKeyForDefHtmlEditorForIERegistration() const
121 return WindowsRegistry().GetCurrentUserKey();
124 //--------------------------------------
127 void UserRegistrar::DeleteHtmFileAssociationKeys() const
129 // Later delete the created keys if they are empty and have not changed meanwhile.
130 // Remeber: if we create a new registry key in the user part of the
131 // registry, changes to that key via the merged key HKEY_CLASSES_ROOT
132 // go into the user branch HKEY_CURRENT_USER and are not visible for other users.
133 // so we must carefully detect if the keys have not changed in order to prevent accidentally
134 // deleting a key and so destroying existing associations
135 // See MSDN: "Merged View of HKEY_CLASSES_ROOT"