1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: respintest.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
34 #define _WIN32_WINDOWS 0x0410
37 #pragma warning(push, 1) /* disable warnings within system headers */
39 #define WIN32_LEAN_AND_MEAN
51 #include <systools/win32/uwinapi.h>
53 #include <../tools/seterror.hxx>
59 string
GetMsiProperty(MSIHANDLE handle
, const string
& sProperty
)
62 TCHAR szDummy
[1] = TEXT("");
65 if (MsiGetProperty(handle
, sProperty
.c_str(), szDummy
, &nChars
) == ERROR_MORE_DATA
)
67 DWORD nBytes
= ++nChars
* sizeof(TCHAR
);
68 LPTSTR buffer
= reinterpret_cast<LPTSTR
>(_alloca(nBytes
));
69 ZeroMemory( buffer
, nBytes
);
70 MsiGetProperty(handle
, sProperty
.c_str(), buffer
, &nChars
);
76 inline bool IsSetMsiProperty(MSIHANDLE handle
, const string
& sProperty
)
78 return (GetMsiProperty(handle
, sProperty
).length() > 0);
81 inline void UnsetMsiProperty(MSIHANDLE handle
, const string
& sProperty
)
83 MsiSetProperty(handle
, sProperty
.c_str(), NULL
);
86 inline void SetMsiProperty(MSIHANDLE handle
, const string
& sProperty
, const string
&)
88 MsiSetProperty(handle
, sProperty
.c_str(), TEXT("1"));
92 extern "C" UINT __stdcall
GetUserInstallMode(MSIHANDLE handle
)
94 string sOfficeInstallPath
= GetMsiProperty(handle
, TEXT("OFFICEINSTALLLOCATION"));
96 // MessageBox(NULL, sOfficeInstallPath.c_str(), "DEBUG", MB_OK);
98 // unsetting all properties
100 UnsetMsiProperty( handle
, TEXT("INVALIDDIRECTORY") );
101 UnsetMsiProperty( handle
, TEXT("ISWRONGPRODUCT") );
102 UnsetMsiProperty( handle
, TEXT("PATCHISOLDER") );
103 UnsetMsiProperty( handle
, TEXT("ALLUSERS") );
105 // 1. Searching for "ProductCode" in setup.ini
107 string sSetupiniPath
= sOfficeInstallPath
+ TEXT("program\\setup.ini");
109 TCHAR szValue
[32767];
111 GetPrivateProfileString(
114 TEXT("INVALIDDIRECTORY"),
117 sSetupiniPath
.c_str()
120 if ( !_tcsicmp( szValue
, TEXT("INVALIDDIRECTORY") ) )
122 // No setup.ini or no "ProductCode" in setup.ini. This is an invalid directory.
123 SetMsiProperty( handle
, TEXT("INVALIDDIRECTORY"), TEXT("YES") );
124 // MessageBox(NULL, "INVALIDDIRECTORY set, no setup.ini or ProductCode in setup.ini.", "DEBUG", MB_OK);
125 SetMsiErrorCode( MSI_ERROR_INVALIDDIRECTORY
);
126 return ERROR_SUCCESS
;
129 // 2. Comparing first three characters of "PRODUCTMAJOR" from property table and "buildid" from InfoFile
133 GetPrivateProfileString(
136 TEXT("ISWRONGPRODUCT"),
139 sSetupiniPath
.c_str()
142 if ( !_tcsicmp( szValue
, TEXT("ISWRONGPRODUCT") ) )
144 SetMsiProperty( handle
, TEXT("ISWRONGPRODUCT"), TEXT("YES") );
145 // MessageBox(NULL, "ISWRONGPRODUCT 1 set after searching buildid", "DEBUG", MB_OK);
146 SetMsiErrorCode( MSI_ERROR_ISWRONGPRODUCT
);
147 return ERROR_SUCCESS
;
150 string ProductMajor
= GetMsiProperty(handle
, TEXT("PRODUCTMAJOR"));
152 // Comparing the first three characters, for example "680"
153 // If not equal, this version is not suited for patch or language pack
155 if (_tcsnicmp(ProductMajor
.c_str(), szValue
, 3))
157 SetMsiProperty( handle
, TEXT("ISWRONGPRODUCT"), TEXT("YES") );
158 // MessageBox(NULL, "ISWRONGPRODUCT 2 set after searching PRODUCTMAJOR", "DEBUG", MB_OK);
159 SetMsiErrorCode( MSI_ERROR_ISWRONGPRODUCT
);
160 return ERROR_SUCCESS
;
163 // 3. Only for patch: Comparing "PRODUCTMINOR from property table and "ProductMinor" from InfoFile
165 string isPatch
= GetMsiProperty(handle
, TEXT("ISPATCH"));
169 string ProductMinor
= GetMsiProperty(handle
, TEXT("PRODUCTBUILDID"));
170 int PatchProductMinor
= atoi(ProductMinor
.c_str());
174 GetPrivateProfileString(
176 TEXT("ProductBuildid"),
180 sSetupiniPath
.c_str()
183 int InstalledProductMinor
= atoi(szValue
);
185 if ( InstalledProductMinor
>= PatchProductMinor
)
187 SetMsiProperty( handle
, TEXT("PATCHISOLDER"), TEXT("YES") );
188 // MessageBox(NULL, "PATCHISOLDER set", "DEBUG", MB_OK);
189 SetMsiErrorCode( MSI_ERROR_PATCHISOLDER
);
190 return ERROR_SUCCESS
;
194 // 4. Setting property ALLUSERS with value from "setup.ini"
198 GetPrivateProfileString(
204 sSetupiniPath
.c_str()
209 SetMsiProperty( handle
, TEXT("ALLUSERS"), szValue
);
210 // MessageBox(NULL, "ALLUSERS set", "DEBUG", MB_OK);
213 return ERROR_SUCCESS
;