@@ -16,10 +16,10 @@ void log_last_error(MSIHANDLE hInstall) noexcept {
16
16
(void )MsiProcessMessage (hInstall, INSTALLMESSAGE_ERROR, record);
17
17
}
18
18
19
- std::wstring get_action_data (MSIHANDLE hInstall, UINT &result) noexcept {
19
+ std::wstring get_property (MSIHANDLE hInstall, std::wstring name , UINT &result) noexcept {
20
20
DWORD size = 0 ;
21
21
22
- result = MsiGetPropertyW (hInstall, L" CustomActionData " , L" " , &size);
22
+ result = MsiGetPropertyW (hInstall, name. c_str () , L" " , &size);
23
23
switch (result) {
24
24
case ERROR_MORE_DATA:
25
25
break ;
@@ -35,7 +35,7 @@ std::wstring get_action_data(MSIHANDLE hInstall, UINT &result) noexcept {
35
35
buffer.resize (size + 1 );
36
36
37
37
size = buffer.capacity ();
38
- result = MsiGetPropertyW (hInstall, L" CustomActionData " , buffer.data (), &size);
38
+ result = MsiGetPropertyW (hInstall, name. c_str () , buffer.data (), &size);
39
39
switch (result) {
40
40
case ERROR_SUCCESS:
41
41
break ;
@@ -52,7 +52,7 @@ extern "C" _declspec(dllexport) UINT __stdcall CopyClangResources(MSIHANDLE hIns
52
52
UINT result = ERROR_SUCCESS;
53
53
54
54
// Get the runtime resource directory path
55
- auto resourceDirectory = msi::get_action_data (hInstall, result);
55
+ auto resourceDirectory = msi::get_property (hInstall, L" CustomActionData " , result);
56
56
if (result != ERROR_SUCCESS) {
57
57
return result;
58
58
}
@@ -101,6 +101,31 @@ extern "C" _declspec(dllexport) UINT __stdcall CopyClangResources(MSIHANDLE hIns
101
101
return result;
102
102
}
103
103
104
+ extern " C" _declspec(dllexport) UINT __stdcall RemoveClangResources (MSIHANDLE hInstall) {
105
+ UINT result = ERROR_SUCCESS;
106
+
107
+ // Get the directory path for removal
108
+ auto directory = msi::get_property (hInstall, L" _usr_lib_swift_clang" , result);
109
+ if (result != ERROR_SUCCESS) {
110
+ return result;
111
+ }
112
+ std::filesystem::path directoryPath (directory);
113
+ msi::log (hInstall, INSTALLMESSAGE_INFO, L" Clang resources for Swift: " + directoryPath.wstring ());
114
+
115
+ // Remove the directory and its contents
116
+ std::error_code error;
117
+ auto count = std::filesystem::remove_all (directoryPath, error);
118
+ if (error) {
119
+ std::string errorMessage = " Error during directory removal: " + error.message ();
120
+ msi::log (hInstall, INSTALLMESSAGE_ERROR | MB_OK, {errorMessage.begin (), errorMessage.end ()});
121
+ return ERROR_DISK_OPERATION_FAILED;
122
+ } else if (count == 0 ) {
123
+ msi::log (hInstall, INSTALLMESSAGE_INFO, L" Clang resources for Swift doesn't exist!" );
124
+ }
125
+
126
+ return result;
127
+ }
128
+
104
129
BOOL APIENTRY DllMain (HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) {
105
130
switch (ul_reason_for_call) {
106
131
case DLL_PROCESS_ATTACH:
0 commit comments