1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #ifdef _MSC_VER 25 #pragma warning(push, 1) /* disable warnings within system headers */ 26 #endif 27 #define WIN32_LEAN_AND_MEAN 28 #include <windows.h> 29 #include <msiquery.h> 30 #ifdef _MSC_VER 31 #pragma warning(pop) 32 #endif 33 34 #include <tchar.h> 35 #include "register.hxx" 36 #include "msihelper.hxx" 37 38 #include <memory> 39 #include <string> 40 41 #define ELEMENTS_OF_ARRAY(a) (sizeof(a)/sizeof(a[0])) 42 43 void DetermineWordPreselectionState(MSIHANDLE handle) 44 { 45 if (query_preselect_registration_for_ms_application(handle, MSWORD)) 46 SetMsiProp(handle, TEXT("SELECT_WORD")); 47 } 48 49 void DetermineExcelPreselectionState(MSIHANDLE handle) 50 { 51 if (query_preselect_registration_for_ms_application(handle, MSEXCEL)) 52 SetMsiProp(handle, TEXT("SELECT_EXCEL")); 53 } 54 55 void DeterminePowerPointPreselectionState(MSIHANDLE handle) 56 { 57 if (query_preselect_registration_for_ms_application(handle, MSPOWERPOINT)) 58 SetMsiProp(handle, TEXT("SELECT_POWERPOINT")); 59 } 60 61 extern "C" UINT __stdcall InstallUiSequenceEntry(MSIHANDLE handle) 62 { 63 //MessageBox(NULL, TEXT("InstallUiSequenceEntry"), TEXT("Information"), MB_OK | MB_ICONINFORMATION); 64 65 if (IsModuleSelectedForInstallation(handle, TEXT("gm_p_Wrt_Bin"))) 66 { 67 DetermineWordPreselectionState(handle); 68 } 69 else if (IsModuleInstalled(handle, TEXT("gm_p_Wrt_Bin")) && 70 !IsModuleSelectedForDeinstallation(handle, TEXT("gm_p_Wrt_Bin")) && 71 IsRegisteredFor(handle, MSWORD)) 72 { 73 SetMsiProp(handle, TEXT("SELECT_WORD")); 74 } 75 else 76 { 77 UnsetMsiProp(handle, TEXT("SELECT_WORD")); 78 } 79 80 if (IsModuleSelectedForInstallation(handle, TEXT("gm_p_Calc_Bin"))) 81 { 82 DetermineExcelPreselectionState(handle); 83 } 84 else if (IsModuleInstalled(handle, TEXT("gm_p_Calc_Bin")) && 85 !IsModuleSelectedForDeinstallation(handle, TEXT("gm_p_Calc_Bin")) && 86 IsRegisteredFor(handle, MSEXCEL)) 87 { 88 SetMsiProp(handle, TEXT("SELECT_EXCEL")); 89 } 90 else 91 { 92 UnsetMsiProp(handle, TEXT("SELECT_EXCEL")); 93 } 94 95 if (IsModuleSelectedForInstallation(handle, TEXT("gm_p_Impress_Bin"))) 96 { 97 DeterminePowerPointPreselectionState(handle); 98 } 99 else if (IsModuleInstalled(handle, TEXT("gm_p_Impress_Bin")) && 100 !IsModuleSelectedForDeinstallation(handle, TEXT("gm_p_Impress_Bin")) && 101 IsRegisteredFor(handle, MSPOWERPOINT)) 102 { 103 SetMsiProp(handle, TEXT("SELECT_POWERPOINT")); 104 } 105 else 106 { 107 UnsetMsiProp(handle, TEXT("SELECT_POWERPOINT")); 108 } 109 110 SetMsiProp(handle, TEXT("UI_SEQUENCE_EXECUTED")); 111 112 return ERROR_SUCCESS; 113 } 114 115 extern "C" UINT __stdcall InstallExecSequenceEntry(MSIHANDLE handle) 116 { 117 //MessageBox(NULL, TEXT("InstallExecSequenceEntry"), TEXT("Information"), MB_OK | MB_ICONINFORMATION); 118 119 // Do nothing in repair mode. 120 // Then UI_SEQUENCE_EXECUTED is not set and Installed is set! 121 // In silent installation UI_SEQUENCE_EXECUTED is also not set, but Installed is not set. 122 if ((!IsSetMsiProp(handle, TEXT("UI_SEQUENCE_EXECUTED"))) && (IsMsiPropNotEmpty(handle, TEXT("Installed")))) { return ERROR_SUCCESS; } 123 124 int reg4 = 0; 125 int unreg4 = 0; 126 127 // we always register as html editor for Internet Explorer 128 // if writer is installed because there's no harm if we do so 129 if (IsModuleSelectedForInstallation(handle, TEXT("gm_p_Wrt_Bin"))) 130 reg4 |= HTML_EDITOR; 131 132 if (IsSetMsiProp(handle, TEXT("SELECT_WORD")) && !IsRegisteredFor(handle, MSWORD)) 133 reg4 |= MSWORD; 134 else if (!IsSetMsiProp(handle, TEXT("SELECT_WORD")) && IsRegisteredFor(handle, MSWORD)) 135 unreg4 |= MSWORD; 136 137 if (IsSetMsiProp(handle, TEXT("SELECT_EXCEL")) && !IsRegisteredFor(handle, MSEXCEL)) 138 reg4 |= MSEXCEL; 139 else if (!IsSetMsiProp(handle, TEXT("SELECT_EXCEL")) && IsRegisteredFor(handle, MSEXCEL)) 140 unreg4 |= MSEXCEL; 141 142 if (IsSetMsiProp(handle, TEXT("SELECT_POWERPOINT")) && !IsRegisteredFor(handle, MSPOWERPOINT)) 143 reg4 |= MSPOWERPOINT; 144 else if (!IsSetMsiProp(handle, TEXT("SELECT_POWERPOINT")) && IsRegisteredFor(handle, MSPOWERPOINT)) 145 unreg4 |= MSPOWERPOINT; 146 147 if (reg4) 148 { 149 Register4MsDoc(handle, reg4); 150 } 151 152 if (unreg4) 153 { 154 Unregister4MsDoc(handle, unreg4); 155 } 156 return ERROR_SUCCESS; 157 } 158 159 extern "C" UINT __stdcall DeinstallExecSequenceEntry(MSIHANDLE handle) 160 { 161 //MessageBox(NULL, TEXT("DeinstallExecSequenceEntry"), TEXT("Information"), MB_OK | MB_ICONINFORMATION); 162 163 if (IsCompleteDeinstallation(handle)) 164 { 165 Unregister4MsDocAll(handle); 166 return ERROR_SUCCESS; 167 } 168 169 if (IsModuleSelectedForDeinstallation(handle, TEXT("gm_p_Wrt_Bin"))) 170 { 171 Unregister4MsDoc(handle, MSWORD | HTML_EDITOR); 172 } 173 174 if (IsModuleSelectedForDeinstallation(handle, TEXT("gm_p_Calc_Bin"))) 175 { 176 Unregister4MsDoc(handle, MSEXCEL); 177 } 178 179 if (IsModuleSelectedForDeinstallation(handle, TEXT("gm_p_Impress_Bin"))) 180 { 181 Unregister4MsDoc(handle, MSPOWERPOINT); 182 } 183 184 return ERROR_SUCCESS; 185 } 186