Update ooo320-m1
[ooovba.git] / setup_native / source / win32 / customactions / reg4msdoc / msihelper.cxx
blob83c56f85aaa0d6711c64411c6b9db6309975a62b
1 #include "msihelper.hxx"
3 #include <malloc.h>
4 #include <assert.h>
6 bool GetMsiProp(MSIHANDLE handle, LPCTSTR name, /*out*/std::wstring& value)
8 DWORD sz = 0;
9 LPTSTR dummy = TEXT("");
10 if (MsiGetProperty(handle, name, dummy, &sz) == ERROR_MORE_DATA)
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;
20 return false;
23 void SetMsiProp(MSIHANDLE handle, LPCTSTR name)
25 MsiSetProperty(handle, name, TEXT("1"));
28 void UnsetMsiProp(MSIHANDLE handle, LPCTSTR name)
30 MsiSetProperty(handle, name, TEXT(""));
33 bool IsSetMsiProp(MSIHANDLE handle, LPCTSTR name)
35 std::wstring val;
36 GetMsiProp(handle, name, val);
37 return (val == TEXT("1"));
40 bool IsMsiPropNotEmpty(MSIHANDLE handle, LPCTSTR name)
42 std::wstring val;
43 GetMsiProp(handle, name, val);
44 return (val != TEXT(""));
47 bool IsAllUserInstallation(MSIHANDLE handle)
49 return IsSetMsiProp(handle, TEXT("ALLUSERS"));
52 std::wstring GetOfficeInstallationPath(MSIHANDLE handle)
54 std::wstring progpath;
55 GetMsiProp(handle, TEXT("OFFICEINSTALLLOCATION"), progpath);
56 return progpath;
59 std::wstring GetOfficeExecutablePath(MSIHANDLE handle)
61 std::wstring exepath = GetOfficeInstallationPath(handle);
62 exepath += TEXT("program\\soffice.exe");
63 return exepath;
66 std::wstring GetProductName(MSIHANDLE handle)
68 std::wstring prodname;
69 GetMsiProp(handle, TEXT("ProductName"), prodname);
70 return prodname;
73 bool IsModuleInstalled(MSIHANDLE handle, LPCTSTR name)
75 INSTALLSTATE current_state;
76 INSTALLSTATE future_state;
77 MsiGetFeatureState(handle, name, &current_state, &future_state);
78 return (current_state == INSTALLSTATE_LOCAL);
81 bool IsModuleSelectedForInstallation(MSIHANDLE handle, LPCTSTR name)
83 INSTALLSTATE current_state;
84 INSTALLSTATE future_state;
85 MsiGetFeatureState(handle, name, &current_state, &future_state);
86 return (future_state == INSTALLSTATE_LOCAL);
89 bool IsModuleSelectedForDeinstallation(MSIHANDLE handle, LPCTSTR name)
91 INSTALLSTATE current_state;
92 INSTALLSTATE future_state;
93 MsiGetFeatureState(handle, name, &current_state, &future_state);
94 return ((current_state == INSTALLSTATE_LOCAL) && (future_state == INSTALLSTATE_ABSENT));
97 bool IsCompleteDeinstallation(MSIHANDLE handle)
99 std::wstring rm;
100 GetMsiProp(handle, TEXT("REMOVE"), rm);
101 return (rm == TEXT("ALL"));