- Merge from trunk
[reactos.git] / dll / win32 / msi / custom.c
index 2b2a3e1..b56139f 100644 (file)
@@ -163,17 +163,17 @@ static void set_deferred_action_props(MSIPACKAGE *package, LPWSTR deferred_data)
 
     end = strstrW(beg, sep);
     *end = '\0';
-    MSI_SetPropertyW(package, szCustomActionData, beg);
+    msi_set_property(package->db, szCustomActionData, beg);
     beg = end + 3;
 
     end = strstrW(beg, sep);
     *end = '\0';
-    MSI_SetPropertyW(package, szUserSID, beg);
+    msi_set_property(package->db, szUserSID, beg);
     beg = end + 3;
 
     end = strchrW(beg, ']');
     *end = '\0';
-    MSI_SetPropertyW(package, szProductCode, beg);
+    msi_set_property(package->db, szProductCode, beg);
 }
 
 UINT ACTION_CustomAction(MSIPACKAGE *package, LPCWSTR action, UINT script, BOOL execute)
@@ -222,28 +222,26 @@ UINT ACTION_CustomAction(MSIPACKAGE *package, LPCWSTR action, UINT script, BOOL
         if (type & msidbCustomActionTypeNoImpersonate)
             WARN("msidbCustomActionTypeNoImpersonate not handled\n");
 
-        if (type & msidbCustomActionTypeRollback)
-        {
-            FIXME("Rollback only action... rollbacks not supported yet\n");
-            schedule_action(package, ROLLBACK_SCRIPT, action);
-            rc = ERROR_SUCCESS;
-            goto end;
-        }
         if (!execute)
         {
-            LPWSTR actiondata = msi_dup_property(package, action);
-            LPWSTR usersid = msi_dup_property(package, szUserSID);
-            LPWSTR prodcode = msi_dup_property(package, szProductCode);
+            LPWSTR actiondata = msi_dup_property(package->db, action);
+            LPWSTR usersid = msi_dup_property(package->db, szUserSID);
+            LPWSTR prodcode = msi_dup_property(package->db, szProductCode);
             LPWSTR deferred = msi_get_deferred_action(action, actiondata, usersid, prodcode);
 
             if (type & msidbCustomActionTypeCommit)
             {
-                TRACE("Deferring Commit Action!\n");
+                TRACE("Deferring commit action\n");
                 schedule_action(package, COMMIT_SCRIPT, deferred);
             }
+            else if (type & msidbCustomActionTypeRollback)
+            {
+                FIXME("Deferring rollback only action... rollbacks not supported yet\n");
+                schedule_action(package, ROLLBACK_SCRIPT, deferred);
+            }
             else
             {
-                TRACE("Deferring Action!\n");
+                TRACE("Deferring action\n");
                 schedule_action(package, INSTALL_SCRIPT, deferred);
             }
 
@@ -256,29 +254,23 @@ UINT ACTION_CustomAction(MSIPACKAGE *package, LPCWSTR action, UINT script, BOOL
         }
         else
         {
-            LPWSTR actiondata = msi_dup_property( package, action );
+            LPWSTR actiondata = msi_dup_property( package->db, action );
 
-            switch (script)
-            {
-            case INSTALL_SCRIPT:
+            if (type & msidbCustomActionTypeInScript)
                 package->scheduled_action_running = TRUE;
-                break;
-            case COMMIT_SCRIPT:
+
+            if (type & msidbCustomActionTypeCommit)
                 package->commit_action_running = TRUE;
-                break;
-            case ROLLBACK_SCRIPT:
+
+            if (type & msidbCustomActionTypeRollback)
                 package->rollback_action_running = TRUE;
-                break;
-            default:
-                break;
-            }
 
             if (deferred_data)
                 set_deferred_action_props(package, deferred_data);
             else if (actiondata)
-                MSI_SetPropertyW(package, szCustomActionData, actiondata);
+                msi_set_property(package->db, szCustomActionData, actiondata);
             else
-                MSI_SetPropertyW(package, szCustomActionData, szEmpty);
+                msi_set_property(package->db, szCustomActionData, szEmpty);
 
             msi_free(actiondata);
         }
@@ -327,7 +319,9 @@ UINT ACTION_CustomAction(MSIPACKAGE *package, LPCWSTR action, UINT script, BOOL
                 break;
 
             deformat_string(package,target,&deformated);
-            rc = MSI_SetPropertyW(package,source,deformated);
+            rc = msi_set_property( package->db, source, deformated );
+            if (rc == ERROR_SUCCESS && !strcmpW( source, cszSourceDir ))
+                msi_reset_folders( package, TRUE );
             msi_free(deformated);
             break;
        case 37: /* JScript/VBScript text stored in target column. */
@@ -376,7 +370,7 @@ static UINT store_binary_to_temp(MSIPACKAGE *package, LPCWSTR source,
     DWORD sz = MAX_PATH;
     UINT r;
 
-    if (MSI_GetPropertyW(package, cszTempFolder, fmt, &sz) != ERROR_SUCCESS)
+    if (msi_get_property(package->db, cszTempFolder, fmt, &sz) != ERROR_SUCCESS)
         GetTempPathW(MAX_PATH, fmt);
 
     if (GetTempFileNameW(fmt, szMsi, 0, tmp_file) == 0)
@@ -864,7 +858,7 @@ static UINT HANDLE_CustomType23(MSIPACKAGE *package, LPCWSTR source,
     UINT r;
 
     size = MAX_PATH;
-    MSI_GetPropertyW(package, cszSourceDir, package_path, &size);
+    msi_get_property(package->db, cszSourceDir, package_path, &size);
     lstrcatW(package_path, szBackSlash);
     lstrcatW(package_path, source);
 
@@ -1078,7 +1072,7 @@ static UINT HANDLE_CustomType50(MSIPACKAGE *package, LPCWSTR source,
     memset(&si,0,sizeof(STARTUPINFOW));
     memset(&info,0,sizeof(PROCESS_INFORMATION));
 
-    prop = msi_dup_property( package, source );
+    prop = msi_dup_property( package->db, source );
     if (!prop)
         return ERROR_SUCCESS;
 
@@ -1120,38 +1114,44 @@ static UINT HANDLE_CustomType50(MSIPACKAGE *package, LPCWSTR source,
 static UINT HANDLE_CustomType34(MSIPACKAGE *package, LPCWSTR source,
                                 LPCWSTR target, const INT type, LPCWSTR action)
 {
-    LPWSTR filename, deformated;
+    LPWSTR workingdir, filename;
     STARTUPINFOW si;
     PROCESS_INFORMATION info;
     BOOL rc;
 
-    memset(&si,0,sizeof(STARTUPINFOW));
+    memset(&si, 0, sizeof(STARTUPINFOW));
 
-    filename = resolve_folder(package, source, FALSE, FALSE, TRUE, NULL);
+    workingdir = resolve_folder(package, source, FALSE, FALSE, TRUE, NULL);
 
-    if (!filename)
+    if (!workingdir)
         return ERROR_FUNCTION_FAILED;
 
-    SetCurrentDirectoryW(filename);
-    msi_free(filename);
+    deformat_string(package, target, &filename);
 
-    deformat_string(package,target,&deformated);
-
-    if (!deformated)
+    if (!filename)
+    {
+        msi_free(workingdir);
         return ERROR_FUNCTION_FAILED;
+    }
 
-    TRACE("executing exe %s\n", debugstr_w(deformated));
+    TRACE("executing exe %s with working directory %s\n",
+          debugstr_w(filename), debugstr_w(workingdir));
 
-    rc = CreateProcessW(NULL, deformated, NULL, NULL, FALSE, 0, NULL,
-                  c_collen, &si, &info);
+    rc = CreateProcessW(NULL, filename, NULL, NULL, FALSE, 0, NULL,
+                        workingdir, &si, &info);
 
     if ( !rc )
     {
-        ERR("Unable to execute command %s\n", debugstr_w(deformated));
-        msi_free(deformated);
+        ERR("Unable to execute command %s with working directory %s\n",
+            debugstr_w(filename), debugstr_w(workingdir));
+        msi_free(filename);
+        msi_free(workingdir);
         return ERROR_SUCCESS;
     }
-    msi_free(deformated);
+
+    msi_free(filename);
+    msi_free(workingdir);
+
     CloseHandle( info.hThread );
 
     return wait_process_handle(package, type, info.hProcess, action);
@@ -1374,7 +1374,7 @@ static UINT HANDLE_CustomType53_54(MSIPACKAGE *package, LPCWSTR source,
 
     TRACE("%s %s\n", debugstr_w(source), debugstr_w(target));
 
-    prop = msi_dup_property(package,source);
+    prop = msi_dup_property( package->db, source );
     if (!prop)
        return ERROR_SUCCESS;
 
@@ -1409,7 +1409,7 @@ void ACTION_FinishCustomActions(const MSIPACKAGE* package)
     EnterCriticalSection( &msi_custom_action_cs );
 
     handle_count = list_count( &msi_pending_custom_actions );
-    wait_handles = HeapAlloc( GetProcessHeap(), 0, handle_count * sizeof(HANDLE) );
+    wait_handles = msi_alloc( handle_count * sizeof(HANDLE) );
 
     handle_count = 0;
     LIST_FOR_EACH_ENTRY_SAFE( info, cursor, &msi_pending_custom_actions, msi_custom_action_info, entry )
@@ -1429,7 +1429,7 @@ void ACTION_FinishCustomActions(const MSIPACKAGE* package)
         CloseHandle( wait_handles[i] );
     }
 
-    HeapFree( GetProcessHeap(), 0, wait_handles );
+    msi_free( wait_handles );
 }
 
 typedef struct _msi_custom_remote_impl {