1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifdef _MSC_VER
29 #pragma warning(push, 1) /* disable warnings within system headers */
30 #endif
31 #define WIN32_LEAN_AND_MEAN
32 #include <windows.h>
33 #include <msiquery.h>
34 #ifdef _MSC_VER
35 #pragma warning(pop)
36 #endif
37 
38 #include <tchar.h>
39 #include "register.hxx"
40 #include "msihelper.hxx"
41 
42 #include <memory>
43 #include <string>
44 
45 #define ELEMENTS_OF_ARRAY(a) (sizeof(a)/sizeof(a[0]))
46 
47 void DetermineWordPreselectionState(MSIHANDLE handle)
48 {
49     if (query_preselect_registration_for_ms_application(handle, MSWORD))
50         SetMsiProp(handle, TEXT("SELECT_WORD"));
51 }
52 
53 void DetermineExcelPreselectionState(MSIHANDLE handle)
54 {
55     if (query_preselect_registration_for_ms_application(handle, MSEXCEL))
56         SetMsiProp(handle, TEXT("SELECT_EXCEL"));
57 }
58 
59 void DeterminePowerPointPreselectionState(MSIHANDLE handle)
60 {
61     if (query_preselect_registration_for_ms_application(handle, MSPOWERPOINT))
62         SetMsiProp(handle, TEXT("SELECT_POWERPOINT"));
63 }
64 
65 extern "C" UINT __stdcall InstallUiSequenceEntry(MSIHANDLE handle)
66 {
67     //MessageBox(NULL, TEXT("InstallUiSequenceEntry"), TEXT("Information"), MB_OK | MB_ICONINFORMATION);
68 
69     if (IsModuleSelectedForInstallation(handle, TEXT("gm_p_Wrt_Bin")))
70     {
71         DetermineWordPreselectionState(handle);
72     }
73     else if (IsModuleInstalled(handle, TEXT("gm_p_Wrt_Bin")) &&
74              !IsModuleSelectedForDeinstallation(handle, TEXT("gm_p_Wrt_Bin")) &&
75              IsRegisteredFor(handle, MSWORD))
76     {
77         SetMsiProp(handle, TEXT("SELECT_WORD"));
78     }
79     else
80     {
81         UnsetMsiProp(handle, TEXT("SELECT_WORD"));
82     }
83 
84     if (IsModuleSelectedForInstallation(handle, TEXT("gm_p_Calc_Bin")))
85     {
86         DetermineExcelPreselectionState(handle);
87     }
88     else if (IsModuleInstalled(handle, TEXT("gm_p_Calc_Bin")) &&
89              !IsModuleSelectedForDeinstallation(handle, TEXT("gm_p_Calc_Bin")) &&
90              IsRegisteredFor(handle, MSEXCEL))
91     {
92         SetMsiProp(handle, TEXT("SELECT_EXCEL"));
93     }
94     else
95     {
96         UnsetMsiProp(handle, TEXT("SELECT_EXCEL"));
97     }
98 
99     if (IsModuleSelectedForInstallation(handle, TEXT("gm_p_Impress_Bin")))
100     {
101         DeterminePowerPointPreselectionState(handle);
102     }
103     else if (IsModuleInstalled(handle, TEXT("gm_p_Impress_Bin")) &&
104             !IsModuleSelectedForDeinstallation(handle, TEXT("gm_p_Impress_Bin")) &&
105             IsRegisteredFor(handle, MSPOWERPOINT))
106     {
107         SetMsiProp(handle, TEXT("SELECT_POWERPOINT"));
108     }
109     else
110     {
111         UnsetMsiProp(handle, TEXT("SELECT_POWERPOINT"));
112     }
113 
114     SetMsiProp(handle, TEXT("UI_SEQUENCE_EXECUTED"));
115 
116 	return ERROR_SUCCESS;
117 }
118 
119 extern "C" UINT __stdcall InstallExecSequenceEntry(MSIHANDLE handle)
120 {
121     //MessageBox(NULL, TEXT("InstallExecSequenceEntry"), TEXT("Information"), MB_OK | MB_ICONINFORMATION);
122 
123     // Do nothing in repair mode.
124     // Then UI_SEQUENCE_EXECUTED is not set and Installed is set!
125     // In silent installation UI_SEQUENCE_EXECUTED is also not set, but Installed is not set.
126     if ((!IsSetMsiProp(handle, TEXT("UI_SEQUENCE_EXECUTED"))) && (IsMsiPropNotEmpty(handle, TEXT("Installed")))) { return ERROR_SUCCESS; }
127 
128     int reg4 = 0;
129     int unreg4 = 0;
130 
131     // we always register as html editor for Internet Explorer
132     // if writer is installed because there's no harm if we do so
133 	if (IsModuleSelectedForInstallation(handle, TEXT("gm_p_Wrt_Bin")))
134 		reg4 |= HTML_EDITOR;
135 
136     if (IsSetMsiProp(handle, TEXT("SELECT_WORD")) && !IsRegisteredFor(handle, MSWORD))
137         reg4 |= MSWORD;
138     else if (!IsSetMsiProp(handle, TEXT("SELECT_WORD")) && IsRegisteredFor(handle, MSWORD))
139         unreg4 |= MSWORD;
140 
141     if (IsSetMsiProp(handle, TEXT("SELECT_EXCEL")) && !IsRegisteredFor(handle, MSEXCEL))
142         reg4 |= MSEXCEL;
143     else if (!IsSetMsiProp(handle, TEXT("SELECT_EXCEL")) && IsRegisteredFor(handle, MSEXCEL))
144         unreg4 |= MSEXCEL;
145 
146     if (IsSetMsiProp(handle, TEXT("SELECT_POWERPOINT")) && !IsRegisteredFor(handle, MSPOWERPOINT))
147         reg4 |= MSPOWERPOINT;
148     else if (!IsSetMsiProp(handle, TEXT("SELECT_POWERPOINT")) && IsRegisteredFor(handle, MSPOWERPOINT))
149         unreg4 |= MSPOWERPOINT;
150 
151     if (reg4)
152     {
153 	    Register4MsDoc(handle, reg4);
154     }
155 
156     if (unreg4)
157     {
158         Unregister4MsDoc(handle, unreg4);
159     }
160     return ERROR_SUCCESS;
161 }
162 
163 extern "C" UINT __stdcall DeinstallExecSequenceEntry(MSIHANDLE handle)
164 {
165     //MessageBox(NULL, TEXT("DeinstallExecSequenceEntry"), TEXT("Information"), MB_OK | MB_ICONINFORMATION);
166 
167     if (IsCompleteDeinstallation(handle))
168     {
169         Unregister4MsDocAll(handle);
170         return ERROR_SUCCESS;
171     }
172 
173     if (IsModuleSelectedForDeinstallation(handle, TEXT("gm_p_Wrt_Bin")))
174     {
175         Unregister4MsDoc(handle, MSWORD | HTML_EDITOR);
176     }
177 
178     if (IsModuleSelectedForDeinstallation(handle, TEXT("gm_p_Calc_Bin")))
179     {
180         Unregister4MsDoc(handle, MSEXCEL);
181     }
182 
183     if (IsModuleSelectedForDeinstallation(handle, TEXT("gm_p_Impress_Bin")))
184     {
185         Unregister4MsDoc(handle, MSPOWERPOINT);
186     }
187 
188     return ERROR_SUCCESS;
189 }
190