Update ooo320-m1
[ooovba.git] / setup_native / source / win32 / customactions / languagepacks / respintest.cxx
blob9cf492fa6f0393f39166cc0f359c3129871ebb7a
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: respintest.cxx,v $
10 * $Revision: 1.14 $
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 ************************************************************************/
31 #undef UNICODE
32 #undef _UNICODE
34 #define _WIN32_WINDOWS 0x0410
36 #ifdef _MSC_VER
37 #pragma warning(push, 1) /* disable warnings within system headers */
38 #endif
39 #define WIN32_LEAN_AND_MEAN
40 #include <windows.h>
41 #include <msiquery.h>
42 #ifdef _MSC_VER
43 #pragma warning(pop)
44 #endif
46 #include <malloc.h>
47 #include <assert.h>
49 #include <tchar.h>
50 #include <string>
51 #include <systools/win32/uwinapi.h>
53 #include <../tools/seterror.hxx>
55 using namespace std;
57 namespace
59 string GetMsiProperty(MSIHANDLE handle, const string& sProperty)
61 string result;
62 TCHAR szDummy[1] = TEXT("");
63 DWORD nChars = 0;
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);
71 result = buffer;
73 return result;
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"));
90 } // namespace
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(
112 TEXT("Bootstrap"),
113 TEXT("ProductCode"),
114 TEXT("INVALIDDIRECTORY"),
115 szValue,
116 elementsof(szValue),
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
131 szValue[0] = '\0';
133 GetPrivateProfileString(
134 TEXT("Bootstrap"),
135 TEXT("buildid"),
136 TEXT("ISWRONGPRODUCT"),
137 szValue,
138 elementsof(szValue),
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"));
167 if (isPatch=="1")
169 string ProductMinor = GetMsiProperty(handle, TEXT("PRODUCTBUILDID"));
170 int PatchProductMinor = atoi(ProductMinor.c_str());
172 szValue[0] = '\0';
174 GetPrivateProfileString(
175 TEXT("Bootstrap"),
176 TEXT("ProductBuildid"),
177 TEXT("8918"),
178 szValue,
179 elementsof(szValue),
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"
196 szValue[0] = '\0';
198 GetPrivateProfileString(
199 TEXT("Bootstrap"),
200 TEXT("ALLUSERS"),
201 TEXT(""),
202 szValue,
203 elementsof(szValue),
204 sSetupiniPath.c_str()
207 if ( szValue[0] )
209 SetMsiProperty( handle, TEXT("ALLUSERS"), szValue );
210 // MessageBox(NULL, "ALLUSERS set", "DEBUG", MB_OK);
213 return ERROR_SUCCESS;