Update ooo320-m1
[ooovba.git] / setup_native / source / win32 / customactions / shellextensions / dotnetcheck.cxx
blobb5ded0ab7d5e2723917ce300c7960cae2b9586aa
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: dotnetcheck.cxx,v $
10 * $Revision: 1.2.42.1 $
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 void SetMsiProperty(MSIHANDLE handle, const string& sProperty, const string& sValue)
78 MsiSetProperty(handle, sProperty.c_str(), sValue.c_str());
81 void stripFinalBackslash(std::string * path) {
82 std::string::size_type i = path->size();
83 if (i > 1) {
84 --i;
85 if ((*path)[i] == '\\') {
86 path->erase(i);
91 // Copied more or less verbatim from
92 // desktop/source/deployment/inc/dp_version.hxx:1.5 and
93 // desktop/source/deployment/misc/dp_version.cxx:1.5:
95 enum Order { ORDER_LESS, ORDER_EQUAL, ORDER_GREATER };
97 string getElement(string const & version, string::size_type * index) {
98 while (*index < version.size() && version[*index] == '0') {
99 ++*index;
101 string::size_type i = *index;
102 *index = version.find('.', i);
103 if (*index == string::npos) {
104 *index = version.size();
105 return string(version, i);
106 } else {
107 ++*index;
108 return string(version, i, *index - 1 - i);
112 Order compareVersions(string const & version1, string const & version2) {
113 for (string::size_type i1 = 0, i2 = 0;
114 i1 < version1.size() || i2 < version2.size();)
116 string e1(getElement(version1, &i1));
117 string e2(getElement(version2, &i2));
119 // string myText1 = TEXT("e1: ") + e1;
120 // string myText2 = TEXT("e2: ") + e2;
121 // MessageBox(NULL, myText1.c_str(), "DEBUG", MB_OK);
122 // MessageBox(NULL, myText2.c_str(), "DEBUG", MB_OK);
124 if (e1.size() < e2.size()) {
125 return ORDER_LESS;
126 } else if (e1.size() > e2.size()) {
127 return ORDER_GREATER;
128 } else if (e1 < e2) {
129 return ORDER_LESS;
130 } else if (e1 > e2) {
131 return ORDER_GREATER;
134 return ORDER_EQUAL;
137 } // namespace
139 extern "C" UINT __stdcall DotNetCheck(MSIHANDLE handle) {
140 string present(GetMsiProperty(handle, TEXT("MsiNetAssemblySupport")));
141 string required(GetMsiProperty(handle, TEXT("REQUIRED_DOTNET_VERSION")));
143 // string myText1 = TEXT("MsiNetAssemblySupport: ") + present;
144 // string myText2 = TEXT("REQUIRED_DOTNET_VERSION: ") + required;
145 // MessageBox(NULL, myText1.c_str(), "DEBUG", MB_OK);
146 // MessageBox(NULL, myText2.c_str(), "DEBUG", MB_OK);
148 SetMsiProperty(
149 handle, TEXT("DOTNET_SUFFICIENT"),
150 (present.empty() || compareVersions(present, required) == ORDER_LESS ?
151 TEXT("0") : TEXT("1")));
153 // string result(GetMsiProperty(handle, TEXT("DOTNET_SUFFICIENT")));
154 // string myText3 = TEXT("DOTNET_SUFFICIENT: ") + result;
155 // MessageBox(NULL, myText3.c_str(), "DEBUG", MB_OK);
158 return ERROR_SUCCESS;
161 extern "C" UINT __stdcall ShowProperties(MSIHANDLE handle)
163 string property = GetMsiProperty(handle, TEXT("INSTALLLOCATION"));
164 string myText = TEXT("INSTALLLOCATION: ") + property;
165 MessageBox(NULL, myText.c_str(), "INSTALLLOCATION", MB_OK);
167 property = GetMsiProperty(handle, TEXT("UREINSTALLLOCATION"));
168 myText = TEXT("UREINSTALLLOCATION: ") + property;
169 MessageBox(NULL, myText.c_str(), "UREINSTALLLOCATION", MB_OK);
171 property = GetMsiProperty(handle, TEXT("BASISINSTALLLOCATION"));
172 myText = TEXT("BASISINSTALLLOCATION: ") + property;
173 MessageBox(NULL, myText.c_str(), "BASISINSTALLLOCATION", MB_OK);
175 property = GetMsiProperty(handle, TEXT("OFFICEINSTALLLOCATION"));
176 myText = TEXT("OFFICEINSTALLLOCATION: ") + property;
177 MessageBox(NULL, myText.c_str(), "OFFICEINSTALLLOCATION", MB_OK);
179 property = GetMsiProperty(handle, TEXT("Installed"));
180 myText = TEXT("Installed: ") + property;
181 MessageBox(NULL, myText.c_str(), "Installed", MB_OK);
183 property = GetMsiProperty(handle, TEXT("PATCH"));
184 myText = TEXT("PATCH: ") + property;
185 MessageBox(NULL, myText.c_str(), "PATCH", MB_OK);
187 property = GetMsiProperty(handle, TEXT("REMOVE"));
188 myText = TEXT("REMOVE: ") + property;
189 MessageBox(NULL, myText.c_str(), "REMOVE", MB_OK);
191 property = GetMsiProperty(handle, TEXT("ALLUSERS"));
192 myText = TEXT("ALLUSERS: ") + property;
193 MessageBox(NULL, myText.c_str(), "ALLUSERS", MB_OK);
195 return ERROR_SUCCESS;