Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / setup_native / source / win32 / customactions / shellextensions / dotnetcheck.cxx
blobffd6ef1a87dd3e180c18c1ac34f7f22824cbcce3
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #undef UNICODE
30 #undef _UNICODE
32 #define _WIN32_WINDOWS 0x0410
34 #ifdef _MSC_VER
35 #pragma warning(push, 1) /* disable warnings within system headers */
36 #endif
37 #define WIN32_LEAN_AND_MEAN
38 #include <windows.h>
39 #include <msiquery.h>
40 #ifdef _MSC_VER
41 #pragma warning(pop)
42 #endif
44 #include <malloc.h>
45 #include <assert.h>
47 #include <tchar.h>
48 #include <string>
49 #include <systools/win32/uwinapi.h>
51 #include <../tools/seterror.hxx>
53 using namespace std;
55 namespace
57 string GetMsiProperty(MSIHANDLE handle, const string& sProperty)
59 string result;
60 TCHAR szDummy[1] = TEXT("");
61 DWORD nChars = 0;
63 if (MsiGetProperty(handle, sProperty.c_str(), szDummy, &nChars) == ERROR_MORE_DATA)
65 DWORD nBytes = ++nChars * sizeof(TCHAR);
66 LPTSTR buffer = reinterpret_cast<LPTSTR>(_alloca(nBytes));
67 ZeroMemory( buffer, nBytes );
68 MsiGetProperty(handle, sProperty.c_str(), buffer, &nChars);
69 result = buffer;
71 return result;
74 inline void SetMsiProperty(MSIHANDLE handle, const string& sProperty, const string& sValue)
76 MsiSetProperty(handle, sProperty.c_str(), sValue.c_str());
79 void stripFinalBackslash(std::string * path) {
80 std::string::size_type i = path->size();
81 if (i > 1) {
82 --i;
83 if ((*path)[i] == '\\') {
84 path->erase(i);
89 // Copied more or less verbatim from
90 // desktop/source/deployment/inc/dp_version.hxx:1.5 and
91 // desktop/source/deployment/misc/dp_version.cxx:1.5:
93 enum Order { ORDER_LESS, ORDER_EQUAL, ORDER_GREATER };
95 string getElement(string const & version, string::size_type * index) {
96 while (*index < version.size() && version[*index] == '0') {
97 ++*index;
99 string::size_type i = *index;
100 *index = version.find('.', i);
101 if (*index == string::npos) {
102 *index = version.size();
103 return string(version, i);
104 } else {
105 ++*index;
106 return string(version, i, *index - 1 - i);
110 Order compareVersions(string const & version1, string const & version2) {
111 for (string::size_type i1 = 0, i2 = 0;
112 i1 < version1.size() || i2 < version2.size();)
114 string e1(getElement(version1, &i1));
115 string e2(getElement(version2, &i2));
117 // string myText1 = TEXT("e1: ") + e1;
118 // string myText2 = TEXT("e2: ") + e2;
119 // MessageBox(NULL, myText1.c_str(), "DEBUG", MB_OK);
120 // MessageBox(NULL, myText2.c_str(), "DEBUG", MB_OK);
122 if (e1.size() < e2.size()) {
123 return ORDER_LESS;
124 } else if (e1.size() > e2.size()) {
125 return ORDER_GREATER;
126 } else if (e1 < e2) {
127 return ORDER_LESS;
128 } else if (e1 > e2) {
129 return ORDER_GREATER;
132 return ORDER_EQUAL;
135 } // namespace
137 extern "C" UINT __stdcall DotNetCheck(MSIHANDLE handle) {
138 string present(GetMsiProperty(handle, TEXT("MsiNetAssemblySupport")));
139 string required(GetMsiProperty(handle, TEXT("REQUIRED_DOTNET_VERSION")));
141 // string myText1 = TEXT("MsiNetAssemblySupport: ") + present;
142 // string myText2 = TEXT("REQUIRED_DOTNET_VERSION: ") + required;
143 // MessageBox(NULL, myText1.c_str(), "DEBUG", MB_OK);
144 // MessageBox(NULL, myText2.c_str(), "DEBUG", MB_OK);
146 SetMsiProperty(
147 handle, TEXT("DOTNET_SUFFICIENT"),
148 (present.empty() || compareVersions(present, required) == ORDER_LESS ?
149 TEXT("0") : TEXT("1")));
151 // string result(GetMsiProperty(handle, TEXT("DOTNET_SUFFICIENT")));
152 // string myText3 = TEXT("DOTNET_SUFFICIENT: ") + result;
153 // MessageBox(NULL, myText3.c_str(), "DEBUG", MB_OK);
156 return ERROR_SUCCESS;
159 extern "C" UINT __stdcall ShowProperties(MSIHANDLE handle)
161 string property = GetMsiProperty(handle, TEXT("INSTALLLOCATION"));
162 string myText = TEXT("INSTALLLOCATION: ") + property;
163 MessageBox(NULL, myText.c_str(), "INSTALLLOCATION", MB_OK);
165 property = GetMsiProperty(handle, TEXT("Installed"));
166 myText = TEXT("Installed: ") + property;
167 MessageBox(NULL, myText.c_str(), "Installed", MB_OK);
169 property = GetMsiProperty(handle, TEXT("PATCH"));
170 myText = TEXT("PATCH: ") + property;
171 MessageBox(NULL, myText.c_str(), "PATCH", MB_OK);
173 property = GetMsiProperty(handle, TEXT("REMOVE"));
174 myText = TEXT("REMOVE: ") + property;
175 MessageBox(NULL, myText.c_str(), "REMOVE", MB_OK);
177 property = GetMsiProperty(handle, TEXT("ALLUSERS"));
178 myText = TEXT("ALLUSERS: ") + property;
179 MessageBox(NULL, myText.c_str(), "ALLUSERS", MB_OK);
181 return ERROR_SUCCESS;
184 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */