Commit 09b7503f authored by Aric Stewart's avatar Aric Stewart Committed by Alexandre Julliard

Use MSI_IterateRecords for DuplicateFiles.

parent 2703d717
...@@ -562,138 +562,122 @@ UINT ACTION_InstallFiles(MSIPACKAGE *package) ...@@ -562,138 +562,122 @@ UINT ACTION_InstallFiles(MSIPACKAGE *package)
return rc; return rc;
} }
UINT ACTION_DuplicateFiles(MSIPACKAGE *package) static UINT ITERATE_DuplicateFiles(MSIRECORD *row, LPVOID param)
{ {
UINT rc; MSIPACKAGE *package = (MSIPACKAGE*)param;
MSIQUERY * view; WCHAR *file_source = NULL;
MSIRECORD * row = 0; WCHAR dest_name[0x100];
static const WCHAR ExecSeqQuery[] = LPWSTR dest_path, dest;
{'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ', LPCWSTR file_key, component;
'`','D','u','p','l','i','c','a','t','e','F','i','l','e','`',0}; INT component_index;
DWORD sz;
DWORD rc;
if (!package) component = MSI_RecordGetString(row,2);
return ERROR_INVALID_HANDLE; component_index = get_loaded_component(package,component);
if (!ACTION_VerifyComponentForAction(package, component_index,
INSTALLSTATE_LOCAL))
{
TRACE("Skipping copy due to disabled component %s\n",
debugstr_w(component));
/* the action taken was the same as the current install state */
package->components[component_index].Action =
package->components[component_index].Installed;
rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
if (rc != ERROR_SUCCESS)
return ERROR_SUCCESS; return ERROR_SUCCESS;
}
rc = MSI_ViewExecute(view, 0); package->components[component_index].Action = INSTALLSTATE_LOCAL;
if (rc != ERROR_SUCCESS)
file_key = MSI_RecordGetString(row,3);
if (!file_key)
{ {
MSI_ViewClose(view); ERR("Unable to get file key\n");
msiobj_release(&view->hdr); return ERROR_FUNCTION_FAILED;
return rc;
} }
while (1) rc = get_file_target(package,file_key,&file_source);
if (rc != ERROR_SUCCESS)
{ {
WCHAR *file_source = NULL; ERR("Original file unknown %s\n",debugstr_w(file_key));
WCHAR dest_name[0x100]; HeapFree(GetProcessHeap(),0,file_source);
LPWSTR dest_path, dest; return ERROR_SUCCESS;
LPCWSTR file_key, component; }
INT component_index;
DWORD sz; if (MSI_RecordIsNull(row,4))
{
strcpyW(dest_name,strrchrW(file_source,'\\')+1);
}
else
{
sz=0x100;
MSI_RecordGetStringW(row,4,dest_name,&sz);
reduce_to_longfilename(dest_name);
}
rc = MSI_ViewFetch(view,&row); if (MSI_RecordIsNull(row,5))
if (rc != ERROR_SUCCESS) {
LPWSTR p;
dest_path = strdupW(file_source);
p = strrchrW(dest_path,'\\');
if (p)
*p=0;
}
else
{
LPCWSTR destkey;
destkey = MSI_RecordGetString(row,5);
dest_path = resolve_folder(package, destkey, FALSE,FALSE,NULL);
if (!dest_path)
{ {
rc = ERROR_SUCCESS; ERR("Unable to get destination folder\n");
break; HeapFree(GetProcessHeap(),0,file_source);
return ERROR_FUNCTION_FAILED;
} }
}
component = MSI_RecordGetString(row,2); dest = build_directory_name(2, dest_path, dest_name);
component_index = get_loaded_component(package,component);
TRACE("Duplicating file %s to %s\n",debugstr_w(file_source),
if (!ACTION_VerifyComponentForAction(package, component_index, debugstr_w(dest));
INSTALLSTATE_LOCAL))
{ if (strcmpW(file_source,dest))
TRACE("Skipping copy due to disabled component %s\n", rc = !CopyFileW(file_source,dest,TRUE);
debugstr_w(component)); else
rc = ERROR_SUCCESS;
/* the action taken was the same as the current install state */
package->components[component_index].Action = if (rc != ERROR_SUCCESS)
package->components[component_index].Installed; ERR("Failed to copy file %s -> %s, last error %ld\n", debugstr_w(file_source), debugstr_w(dest_path), GetLastError());
msiobj_release(&row->hdr);
continue;
}
package->components[component_index].Action = INSTALLSTATE_LOCAL; FIXME("We should track these duplicate files as well\n");
file_key = MSI_RecordGetString(row,3); HeapFree(GetProcessHeap(),0,dest_path);
if (!file_key) HeapFree(GetProcessHeap(),0,dest);
{ HeapFree(GetProcessHeap(),0,file_source);
ERR("Unable to get file key\n");
msiobj_release(&row->hdr);
break;
}
rc = get_file_target(package,file_key,&file_source); return ERROR_SUCCESS;
}
if (rc != ERROR_SUCCESS) UINT ACTION_DuplicateFiles(MSIPACKAGE *package)
{ {
ERR("Original file unknown %s\n",debugstr_w(file_key)); UINT rc;
msiobj_release(&row->hdr); MSIQUERY * view;
HeapFree(GetProcessHeap(),0,file_source); static const WCHAR ExecSeqQuery[] =
continue; {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
} '`','D','u','p','l','i','c','a','t','e','F','i','l','e','`',0};
if (MSI_RecordIsNull(row,4)) if (!package)
{ return ERROR_INVALID_HANDLE;
strcpyW(dest_name,strrchrW(file_source,'\\')+1);
}
else
{
sz=0x100;
MSI_RecordGetStringW(row,4,dest_name,&sz);
reduce_to_longfilename(dest_name);
}
if (MSI_RecordIsNull(row,5)) rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
{ if (rc != ERROR_SUCCESS)
LPWSTR p; return ERROR_SUCCESS;
dest_path = strdupW(file_source);
p = strrchrW(dest_path,'\\');
if (p)
*p=0;
}
else
{
LPCWSTR destkey;
destkey = MSI_RecordGetString(row,5);
dest_path = resolve_folder(package, destkey, FALSE,FALSE,NULL);
if (!dest_path)
{
ERR("Unable to get destination folder\n");
msiobj_release(&row->hdr);
HeapFree(GetProcessHeap(),0,file_source);
break;
}
}
dest = build_directory_name(2, dest_path, dest_name); rc = MSI_IterateRecords(view, NULL, ITERATE_DuplicateFiles, package);
TRACE("Duplicating file %s to %s\n",debugstr_w(file_source),
debugstr_w(dest));
if (strcmpW(file_source,dest))
rc = !CopyFileW(file_source,dest,TRUE);
else
rc = ERROR_SUCCESS;
if (rc != ERROR_SUCCESS)
ERR("Failed to copy file %s -> %s, last error %ld\n", debugstr_w(file_source), debugstr_w(dest_path), GetLastError());
FIXME("We should track these duplicate files as well\n");
msiobj_release(&row->hdr);
HeapFree(GetProcessHeap(),0,dest_path);
HeapFree(GetProcessHeap(),0,dest);
HeapFree(GetProcessHeap(),0,file_source);
}
MSI_ViewClose(view);
msiobj_release(&view->hdr); msiobj_release(&view->hdr);
return rc; return rc;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment