Sync to trunk head (r47736)
[reactos.git] / dll / win32 / msi / files.c
index 4050163..052a158 100644 (file)
@@ -98,6 +98,8 @@ static void schedule_install_files(MSIPACKAGE *package)
             ui_progress(package,2,file->FileSize,0,0);
             file->state = msifs_skipped;
         }
+        else
+            file->Component->Action = INSTALLSTATE_LOCAL;
     }
 }
 
@@ -119,8 +121,7 @@ static UINT copy_install_file(MSIPACKAGE *package, MSIFILE *file, LPWSTR source)
 {
     UINT gle;
 
-    TRACE("Copying %s to %s\n", debugstr_w(source),
-          debugstr_w(file->TargetPath));
+    TRACE("Copying %s to %s\n", debugstr_w(source), debugstr_w(file->TargetPath));
 
     gle = copy_file(file, source);
     if (gle == ERROR_SUCCESS)
@@ -147,7 +148,7 @@ static UINT copy_install_file(MSIPACKAGE *package, MSIFILE *file, LPWSTR source)
 
         GetTempFileNameW(szBackSlash, szMsi, 0, tmpfileW);
         len = strlenW(file->TargetPath) + strlenW(tmpfileW) + 1;
-        if (!(pathW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR))))
+        if (!(pathW = msi_alloc(len * sizeof(WCHAR))))
             return ERROR_OUTOFMEMORY;
 
         strcpyW(pathW, file->TargetPath);
@@ -167,32 +168,17 @@ static UINT copy_install_file(MSIPACKAGE *package, MSIFILE *file, LPWSTR source)
             gle = GetLastError();
             WARN("failed to schedule rename operation: %d)\n", gle);
         }
-        HeapFree(GetProcessHeap(), 0, pathW);
+        msi_free(pathW);
     }
 
     return gle;
 }
 
-static BOOL check_dest_hash_matches(MSIFILE *file)
-{
-    MSIFILEHASHINFO hash;
-    UINT r;
-
-    if (!file->hash.dwFileHashInfoSize)
-        return FALSE;
-
-    hash.dwFileHashInfoSize = sizeof(MSIFILEHASHINFO);
-    r = MsiGetFileHashW(file->TargetPath, 0, &hash);
-    if (r != ERROR_SUCCESS)
-        return FALSE;
-
-    return !memcmp(&hash, &file->hash, sizeof(MSIFILEHASHINFO));
-}
-
 static BOOL installfiles_cb(MSIPACKAGE *package, LPCWSTR file, DWORD action,
                             LPWSTR *path, DWORD *attrs, PVOID user)
 {
     static MSIFILE *f = NULL;
+    MSIMEDIAINFO *mi = user;
 
     if (action == MSICABEXTRACT_BEGINEXTRACT)
     {
@@ -203,11 +189,8 @@ static BOOL installfiles_cb(MSIPACKAGE *package, LPCWSTR file, DWORD action,
             return FALSE;
         }
 
-        if (f->state != msifs_missing && f->state != msifs_overwrite)
-        {
-            TRACE("Skipping extraction of %s\n", debugstr_w(file));
+        if (f->disk_id != mi->disk_id || (f->state != msifs_missing && f->state != msifs_overwrite))
             return FALSE;
-        }
 
         msi_file_update_ui(package, f, szInstallFiles);
 
@@ -256,19 +239,6 @@ UINT ACTION_InstallFiles(MSIPACKAGE *package)
         if (file->state != msifs_missing && !mi->is_continuous && file->state != msifs_overwrite)
             continue;
 
-        if (check_dest_hash_matches(file))
-        {
-            TRACE("File hashes match, not overwriting\n");
-            continue;
-        }
-
-        if (MsiGetFileVersionW(file->TargetPath, NULL, NULL, NULL, NULL) == ERROR_SUCCESS &&
-            msi_compare_file_version(file) >= 0)
-        {
-            TRACE("Destination file version greater, not overwriting\n");
-            continue;
-        }
-
         if (file->Sequence > mi->last_sequence || mi->is_continuous ||
             (file->IsCompressed && !mi->is_extracted))
         {
@@ -277,20 +247,20 @@ UINT ACTION_InstallFiles(MSIPACKAGE *package)
             rc = ready_media(package, file, mi);
             if (rc != ERROR_SUCCESS)
             {
-                ERR("Failed to ready media\n");
+                ERR("Failed to ready media for %s\n", debugstr_w(file->File));
                 break;
             }
 
             data.mi = mi;
             data.package = package;
             data.cb = installfiles_cb;
-            data.user = NULL;
+            data.user = mi;
 
             if (file->IsCompressed &&
                 !msi_cabextract(package, mi, &data))
             {
                 ERR("Failed to extract cabinet: %s\n", debugstr_w(mi->cabinet));
-                rc = ERROR_FUNCTION_FAILED;
+                rc = ERROR_INSTALL_FAILURE;
                 break;
             }
         }
@@ -317,8 +287,7 @@ UINT ACTION_InstallFiles(MSIPACKAGE *package)
         }
         else if (file->state != msifs_installed)
         {
-            ERR("compressed file wasn't extracted (%s)\n",
-                debugstr_w(file->TargetPath));
+            ERR("compressed file wasn't installed (%s)\n", debugstr_w(file->TargetPath));
             rc = ERROR_INSTALL_FAILURE;
             break;
         }
@@ -555,11 +524,11 @@ static UINT ITERATE_MoveFiles( MSIRECORD *rec, LPVOID param )
     sourcename = MSI_RecordGetString(rec, 3);
     options = MSI_RecordGetInteger(rec, 7);
 
-    sourcedir = msi_dup_property(package, MSI_RecordGetString(rec, 5));
+    sourcedir = msi_dup_property(package->db, MSI_RecordGetString(rec, 5));
     if (!sourcedir)
         goto done;
 
-    destdir = msi_dup_property(package, MSI_RecordGetString(rec, 6));
+    destdir = msi_dup_property(package->db, MSI_RecordGetString(rec, 6));
     if (!destdir)
         goto done;
 
@@ -704,7 +673,7 @@ static WCHAR *get_duplicate_filename( MSIPACKAGE *package, MSIRECORD *row, const
         if (!dst_path)
         {
             /* try a property */
-            dst_path = msi_dup_property( package, dst_key );
+            dst_path = msi_dup_property( package->db, dst_key );
             if (!dst_path)
             {
                 FIXME("Unable to get destination folder, try AppSearch properties\n");
@@ -917,7 +886,7 @@ static UINT ITERATE_RemoveFiles(MSIRECORD *row, LPVOID param)
     UINT install_mode;
     LPWSTR dir = NULL, path = NULL;
     DWORD size;
-    UINT r;
+    UINT ret = ERROR_SUCCESS;
 
     component = MSI_RecordGetString(row, 2);
     filename = MSI_RecordGetString(row, 3);
@@ -938,7 +907,7 @@ static UINT ITERATE_RemoveFiles(MSIRECORD *row, LPVOID param)
         return ERROR_SUCCESS;
     }
 
-    dir = msi_dup_property(package, dirprop);
+    dir = msi_dup_property(package->db, dirprop);
     if (!dir)
         return ERROR_OUTOFMEMORY;
 
@@ -947,7 +916,7 @@ static UINT ITERATE_RemoveFiles(MSIRECORD *row, LPVOID param)
     path = msi_alloc(size * sizeof(WCHAR));
     if (!path)
     {
-        r = ERROR_OUTOFMEMORY;
+        ret = ERROR_OUTOFMEMORY;
         goto done;
     }
 
@@ -975,7 +944,7 @@ done:
 
     msi_free(path);
     msi_free(dir);
-    return ERROR_SUCCESS;
+    return ret;
 }
 
 UINT ACTION_RemoveFiles( MSIPACKAGE *package )