Update ooo320-m1
[ooovba.git] / setup_native / source / win32 / customactions / reg4msdoc / userregistrar.cxx
blob6d94d386e325b45b673d399fcc2542b65a425409
1 // UserRegistrar.cpp: Implementierung der Klasse UserRegistrar.
2 //
3 //////////////////////////////////////////////////////////////////////
5 #include "userregistrar.hxx"
6 #include "registryvalueimpl.hxx"
7 #include "windowsregistry.hxx"
8 #include "registryexception.hxx"
10 #ifdef _MSC_VER
11 #pragma warning(disable : 4350)
12 #endif
14 //--------------------------------------
15 /**
17 UserRegistrar::UserRegistrar(const RegistrationContextInformation& RegContext) :
18 Registrar(RegContext)
20 RegistryKey RegKey = WindowsRegistry().GetCurrentUserKey();
21 m_RootKey = RegKey->OpenSubKey(L"Software\\Classes");
24 //###################################
25 // Command
26 //###################################
28 //--------------------------------------
29 /**
31 void UserRegistrar::UnregisterAsHtmlEditorForInternetExplorer() const
33 Registrar::UnregisterAsHtmlEditorForInternetExplorer();
35 DeleteHtmFileAssociationKeys();
37 try
39 RegistryKey RegKey = m_RootKey->OpenSubKey(L"Applications");
40 if ((0 == RegKey->GetSubValueCount()) && (0 == RegKey->GetSubKeyCount()))
42 RegKey->Close();
43 m_RootKey->DeleteSubKey(L"Applications");
46 catch(RegistryKeyNotFoundException&)
51 //--------------------------------------
52 /**
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 //--------------------------------------
86 /**
88 void UserRegistrar::UnregisterAsDefaultShellHtmlEditor() const
90 // calling base class method
91 Registrar::UnregisterAsDefaultShellHtmlEditor();
92 DeleteHtmFileAssociationKeys();
95 //--------------------------------------
96 /**
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()))
110 RegKey->Close();
111 m_RootKey->DeleteSubKey(FileExtension);
116 //--------------------------------------
119 RegistryKey UserRegistrar::GetRootKeyForDefHtmlEditorForIERegistration() const
121 return WindowsRegistry().GetCurrentUserKey();
124 //--------------------------------------
125 /**
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"