1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: layerlinks.cxx,v $
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 ************************************************************************/
34 #define _WIN32_WINDOWS 0x0410
37 #pragma warning(push, 1) /* disable warnings within system headers */
39 #define WIN32_LEAN_AND_MEAN
51 #include <systools/win32/uwinapi.h>
53 #include <../tools/seterror.hxx>
59 string
GetMsiProperty(MSIHANDLE handle
, const string
& sProperty
)
62 TCHAR szDummy
[1] = TEXT("");
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
);
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"));
91 void stripFinalBackslash(std::string
* path
) {
92 std::string::size_type i
= path
->size();
95 if ((*path
)[i
] == '\\') {
102 extern "C" UINT __stdcall
CreateLayerLinks(MSIHANDLE handle
)
104 string sOfficeInstallPath
= GetMsiProperty(handle
, TEXT("OFFICEINSTALLLOCATION"));
105 string sBasisInstallPath
= GetMsiProperty(handle
, TEXT("BASISINSTALLLOCATION"));
106 string sUreInstallPath
= GetMsiProperty(handle
, TEXT("UREINSTALLLOCATION"));
108 string sBasisLinkPath
= sOfficeInstallPath
+ TEXT("basis-link");
109 string sUreLinkPath
= sBasisInstallPath
+ TEXT("ure-link");
111 if ( IsSetMsiProperty(handle
, TEXT("ADMININSTALL")) )
113 sBasisInstallPath
= TEXT("Basis");
114 sUreInstallPath
= TEXT("..\\URE");
117 stripFinalBackslash(&sBasisInstallPath
);
118 stripFinalBackslash(&sUreInstallPath
);
120 // string myText1 = TEXT("Creating Basis-Link: ") + sBasisLinkPath;
121 // string myText2 = TEXT("Creating Ure-Link: ") + sUreLinkPath;
122 // MessageBox(NULL, myText1.c_str(), "DEBUG", MB_OK);
123 // MessageBox(NULL, myText2.c_str(), "DEBUG", MB_OK);
125 // creating basis-link in brand layer
127 HANDLE h1file
= CreateFile(
128 sBasisLinkPath
.c_str(),
133 FILE_ATTRIBUTE_NORMAL
,
136 if (IsValidHandle(h1file
))
140 // Converting string into UTF-8 encoding and writing into file "basis-link"
142 int nCharsRequired
= MultiByteToWideChar( CP_ACP
, 0, sBasisInstallPath
.c_str(), -1, NULL
, 0 );
143 if ( nCharsRequired
)
145 LPWSTR lpPathW
= new WCHAR
[nCharsRequired
];
146 if ( MultiByteToWideChar( CP_ACP
, 0, sBasisInstallPath
.c_str(), -1, lpPathW
, nCharsRequired
) )
148 nCharsRequired
= WideCharToMultiByte( CP_UTF8
, 0, lpPathW
, -1, NULL
, 0, NULL
, NULL
);
149 if ( nCharsRequired
)
151 LPSTR lpPathUTF8
= new CHAR
[nCharsRequired
];
152 WideCharToMultiByte( CP_UTF8
, 0, lpPathW
, -1, lpPathUTF8
, nCharsRequired
, NULL
, NULL
);
154 // WriteFile( h1file, sBasisInstallPath.c_str(), sBasisInstallPath.size() ,&dummy, 0 );
155 WriteFile( h1file
, lpPathUTF8
, strlen(lpPathUTF8
) ,&dummy
, 0 );
167 // creating ure-link in basis layer
169 HANDLE h2file
= CreateFile(
170 sUreLinkPath
.c_str(),
175 FILE_ATTRIBUTE_NORMAL
,
178 if (IsValidHandle(h2file
))
182 // Converting string into UTF-8 encoding and writing into file "basis-link"
184 int nCharsRequired
= MultiByteToWideChar( CP_ACP
, 0, sUreInstallPath
.c_str(), -1, NULL
, 0 );
185 if ( nCharsRequired
)
187 LPWSTR lpPathW
= new WCHAR
[nCharsRequired
];
188 if ( MultiByteToWideChar( CP_ACP
, 0, sUreInstallPath
.c_str(), -1, lpPathW
, nCharsRequired
) )
190 nCharsRequired
= WideCharToMultiByte( CP_UTF8
, 0, lpPathW
, -1, NULL
, 0, NULL
, NULL
);
191 if ( nCharsRequired
)
193 LPSTR lpPathUTF8
= new CHAR
[nCharsRequired
];
194 WideCharToMultiByte( CP_UTF8
, 0, lpPathW
, -1, lpPathUTF8
, nCharsRequired
, NULL
, NULL
);
196 // WriteFile( h2file, sUreInstallPath.c_str(), sUreInstallPath.size() ,&dummy, 0 );
197 WriteFile( h2file
, lpPathUTF8
, strlen(lpPathUTF8
) ,&dummy
, 0 );
209 return ERROR_SUCCESS
;
212 extern "C" UINT __stdcall
RemoveLayerLinks(MSIHANDLE handle
)
214 string sOfficeInstallPath
= GetMsiProperty(handle
, TEXT("OFFICEUNINSTALLLOCATION"));
215 string sBasisInstallPath
= GetMsiProperty(handle
, TEXT("BASISUNINSTALLLOCATION"));
216 string sUreInstallPath
= GetMsiProperty(handle
, TEXT("UREUNINSTALLLOCATION"));
218 string sBasisLinkPath
= sOfficeInstallPath
+ TEXT("basis-link");
219 string sUreLinkPath
= sBasisInstallPath
+ TEXT("ure-link");
220 string sUreDirName
= sUreInstallPath
+ TEXT("bin");
222 // string myText2 = TEXT("Deleting Ure-Link: ") + sUreLinkPath;
223 // MessageBox(NULL, myText2.c_str(), "DEBUG", MB_OK);
225 // Deleting link to basis layer
226 // string myText1 = TEXT("Deleting Basis-Link: ") + sBasisLinkPath;
227 // MessageBox(NULL, myText1.c_str(), "DEBUG", MB_OK);
228 DeleteFile(sBasisLinkPath
.c_str());
230 // Check, if URE is still installed
231 bool ureDirExists
= true;
232 WIN32_FIND_DATA aFindData
;
233 HANDLE hFindContent
= FindFirstFile( sUreDirName
.c_str(), &aFindData
);
234 if ( hFindContent
== INVALID_HANDLE_VALUE
) { ureDirExists
= false; }
235 FindClose( hFindContent
);
237 // if ( ureDirExists )
239 // string myText3 = TEXT("URE directory still exists: ") + sUreDirName;
240 // MessageBox(NULL, myText3.c_str(), "DEBUG", MB_OK);
241 // string myText4 = TEXT("URE link NOT removed: ") + sUreLinkPath;
242 // MessageBox(NULL, myText4.c_str(), "DEBUG", MB_OK);
245 // Deleting link to URE layer, if URE dir no longer exists
246 if ( ! ureDirExists
)
248 // string myText5 = TEXT("URE directory does not exist: ") + sUreDirName;
249 // MessageBox(NULL, myText5.c_str(), "DEBUG", MB_OK);
250 DeleteFile(sUreLinkPath
.c_str());
251 // string myText6 = TEXT("URE link removed: ") + sUreLinkPath;
252 // MessageBox(NULL, myText6.c_str(), "DEBUG", MB_OK);
255 return ERROR_SUCCESS
;