msi: Store component cost in 512-byte units.

This avoids overflow when component costs exceed 4 GB.
This commit is contained in:
Zebediah Figura 2024-03-02 15:23:56 -06:00 committed by Alexandre Julliard
parent 9725a2286a
commit d7bbe884ef
5 changed files with 14 additions and 14 deletions

View file

@ -2070,7 +2070,7 @@ static UINT calculate_file_cost( MSIPACKAGE *package )
if (msi_get_file_attributes( package, file->TargetPath ) == INVALID_FILE_ATTRIBUTES)
{
comp->Cost += file->FileSize;
comp->cost += cost_from_size( file->FileSize );
continue;
}
file_size = msi_get_disk_file_size( package, file->TargetPath );
@ -2082,7 +2082,7 @@ static UINT calculate_file_cost( MSIPACKAGE *package )
{
if (msi_compare_file_versions( file_version, file->Version ) < 0)
{
comp->Cost += file->FileSize - file_size;
comp->cost += cost_from_size( file->FileSize - file_size );
}
free( file_version );
continue;
@ -2091,7 +2091,7 @@ static UINT calculate_file_cost( MSIPACKAGE *package )
{
if (msi_compare_font_versions( font_version, file->Version ) < 0)
{
comp->Cost += file->FileSize - file_size;
comp->cost += cost_from_size( file->FileSize - file_size );
}
free( font_version );
continue;
@ -2099,7 +2099,7 @@ static UINT calculate_file_cost( MSIPACKAGE *package )
}
if (file_size != file->FileSize)
{
comp->Cost += file->FileSize - file_size;
comp->cost += cost_from_size( file->FileSize - file_size );
}
}
@ -2217,7 +2217,7 @@ static ULONGLONG get_volume_space_required( MSIPACKAGE *package )
LIST_FOR_EACH_ENTRY( comp, &package->components, MSICOMPONENT, entry )
{
if (comp->Action == INSTALLSTATE_LOCAL) ret += comp->Cost;
if (comp->Action == INSTALLSTATE_LOCAL) ret += comp->cost;
}
return ret;
}
@ -2292,10 +2292,10 @@ static UINT ACTION_CostFinalize(MSIPACKAGE *package)
msi_set_property( package->db, L"PrimaryVolumeSpaceAvailable", buf, -1 );
}
required = get_volume_space_required( package );
swprintf( buf, ARRAY_SIZE(buf), L"%lu", required / 512 );
swprintf( buf, ARRAY_SIZE(buf), L"%lu", required );
msi_set_property( package->db, L"PrimaryVolumeSpaceRequired", buf, -1 );
swprintf( buf, ARRAY_SIZE(buf), L"%lu", (free.QuadPart - required) / 512 );
swprintf( buf, ARRAY_SIZE(buf), L"%lu", (free.QuadPart / 512) - required );
msi_set_property( package->db, L"PrimaryVolumeSpaceRemaining", buf, -1 );
msi_set_property( package->db, L"PrimaryVolumePath", primary_folder, 2 );
}

View file

@ -1147,7 +1147,7 @@ static INT feature_cost( MSIFEATURE *feature )
LIST_FOR_EACH_ENTRY( cl, &feature->Components, ComponentList, entry )
{
cost += cl->component->Cost;
cost += cl->component->cost;
}
return cost;
}
@ -1197,7 +1197,6 @@ UINT MSI_GetFeatureCost( MSIPACKAGE *package, MSIFEATURE *feature, MSICOSTTREE t
break;
}
*cost /= 512;
return ERROR_SUCCESS;
}

View file

@ -2028,7 +2028,7 @@ UINT WINAPI MsiEnumComponentCostsW( MSIHANDLE handle, const WCHAR *component, DW
GetWindowsDirectoryW( path, MAX_PATH );
if (component && component[0])
{
if (msi_is_global_assembly( comp )) *temp = comp->Cost;
if (msi_is_global_assembly( comp )) *temp = comp->cost;
if (!comp->Enabled || !comp->KeyPath)
{
*cost = 0;
@ -2037,7 +2037,7 @@ UINT WINAPI MsiEnumComponentCostsW( MSIHANDLE handle, const WCHAR *component, DW
}
else if ((file = msi_get_loaded_file( package, comp->KeyPath )))
{
*cost = cost_from_size( comp->Cost );
*cost = comp->cost;
*buflen = set_drive( drive, file->TargetPath[0] );
r = ERROR_SUCCESS;
}

View file

@ -532,7 +532,8 @@ typedef struct tagMSICOMPONENT
INSTALLSTATE Action;
BOOL ForceLocalState;
BOOL Enabled;
INT Cost;
/* Cost is in 512-byte units, as returned from MsiEnumComponentCosts() et al. */
int cost;
INT RefCount;
LPWSTR FullKeypath;
LPWSTR AdvertiseString;

View file

@ -8607,7 +8607,7 @@ static void test_costs(void)
ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r );
ok( len == 2, "expected len == 2, got %lu\n", len );
ok( drive[0], "expected a drive\n" );
todo_wine ok( cost == 12000024, "got %d\n", cost );
ok( cost == 12000024, "got %d\n", cost );
ok( !temp, "expected temp == 0, got %d\n", temp );
len = sizeof(drive);
@ -8651,7 +8651,7 @@ static void test_costs(void)
cost = 0xdead;
r = MsiGetFeatureCostA( hpkg, "one", MSICOSTTREE_SELFONLY, INSTALLSTATE_LOCAL, &cost );
ok( !r, "got %u\n", r);
todo_wine ok( cost == 12000024, "got %d\n", cost );
ok( cost == 12000024, "got %d\n", cost );
MsiCloseHandle( hpkg );
error: