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 #include "sal/config.h"
33 #include <string.h> // <cstring> not supported by old MSC versions
35 #define WIN32_LEAN_AND_MEAN
37 #pragma warning(push, 1)
46 #include "boost/scoped_array.hpp"
48 #define LCL_LENGTH0(s) (sizeof (s) / sizeof *(s))
49 #define LCL_STRING0(s) (s), LCL_LENGTH0(s)
53 enum Status
{ STATUS_NO
, STATUS_YES
, STATUS_ERROR
};
55 Status
fileExists(wchar_t const * path
) {
56 return GetFileAttributesW(path
) == INVALID_FILE_ATTRIBUTES
57 ? GetLastError() == ERROR_FILE_NOT_FOUND
? STATUS_NO
: STATUS_ERROR
61 wchar_t * getProperty(
62 MSIHANDLE install
, wchar_t const * name
, wchar_t const * suffix
,
63 std::size_t suffixLength
, wchar_t ** end
= NULL
)
66 UINT err
= MsiGetPropertyW(install
, name
, L
"", &n
);
67 if (err
!= ERROR_SUCCESS
&& err
!= ERROR_MORE_DATA
) {
70 DWORD n2
= n
+ suffixLength
; //TODO: overflow
71 wchar_t * data
= new(std::nothrow
) wchar_t[n2
];
75 if (MsiGetPropertyW(install
, name
, data
, &n2
) != ERROR_SUCCESS
|| n2
!= n
) {
79 memcpy(data
+ n
, suffix
, suffixLength
* sizeof (wchar_t)); //TODO: overflow
81 *end
= data
+ n
+ suffixLength
;
88 extern "C" UINT __stdcall
copyEditionData(MSIHANDLE install
) {
89 boost::scoped_array
<wchar_t> from(
90 getProperty(install
, L
"SourceDir", LCL_STRING0(L
"edition\0")));
92 return ERROR_INSTALL_FAILURE
;
94 Status stat
= fileExists(from
.get());
95 if (stat
== STATUS_ERROR
) {
96 return ERROR_INSTALL_FAILURE
;
98 if (stat
== STATUS_NO
) {
102 boost::scoped_array
<wchar_t> to(
104 install
, L
"INSTALLLOCATION",
105 LCL_STRING0(L
"program\\edition\0"), &end
));
107 return ERROR_INSTALL_FAILURE
;
109 stat
= fileExists(to
.get());
110 if (stat
== STATUS_ERROR
) {
111 return ERROR_INSTALL_FAILURE
;
113 if (stat
== STATUS_YES
) {
114 SHFILEOPSTRUCTW opDelete
= {
115 NULL
, FO_DELETE
, to
.get(), NULL
, FOF_NOCONFIRMATION
| FOF_SILENT
,
116 FALSE
, NULL
, NULL
}; //TODO: non-NULL hwnd
117 if (SHFileOperationW(&opDelete
) != 0) {
118 return ERROR_INSTALL_FAILURE
;
121 *(end
- LCL_LENGTH0(L
"\\edition\0")) = L
'\0';
122 *(end
- LCL_LENGTH0(L
"\\edition\0") + 1) = L
'\0';
123 SHFILEOPSTRUCTW opCopy
= {
124 NULL
, FO_COPY
, from
.get(), to
.get(),
125 FOF_NOCONFIRMATION
| FOF_NOCONFIRMMKDIR
| FOF_SILENT
, FALSE
, NULL
,
126 NULL
}; //TODO: non-NULL hwnd
127 if (SHFileOperationW(&opCopy
) != 0) {
128 return ERROR_INSTALL_FAILURE
;
130 return ERROR_SUCCESS
;
133 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */