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 #include "msihelper.hxx" 25 26 #include <malloc.h> 27 #include <assert.h> 28 29 bool GetMsiProp(MSIHANDLE handle, LPCTSTR name, /*out*/std::wstring& value) 30 { 31 DWORD sz = 0; 32 LPTSTR dummy = TEXT(""); 33 if (MsiGetProperty(handle, name, dummy, &sz) == ERROR_MORE_DATA) 34 { 35 sz++; 36 DWORD nbytes = sz * sizeof(TCHAR); 37 LPTSTR buff = reinterpret_cast<LPTSTR>(_alloca(nbytes)); 38 ZeroMemory(buff, nbytes); 39 MsiGetProperty(handle, name, buff, &sz); 40 value = buff; 41 return true; 42 } 43 return false; 44 } 45 46 void SetMsiProp(MSIHANDLE handle, LPCTSTR name) 47 { 48 MsiSetProperty(handle, name, TEXT("1")); 49 } 50 51 void UnsetMsiProp(MSIHANDLE handle, LPCTSTR name) 52 { 53 MsiSetProperty(handle, name, TEXT("")); 54 } 55 56 bool IsSetMsiProp(MSIHANDLE handle, LPCTSTR name) 57 { 58 std::wstring val; 59 GetMsiProp(handle, name, val); 60 return (val == TEXT("1")); 61 } 62 63 bool IsMsiPropNotEmpty(MSIHANDLE handle, LPCTSTR name) 64 { 65 std::wstring val; 66 GetMsiProp(handle, name, val); 67 return (val != TEXT("")); 68 } 69 70 bool IsAllUserInstallation(MSIHANDLE handle) 71 { 72 return IsSetMsiProp(handle, TEXT("ALLUSERS")); 73 } 74 75 std::wstring GetOfficeInstallationPath(MSIHANDLE handle) 76 { 77 std::wstring progpath; 78 GetMsiProp(handle, TEXT("INSTALLLOCATION"), progpath); 79 return progpath; 80 } 81 82 std::wstring GetOfficeExecutablePath(MSIHANDLE handle) 83 { 84 std::wstring exepath = GetOfficeInstallationPath(handle); 85 exepath += TEXT("program\\soffice.exe"); 86 return exepath; 87 } 88 89 std::wstring GetProductName(MSIHANDLE handle) 90 { 91 std::wstring prodname; 92 GetMsiProp(handle, TEXT("ProductName"), prodname); 93 return prodname; 94 } 95 96 bool IsModuleInstalled(MSIHANDLE handle, LPCTSTR name) 97 { 98 INSTALLSTATE current_state; 99 INSTALLSTATE future_state; 100 MsiGetFeatureState(handle, name, ¤t_state, &future_state); 101 return (current_state == INSTALLSTATE_LOCAL); 102 } 103 104 bool IsModuleSelectedForInstallation(MSIHANDLE handle, LPCTSTR name) 105 { 106 INSTALLSTATE current_state; 107 INSTALLSTATE future_state; 108 MsiGetFeatureState(handle, name, ¤t_state, &future_state); 109 return (future_state == INSTALLSTATE_LOCAL); 110 } 111 112 bool IsModuleSelectedForDeinstallation(MSIHANDLE handle, LPCTSTR name) 113 { 114 INSTALLSTATE current_state; 115 INSTALLSTATE future_state; 116 MsiGetFeatureState(handle, name, ¤t_state, &future_state); 117 return ((current_state == INSTALLSTATE_LOCAL) && (future_state == INSTALLSTATE_ABSENT)); 118 } 119 120 bool IsCompleteDeinstallation(MSIHANDLE handle) 121 { 122 std::wstring rm; 123 GetMsiProp(handle, TEXT("REMOVE"), rm); 124 return (rm == TEXT("ALL")); 125 } 126