Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / setup_native / source / win32 / customactions / shellextensions / copyextensiondata.cxx
blobffa1dfe0d50b6cb471392c58c34f822bf9e3b158
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 ************************************************************************/
30 #undef UNICODE
31 #undef _UNICODE
33 #define _WIN32_WINDOWS 0x0410
35 #ifdef _MSC_VER
36 #pragma warning(push, 1) /* disable warnings within system headers */
37 #define WIN32_LEAN_AND_MEAN
38 #endif
39 #include <windows.h>
40 #include <msiquery.h>
41 #include <shellapi.h>
42 #ifdef _MSC_VER
43 #pragma warning(pop)
44 #endif
46 #include <malloc.h>
47 #include <assert.h>
48 #include <string.h>
50 #ifdef UNICODE
51 #define _UNICODE
52 #define _tstring wstring
53 #else
54 #define _tstring string
55 #endif
56 #include <tchar.h>
57 #include <string>
60 static std::_tstring GetMsiProperty( MSIHANDLE handle, const std::_tstring& sProperty )
62 std::_tstring result;
63 TCHAR szDummy[1] = TEXT("");
64 DWORD nChars = 0;
66 if ( MsiGetProperty( handle, sProperty.c_str(), szDummy, &nChars ) == ERROR_MORE_DATA )
68 DWORD nBytes = ++nChars * sizeof(TCHAR);
69 LPTSTR buffer = reinterpret_cast<LPTSTR>(_alloca(nBytes));
70 ZeroMemory( buffer, nBytes );
71 MsiGetProperty(handle, sProperty.c_str(), buffer, &nChars);
72 result = buffer;
75 return result;
78 extern "C" UINT __stdcall copyExtensionData(MSIHANDLE handle) {
80 std::_tstring sSourceDir = GetMsiProperty( handle, TEXT("SourceDir") );
81 std::_tstring sExtensionDir = sSourceDir + TEXT("extension\\");
82 std::_tstring sPattern = sExtensionDir + TEXT("*.oxt");
84 // Finding all oxt files in sExtensionDir
86 WIN32_FIND_DATA aFindFileData;
88 HANDLE hFindOxt = FindFirstFile( sPattern.c_str(), &aFindFileData );
90 if ( hFindOxt != INVALID_HANDLE_VALUE )
92 bool fNextFile = false;
93 bool bFailIfExist = true;
95 std::_tstring sDestDir = GetMsiProperty( handle, TEXT("INSTALLLOCATION") );
96 std::_tstring sShareInstallDir = sDestDir + TEXT("share\\extension\\install\\");
98 // creating directories
99 std::_tstring sShareDir = sDestDir + TEXT("share");
100 std::_tstring sExtDir = sShareDir + TEXT("\\extension");
101 std::_tstring sExtInstDir = sExtDir + TEXT("\\install");
102 CreateDirectory(sShareDir.c_str(), NULL);
103 CreateDirectory(sExtDir.c_str(), NULL);
104 CreateDirectory(sExtInstDir.c_str(), NULL);
108 std::_tstring sOxtFile = aFindFileData.cFileName;
110 std::_tstring sSourceFile = sExtensionDir + sOxtFile;
111 std::_tstring sDestFile = sShareInstallDir + sOxtFile;
113 CopyFile( sSourceFile.c_str(), sDestFile.c_str(), bFailIfExist );
115 fNextFile = FindNextFile( hFindOxt, &aFindFileData );
117 } while ( fNextFile );
119 FindClose( hFindOxt );
122 return ERROR_SUCCESS;
125 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */