1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 // UserRegistrar.cpp: Implementierung der Klasse UserRegistrar.
4 //////////////////////////////////////////////////////////////////////
6 #include "userregistrar.hxx"
7 #include "registryvalueimpl.hxx"
8 #include "windowsregistry.hxx"
9 #include "registryexception.hxx"
12 #pragma warning(disable : 4350)
15 //--------------------------------------
18 UserRegistrar::UserRegistrar(const RegistrationContextInformation
& RegContext
) :
21 RegistryKey RegKey
= WindowsRegistry().GetCurrentUserKey();
22 m_RootKey
= RegKey
->OpenSubKey(L
"Software\\Classes");
25 //###################################
27 //###################################
29 //--------------------------------------
32 void UserRegistrar::UnregisterAsHtmlEditorForInternetExplorer() const
34 Registrar::UnregisterAsHtmlEditorForInternetExplorer();
36 DeleteHtmFileAssociationKeys();
40 RegistryKey RegKey
= m_RootKey
->OpenSubKey(L
"Applications");
41 if ((0 == RegKey
->GetSubValueCount()) && (0 == RegKey
->GetSubKeyCount()))
44 m_RootKey
->DeleteSubKey(L
"Applications");
47 catch(RegistryKeyNotFoundException
&)
52 //--------------------------------------
55 void UserRegistrar::RegisterAsDefaultShellHtmlEditor() const
57 RegistryKey LocalHtmKey
= m_RootKey
->CreateSubKey(L
".htm");
59 if (!LocalHtmKey
->HasValue(DEFAULT_VALUE_NAME
))
61 RegistryKey HKCRKey
= WindowsRegistry().GetClassesRootKey();
63 if (HKCRKey
->HasSubKey(L
".htm"))
65 RegistryKey RootHtmKey
= HKCRKey
->OpenSubKey(L
".htm", false);
67 if (RootHtmKey
->HasValue(DEFAULT_VALUE_NAME
))
69 RegistryValue RegVal
= RootHtmKey
->GetValue(DEFAULT_VALUE_NAME
);
71 std::wstring RootHtmFwdKey
= RegVal
->GetDataAsUniString();
73 if (HKCRKey
->HasSubKey(RootHtmFwdKey
))
75 m_RootKey
->CreateSubKey(RootHtmFwdKey
);
76 LocalHtmKey
->CopyValue(RootHtmKey
, DEFAULT_VALUE_NAME
);
82 // calling base class method
83 Registrar::RegisterAsDefaultShellHtmlEditor();
86 //--------------------------------------
89 void UserRegistrar::UnregisterAsDefaultShellHtmlEditor() const
91 // calling base class method
92 Registrar::UnregisterAsDefaultShellHtmlEditor();
93 DeleteHtmFileAssociationKeys();
96 //--------------------------------------
99 void UserRegistrar::UnregisterForMsOfficeApplication(
100 const std::wstring
& FileExtension
) const
102 /// calling base class method
103 Registrar::UnregisterForMsOfficeApplication(FileExtension
);
105 if (m_RootKey
->HasSubKey(FileExtension
))
107 RegistryKey RegKey
= m_RootKey
->OpenSubKey(FileExtension
);
109 if ((0 == RegKey
->GetSubKeyCount()) && (0 == RegKey
->GetSubValueCount()))
112 m_RootKey
->DeleteSubKey(FileExtension
);
117 //--------------------------------------
120 RegistryKey
UserRegistrar::GetRootKeyForDefHtmlEditorForIERegistration() const
122 return WindowsRegistry().GetCurrentUserKey();
125 //--------------------------------------
128 void UserRegistrar::DeleteHtmFileAssociationKeys() const
130 // Later delete the created keys if they are empty and have not changed meanwhile.
131 // Remeber: if we create a new registry key in the user part of the
132 // registry, changes to that key via the merged key HKEY_CLASSES_ROOT
133 // go into the user branch HKEY_CURRENT_USER and are not visible for other users.
134 // so we must carefully detect if the keys have not changed in order to prevent accidentally
135 // deleting a key and so destroying existing associations
136 // See MSDN: "Merged View of HKEY_CLASSES_ROOT"
139 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */