Update ooo320-m1
[ooovba.git] / setup_native / source / win32 / customactions / shellextensions / copyextensiondata.cxx
bloba7560f5ba5edab4bcd3b92d340fac977c37cf7e3
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: copyeditiondata.cxx,v $
10 * $Revision: 1.2 $
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 ************************************************************************/
32 #undef UNICODE
33 #undef _UNICODE
35 #define _WIN32_WINDOWS 0x0410
37 #ifdef _MSC_VER
38 #pragma warning(push, 1) /* disable warnings within system headers */
39 #define WIN32_LEAN_AND_MEAN
40 #endif
41 #include <windows.h>
42 #include <msiquery.h>
43 #include <shellapi.h>
44 #ifdef _MSC_VER
45 #pragma warning(pop)
46 #endif
48 #include <malloc.h>
49 #include <assert.h>
50 #include <string.h>
52 #ifdef UNICODE
53 #define _UNICODE
54 #define _tstring wstring
55 #else
56 #define _tstring string
57 #endif
58 #include <tchar.h>
59 #include <string>
62 static std::_tstring GetMsiProperty( MSIHANDLE handle, const std::_tstring& sProperty )
64 std::_tstring result;
65 TCHAR szDummy[1] = TEXT("");
66 DWORD nChars = 0;
68 if ( MsiGetProperty( handle, sProperty.c_str(), szDummy, &nChars ) == ERROR_MORE_DATA )
70 DWORD nBytes = ++nChars * sizeof(TCHAR);
71 LPTSTR buffer = reinterpret_cast<LPTSTR>(_alloca(nBytes));
72 ZeroMemory( buffer, nBytes );
73 MsiGetProperty(handle, sProperty.c_str(), buffer, &nChars);
74 result = buffer;
77 return result;
80 extern "C" UINT __stdcall copyExtensionData(MSIHANDLE handle) {
82 std::_tstring sSourceDir = GetMsiProperty( handle, TEXT("SourceDir") );
83 std::_tstring sExtensionDir = sSourceDir + TEXT("extension\\");
84 std::_tstring sPattern = sExtensionDir + TEXT("*.oxt");
85 // std::_tstring mystr;
87 // Finding all oxt files in sExtensionDir
89 WIN32_FIND_DATA aFindFileData;
91 HANDLE hFindOxt = FindFirstFile( sPattern.c_str(), &aFindFileData );
93 if ( hFindOxt != INVALID_HANDLE_VALUE )
95 bool fNextFile = false;
96 bool fSuccess = true;
97 bool bFailIfExist = true;
99 std::_tstring sDestDir = GetMsiProperty( handle, TEXT("OFFICEINSTALLLOCATION") );
100 std::_tstring sShareInstallDir = sDestDir + TEXT("share\\extension\\install\\");
102 // creating directories
103 std::_tstring sShareDir = sDestDir + TEXT("share");
104 std::_tstring sExtDir = sShareDir + TEXT("\\extension");
105 std::_tstring sExtInstDir = sExtDir + TEXT("\\install");
106 bool bDir = CreateDirectory(sShareDir.c_str(), NULL);
107 bDir = CreateDirectory(sExtDir.c_str(), NULL);
108 bDir = CreateDirectory(sExtInstDir.c_str(), NULL);
112 std::_tstring sOxtFile = aFindFileData.cFileName;
114 std::_tstring sSourceFile = sExtensionDir + sOxtFile;
115 std::_tstring sDestFile = sShareInstallDir + sOxtFile;
117 fSuccess = CopyFile( sSourceFile.c_str(), sDestFile.c_str(), bFailIfExist );
119 fNextFile = FindNextFile( hFindOxt, &aFindFileData );
121 } while ( fNextFile );
123 FindClose( hFindOxt );
126 return ERROR_SUCCESS;