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