Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / setup_native / source / win32 / customactions / reg4msdoc / msihelper.cxx
blob648d4f33fdd3bfc00405d26c1f20c4c1677f99e5
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 #include "msihelper.hxx"
4 #include <malloc.h>
5 #include <assert.h>
7 bool GetMsiProp(MSIHANDLE handle, LPCTSTR name, /*out*/std::wstring& value)
9 DWORD sz = 0;
10 LPTSTR dummy = TEXT("");
11 if (MsiGetProperty(handle, name, dummy, &sz) == ERROR_MORE_DATA)
13 sz++;
14 DWORD nbytes = sz * sizeof(TCHAR);
15 LPTSTR buff = reinterpret_cast<LPTSTR>(_alloca(nbytes));
16 ZeroMemory(buff, nbytes);
17 MsiGetProperty(handle, name, buff, &sz);
18 value = buff;
19 return true;
21 return false;
24 void SetMsiProp(MSIHANDLE handle, LPCTSTR name)
26 MsiSetProperty(handle, name, TEXT("1"));
29 void UnsetMsiProp(MSIHANDLE handle, LPCTSTR name)
31 MsiSetProperty(handle, name, TEXT(""));
34 bool IsSetMsiProp(MSIHANDLE handle, LPCTSTR name)
36 std::wstring val;
37 GetMsiProp(handle, name, val);
38 return (val == TEXT("1"));
41 bool IsMsiPropNotEmpty(MSIHANDLE handle, LPCTSTR name)
43 std::wstring val;
44 GetMsiProp(handle, name, val);
45 return (val != TEXT(""));
48 bool IsAllUserInstallation(MSIHANDLE handle)
50 return IsSetMsiProp(handle, TEXT("ALLUSERS"));
53 std::wstring GetOfficeInstallationPath(MSIHANDLE handle)
55 std::wstring progpath;
56 GetMsiProp(handle, TEXT("INSTALLLOCATION"), progpath);
57 return progpath;
60 std::wstring GetOfficeExecutablePath(MSIHANDLE handle)
62 std::wstring exepath = GetOfficeInstallationPath(handle);
63 exepath += TEXT("program\\soffice.exe");
64 return exepath;
67 std::wstring GetProductName(MSIHANDLE handle)
69 std::wstring prodname;
70 GetMsiProp(handle, TEXT("ProductName"), prodname);
71 return prodname;
74 bool IsModuleInstalled(MSIHANDLE handle, LPCTSTR name)
76 INSTALLSTATE current_state;
77 INSTALLSTATE future_state;
78 MsiGetFeatureState(handle, name, &current_state, &future_state);
79 return (current_state == INSTALLSTATE_LOCAL);
82 bool IsModuleSelectedForInstallation(MSIHANDLE handle, LPCTSTR name)
84 INSTALLSTATE current_state;
85 INSTALLSTATE future_state;
86 MsiGetFeatureState(handle, name, &current_state, &future_state);
87 return (future_state == INSTALLSTATE_LOCAL);
90 bool IsModuleSelectedForDeinstallation(MSIHANDLE handle, LPCTSTR name)
92 INSTALLSTATE current_state;
93 INSTALLSTATE future_state;
94 MsiGetFeatureState(handle, name, &current_state, &future_state);
95 return ((current_state == INSTALLSTATE_LOCAL) && (future_state == INSTALLSTATE_ABSENT));
98 bool IsCompleteDeinstallation(MSIHANDLE handle)
100 std::wstring rm;
101 GetMsiProp(handle, TEXT("REMOVE"), rm);
102 return (rm == TEXT("ALL"));
105 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */