@@ -16,10 +16,10 @@ void log_last_error(MSIHANDLE hInstall) noexcept {
1616 (void )MsiProcessMessage (hInstall, INSTALLMESSAGE_ERROR, record);
1717}
1818
19- std::wstring get_action_data (MSIHANDLE hInstall, UINT &result) noexcept {
19+ std::wstring get_property (MSIHANDLE hInstall, std::wstring name , UINT &result) noexcept {
2020 DWORD size = 0 ;
2121
22- result = MsiGetPropertyW (hInstall, L" CustomActionData " , L" " , &size);
22+ result = MsiGetPropertyW (hInstall, name. c_str () , L" " , &size);
2323 switch (result) {
2424 case ERROR_MORE_DATA:
2525 break ;
@@ -35,7 +35,7 @@ std::wstring get_action_data(MSIHANDLE hInstall, UINT &result) noexcept {
3535 buffer.resize (size + 1 );
3636
3737 size = buffer.capacity ();
38- result = MsiGetPropertyW (hInstall, L" CustomActionData " , buffer.data (), &size);
38+ result = MsiGetPropertyW (hInstall, name. c_str () , buffer.data (), &size);
3939 switch (result) {
4040 case ERROR_SUCCESS:
4141 break ;
@@ -52,7 +52,7 @@ extern "C" _declspec(dllexport) UINT __stdcall CopyClangResources(MSIHANDLE hIns
5252 UINT result = ERROR_SUCCESS;
5353
5454 // 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);
5656 if (result != ERROR_SUCCESS) {
5757 return result;
5858 }
@@ -101,6 +101,31 @@ extern "C" _declspec(dllexport) UINT __stdcall CopyClangResources(MSIHANDLE hIns
101101 return result;
102102}
103103
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+
104129BOOL APIENTRY DllMain (HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) {
105130 switch (ul_reason_for_call) {
106131 case DLL_PROCESS_ATTACH:
0 commit comments