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