1 #include "msihelper.hxx" 2 3 #include <malloc.h> 4 #include <assert.h> 5 6 bool GetMsiProp(MSIHANDLE handle, LPCTSTR name, /*out*/std::wstring& value) 7 { 8 DWORD sz = 0; 9 LPTSTR dummy = TEXT(""); 10 if (MsiGetProperty(handle, name, dummy, &sz) == ERROR_MORE_DATA) 11 { 12 sz++; 13 DWORD nbytes = sz * sizeof(TCHAR); 14 LPTSTR buff = reinterpret_cast<LPTSTR>(_alloca(nbytes)); 15 ZeroMemory(buff, nbytes); 16 MsiGetProperty(handle, name, buff, &sz); 17 value = buff; 18 return true; 19 } 20 return false; 21 } 22 23 void SetMsiProp(MSIHANDLE handle, LPCTSTR name) 24 { 25 MsiSetProperty(handle, name, TEXT("1")); 26 } 27 28 void UnsetMsiProp(MSIHANDLE handle, LPCTSTR name) 29 { 30 MsiSetProperty(handle, name, TEXT("")); 31 } 32 33 bool IsSetMsiProp(MSIHANDLE handle, LPCTSTR name) 34 { 35 std::wstring val; 36 GetMsiProp(handle, name, val); 37 return (val == TEXT("1")); 38 } 39 40 bool IsMsiPropNotEmpty(MSIHANDLE handle, LPCTSTR name) 41 { 42 std::wstring val; 43 GetMsiProp(handle, name, val); 44 return (val != TEXT("")); 45 } 46 47 bool IsAllUserInstallation(MSIHANDLE handle) 48 { 49 return IsSetMsiProp(handle, TEXT("ALLUSERS")); 50 } 51 52 std::wstring GetOfficeInstallationPath(MSIHANDLE handle) 53 { 54 std::wstring progpath; 55 GetMsiProp(handle, TEXT("INSTALLLOCATION"), progpath); 56 return progpath; 57 } 58 59 std::wstring GetOfficeExecutablePath(MSIHANDLE handle) 60 { 61 std::wstring exepath = GetOfficeInstallationPath(handle); 62 exepath += TEXT("program\\soffice.exe"); 63 return exepath; 64 } 65 66 std::wstring GetProductName(MSIHANDLE handle) 67 { 68 std::wstring prodname; 69 GetMsiProp(handle, TEXT("ProductName"), prodname); 70 return prodname; 71 } 72 73 bool IsModuleInstalled(MSIHANDLE handle, LPCTSTR name) 74 { 75 INSTALLSTATE current_state; 76 INSTALLSTATE future_state; 77 MsiGetFeatureState(handle, name, ¤t_state, &future_state); 78 return (current_state == INSTALLSTATE_LOCAL); 79 } 80 81 bool IsModuleSelectedForInstallation(MSIHANDLE handle, LPCTSTR name) 82 { 83 INSTALLSTATE current_state; 84 INSTALLSTATE future_state; 85 MsiGetFeatureState(handle, name, ¤t_state, &future_state); 86 return (future_state == INSTALLSTATE_LOCAL); 87 } 88 89 bool IsModuleSelectedForDeinstallation(MSIHANDLE handle, LPCTSTR name) 90 { 91 INSTALLSTATE current_state; 92 INSTALLSTATE future_state; 93 MsiGetFeatureState(handle, name, ¤t_state, &future_state); 94 return ((current_state == INSTALLSTATE_LOCAL) && (future_state == INSTALLSTATE_ABSENT)); 95 } 96 97 bool IsCompleteDeinstallation(MSIHANDLE handle) 98 { 99 std::wstring rm; 100 GetMsiProp(handle, TEXT("REMOVE"), rm); 101 return (rm == TEXT("ALL")); 102 } 103