1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "shlxtmsi.hxx"
24 #include <systools/win32/uwinapi.h>
25 #include "../tools/seterror.hxx"
27 static BOOL
RemoveCompleteDirectoryW(const std::wstring
& rPath
)
29 bool bDirectoryRemoved
= true;
31 std::wstring sPattern
= rPath
+ L
"\\" + L
"*.*";
32 WIN32_FIND_DATAW aFindData
;
34 // Finding all content in rPath
36 HANDLE hFindContent
= FindFirstFileW( sPattern
.c_str(), &aFindData
);
38 if ( hFindContent
!= INVALID_HANDLE_VALUE
)
40 bool fNextFile
= false;
41 std::wstring sCurrentDir
= L
".";
42 std::wstring sParentDir
= L
"..";
46 std::wstring sFileName
= aFindData
.cFileName
;
48 if (( wcscmp(sFileName
.c_str(),sCurrentDir
.c_str()) != 0 ) &&
49 ( wcscmp(sFileName
.c_str(),sParentDir
.c_str()) != 0 ))
51 std::wstring sCompleteFileName
= rPath
+ L
"\\" + sFileName
;
53 if ( aFindData
.dwFileAttributes
== FILE_ATTRIBUTE_DIRECTORY
)
55 RemoveCompleteDirectoryW(sCompleteFileName
);
59 DeleteFileW( sCompleteFileName
.c_str() );
63 fNextFile
= FindNextFileW( hFindContent
, &aFindData
);
65 } while ( fNextFile
);
67 FindClose( hFindContent
);
69 // empty directory can be removed now
70 // RemoveDirectory is only successful, if the last handle to the directory is closed
71 // -> first removing content -> closing handle -> remove empty directory
74 if( !( RemoveDirectoryW(rPath
.c_str()) ) )
76 bDirectoryRemoved
= false;
80 return bDirectoryRemoved
;
83 extern "C" __declspec(dllexport
) UINT __stdcall
RenamePrgFolder( MSIHANDLE handle
)
85 std::wstring sOfficeInstallPath
= GetMsiPropertyW(handle
, L
"INSTALLLOCATION");
87 std::wstring sRenameSrc
= sOfficeInstallPath
+ L
"program";
88 std::wstring sRenameDst
= sOfficeInstallPath
+ L
"program_old";
90 bool bSuccess
= MoveFileW( sRenameSrc
.c_str(), sRenameDst
.c_str() );
93 WCHAR sAppend
[2] = L
"0";
94 for ( int i
= 0; i
< 10; i
++ )
96 sRenameDst
= sOfficeInstallPath
+ L
"program_old" + sAppend
;
97 bSuccess
= MoveFileW( sRenameSrc
.c_str(), sRenameDst
.c_str() );
104 // ? This succeeds unconditionally, even if bSuccess is false!
105 return ERROR_SUCCESS
;
108 extern "C" __declspec(dllexport
) UINT __stdcall
RemovePrgFolder( MSIHANDLE handle
)
110 std::wstring sOfficeInstallPath
= GetMsiPropertyW(handle
, L
"INSTALLLOCATION");
111 std::wstring sRemoveDir
= sOfficeInstallPath
+ L
"program_old";
113 RemoveCompleteDirectoryW( sRemoveDir
);
115 WCHAR sAppend
[2] = L
"0";
116 for ( int i
= 0; i
< 10; i
++ )
118 sRemoveDir
= sOfficeInstallPath
+ L
"program_old" + sAppend
;
119 RemoveCompleteDirectoryW( sRemoveDir
);
123 return ERROR_SUCCESS
;
126 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */