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