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 ************************************************************************/
32 #define _WIN32_WINDOWS 0x0410
35 #pragma warning(push, 1) /* disable warnings within system headers */
37 #define WIN32_LEAN_AND_MEAN
49 #include <systools/win32/uwinapi.h>
51 #include <../tools/seterror.hxx>
57 string
GetMsiProperty(MSIHANDLE handle
, const string
& sProperty
)
60 TCHAR szDummy
[1] = TEXT("");
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
);
74 inline bool IsSetMsiProperty(MSIHANDLE handle
, const string
& sProperty
)
76 return (GetMsiProperty(handle
, sProperty
).length() > 0);
79 inline void UnsetMsiProperty(MSIHANDLE handle
, const string
& sProperty
)
81 MsiSetProperty(handle
, sProperty
.c_str(), NULL
);
84 inline void SetMsiProperty(MSIHANDLE handle
, const string
& sProperty
, const string
&)
86 MsiSetProperty(handle
, sProperty
.c_str(), TEXT("1"));
89 void stripFinalBackslash(std::string
* path
) {
90 std::string::size_type i
= path
->size();
93 if ((*path
)[i
] == '\\') {
100 extern "C" UINT __stdcall
CreateLayerLinks(MSIHANDLE handle
)
102 string sInstallPath
= GetMsiProperty(handle
, TEXT("INSTALLLOCATION"));
104 string sUreInstallPath
= sInstallPath
+ TEXT("URE");
106 string sUreLinkPath
= sInstallPath
+ TEXT("ure-link");
108 if ( IsSetMsiProperty(handle
, TEXT("ADMININSTALL")) )
110 sUreInstallPath
= TEXT("..\\URE");
113 stripFinalBackslash(&sUreInstallPath
);
117 HANDLE hfile
= CreateFile(
118 sUreLinkPath
.c_str(),
123 FILE_ATTRIBUTE_NORMAL
,
126 if (IsValidHandle(hfile
))
130 // Converting string into UTF-8 encoding and writing into file "ure-link"
132 int nCharsRequired
= MultiByteToWideChar( CP_ACP
, 0, sUreInstallPath
.c_str(), -1, NULL
, 0 );
133 if ( nCharsRequired
)
135 LPWSTR lpPathW
= new WCHAR
[nCharsRequired
];
136 if ( MultiByteToWideChar( CP_ACP
, 0, sUreInstallPath
.c_str(), -1, lpPathW
, nCharsRequired
) )
138 nCharsRequired
= WideCharToMultiByte( CP_UTF8
, 0, lpPathW
, -1, NULL
, 0, NULL
, NULL
);
139 if ( nCharsRequired
)
141 LPSTR lpPathUTF8
= new CHAR
[nCharsRequired
];
142 WideCharToMultiByte( CP_UTF8
, 0, lpPathW
, -1, lpPathUTF8
, nCharsRequired
, NULL
, NULL
);
144 WriteFile( hfile
, lpPathUTF8
, strlen(lpPathUTF8
) ,&dummy
, 0 );
156 return ERROR_SUCCESS
;
159 extern "C" UINT __stdcall
RemoveLayerLinks(MSIHANDLE handle
)
161 string sInstallPath
= GetMsiProperty(handle
, TEXT("INSTALLLOCATION"));
163 string sUreLinkPath
= sInstallPath
+ TEXT("ure-link");
164 string sUreDirName
= sInstallPath
+ TEXT("URE\\bin");
166 // Check, if URE is still installed
167 bool ureDirExists
= true;
168 WIN32_FIND_DATA aFindData
;
169 HANDLE hFindContent
= FindFirstFile( sUreDirName
.c_str(), &aFindData
);
170 if ( hFindContent
== INVALID_HANDLE_VALUE
) { ureDirExists
= false; }
171 FindClose( hFindContent
);
173 // Deleting link to URE layer, if URE dir no longer exists
174 if ( ! ureDirExists
)
176 DeleteFile(sUreLinkPath
.c_str());
179 return ERROR_SUCCESS
;
182 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */