1*cdf0e10cSrcweir // Registrar.cpp: Implementierung der Klasse Registrar. 2*cdf0e10cSrcweir // 3*cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////// 4*cdf0e10cSrcweir 5*cdf0e10cSrcweir #include "registrar.hxx" 6*cdf0e10cSrcweir 7*cdf0e10cSrcweir #ifndef _REGISTRYVALUEIMPL_HXX_ 8*cdf0e10cSrcweir #include "RegistryValueImpl.hxx" 9*cdf0e10cSrcweir #endif 10*cdf0e10cSrcweir #include "windowsregistry.hxx" 11*cdf0e10cSrcweir #include "registryexception.hxx" 12*cdf0e10cSrcweir 13*cdf0e10cSrcweir #include <assert.h> 14*cdf0e10cSrcweir #ifdef _MSC_VER 15*cdf0e10cSrcweir #pragma warning(disable: 4350 4482) 16*cdf0e10cSrcweir #include "strsafe.h" 17*cdf0e10cSrcweir #endif 18*cdf0e10cSrcweir 19*cdf0e10cSrcweir //---------------------------------------------------------- 20*cdf0e10cSrcweir #ifdef DEBUG 21*cdf0e10cSrcweir inline void OutputDebugStringFormat( LPCTSTR pFormat, ... ) 22*cdf0e10cSrcweir { 23*cdf0e10cSrcweir TCHAR buffer[1024]; 24*cdf0e10cSrcweir va_list args; 25*cdf0e10cSrcweir 26*cdf0e10cSrcweir va_start( args, pFormat ); 27*cdf0e10cSrcweir StringCchVPrintf( buffer, sizeof(buffer), pFormat, args ); 28*cdf0e10cSrcweir OutputDebugString( buffer ); 29*cdf0e10cSrcweir } 30*cdf0e10cSrcweir #else 31*cdf0e10cSrcweir static inline void OutputDebugStringFormat( LPCTSTR, ... ) 32*cdf0e10cSrcweir { 33*cdf0e10cSrcweir } 34*cdf0e10cSrcweir #endif 35*cdf0e10cSrcweir //---------------------------------------------------------- 36*cdf0e10cSrcweir 37*cdf0e10cSrcweir const int MSWORD = 0x1; 38*cdf0e10cSrcweir const int MSEXCEL = 0x2; 39*cdf0e10cSrcweir const int MSPOWERPOINT = 0x4; 40*cdf0e10cSrcweir const int DEFAULT_HTML_EDITOR_FOR_IE = 0x8; 41*cdf0e10cSrcweir const int HTML_EDITOR = 0x10; 42*cdf0e10cSrcweir const int DEFAULT_SHELL_HTML_EDITOR = 0x20; 43*cdf0e10cSrcweir 44*cdf0e10cSrcweir namespace /* private */ 45*cdf0e10cSrcweir { 46*cdf0e10cSrcweir const std::wstring HTM_OPENWITHLIST = L".htm\\OpenWithList"; 47*cdf0e10cSrcweir const std::wstring APPLICATIONS = L"Applications"; 48*cdf0e10cSrcweir const std::wstring SHELL_EDIT_COMMAND = L"shell\\edit\\command"; 49*cdf0e10cSrcweir const std::wstring HTML_EDIT = L"HTML Edit"; 50*cdf0e10cSrcweir const std::wstring HTML_EDIT_DISPLAY_NAME = L"Edit Display Name"; 51*cdf0e10cSrcweir const std::wstring SHELL_EDIT_COMMAND_BACKUP = L"Shell Edit Cmd"; 52*cdf0e10cSrcweir const std::wstring DEFAULT_HTML_EDITOR = L"Default HTML Editor"; 53*cdf0e10cSrcweir const std::wstring MS_IE_DEF_HTML_EDITOR = L"Software\\Microsoft\\Internet Explorer\\Default HTML Editor"; 54*cdf0e10cSrcweir const std::wstring MS_IE_DEF_HTML_EDITOR_SHL_EDIT_CMD = L"Software\\Microsoft\\Internet Explorer\\Default HTML Editor\\shell\\edit\\command"; 55*cdf0e10cSrcweir } 56*cdf0e10cSrcweir 57*cdf0e10cSrcweir Registrar::Registrar(const RegistrationContextInformation& RegContext) : 58*cdf0e10cSrcweir m_ContextInformation(RegContext), 59*cdf0e10cSrcweir FORWARD_KEY_PREFIX(L"OpenOffice.org"),//FORWARD_KEY_PREFIX(L"soffice6"), 60*cdf0e10cSrcweir DEFAULT_VALUE_NAME(L""), 61*cdf0e10cSrcweir BACKUP_VALUE_NAME(L"Backup"), 62*cdf0e10cSrcweir PRIVATE_BACKUP_KEY_NAME(L"OpenOffice.org.reg4msdocmsi"),//PRIVATE_BACKUP_KEY_NAME(L"soffice6.bak"), 63*cdf0e10cSrcweir REGISTRATION_STATE(L"Reg4MsDocState") 64*cdf0e10cSrcweir { 65*cdf0e10cSrcweir m_RootKey = WindowsRegistry().GetClassesRootKey(); 66*cdf0e10cSrcweir } 67*cdf0e10cSrcweir 68*cdf0e10cSrcweir Registrar::~Registrar() 69*cdf0e10cSrcweir { 70*cdf0e10cSrcweir } 71*cdf0e10cSrcweir 72*cdf0e10cSrcweir void Registrar::RegisterForMsWord() const 73*cdf0e10cSrcweir { 74*cdf0e10cSrcweir assert(m_RootKey.get()); 75*cdf0e10cSrcweir 76*cdf0e10cSrcweir RegisterForMsOfficeApplication( 77*cdf0e10cSrcweir m_ContextInformation.GetWordDocumentFileExtension(), 78*cdf0e10cSrcweir m_ContextInformation.GetWordDocumentDisplayName(), 79*cdf0e10cSrcweir m_ContextInformation.GetWordDocumentDefaultIconEntry(), 80*cdf0e10cSrcweir m_ContextInformation.GetWordDocumentDefaultShellCommand(), 81*cdf0e10cSrcweir m_ContextInformation.ShellNewCommandDisplayName(), 82*cdf0e10cSrcweir RegistrationContextInformation::Writer); 83*cdf0e10cSrcweir 84*cdf0e10cSrcweir RegisterForMsOfficeApplication( 85*cdf0e10cSrcweir m_ContextInformation.GetWordTemplateFileExtension(), 86*cdf0e10cSrcweir m_ContextInformation.GetWordTemplateDisplayName(), 87*cdf0e10cSrcweir m_ContextInformation.GetWordTemplateDefaultIconEntry(), 88*cdf0e10cSrcweir m_ContextInformation.GetWordTemplateDefaultShellCommand(), 89*cdf0e10cSrcweir m_ContextInformation.ShellNewCommandDisplayName(), 90*cdf0e10cSrcweir RegistrationContextInformation::Writer); 91*cdf0e10cSrcweir 92*cdf0e10cSrcweir RegisterForMsOfficeApplication( 93*cdf0e10cSrcweir m_ContextInformation.GetRtfDocumentFileExtension(), 94*cdf0e10cSrcweir m_ContextInformation.GetRtfDocumentDisplayName(), 95*cdf0e10cSrcweir m_ContextInformation.GetRtfDocumentDefaultIconEntry(), 96*cdf0e10cSrcweir m_ContextInformation.GetRtfDocumentDefaultShellCommand(), 97*cdf0e10cSrcweir m_ContextInformation.ShellNewCommandDisplayName(), 98*cdf0e10cSrcweir RegistrationContextInformation::Writer); 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir SaveRegisteredFor(MSWORD); 101*cdf0e10cSrcweir } 102*cdf0e10cSrcweir 103*cdf0e10cSrcweir void Registrar::UnregisterForMsWord() const 104*cdf0e10cSrcweir { 105*cdf0e10cSrcweir assert(m_RootKey.get()); 106*cdf0e10cSrcweir 107*cdf0e10cSrcweir try 108*cdf0e10cSrcweir { 109*cdf0e10cSrcweir UnregisterForMsOfficeApplication( 110*cdf0e10cSrcweir m_ContextInformation.GetWordDocumentFileExtension()); 111*cdf0e10cSrcweir } 112*cdf0e10cSrcweir catch(RegistryKeyNotFoundException&) 113*cdf0e10cSrcweir {} 114*cdf0e10cSrcweir 115*cdf0e10cSrcweir try 116*cdf0e10cSrcweir { 117*cdf0e10cSrcweir UnregisterForMsOfficeApplication( 118*cdf0e10cSrcweir m_ContextInformation.GetWordTemplateFileExtension()); 119*cdf0e10cSrcweir } 120*cdf0e10cSrcweir catch(RegistryKeyNotFoundException&) 121*cdf0e10cSrcweir {} 122*cdf0e10cSrcweir 123*cdf0e10cSrcweir try 124*cdf0e10cSrcweir { 125*cdf0e10cSrcweir UnregisterForMsOfficeApplication( 126*cdf0e10cSrcweir m_ContextInformation.GetRtfDocumentFileExtension()); 127*cdf0e10cSrcweir } 128*cdf0e10cSrcweir catch(RegistryKeyNotFoundException&) 129*cdf0e10cSrcweir {} 130*cdf0e10cSrcweir 131*cdf0e10cSrcweir SaveNotRegisteredFor(MSWORD); 132*cdf0e10cSrcweir } 133*cdf0e10cSrcweir 134*cdf0e10cSrcweir bool Registrar::QueryPreselectForMsApplication(const std::wstring& file_extension) const 135*cdf0e10cSrcweir { 136*cdf0e10cSrcweir bool preselect = false; 137*cdf0e10cSrcweir 138*cdf0e10cSrcweir // We use HKCR else we would not see that a registration for 139*cdf0e10cSrcweir // MS Office applications already exist if we are about to 140*cdf0e10cSrcweir // register in HKCU\Software\Classes 141*cdf0e10cSrcweir RegistryKey root_key = WindowsRegistry().GetClassesRootKey(); 142*cdf0e10cSrcweir 143*cdf0e10cSrcweir if (!root_key->HasSubKey(file_extension)) 144*cdf0e10cSrcweir { 145*cdf0e10cSrcweir preselect = true; 146*cdf0e10cSrcweir OutputDebugStringFormat( TEXT("QueryPreselect: No SubKey found for (%s), preselected!\n"), file_extension.c_str() ); 147*cdf0e10cSrcweir } 148*cdf0e10cSrcweir else 149*cdf0e10cSrcweir { 150*cdf0e10cSrcweir RegistryKey RegKey = root_key->OpenSubKey(file_extension, false); 151*cdf0e10cSrcweir 152*cdf0e10cSrcweir if (RegKey->HasValue(DEFAULT_VALUE_NAME)) 153*cdf0e10cSrcweir { 154*cdf0e10cSrcweir RegistryValue RegVal = RegKey->GetValue(DEFAULT_VALUE_NAME); 155*cdf0e10cSrcweir 156*cdf0e10cSrcweir if (REG_SZ == RegVal->GetType() && 157*cdf0e10cSrcweir IsOpenOfficeRegisteredForMsApplication(RegVal->GetDataAsUniString())) 158*cdf0e10cSrcweir { 159*cdf0e10cSrcweir preselect = true; 160*cdf0e10cSrcweir OutputDebugStringFormat( TEXT("QueryPreselect: (%s) registered to Office, preselected!\n"), file_extension.c_str() ); 161*cdf0e10cSrcweir } 162*cdf0e10cSrcweir else if ( (REG_SZ == RegVal->GetType()) && ! root_key->HasSubKey( RegVal->GetDataAsUniString() ) ) 163*cdf0e10cSrcweir { 164*cdf0e10cSrcweir preselect = true; 165*cdf0e10cSrcweir OutputDebugStringFormat( TEXT("QueryPreselect: (%s) registered but destination is empty, preselected!\n"), file_extension.c_str() ); 166*cdf0e10cSrcweir } 167*cdf0e10cSrcweir } 168*cdf0e10cSrcweir else 169*cdf0e10cSrcweir { 170*cdf0e10cSrcweir preselect = true; 171*cdf0e10cSrcweir OutputDebugStringFormat( TEXT("QueryPreselect: No default found for SubKey (%s), preselected!\n"), file_extension.c_str() ); 172*cdf0e10cSrcweir } 173*cdf0e10cSrcweir } 174*cdf0e10cSrcweir return preselect; 175*cdf0e10cSrcweir } 176*cdf0e10cSrcweir 177*cdf0e10cSrcweir bool Registrar::QueryPreselectMsWordRegistration() const 178*cdf0e10cSrcweir { 179*cdf0e10cSrcweir return QueryPreselectForMsApplication( 180*cdf0e10cSrcweir m_ContextInformation.GetWordDocumentFileExtension()); 181*cdf0e10cSrcweir } 182*cdf0e10cSrcweir 183*cdf0e10cSrcweir void Registrar::RegisterForMsExcel() const 184*cdf0e10cSrcweir { 185*cdf0e10cSrcweir assert(m_RootKey.get()); 186*cdf0e10cSrcweir 187*cdf0e10cSrcweir RegisterForMsOfficeApplication( 188*cdf0e10cSrcweir m_ContextInformation.GetExcelSheetFileExtension(), 189*cdf0e10cSrcweir m_ContextInformation.GetExcelSheetDisplayName(), 190*cdf0e10cSrcweir m_ContextInformation.GetExcelSheetDefaultIconEntry(), 191*cdf0e10cSrcweir m_ContextInformation.GetExcelSheetDefaultShellCommand(), 192*cdf0e10cSrcweir m_ContextInformation.ShellNewCommandDisplayName(), 193*cdf0e10cSrcweir RegistrationContextInformation::Calc); 194*cdf0e10cSrcweir 195*cdf0e10cSrcweir RegisterForMsOfficeApplication( 196*cdf0e10cSrcweir m_ContextInformation.GetExcelTemplateFileExtension(), 197*cdf0e10cSrcweir m_ContextInformation.GetExcelTemplateDisplayName(), 198*cdf0e10cSrcweir m_ContextInformation.GetExcelTemplateDefaultIconEntry(), 199*cdf0e10cSrcweir m_ContextInformation.GetExcelTemplateDefaultShellCommand(), 200*cdf0e10cSrcweir m_ContextInformation.ShellNewCommandDisplayName(), 201*cdf0e10cSrcweir RegistrationContextInformation::Calc); 202*cdf0e10cSrcweir 203*cdf0e10cSrcweir SaveRegisteredFor(MSEXCEL); 204*cdf0e10cSrcweir } 205*cdf0e10cSrcweir 206*cdf0e10cSrcweir void Registrar::UnregisterForMsExcel() const 207*cdf0e10cSrcweir { 208*cdf0e10cSrcweir assert(m_RootKey.get()); 209*cdf0e10cSrcweir 210*cdf0e10cSrcweir try 211*cdf0e10cSrcweir { 212*cdf0e10cSrcweir UnregisterForMsOfficeApplication( 213*cdf0e10cSrcweir m_ContextInformation.GetExcelSheetFileExtension()); 214*cdf0e10cSrcweir } 215*cdf0e10cSrcweir catch(RegistryKeyNotFoundException&) 216*cdf0e10cSrcweir {} 217*cdf0e10cSrcweir 218*cdf0e10cSrcweir try 219*cdf0e10cSrcweir { 220*cdf0e10cSrcweir UnregisterForMsOfficeApplication( 221*cdf0e10cSrcweir m_ContextInformation.GetExcelTemplateFileExtension()); 222*cdf0e10cSrcweir } 223*cdf0e10cSrcweir catch(RegistryKeyNotFoundException&) 224*cdf0e10cSrcweir {} 225*cdf0e10cSrcweir 226*cdf0e10cSrcweir SaveNotRegisteredFor(MSEXCEL); 227*cdf0e10cSrcweir } 228*cdf0e10cSrcweir 229*cdf0e10cSrcweir bool Registrar::QueryPreselectMsExcelRegistration() const 230*cdf0e10cSrcweir { 231*cdf0e10cSrcweir return QueryPreselectForMsApplication( 232*cdf0e10cSrcweir m_ContextInformation.GetExcelSheetFileExtension()); 233*cdf0e10cSrcweir } 234*cdf0e10cSrcweir 235*cdf0e10cSrcweir void Registrar::RegisterForMsPowerPoint() const 236*cdf0e10cSrcweir { 237*cdf0e10cSrcweir assert(m_RootKey.get()); 238*cdf0e10cSrcweir 239*cdf0e10cSrcweir RegisterForMsOfficeApplication( 240*cdf0e10cSrcweir m_ContextInformation.GetPowerPointDocumentFileExtension(), 241*cdf0e10cSrcweir m_ContextInformation.GetPowerPointDocumentDisplayName(), 242*cdf0e10cSrcweir m_ContextInformation.GetPowerPointDocumentDefaultIconEntry(), 243*cdf0e10cSrcweir m_ContextInformation.GetPowerPointDocumentDefaultShellCommand(), 244*cdf0e10cSrcweir m_ContextInformation.ShellNewCommandDisplayName(), 245*cdf0e10cSrcweir RegistrationContextInformation::Impress); 246*cdf0e10cSrcweir 247*cdf0e10cSrcweir RegisterForMsOfficeApplication( 248*cdf0e10cSrcweir m_ContextInformation.GetPowerPointShowFileExtension(), 249*cdf0e10cSrcweir m_ContextInformation.GetPowerPointShowDisplayName(), 250*cdf0e10cSrcweir m_ContextInformation.GetPowerPointShowDefaultIconEntry(), 251*cdf0e10cSrcweir m_ContextInformation.GetPowerPointShowDefaultShellCommand(), 252*cdf0e10cSrcweir m_ContextInformation.ShellNewCommandDisplayName(), 253*cdf0e10cSrcweir RegistrationContextInformation::Impress); 254*cdf0e10cSrcweir 255*cdf0e10cSrcweir RegisterForMsOfficeApplication( 256*cdf0e10cSrcweir m_ContextInformation.GetPowerPointTemplateFileExtension(), 257*cdf0e10cSrcweir m_ContextInformation.GetPowerPointTemplateDisplayName(), 258*cdf0e10cSrcweir m_ContextInformation.GetPowerPointTemplateDefaultIconEntry(), 259*cdf0e10cSrcweir m_ContextInformation.GetPowerPointTemplateDefaultShellCommand(), 260*cdf0e10cSrcweir m_ContextInformation.ShellNewCommandDisplayName(), 261*cdf0e10cSrcweir RegistrationContextInformation::Impress); 262*cdf0e10cSrcweir 263*cdf0e10cSrcweir SaveRegisteredFor(MSPOWERPOINT); 264*cdf0e10cSrcweir } 265*cdf0e10cSrcweir 266*cdf0e10cSrcweir void Registrar::UnregisterForMsPowerPoint() const 267*cdf0e10cSrcweir { 268*cdf0e10cSrcweir assert(m_RootKey.get()); 269*cdf0e10cSrcweir 270*cdf0e10cSrcweir try 271*cdf0e10cSrcweir { 272*cdf0e10cSrcweir UnregisterForMsOfficeApplication( 273*cdf0e10cSrcweir m_ContextInformation.GetPowerPointDocumentFileExtension()); 274*cdf0e10cSrcweir } 275*cdf0e10cSrcweir catch(RegistryKeyNotFoundException&) 276*cdf0e10cSrcweir {} 277*cdf0e10cSrcweir 278*cdf0e10cSrcweir try 279*cdf0e10cSrcweir { 280*cdf0e10cSrcweir UnregisterForMsOfficeApplication( 281*cdf0e10cSrcweir m_ContextInformation.GetPowerPointShowFileExtension()); 282*cdf0e10cSrcweir } 283*cdf0e10cSrcweir catch(RegistryKeyNotFoundException&) 284*cdf0e10cSrcweir {} 285*cdf0e10cSrcweir 286*cdf0e10cSrcweir try 287*cdf0e10cSrcweir { 288*cdf0e10cSrcweir UnregisterForMsOfficeApplication( 289*cdf0e10cSrcweir m_ContextInformation.GetPowerPointTemplateFileExtension()); 290*cdf0e10cSrcweir } 291*cdf0e10cSrcweir catch(RegistryKeyNotFoundException&) 292*cdf0e10cSrcweir {} 293*cdf0e10cSrcweir 294*cdf0e10cSrcweir SaveNotRegisteredFor(MSPOWERPOINT); 295*cdf0e10cSrcweir } 296*cdf0e10cSrcweir 297*cdf0e10cSrcweir //----------------------------------------- 298*cdf0e10cSrcweir /* 299*cdf0e10cSrcweir */ 300*cdf0e10cSrcweir bool Registrar::QueryPreselectMsPowerPointRegistration() const 301*cdf0e10cSrcweir { 302*cdf0e10cSrcweir return QueryPreselectForMsApplication( m_ContextInformation.GetPowerPointDocumentFileExtension()) && 303*cdf0e10cSrcweir QueryPreselectForMsApplication( m_ContextInformation.GetPowerPointShowFileExtension()); 304*cdf0e10cSrcweir } 305*cdf0e10cSrcweir 306*cdf0e10cSrcweir //----------------------------------------- 307*cdf0e10cSrcweir /** The documentation says we have to 308*cdf0e10cSrcweir make the following entries to register 309*cdf0e10cSrcweir a html editor for the Internet Explorer 310*cdf0e10cSrcweir HKCR\.htm\OpenWithList\App Friendly Name\shell\edit\command 311*cdf0e10cSrcweir But the reality shows that this works only 312*cdf0e10cSrcweir with Internet Explorer 5.x 313*cdf0e10cSrcweir Internet Explorer 6.0 wants the follwoing 314*cdf0e10cSrcweir entries: 315*cdf0e10cSrcweir HKCR\.htm\OpenWithList\App.exe 316*cdf0e10cSrcweir HKCR\Applications\App.ex\shell\edit\command 317*cdf0e10cSrcweir */ 318*cdf0e10cSrcweir void Registrar::RegisterAsHtmlEditorForInternetExplorer() const 319*cdf0e10cSrcweir { 320*cdf0e10cSrcweir assert(m_RootKey.get()); 321*cdf0e10cSrcweir 322*cdf0e10cSrcweir std::wstring OOFriendlyAppName = m_ContextInformation.GetOpenOfficeFriendlyAppName(); 323*cdf0e10cSrcweir 324*cdf0e10cSrcweir std::wstring RegKeyName = HTM_OPENWITHLIST + std::wstring(L"\\") + OOFriendlyAppName; 325*cdf0e10cSrcweir RegistryKey RegKey = m_RootKey->CreateSubKey(RegKeyName); 326*cdf0e10cSrcweir 327*cdf0e10cSrcweir RegKey = RegKey->CreateSubKey(SHELL_EDIT_COMMAND); 328*cdf0e10cSrcweir 329*cdf0e10cSrcweir RegistryValue RegVal( 330*cdf0e10cSrcweir new RegistryValueImpl( 331*cdf0e10cSrcweir DEFAULT_VALUE_NAME, 332*cdf0e10cSrcweir m_ContextInformation.GetOpenOfficeCommandline(RegistrationContextInformation::Open, 333*cdf0e10cSrcweir RegistrationContextInformation::Writer))); 334*cdf0e10cSrcweir 335*cdf0e10cSrcweir RegKey->SetValue(RegVal); 336*cdf0e10cSrcweir 337*cdf0e10cSrcweir RegKeyName = APPLICATIONS + std::wstring(L"\\") + OOFriendlyAppName; 338*cdf0e10cSrcweir RegKey = m_RootKey->CreateSubKey(RegKeyName); 339*cdf0e10cSrcweir 340*cdf0e10cSrcweir RegVal->SetName(L"FriendlyAppName"); 341*cdf0e10cSrcweir RegVal->SetValue(OOFriendlyAppName); 342*cdf0e10cSrcweir RegKey->SetValue(RegVal); 343*cdf0e10cSrcweir 344*cdf0e10cSrcweir RegKey = RegKey->CreateSubKey(SHELL_EDIT_COMMAND); 345*cdf0e10cSrcweir RegVal->SetName(DEFAULT_VALUE_NAME); 346*cdf0e10cSrcweir RegVal->SetValue( 347*cdf0e10cSrcweir m_ContextInformation.GetOpenOfficeCommandline(RegistrationContextInformation::Open, 348*cdf0e10cSrcweir RegistrationContextInformation::Writer)); 349*cdf0e10cSrcweir RegKey->SetValue(RegVal); 350*cdf0e10cSrcweir 351*cdf0e10cSrcweir SaveRegisteredFor(HTML_EDITOR); 352*cdf0e10cSrcweir } 353*cdf0e10cSrcweir 354*cdf0e10cSrcweir void Registrar::UnregisterAsHtmlEditorForInternetExplorer() const 355*cdf0e10cSrcweir { 356*cdf0e10cSrcweir assert(m_RootKey.get()); 357*cdf0e10cSrcweir 358*cdf0e10cSrcweir try 359*cdf0e10cSrcweir { 360*cdf0e10cSrcweir std::wstring OOFriendlyAppName = m_ContextInformation.GetOpenOfficeFriendlyAppName(); 361*cdf0e10cSrcweir 362*cdf0e10cSrcweir RegistryKey aRegKey = m_RootKey->OpenSubKey( APPLICATIONS ); 363*cdf0e10cSrcweir if ( aRegKey->HasSubKey( OOFriendlyAppName ) ) 364*cdf0e10cSrcweir aRegKey->DeleteSubKeyTree( OOFriendlyAppName ); 365*cdf0e10cSrcweir 366*cdf0e10cSrcweir aRegKey = m_RootKey->OpenSubKey( HTM_OPENWITHLIST ); 367*cdf0e10cSrcweir if ( aRegKey->HasSubKey( OOFriendlyAppName ) ) 368*cdf0e10cSrcweir aRegKey->DeleteSubKeyTree( OOFriendlyAppName ); 369*cdf0e10cSrcweir } 370*cdf0e10cSrcweir catch(RegistryKeyNotFoundException&) 371*cdf0e10cSrcweir {} 372*cdf0e10cSrcweir 373*cdf0e10cSrcweir SaveNotRegisteredFor(HTML_EDITOR); 374*cdf0e10cSrcweir } 375*cdf0e10cSrcweir 376*cdf0e10cSrcweir void Registrar::RegisterAsDefaultHtmlEditorForInternetExplorer() const 377*cdf0e10cSrcweir { 378*cdf0e10cSrcweir assert(m_RootKey.get()); 379*cdf0e10cSrcweir 380*cdf0e10cSrcweir RegistryKey RegistrationRootKey = GetRootKeyForDefHtmlEditorForIERegistration(); 381*cdf0e10cSrcweir 382*cdf0e10cSrcweir RegistryKey RegKey = RegistrationRootKey->CreateSubKey(MS_IE_DEF_HTML_EDITOR_SHL_EDIT_CMD); 383*cdf0e10cSrcweir 384*cdf0e10cSrcweir RegistryValue RegVal = RegistryValue(new RegistryValueImpl(DEFAULT_VALUE_NAME, L"")); 385*cdf0e10cSrcweir 386*cdf0e10cSrcweir if (RegKey->HasValue(DEFAULT_VALUE_NAME)) 387*cdf0e10cSrcweir { 388*cdf0e10cSrcweir RegVal = RegKey->GetValue(DEFAULT_VALUE_NAME); 389*cdf0e10cSrcweir 390*cdf0e10cSrcweir std::wstring CmdLine = RegVal->GetDataAsUniString(); 391*cdf0e10cSrcweir 392*cdf0e10cSrcweir if (std::wstring::npos == CmdLine.find(m_ContextInformation.GetOpenOfficeExecutableName())) 393*cdf0e10cSrcweir { 394*cdf0e10cSrcweir RegistryKey BackupRegKey = m_RootKey->CreateSubKey(PRIVATE_BACKUP_KEY_NAME + L"\\" + DEFAULT_HTML_EDITOR); 395*cdf0e10cSrcweir 396*cdf0e10cSrcweir if (RegKey->HasValue(DEFAULT_VALUE_NAME)) 397*cdf0e10cSrcweir BackupRegKey->CopyValue(RegKey, DEFAULT_VALUE_NAME); 398*cdf0e10cSrcweir 399*cdf0e10cSrcweir RegKey = RegistrationRootKey->OpenSubKey(MS_IE_DEF_HTML_EDITOR); 400*cdf0e10cSrcweir if (RegKey->HasValue(L"Description")) 401*cdf0e10cSrcweir BackupRegKey->CopyValue(RegKey, L"Description"); 402*cdf0e10cSrcweir } 403*cdf0e10cSrcweir } 404*cdf0e10cSrcweir 405*cdf0e10cSrcweir RegVal->SetValue( 406*cdf0e10cSrcweir m_ContextInformation.GetOpenOfficeCommandline(RegistrationContextInformation::Open, 407*cdf0e10cSrcweir RegistrationContextInformation::Writer)); 408*cdf0e10cSrcweir RegKey = RegistrationRootKey->OpenSubKey(MS_IE_DEF_HTML_EDITOR_SHL_EDIT_CMD); 409*cdf0e10cSrcweir RegKey->SetValue(RegVal); 410*cdf0e10cSrcweir 411*cdf0e10cSrcweir RegVal->SetName(L"Description"); 412*cdf0e10cSrcweir RegVal->SetValue(m_ContextInformation.GetOpenOfficeFriendlyAppName()); 413*cdf0e10cSrcweir RegKey = RegistrationRootKey->OpenSubKey(MS_IE_DEF_HTML_EDITOR); 414*cdf0e10cSrcweir RegKey->SetValue(RegVal); 415*cdf0e10cSrcweir 416*cdf0e10cSrcweir SaveRegisteredFor(DEFAULT_HTML_EDITOR_FOR_IE); 417*cdf0e10cSrcweir } 418*cdf0e10cSrcweir 419*cdf0e10cSrcweir void Registrar::UnregisterAsDefaultHtmlEditorForInternetExplorer() const 420*cdf0e10cSrcweir { 421*cdf0e10cSrcweir assert(m_RootKey.get()); 422*cdf0e10cSrcweir 423*cdf0e10cSrcweir RegistryKey RegistrationRootKey = GetRootKeyForDefHtmlEditorForIERegistration(); 424*cdf0e10cSrcweir 425*cdf0e10cSrcweir RegistryKey RegKey = RegistrationRootKey->OpenSubKey(MS_IE_DEF_HTML_EDITOR_SHL_EDIT_CMD); 426*cdf0e10cSrcweir 427*cdf0e10cSrcweir if (RegKey->HasValue(DEFAULT_VALUE_NAME)) 428*cdf0e10cSrcweir { 429*cdf0e10cSrcweir RegistryValue RegVal = RegKey->GetValue(DEFAULT_VALUE_NAME); 430*cdf0e10cSrcweir 431*cdf0e10cSrcweir std::wstring CmdLine = RegVal->GetDataAsUniString(); 432*cdf0e10cSrcweir 433*cdf0e10cSrcweir if (std::wstring::npos != CmdLine.find(m_ContextInformation.GetOpenOfficeExecutableName())) 434*cdf0e10cSrcweir { 435*cdf0e10cSrcweir RegistryKey BackupRegKey = m_RootKey->OpenSubKey(PRIVATE_BACKUP_KEY_NAME); 436*cdf0e10cSrcweir 437*cdf0e10cSrcweir if (BackupRegKey->HasSubKey(DEFAULT_HTML_EDITOR)) 438*cdf0e10cSrcweir { 439*cdf0e10cSrcweir BackupRegKey = BackupRegKey->OpenSubKey(DEFAULT_HTML_EDITOR); 440*cdf0e10cSrcweir 441*cdf0e10cSrcweir if (BackupRegKey->HasValue(DEFAULT_VALUE_NAME)) 442*cdf0e10cSrcweir RegKey->CopyValue(BackupRegKey, DEFAULT_VALUE_NAME); 443*cdf0e10cSrcweir else 444*cdf0e10cSrcweir RegKey->DeleteValue(DEFAULT_VALUE_NAME); 445*cdf0e10cSrcweir 446*cdf0e10cSrcweir RegKey = RegistrationRootKey->OpenSubKey(MS_IE_DEF_HTML_EDITOR); 447*cdf0e10cSrcweir 448*cdf0e10cSrcweir if (BackupRegKey->HasValue(L"Description")) 449*cdf0e10cSrcweir RegKey->CopyValue(BackupRegKey, L"Description"); 450*cdf0e10cSrcweir else 451*cdf0e10cSrcweir RegKey->DeleteValue(L"Description"); 452*cdf0e10cSrcweir } 453*cdf0e10cSrcweir else 454*cdf0e10cSrcweir { 455*cdf0e10cSrcweir RegKey->DeleteValue(DEFAULT_VALUE_NAME); 456*cdf0e10cSrcweir RegKey = RegistrationRootKey->OpenSubKey(MS_IE_DEF_HTML_EDITOR); 457*cdf0e10cSrcweir RegKey->DeleteValue(L"Description"); 458*cdf0e10cSrcweir } 459*cdf0e10cSrcweir } 460*cdf0e10cSrcweir } 461*cdf0e10cSrcweir 462*cdf0e10cSrcweir SaveNotRegisteredFor(DEFAULT_HTML_EDITOR_FOR_IE); 463*cdf0e10cSrcweir } 464*cdf0e10cSrcweir 465*cdf0e10cSrcweir void Registrar::RegisterAsDefaultShellHtmlEditor() const 466*cdf0e10cSrcweir { 467*cdf0e10cSrcweir assert(m_RootKey.get()); 468*cdf0e10cSrcweir 469*cdf0e10cSrcweir RegistryKey RegKey = m_RootKey->CreateSubKey(L".htm"); 470*cdf0e10cSrcweir 471*cdf0e10cSrcweir RegistryValue RegVal = RegistryValue( 472*cdf0e10cSrcweir new RegistryValueImpl(DEFAULT_VALUE_NAME, L"")); 473*cdf0e10cSrcweir 474*cdf0e10cSrcweir if (RegKey->HasValue(DEFAULT_VALUE_NAME)) 475*cdf0e10cSrcweir RegVal = RegKey->GetValue(DEFAULT_VALUE_NAME); 476*cdf0e10cSrcweir 477*cdf0e10cSrcweir std::wstring HtmFwdKey = RegVal->GetDataAsUniString(); 478*cdf0e10cSrcweir if (0 == HtmFwdKey.length() || !m_RootKey->HasSubKey(HtmFwdKey)) 479*cdf0e10cSrcweir HtmFwdKey = L".htm"; 480*cdf0e10cSrcweir 481*cdf0e10cSrcweir RegKey = m_RootKey->CreateSubKey(HtmFwdKey + L"\\" + SHELL_EDIT_COMMAND); 482*cdf0e10cSrcweir 483*cdf0e10cSrcweir if (RegKey->HasValue(DEFAULT_VALUE_NAME)) 484*cdf0e10cSrcweir { 485*cdf0e10cSrcweir RegVal = RegKey->GetValue(DEFAULT_VALUE_NAME); 486*cdf0e10cSrcweir 487*cdf0e10cSrcweir std::wstring CmdLine = RegVal->GetDataAsUniString(); 488*cdf0e10cSrcweir 489*cdf0e10cSrcweir // backup old values if we are not in place 490*cdf0e10cSrcweir if (std::wstring::npos == CmdLine.find(m_ContextInformation.GetOpenOfficeExecutableName())) 491*cdf0e10cSrcweir { 492*cdf0e10cSrcweir RegistryKey BackupRegKey = m_RootKey->CreateSubKey(PRIVATE_BACKUP_KEY_NAME + L"\\" + HTML_EDIT); 493*cdf0e10cSrcweir BackupRegKey->CopyValue(RegKey, DEFAULT_VALUE_NAME, SHELL_EDIT_COMMAND_BACKUP); 494*cdf0e10cSrcweir } 495*cdf0e10cSrcweir } 496*cdf0e10cSrcweir 497*cdf0e10cSrcweir RegVal->SetValue( 498*cdf0e10cSrcweir m_ContextInformation.GetOpenOfficeCommandline(RegistrationContextInformation::Open, 499*cdf0e10cSrcweir RegistrationContextInformation::Writer)); 500*cdf0e10cSrcweir 501*cdf0e10cSrcweir RegKey->SetValue(RegVal); 502*cdf0e10cSrcweir 503*cdf0e10cSrcweir SaveRegisteredFor(DEFAULT_SHELL_HTML_EDITOR); 504*cdf0e10cSrcweir } 505*cdf0e10cSrcweir 506*cdf0e10cSrcweir void Registrar::UnregisterAsDefaultShellHtmlEditor() const 507*cdf0e10cSrcweir { 508*cdf0e10cSrcweir assert(m_RootKey.get()); 509*cdf0e10cSrcweir 510*cdf0e10cSrcweir try 511*cdf0e10cSrcweir { 512*cdf0e10cSrcweir RegistryKey RegKey = m_RootKey->OpenSubKey(L".htm"); 513*cdf0e10cSrcweir 514*cdf0e10cSrcweir RegistryValue RegVal = RegistryValue( 515*cdf0e10cSrcweir new RegistryValueImpl(DEFAULT_VALUE_NAME, L"")); 516*cdf0e10cSrcweir 517*cdf0e10cSrcweir if (RegKey->HasValue(DEFAULT_VALUE_NAME)) 518*cdf0e10cSrcweir RegVal = RegKey->GetValue(DEFAULT_VALUE_NAME); 519*cdf0e10cSrcweir 520*cdf0e10cSrcweir std::wstring HtmFwdKey = RegVal->GetDataAsUniString(); 521*cdf0e10cSrcweir 522*cdf0e10cSrcweir if (0 == HtmFwdKey.length() || !m_RootKey->HasSubKey(HtmFwdKey)) 523*cdf0e10cSrcweir HtmFwdKey = L".htm"; 524*cdf0e10cSrcweir 525*cdf0e10cSrcweir RegKey = m_RootKey->OpenSubKey(HtmFwdKey + L"\\" + SHELL_EDIT_COMMAND); 526*cdf0e10cSrcweir 527*cdf0e10cSrcweir RegVal = RegKey->GetValue(DEFAULT_VALUE_NAME); 528*cdf0e10cSrcweir 529*cdf0e10cSrcweir std::wstring CmdLine = RegVal->GetDataAsUniString(); 530*cdf0e10cSrcweir 531*cdf0e10cSrcweir if (std::wstring::npos != CmdLine.find(m_ContextInformation.GetOpenOfficeExecutableName())) 532*cdf0e10cSrcweir { 533*cdf0e10cSrcweir RegistryKey BackupRegKey = m_RootKey->CreateSubKey(PRIVATE_BACKUP_KEY_NAME + L"\\" + HTML_EDIT); 534*cdf0e10cSrcweir 535*cdf0e10cSrcweir if (BackupRegKey->HasValue(SHELL_EDIT_COMMAND_BACKUP)) 536*cdf0e10cSrcweir RegKey->CopyValue(BackupRegKey, SHELL_EDIT_COMMAND_BACKUP, DEFAULT_VALUE_NAME); 537*cdf0e10cSrcweir else 538*cdf0e10cSrcweir RegKey->DeleteValue(DEFAULT_VALUE_NAME); 539*cdf0e10cSrcweir } 540*cdf0e10cSrcweir } 541*cdf0e10cSrcweir catch(RegistryKeyNotFoundException&) 542*cdf0e10cSrcweir { 543*cdf0e10cSrcweir } 544*cdf0e10cSrcweir 545*cdf0e10cSrcweir SaveNotRegisteredFor(DEFAULT_SHELL_HTML_EDITOR); 546*cdf0e10cSrcweir } 547*cdf0e10cSrcweir 548*cdf0e10cSrcweir void Registrar::SaveRegisteredFor(int State) const 549*cdf0e10cSrcweir { 550*cdf0e10cSrcweir assert(m_RootKey.get()); 551*cdf0e10cSrcweir 552*cdf0e10cSrcweir int NewState = GetRegisterState(); 553*cdf0e10cSrcweir NewState |= State; 554*cdf0e10cSrcweir SetRegisterState(NewState); 555*cdf0e10cSrcweir } 556*cdf0e10cSrcweir 557*cdf0e10cSrcweir void Registrar::SaveNotRegisteredFor(int State) const 558*cdf0e10cSrcweir { 559*cdf0e10cSrcweir assert(m_RootKey.get()); 560*cdf0e10cSrcweir 561*cdf0e10cSrcweir int NewState = GetRegisterState(); 562*cdf0e10cSrcweir NewState &= ~State; 563*cdf0e10cSrcweir SetRegisterState(NewState); 564*cdf0e10cSrcweir } 565*cdf0e10cSrcweir 566*cdf0e10cSrcweir int Registrar::GetRegisterState() const 567*cdf0e10cSrcweir { 568*cdf0e10cSrcweir int State = 0; 569*cdf0e10cSrcweir 570*cdf0e10cSrcweir RegistryKey RegKey = m_RootKey->CreateSubKey(PRIVATE_BACKUP_KEY_NAME); 571*cdf0e10cSrcweir 572*cdf0e10cSrcweir if (RegKey->HasValue(REGISTRATION_STATE)) 573*cdf0e10cSrcweir { 574*cdf0e10cSrcweir RegistryValue RegVal = RegKey->GetValue(REGISTRATION_STATE); 575*cdf0e10cSrcweir if (REG_DWORD == RegVal->GetType()) 576*cdf0e10cSrcweir State = RegVal->GetDataAsInt(); 577*cdf0e10cSrcweir } 578*cdf0e10cSrcweir 579*cdf0e10cSrcweir return State; 580*cdf0e10cSrcweir } 581*cdf0e10cSrcweir 582*cdf0e10cSrcweir void Registrar::SetRegisterState(int NewState) const 583*cdf0e10cSrcweir { 584*cdf0e10cSrcweir RegistryKey RegKey = m_RootKey->CreateSubKey(PRIVATE_BACKUP_KEY_NAME); 585*cdf0e10cSrcweir RegistryValue RegVal = RegistryValue(new RegistryValueImpl(REGISTRATION_STATE, NewState)); 586*cdf0e10cSrcweir RegKey->SetValue(RegVal); 587*cdf0e10cSrcweir } 588*cdf0e10cSrcweir 589*cdf0e10cSrcweir bool Registrar::IsRegisteredFor(int State) const 590*cdf0e10cSrcweir { 591*cdf0e10cSrcweir assert(m_RootKey.get()); 592*cdf0e10cSrcweir 593*cdf0e10cSrcweir RegistryKey RegKey = m_RootKey->CreateSubKey(PRIVATE_BACKUP_KEY_NAME); 594*cdf0e10cSrcweir 595*cdf0e10cSrcweir int SavedState = 0; 596*cdf0e10cSrcweir 597*cdf0e10cSrcweir if (RegKey->HasValue(REGISTRATION_STATE)) 598*cdf0e10cSrcweir { 599*cdf0e10cSrcweir RegistryValue RegVal = RegKey->GetValue(REGISTRATION_STATE); 600*cdf0e10cSrcweir if (REG_DWORD == RegVal->GetType()) 601*cdf0e10cSrcweir SavedState = RegVal->GetDataAsInt(); 602*cdf0e10cSrcweir } 603*cdf0e10cSrcweir 604*cdf0e10cSrcweir return ((SavedState & State) == State); 605*cdf0e10cSrcweir } 606*cdf0e10cSrcweir 607*cdf0e10cSrcweir //-------------------------------------- 608*cdf0e10cSrcweir /** Restore the last registration state (necessary for 609*cdf0e10cSrcweir Setup repair) */ 610*cdf0e10cSrcweir void Registrar::RepairRegistrationState() const 611*cdf0e10cSrcweir { 612*cdf0e10cSrcweir assert(m_RootKey.get()); 613*cdf0e10cSrcweir 614*cdf0e10cSrcweir if (IsRegisteredFor(MSWORD)) 615*cdf0e10cSrcweir RegisterForMsWord(); 616*cdf0e10cSrcweir 617*cdf0e10cSrcweir if (IsRegisteredFor(MSEXCEL)) 618*cdf0e10cSrcweir RegisterForMsExcel(); 619*cdf0e10cSrcweir 620*cdf0e10cSrcweir if (IsRegisteredFor(MSPOWERPOINT)) 621*cdf0e10cSrcweir RegisterForMsPowerPoint(); 622*cdf0e10cSrcweir 623*cdf0e10cSrcweir if (IsRegisteredFor(DEFAULT_HTML_EDITOR_FOR_IE)) 624*cdf0e10cSrcweir RegisterAsDefaultHtmlEditorForInternetExplorer(); 625*cdf0e10cSrcweir 626*cdf0e10cSrcweir if (IsRegisteredFor(HTML_EDITOR)) 627*cdf0e10cSrcweir RegisterAsHtmlEditorForInternetExplorer(); 628*cdf0e10cSrcweir 629*cdf0e10cSrcweir if (IsRegisteredFor(DEFAULT_SHELL_HTML_EDITOR)) 630*cdf0e10cSrcweir RegisterAsDefaultShellHtmlEditor(); 631*cdf0e10cSrcweir } 632*cdf0e10cSrcweir 633*cdf0e10cSrcweir /** Unregisters all and delete all Registry keys we have written */ 634*cdf0e10cSrcweir void Registrar::UnregisterAllAndCleanUpRegistry() const 635*cdf0e10cSrcweir { 636*cdf0e10cSrcweir assert(m_RootKey.get()); 637*cdf0e10cSrcweir 638*cdf0e10cSrcweir if (IsRegisteredFor(MSWORD)) 639*cdf0e10cSrcweir UnregisterForMsWord(); 640*cdf0e10cSrcweir 641*cdf0e10cSrcweir if (IsRegisteredFor(MSEXCEL)) 642*cdf0e10cSrcweir UnregisterForMsExcel(); 643*cdf0e10cSrcweir 644*cdf0e10cSrcweir if (IsRegisteredFor(MSPOWERPOINT)) 645*cdf0e10cSrcweir UnregisterForMsPowerPoint(); 646*cdf0e10cSrcweir 647*cdf0e10cSrcweir if (IsRegisteredFor(DEFAULT_HTML_EDITOR_FOR_IE)) 648*cdf0e10cSrcweir UnregisterAsDefaultHtmlEditorForInternetExplorer(); 649*cdf0e10cSrcweir 650*cdf0e10cSrcweir if (IsRegisteredFor(HTML_EDITOR)) 651*cdf0e10cSrcweir UnregisterAsHtmlEditorForInternetExplorer(); 652*cdf0e10cSrcweir 653*cdf0e10cSrcweir if (IsRegisteredFor(DEFAULT_SHELL_HTML_EDITOR)) 654*cdf0e10cSrcweir UnregisterAsDefaultShellHtmlEditor(); 655*cdf0e10cSrcweir 656*cdf0e10cSrcweir if (m_RootKey->HasSubKey(PRIVATE_BACKUP_KEY_NAME)) 657*cdf0e10cSrcweir m_RootKey->DeleteSubKeyTree(PRIVATE_BACKUP_KEY_NAME); 658*cdf0e10cSrcweir } 659*cdf0e10cSrcweir 660*cdf0e10cSrcweir void Registrar::RegisterForMsOfficeApplication( 661*cdf0e10cSrcweir const std::wstring& FileExtension, 662*cdf0e10cSrcweir const std::wstring& DocumentDisplayName, 663*cdf0e10cSrcweir const std::wstring& DefaultIconEntry, 664*cdf0e10cSrcweir const std::wstring& DefaultShellCommand, 665*cdf0e10cSrcweir const std::wstring& ShellNewCommandDisplayName, 666*cdf0e10cSrcweir const RegistrationContextInformation::OFFICE_APPLICATION eOfficeApp) const 667*cdf0e10cSrcweir { 668*cdf0e10cSrcweir assert(m_RootKey.get()); 669*cdf0e10cSrcweir 670*cdf0e10cSrcweir std::wstring ForwardKeyName = FORWARD_KEY_PREFIX + FileExtension; 671*cdf0e10cSrcweir 672*cdf0e10cSrcweir RegistryKey ForwardKey = m_RootKey->CreateSubKey(ForwardKeyName); 673*cdf0e10cSrcweir RegistryValue RegVal(new RegistryValueImpl(std::wstring(DEFAULT_VALUE_NAME), DocumentDisplayName)); 674*cdf0e10cSrcweir ForwardKey->SetValue(RegVal); 675*cdf0e10cSrcweir 676*cdf0e10cSrcweir RegistryKey RegKey = ForwardKey->CreateSubKey(L"DefaultIcon"); 677*cdf0e10cSrcweir RegVal->SetValue(DefaultIconEntry); 678*cdf0e10cSrcweir RegKey->SetValue(RegVal); 679*cdf0e10cSrcweir 680*cdf0e10cSrcweir RegistryKey RegKeyShell = ForwardKey->CreateSubKey(L"shell"); 681*cdf0e10cSrcweir RegVal->SetValue(DefaultShellCommand); 682*cdf0e10cSrcweir RegKeyShell->SetValue(RegVal); 683*cdf0e10cSrcweir 684*cdf0e10cSrcweir RegKey = RegKeyShell->CreateSubKey(L"new"); 685*cdf0e10cSrcweir RegVal->SetValue(ShellNewCommandDisplayName); 686*cdf0e10cSrcweir RegKey->SetValue(RegVal); 687*cdf0e10cSrcweir 688*cdf0e10cSrcweir RegKey = RegKey->CreateSubKey(L"command"); 689*cdf0e10cSrcweir RegVal->SetValue(m_ContextInformation.GetOpenOfficeCommandline(RegistrationContextInformation::New, eOfficeApp)); 690*cdf0e10cSrcweir RegKey->SetValue(RegVal); 691*cdf0e10cSrcweir 692*cdf0e10cSrcweir RegKey = RegKeyShell->CreateSubKey(L"open\\command"); 693*cdf0e10cSrcweir RegVal->SetValue(m_ContextInformation.GetOpenOfficeCommandline(RegistrationContextInformation::Open, eOfficeApp)); 694*cdf0e10cSrcweir RegKey->SetValue(RegVal); 695*cdf0e10cSrcweir 696*cdf0e10cSrcweir RegKey = RegKeyShell->CreateSubKey(L"print\\command"); 697*cdf0e10cSrcweir RegVal->SetValue(m_ContextInformation.GetOpenOfficeCommandline(RegistrationContextInformation::Print, eOfficeApp)); 698*cdf0e10cSrcweir RegKey->SetValue(RegVal); 699*cdf0e10cSrcweir 700*cdf0e10cSrcweir RegKey = RegKeyShell->CreateSubKey(L"printto\\command"); 701*cdf0e10cSrcweir RegVal->SetValue(m_ContextInformation.GetOpenOfficeCommandline(RegistrationContextInformation::Printto, eOfficeApp)); 702*cdf0e10cSrcweir RegKey->SetValue(RegVal); 703*cdf0e10cSrcweir 704*cdf0e10cSrcweir // set the new forward key under the appropriate extension 705*cdf0e10cSrcweir RegKey = m_RootKey->CreateSubKey(FileExtension); 706*cdf0e10cSrcweir 707*cdf0e10cSrcweir if (RegKey->HasValue(DEFAULT_VALUE_NAME)) 708*cdf0e10cSrcweir { 709*cdf0e10cSrcweir RegVal = RegKey->GetValue(DEFAULT_VALUE_NAME); 710*cdf0e10cSrcweir 711*cdf0e10cSrcweir if (REG_SZ == RegVal->GetType()) 712*cdf0e10cSrcweir { 713*cdf0e10cSrcweir std::wstring str = RegVal->GetDataAsUniString(); 714*cdf0e10cSrcweir if (!IsOpenOfficeRegisteredForMsApplication(str)) 715*cdf0e10cSrcweir ForwardKey->CopyValue(RegKey, DEFAULT_VALUE_NAME, BACKUP_VALUE_NAME); 716*cdf0e10cSrcweir } 717*cdf0e10cSrcweir } 718*cdf0e10cSrcweir 719*cdf0e10cSrcweir RegVal->SetValue(ForwardKeyName); 720*cdf0e10cSrcweir RegKey->SetValue(RegVal); 721*cdf0e10cSrcweir } 722*cdf0e10cSrcweir 723*cdf0e10cSrcweir void Registrar::UnregisterForMsOfficeApplication(const std::wstring& FileExtension) const 724*cdf0e10cSrcweir { 725*cdf0e10cSrcweir std::wstring FwdRegKeyName = FORWARD_KEY_PREFIX + FileExtension; 726*cdf0e10cSrcweir 727*cdf0e10cSrcweir if (m_RootKey->HasSubKey(FileExtension)) 728*cdf0e10cSrcweir { 729*cdf0e10cSrcweir RegistryKey RegKey = m_RootKey->OpenSubKey(FileExtension); 730*cdf0e10cSrcweir 731*cdf0e10cSrcweir if (RegKey->HasValue(DEFAULT_VALUE_NAME)) 732*cdf0e10cSrcweir { 733*cdf0e10cSrcweir RegistryValue RegVal = RegKey->GetValue(DEFAULT_VALUE_NAME); 734*cdf0e10cSrcweir if (REG_SZ == RegVal->GetType() && 735*cdf0e10cSrcweir IsOpenOfficeRegisteredForMsApplication(RegVal->GetDataAsUniString())) 736*cdf0e10cSrcweir { 737*cdf0e10cSrcweir RegistryKey FwdRegKey = m_RootKey->CreateSubKey(FwdRegKeyName); 738*cdf0e10cSrcweir 739*cdf0e10cSrcweir if (FwdRegKey->HasValue(BACKUP_VALUE_NAME)) 740*cdf0e10cSrcweir RegKey->CopyValue(FwdRegKey, BACKUP_VALUE_NAME, DEFAULT_VALUE_NAME); 741*cdf0e10cSrcweir else 742*cdf0e10cSrcweir RegKey->DeleteValue(DEFAULT_VALUE_NAME); 743*cdf0e10cSrcweir } 744*cdf0e10cSrcweir } 745*cdf0e10cSrcweir } 746*cdf0e10cSrcweir 747*cdf0e10cSrcweir if (m_RootKey->HasSubKey(FwdRegKeyName)) 748*cdf0e10cSrcweir m_RootKey->DeleteSubKeyTree(FwdRegKeyName); 749*cdf0e10cSrcweir } 750*cdf0e10cSrcweir 751*cdf0e10cSrcweir RegistryKey Registrar::GetRootKeyForDefHtmlEditorForIERegistration() const 752*cdf0e10cSrcweir { 753*cdf0e10cSrcweir return WindowsRegistry().GetLocalMachineKey(); 754*cdf0e10cSrcweir } 755*cdf0e10cSrcweir 756*cdf0e10cSrcweir bool Registrar::IsOpenOfficeRegisteredForMsApplication(const std::wstring& DocumentExtensionDefValue) const 757*cdf0e10cSrcweir { 758*cdf0e10cSrcweir return (std::wstring::npos != DocumentExtensionDefValue.find(FORWARD_KEY_PREFIX)); 759*cdf0e10cSrcweir } 760