1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 25 #undef UNICODE 26 #undef _UNICODE 27 28 #define _WIN32_WINDOWS 0x0410 29 30 #ifdef _MSC_VER 31 #pragma warning(push, 1) /* disable warnings within system headers */ 32 #define WIN32_LEAN_AND_MEAN 33 #endif 34 #include <windows.h> 35 #include <msiquery.h> 36 #include <shellapi.h> 37 #ifdef _MSC_VER 38 #pragma warning(pop) 39 #endif 40 41 #include <malloc.h> 42 #include <assert.h> 43 #include <string.h> 44 45 #ifdef UNICODE 46 #define _UNICODE 47 #define _tstring wstring 48 #else 49 #define _tstring string 50 #endif 51 #include <tchar.h> 52 #include <string> 53 54 55 static std::_tstring GetMsiProperty( MSIHANDLE handle, const std::_tstring& sProperty ) 56 { 57 std::_tstring result; 58 TCHAR szDummy[1] = TEXT(""); 59 DWORD nChars = 0; 60 61 if ( MsiGetProperty( handle, sProperty.c_str(), szDummy, &nChars ) == ERROR_MORE_DATA ) 62 { 63 DWORD nBytes = ++nChars * sizeof(TCHAR); 64 LPTSTR buffer = reinterpret_cast<LPTSTR>(_alloca(nBytes)); 65 ZeroMemory( buffer, nBytes ); 66 MsiGetProperty(handle, sProperty.c_str(), buffer, &nChars); 67 result = buffer; 68 } 69 70 return result; 71 } 72 73 extern "C" UINT __stdcall copyExtensionData(MSIHANDLE handle) { 74 75 std::_tstring sSourceDir = GetMsiProperty( handle, TEXT("SourceDir") ); 76 std::_tstring sExtensionDir = sSourceDir + TEXT("extension\\"); 77 std::_tstring sPattern = sExtensionDir + TEXT("*.oxt"); 78 // std::_tstring mystr; 79 80 // Finding all oxt files in sExtensionDir 81 82 WIN32_FIND_DATA aFindFileData; 83 84 HANDLE hFindOxt = FindFirstFile( sPattern.c_str(), &aFindFileData ); 85 86 if ( hFindOxt != INVALID_HANDLE_VALUE ) 87 { 88 bool fNextFile = false; 89 bool fSuccess = true; 90 bool bFailIfExist = true; 91 92 std::_tstring sDestDir = GetMsiProperty( handle, TEXT("INSTALLLOCATION") ); 93 std::_tstring sShareInstallDir = sDestDir + TEXT("share\\extension\\install\\"); 94 95 // creating directories 96 std::_tstring sShareDir = sDestDir + TEXT("share"); 97 std::_tstring sExtDir = sShareDir + TEXT("\\extension"); 98 std::_tstring sExtInstDir = sExtDir + TEXT("\\install"); 99 bool bDir = CreateDirectory(sShareDir.c_str(), NULL); 100 bDir = CreateDirectory(sExtDir.c_str(), NULL); 101 bDir = CreateDirectory(sExtInstDir.c_str(), NULL); 102 103 do 104 { 105 std::_tstring sOxtFile = aFindFileData.cFileName; 106 107 std::_tstring sSourceFile = sExtensionDir + sOxtFile; 108 std::_tstring sDestFile = sShareInstallDir + sOxtFile; 109 110 fSuccess = CopyFile( sSourceFile.c_str(), sDestFile.c_str(), bFailIfExist ); 111 112 fNextFile = FindNextFile( hFindOxt, &aFindFileData ); 113 114 } while ( fNextFile ); 115 116 FindClose( hFindOxt ); 117 } 118 119 return ERROR_SUCCESS; 120 } 121