1*cdf0e10cSrcweir // UserRegistrar.cpp: Implementierung der Klasse UserRegistrar. 2*cdf0e10cSrcweir // 3*cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////// 4*cdf0e10cSrcweir 5*cdf0e10cSrcweir #include "userregistrar.hxx" 6*cdf0e10cSrcweir #include "registryvalueimpl.hxx" 7*cdf0e10cSrcweir #include "windowsregistry.hxx" 8*cdf0e10cSrcweir #include "registryexception.hxx" 9*cdf0e10cSrcweir 10*cdf0e10cSrcweir #ifdef _MSC_VER 11*cdf0e10cSrcweir #pragma warning(disable : 4350) 12*cdf0e10cSrcweir #endif 13*cdf0e10cSrcweir 14*cdf0e10cSrcweir //-------------------------------------- 15*cdf0e10cSrcweir /** 16*cdf0e10cSrcweir */ 17*cdf0e10cSrcweir UserRegistrar::UserRegistrar(const RegistrationContextInformation& RegContext) : 18*cdf0e10cSrcweir Registrar(RegContext) 19*cdf0e10cSrcweir { 20*cdf0e10cSrcweir RegistryKey RegKey = WindowsRegistry().GetCurrentUserKey(); 21*cdf0e10cSrcweir m_RootKey = RegKey->OpenSubKey(L"Software\\Classes"); 22*cdf0e10cSrcweir } 23*cdf0e10cSrcweir 24*cdf0e10cSrcweir //################################### 25*cdf0e10cSrcweir // Command 26*cdf0e10cSrcweir //################################### 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir //-------------------------------------- 29*cdf0e10cSrcweir /** 30*cdf0e10cSrcweir */ 31*cdf0e10cSrcweir void UserRegistrar::UnregisterAsHtmlEditorForInternetExplorer() const 32*cdf0e10cSrcweir { 33*cdf0e10cSrcweir Registrar::UnregisterAsHtmlEditorForInternetExplorer(); 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir DeleteHtmFileAssociationKeys(); 36*cdf0e10cSrcweir 37*cdf0e10cSrcweir try 38*cdf0e10cSrcweir { 39*cdf0e10cSrcweir RegistryKey RegKey = m_RootKey->OpenSubKey(L"Applications"); 40*cdf0e10cSrcweir if ((0 == RegKey->GetSubValueCount()) && (0 == RegKey->GetSubKeyCount())) 41*cdf0e10cSrcweir { 42*cdf0e10cSrcweir RegKey->Close(); 43*cdf0e10cSrcweir m_RootKey->DeleteSubKey(L"Applications"); 44*cdf0e10cSrcweir } 45*cdf0e10cSrcweir } 46*cdf0e10cSrcweir catch(RegistryKeyNotFoundException&) 47*cdf0e10cSrcweir { 48*cdf0e10cSrcweir } 49*cdf0e10cSrcweir } 50*cdf0e10cSrcweir 51*cdf0e10cSrcweir //-------------------------------------- 52*cdf0e10cSrcweir /** 53*cdf0e10cSrcweir */ 54*cdf0e10cSrcweir void UserRegistrar::RegisterAsDefaultShellHtmlEditor() const 55*cdf0e10cSrcweir { 56*cdf0e10cSrcweir RegistryKey LocalHtmKey = m_RootKey->CreateSubKey(L".htm"); 57*cdf0e10cSrcweir 58*cdf0e10cSrcweir if (!LocalHtmKey->HasValue(DEFAULT_VALUE_NAME)) 59*cdf0e10cSrcweir { 60*cdf0e10cSrcweir RegistryKey HKCRKey = WindowsRegistry().GetClassesRootKey(); 61*cdf0e10cSrcweir 62*cdf0e10cSrcweir if (HKCRKey->HasSubKey(L".htm")) 63*cdf0e10cSrcweir { 64*cdf0e10cSrcweir RegistryKey RootHtmKey = HKCRKey->OpenSubKey(L".htm", false); 65*cdf0e10cSrcweir 66*cdf0e10cSrcweir if (RootHtmKey->HasValue(DEFAULT_VALUE_NAME)) 67*cdf0e10cSrcweir { 68*cdf0e10cSrcweir RegistryValue RegVal = RootHtmKey->GetValue(DEFAULT_VALUE_NAME); 69*cdf0e10cSrcweir 70*cdf0e10cSrcweir std::wstring RootHtmFwdKey = RegVal->GetDataAsUniString(); 71*cdf0e10cSrcweir 72*cdf0e10cSrcweir if (HKCRKey->HasSubKey(RootHtmFwdKey)) 73*cdf0e10cSrcweir { 74*cdf0e10cSrcweir m_RootKey->CreateSubKey(RootHtmFwdKey); 75*cdf0e10cSrcweir LocalHtmKey->CopyValue(RootHtmKey, DEFAULT_VALUE_NAME); 76*cdf0e10cSrcweir } 77*cdf0e10cSrcweir } 78*cdf0e10cSrcweir } 79*cdf0e10cSrcweir } 80*cdf0e10cSrcweir 81*cdf0e10cSrcweir // calling base class method 82*cdf0e10cSrcweir Registrar::RegisterAsDefaultShellHtmlEditor(); 83*cdf0e10cSrcweir } 84*cdf0e10cSrcweir 85*cdf0e10cSrcweir //-------------------------------------- 86*cdf0e10cSrcweir /** 87*cdf0e10cSrcweir */ 88*cdf0e10cSrcweir void UserRegistrar::UnregisterAsDefaultShellHtmlEditor() const 89*cdf0e10cSrcweir { 90*cdf0e10cSrcweir // calling base class method 91*cdf0e10cSrcweir Registrar::UnregisterAsDefaultShellHtmlEditor(); 92*cdf0e10cSrcweir DeleteHtmFileAssociationKeys(); 93*cdf0e10cSrcweir } 94*cdf0e10cSrcweir 95*cdf0e10cSrcweir //-------------------------------------- 96*cdf0e10cSrcweir /** 97*cdf0e10cSrcweir */ 98*cdf0e10cSrcweir void UserRegistrar::UnregisterForMsOfficeApplication( 99*cdf0e10cSrcweir const std::wstring& FileExtension) const 100*cdf0e10cSrcweir { 101*cdf0e10cSrcweir /// calling base class method 102*cdf0e10cSrcweir Registrar::UnregisterForMsOfficeApplication(FileExtension); 103*cdf0e10cSrcweir 104*cdf0e10cSrcweir if (m_RootKey->HasSubKey(FileExtension)) 105*cdf0e10cSrcweir { 106*cdf0e10cSrcweir RegistryKey RegKey = m_RootKey->OpenSubKey(FileExtension); 107*cdf0e10cSrcweir 108*cdf0e10cSrcweir if ((0 == RegKey->GetSubKeyCount()) && (0 == RegKey->GetSubValueCount())) 109*cdf0e10cSrcweir { 110*cdf0e10cSrcweir RegKey->Close(); 111*cdf0e10cSrcweir m_RootKey->DeleteSubKey(FileExtension); 112*cdf0e10cSrcweir } 113*cdf0e10cSrcweir } 114*cdf0e10cSrcweir } 115*cdf0e10cSrcweir 116*cdf0e10cSrcweir //-------------------------------------- 117*cdf0e10cSrcweir /** 118*cdf0e10cSrcweir */ 119*cdf0e10cSrcweir RegistryKey UserRegistrar::GetRootKeyForDefHtmlEditorForIERegistration() const 120*cdf0e10cSrcweir { 121*cdf0e10cSrcweir return WindowsRegistry().GetCurrentUserKey(); 122*cdf0e10cSrcweir } 123*cdf0e10cSrcweir 124*cdf0e10cSrcweir //-------------------------------------- 125*cdf0e10cSrcweir /** 126*cdf0e10cSrcweir */ 127*cdf0e10cSrcweir void UserRegistrar::DeleteHtmFileAssociationKeys() const 128*cdf0e10cSrcweir { 129*cdf0e10cSrcweir // Later delete the created keys if they are empty and have not changed meanwhile. 130*cdf0e10cSrcweir // Remeber: if we create a new registry key in the user part of the 131*cdf0e10cSrcweir // registry, changes to that key via the merged key HKEY_CLASSES_ROOT 132*cdf0e10cSrcweir // go into the user branch HKEY_CURRENT_USER and are not visible for other users. 133*cdf0e10cSrcweir // so we must carefully detect if the keys have not changed in order to prevent accidentally 134*cdf0e10cSrcweir // deleting a key and so destroying existing associations 135*cdf0e10cSrcweir // See MSDN: "Merged View of HKEY_CLASSES_ROOT" 136*cdf0e10cSrcweir } 137