1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include "register.hxx"
30 #include "registryexception.hxx"
31 #include "registrationcontextinformation.hxx"
32 #include "userregistrar.hxx"
33 #include "windowsregistry.hxx"
34 #include "stringconverter.hxx"
35 #include "msihelper.hxx"
38 #pragma warning(push, 1) /* disable warnings within system headers */
39 #pragma warning(disable: 4917)
49 #pragma warning(disable: 4350)
52 typedef std::auto_ptr
<Registrar
> RegistrarPtr
;
54 namespace /* private */
56 RegistrarPtr
CreateRegistrar(bool InstallForAllUser
, const RegistrationContextInformation
& RegCtx
)
60 if (InstallForAllUser
)
61 RegPtr
= RegistrarPtr(new Registrar(RegCtx
));
63 RegPtr
= RegistrarPtr(new UserRegistrar(RegCtx
));
67 } // namespace private
69 bool query_preselect_registration_for_ms_application(MSIHANDLE handle
, int Register
)
71 bool preselect
= false;
75 RegistrationContextInformation
RegContext(handle
, GetOfficeExecutablePath(handle
));
76 RegistrarPtr CurrentRegistrar
= CreateRegistrar(IsAllUserInstallation(handle
), RegContext
);
78 if (Register
& MSWORD
)
79 preselect
= CurrentRegistrar
->QueryPreselectMsWordRegistration();
80 else if (Register
& MSEXCEL
)
81 preselect
= CurrentRegistrar
->QueryPreselectMsExcelRegistration();
82 else if (Register
& MSPOWERPOINT
)
83 preselect
= CurrentRegistrar
->QueryPreselectMsPowerPointRegistration();
85 catch(RegistryException
&)
92 //-----------------------------------------
93 // registers StarOffice for MS document
94 // types and as default HTML editor if
96 //-----------------------------------------
98 void Register4MsDoc(MSIHANDLE handle
, int Register
)
102 RegistrationContextInformation
RegContext(handle
, GetOfficeExecutablePath(handle
));
103 RegistrarPtr CurrentRegistrar
= CreateRegistrar(IsAllUserInstallation(handle
), RegContext
);
105 if ((Register
& MSWORD
))
106 CurrentRegistrar
->RegisterForMsWord();
108 if ((Register
& MSEXCEL
))
109 CurrentRegistrar
->RegisterForMsExcel();
111 if ((Register
& MSPOWERPOINT
))
112 CurrentRegistrar
->RegisterForMsPowerPoint();
114 if ((Register
& HTML_EDITOR
))
115 CurrentRegistrar
->RegisterAsHtmlEditorForInternetExplorer();
117 if ((Register
& DEFAULT_SHELL_HTML_EDITOR
))
119 CurrentRegistrar
->RegisterAsDefaultHtmlEditorForInternetExplorer();
120 CurrentRegistrar
->RegisterAsDefaultShellHtmlEditor();
123 catch(RegistryException
&)
129 SHChangeNotify(SHCNE_ASSOCCHANGED
, SHCNF_IDLIST
, 0, 0);
132 void Unregister4MsDoc(MSIHANDLE handle
, int Unregister
)
136 RegistrationContextInformation
RegContext(handle
, GetOfficeExecutablePath(handle
));
137 RegistrarPtr CurrentRegistrar
= CreateRegistrar(IsAllUserInstallation(handle
), RegContext
);
139 if ((Unregister
& MSWORD
) && CurrentRegistrar
->IsRegisteredFor(MSWORD
))
140 CurrentRegistrar
->UnregisterForMsWord();
142 if ((Unregister
& HTML_EDITOR
) && CurrentRegistrar
->IsRegisteredFor(HTML_EDITOR
))
143 CurrentRegistrar
->UnregisterAsHtmlEditorForInternetExplorer();
145 if ((Unregister
& MSEXCEL
) && CurrentRegistrar
->IsRegisteredFor(MSEXCEL
))
146 CurrentRegistrar
->UnregisterForMsExcel();
148 if ((Unregister
& MSPOWERPOINT
) && CurrentRegistrar
->IsRegisteredFor(MSPOWERPOINT
))
149 CurrentRegistrar
->UnregisterForMsPowerPoint();
151 if ((Unregister
& DEFAULT_HTML_EDITOR_FOR_IE
) && CurrentRegistrar
->IsRegisteredFor(DEFAULT_HTML_EDITOR_FOR_IE
))
152 CurrentRegistrar
->UnregisterAsDefaultHtmlEditorForInternetExplorer();
154 if ((Unregister
& DEFAULT_SHELL_HTML_EDITOR
) && CurrentRegistrar
->IsRegisteredFor(DEFAULT_SHELL_HTML_EDITOR
))
155 CurrentRegistrar
->UnregisterAsDefaultShellHtmlEditor();
157 catch(RegistryException
&)
163 SHChangeNotify(SHCNE_ASSOCCHANGED
, SHCNF_IDLIST
, 0, 0);
166 //-----------------------------------------
167 // restores the entries for the selected
172 // Target key exist (e.g. '.doc')
173 // Default value == soffice.?
174 // Backup key != empty
175 // Action: Replace Default value with backup
180 // Default value == soffice.?
181 // Backup key == empty
182 // Action: delete default value
186 // Default value != soffice.?
190 // Target key does not exist
192 //-----------------------------------------
194 void Unregister4MsDocAll(MSIHANDLE handle
)
198 RegistrationContextInformation
RegContext(handle
, GetOfficeExecutablePath(handle
));
199 RegistrarPtr CurrentRegistrar
= CreateRegistrar(IsAllUserInstallation(handle
), RegContext
);
201 CurrentRegistrar
->UnregisterAllAndCleanUpRegistry();
203 catch(RegistryException
&)
209 //-----------------------------------------
210 // restores lost settings formerly made
211 // with Register4MsDoc
212 //-----------------------------------------
214 void RepairRegister4MsDocSettings(MSIHANDLE handle
)
218 RegistrationContextInformation
RegContext(handle
, GetOfficeExecutablePath(handle
));
219 RegistrarPtr CurrentRegistrar
= CreateRegistrar(IsAllUserInstallation(handle
), RegContext
);
221 CurrentRegistrar
->RepairRegistrationState();
223 catch(RegistryException
&)
229 bool IsRegisteredFor(MSIHANDLE handle
, int State
)
231 bool Registered
= false;
235 RegistrationContextInformation
RegContext(handle
, GetOfficeExecutablePath(handle
));
236 RegistrarPtr CurrentRegistrar
= CreateRegistrar(IsAllUserInstallation(handle
), RegContext
);
238 Registered
= CurrentRegistrar
->IsRegisteredFor(State
);
240 catch(RegistryException
&)
247 #define SO60_UNINSTALL_KEY L"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\StarOffice 6.0"
248 #define SO_BACKUP_KEY L"soffice6.bak"
249 #define REGMSDOCSTATE L"Reg4MsDocState"
250 #define SOFTWARE_CLASSES L"Software\\Classes"
252 int FixReturnRegistrationState(MSIHANDLE handle
)
254 int registration_state
= 0;
258 WindowsRegistry registry
;
260 RegistryValue rv_regmsdocstate
= RegistryValue(
261 new RegistryValueImpl(REGMSDOCSTATE
, 0));
263 RegistryKey so_bak_key
;
265 if (IsAllUserInstallation(handle
))
267 RegistryKey hkcr_key
= registry
.GetClassesRootKey();
269 if (hkcr_key
->HasSubKey(SO_BACKUP_KEY
))
270 so_bak_key
= hkcr_key
->OpenSubKey(SO_BACKUP_KEY
);
272 so_bak_key
= hkcr_key
->CreateSubKey(SO_BACKUP_KEY
);
274 if (!so_bak_key
->HasValue(REGMSDOCSTATE
))
276 // set a defined value
277 so_bak_key
->SetValue(rv_regmsdocstate
);
279 RegistryKey hklm_key
= registry
.GetLocalMachineKey();
281 if (hklm_key
->HasSubKey(SO60_UNINSTALL_KEY
))
283 RegistryKey so_uninst_key
=
284 hklm_key
->OpenSubKey(SO60_UNINSTALL_KEY
);
286 if (so_uninst_key
->HasValue(REGMSDOCSTATE
))
287 so_bak_key
->CopyValue(so_uninst_key
, REGMSDOCSTATE
);
293 RegistryKey hkcu_classes_key
=
294 registry
.GetCurrentUserKey()->OpenSubKey(SOFTWARE_CLASSES
);
296 so_bak_key
= hkcu_classes_key
->CreateSubKey(SO_BACKUP_KEY
);
298 if (!so_bak_key
->HasValue(REGMSDOCSTATE
))
300 // set a defined value
301 so_bak_key
->SetValue(rv_regmsdocstate
);
303 RegistryKey hklm_sftw_classes
=
304 registry
.GetLocalMachineKey()->OpenSubKey(SOFTWARE_CLASSES
, false);
306 RegistryKey so_bak_key_old
;
308 if (hklm_sftw_classes
->HasSubKey(SO_BACKUP_KEY
))
310 so_bak_key_old
= hklm_sftw_classes
->OpenSubKey(SO_BACKUP_KEY
, false);
312 if (so_bak_key_old
->HasValue(REGMSDOCSTATE
))
313 so_bak_key
->CopyValue(so_bak_key_old
, REGMSDOCSTATE
);
315 else // try the uninstall key
317 RegistryKey hklm_key
= registry
.GetLocalMachineKey();
319 if (hklm_key
->HasSubKey(SO60_UNINSTALL_KEY
))
321 RegistryKey so_uninst_key
=
322 hklm_key
->OpenSubKey(SO60_UNINSTALL_KEY
);
324 if (so_uninst_key
->HasValue(REGMSDOCSTATE
))
325 so_bak_key
->CopyValue(so_uninst_key
, REGMSDOCSTATE
);
331 rv_regmsdocstate
= so_bak_key
->GetValue(REGMSDOCSTATE
);
332 registration_state
= rv_regmsdocstate
->GetDataAsInt();
334 catch(RegistryException
&)
336 registration_state
= 0;
339 return registration_state
;
342 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */