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 ************************************************************************/
29 #define _WIN32_WINNT 0x0401
32 #pragma warning(push, 1) /* disable warnings within system headers */
34 #define WIN32_LEAN_AND_MEAN
46 #define _tstring wstring
48 #define _tstring string
56 #include <systools/win32/uwinapi.h>
57 #include <../tools/seterror.hxx>
59 //----------------------------------------------------------
61 inline void OutputDebugStringFormat( LPCSTR pFormat
, ... )
66 va_start( args
, pFormat
);
67 StringCchVPrintfA( buffer
, sizeof(buffer
), pFormat
, args
);
68 OutputDebugStringA( buffer
);
71 static inline void OutputDebugStringFormat( LPCSTR
, ... )
77 static std::_tstring
GetMsiProperty( MSIHANDLE handle
, const std::_tstring
& sProperty
)
80 TCHAR szDummy
[1] = TEXT("");
83 if ( MsiGetProperty( handle
, sProperty
.c_str(), szDummy
, &nChars
) == ERROR_MORE_DATA
)
85 DWORD nBytes
= ++nChars
* sizeof(TCHAR
);
86 LPTSTR buffer
= reinterpret_cast<LPTSTR
>(_alloca(nBytes
));
87 ZeroMemory( buffer
, nBytes
);
88 MsiGetProperty(handle
, sProperty
.c_str(), buffer
, &nChars
);
95 static BOOL
RemoveCompleteDirectory( std::_tstring sPath
)
97 bool bDirectoryRemoved
= true;
99 std::_tstring sPattern
= sPath
+ TEXT("\\") + TEXT("*.*");
100 WIN32_FIND_DATA aFindData
;
102 // Finding all content in sPath
104 HANDLE hFindContent
= FindFirstFile( sPattern
.c_str(), &aFindData
);
106 if ( hFindContent
!= INVALID_HANDLE_VALUE
)
108 bool fNextFile
= false;
109 std::_tstring sCurrentDir
= TEXT(".");
110 std::_tstring sParentDir
= TEXT("..");
114 std::_tstring sFileName
= aFindData
.cFileName
;
116 if (( strcmp(sFileName
.c_str(),sCurrentDir
.c_str()) != 0 ) &&
117 ( strcmp(sFileName
.c_str(),sParentDir
.c_str()) != 0 ))
119 std::_tstring sCompleteFileName
= sPath
+ TEXT("\\") + sFileName
;
121 if ( aFindData
.dwFileAttributes
== FILE_ATTRIBUTE_DIRECTORY
)
123 RemoveCompleteDirectory(sCompleteFileName
);
127 DeleteFile( sCompleteFileName
.c_str() );
131 fNextFile
= FindNextFile( hFindContent
, &aFindData
);
133 } while ( fNextFile
);
135 FindClose( hFindContent
);
137 // empty directory can be removed now
138 // RemoveDirectory is only successful, if the last handle to the directory is closed
139 // -> first removing content -> closing handle -> remove empty directory
142 if( !( RemoveDirectory(sPath
.c_str()) ) )
144 bDirectoryRemoved
= false;
148 return bDirectoryRemoved
;
153 extern "C" UINT __stdcall
RenamePrgFolder( MSIHANDLE handle
)
155 std::_tstring sOfficeInstallPath
= GetMsiProperty(handle
, TEXT("INSTALLLOCATION"));
157 std::_tstring sRenameSrc
= sOfficeInstallPath
+ TEXT("program");
158 std::_tstring sRenameDst
= sOfficeInstallPath
+ TEXT("program_old");
160 bool bSuccess
= MoveFile( sRenameSrc
.c_str(), sRenameDst
.c_str() );
163 TCHAR sAppend
[2] = TEXT("0");
164 for ( int i
= 0; i
< 10; i
++ )
166 sRenameDst
= sOfficeInstallPath
+ TEXT("program_old") + sAppend
;
167 bSuccess
= MoveFile( sRenameSrc
.c_str(), sRenameDst
.c_str() );
174 return ERROR_SUCCESS
;
177 extern "C" UINT __stdcall
RemovePrgFolder( MSIHANDLE handle
)
179 std::_tstring sOfficeInstallPath
= GetMsiProperty(handle
, TEXT("INSTALLLOCATION"));
180 std::_tstring sRemoveDir
= sOfficeInstallPath
+ TEXT("program_old");
182 RemoveCompleteDirectory( sRemoveDir
);
184 TCHAR sAppend
[2] = TEXT("0");
185 for ( int i
= 0; i
< 10; i
++ )
187 sRemoveDir
= sOfficeInstallPath
+ TEXT("program_old") + sAppend
;
188 RemoveCompleteDirectory( sRemoveDir
);
192 return ERROR_SUCCESS
;
195 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */