[SETUPLIB] Introduce defines for size units.

[USETUP] Use them in the code.

svn path=/branches/setup_improvements/; revision=75508
This commit is contained in:
Hermès Bélusca-Maïto 2017-08-08 14:05:20 +00:00
parent a95581c4c2
commit 9348fe1f7e
No known key found for this signature in database
GPG key ID: 3B2539C65E7B93D0
3 changed files with 58 additions and 46 deletions

View file

@ -7,6 +7,8 @@
#pragma once
/* INCLUDES *****************************************************************/
/* Needed PSDK headers when using this library */
#if 0
@ -37,4 +39,14 @@ extern HANDLE ProcessHeap;
#include "regutil.h"
#include "registry.h"
/* DEFINES ******************************************************************/
#define KB ((ULONGLONG)1024)
#define MB (KB*KB)
#define GB (KB*KB*KB)
// #define TB (KB*KB*KB*KB)
// #define PB (KB*KB*KB*KB*KB)
/* EOF */

View file

@ -292,21 +292,21 @@ PrintPartitionData(
{
PartSize.QuadPart = PartEntry->SectorCount.QuadPart * DiskEntry->BytesPerSector;
#if 0
if (PartSize.QuadPart >= 10737418240) /* 10 GB */
if (PartSize.QuadPart >= 10 * GB) /* 10 GB */
{
PartSize.QuadPart = RoundingDivide(PartSize.QuadPart, 1073741824);
PartSize.QuadPart = RoundingDivide(PartSize.QuadPart, GB);
Unit = MUIGetString(STRING_GB);
}
else
#endif
if (PartSize.QuadPart >= 10485760) /* 10 MB */
if (PartSize.QuadPart >= 10 * MB) /* 10 MB */
{
PartSize.QuadPart = RoundingDivide(PartSize.QuadPart, 1048576);
PartSize.QuadPart = RoundingDivide(PartSize.QuadPart, MB);
Unit = MUIGetString(STRING_MB);
}
else
{
PartSize.QuadPart = RoundingDivide(PartSize.QuadPart, 1024);
PartSize.QuadPart = RoundingDivide(PartSize.QuadPart, KB);
Unit = MUIGetString(STRING_KB);
}
@ -335,21 +335,21 @@ PrintPartitionData(
PartSize.QuadPart = PartEntry->SectorCount.QuadPart * DiskEntry->BytesPerSector;
#if 0
if (PartSize.QuadPart >= 10737418240) /* 10 GB */
if (PartSize.QuadPart >= 10 * GB) /* 10 GB */
{
PartSize.QuadPart = RoundingDivide(PartSize.QuadPart, 1073741824);
PartSize.QuadPart = RoundingDivide(PartSize.QuadPart, GB);
Unit = MUIGetString(STRING_GB);
}
else
#endif
if (PartSize.QuadPart >= 10485760) /* 10 MB */
if (PartSize.QuadPart >= 10 * MB) /* 10 MB */
{
PartSize.QuadPart = RoundingDivide(PartSize.QuadPart, 1048576);
PartSize.QuadPart = RoundingDivide(PartSize.QuadPart, MB);
Unit = MUIGetString(STRING_MB);
}
else
{
PartSize.QuadPart = RoundingDivide(PartSize.QuadPart, 1024);
PartSize.QuadPart = RoundingDivide(PartSize.QuadPart, KB);
Unit = MUIGetString(STRING_KB);
}
@ -442,14 +442,14 @@ PrintDiskData(
coPos.Y = ListUi->Top + 1 + ListUi->Line;
DiskSize.QuadPart = DiskEntry->SectorCount.QuadPart * DiskEntry->BytesPerSector;
if (DiskSize.QuadPart >= 10737418240) /* 10 GB */
if (DiskSize.QuadPart >= 10 * GB) /* 10 GB */
{
DiskSize.QuadPart = RoundingDivide(DiskSize.QuadPart, 1073741824);
DiskSize.QuadPart = RoundingDivide(DiskSize.QuadPart, GB);
Unit = MUIGetString(STRING_GB);
}
else
{
DiskSize.QuadPart = RoundingDivide(DiskSize.QuadPart, 1048576);
DiskSize.QuadPart = RoundingDivide(DiskSize.QuadPart, MB);
if (DiskSize.QuadPart == 0)
DiskSize.QuadPart = 1;
Unit = MUIGetString(STRING_MB);

View file

@ -1702,7 +1702,7 @@ IsDiskSizeValid(PPARTENTRY PartEntry)
ULONGLONG size;
size = PartEntry->SectorCount.QuadPart * PartEntry->DiskEntry->BytesPerSector;
size = (size + 524288) / 1048576; /* in MBytes */
size = (size + (512 * KB)) / MB; /* in MBytes */
if (size < RequiredPartitionDiskSpace)
{
@ -2215,15 +2215,15 @@ CreatePrimaryPartitionPage(PINPUT_RECORD Ir)
DiskSize = DiskEntry->SectorCount.QuadPart * DiskEntry->BytesPerSector;
#if 0
if (DiskSize >= 10737418240) /* 10 GB */
if (DiskSize >= 10 * GB) /* 10 GB */
{
DiskSize = DiskSize / 1073741824;
DiskSize = DiskSize / GB;
Unit = MUIGetString(STRING_GB);
}
else
#endif
{
DiskSize = DiskSize / 1048576;
DiskSize = DiskSize / MB;
if (DiskSize == 0)
DiskSize = 1;
@ -2260,7 +2260,7 @@ CreatePrimaryPartitionPage(PINPUT_RECORD Ir)
#if 0
CONSOLE_PrintTextXY(8, 10, "Maximum size of the new partition is %I64u MB",
PartitionList->CurrentPartition->SectorCount * DiskEntry->BytesPerSector / 1048576);
PartitionList->CurrentPartition->SectorCount * DiskEntry->BytesPerSector / MB);
#endif
CONSOLE_SetStatusText(MUIGetString(STRING_CREATEPARTITION));
@ -2268,7 +2268,7 @@ CreatePrimaryPartitionPage(PINPUT_RECORD Ir)
PartEntry = PartitionList->CurrentPartition;
while (TRUE)
{
MaxSize = (PartEntry->SectorCount.QuadPart * DiskEntry->BytesPerSector) / 1048576; /* in MBytes (rounded) */
MaxSize = (PartEntry->SectorCount.QuadPart * DiskEntry->BytesPerSector) / MB; /* in MBytes (rounded) */
if (MaxSize > PARTITION_MAXSIZE)
MaxSize = PARTITION_MAXSIZE;
@ -2312,7 +2312,7 @@ CreatePrimaryPartitionPage(PINPUT_RECORD Ir)
else
{
/* Calculate the sector count from the size in MB */
SectorCount = PartSize * 1048576 / DiskEntry->BytesPerSector;
SectorCount = PartSize * MB / DiskEntry->BytesPerSector;
/* But never get larger than the unpartitioned disk space */
if (SectorCount > PartEntry->SectorCount.QuadPart)
@ -2374,15 +2374,15 @@ CreateExtendedPartitionPage(PINPUT_RECORD Ir)
DiskSize = DiskEntry->SectorCount.QuadPart * DiskEntry->BytesPerSector;
#if 0
if (DiskSize >= 10737418240) /* 10 GB */
if (DiskSize >= 10 * GB) /* 10 GB */
{
DiskSize = DiskSize / 1073741824;
DiskSize = DiskSize / GB;
Unit = MUIGetString(STRING_GB);
}
else
#endif
{
DiskSize = DiskSize / 1048576;
DiskSize = DiskSize / MB;
if (DiskSize == 0)
DiskSize = 1;
@ -2419,7 +2419,7 @@ CreateExtendedPartitionPage(PINPUT_RECORD Ir)
#if 0
CONSOLE_PrintTextXY(8, 10, "Maximum size of the new partition is %I64u MB",
PartitionList->CurrentPartition->SectorCount * DiskEntry->BytesPerSector / 1048576);
PartitionList->CurrentPartition->SectorCount * DiskEntry->BytesPerSector / MB);
#endif
CONSOLE_SetStatusText(MUIGetString(STRING_CREATEPARTITION));
@ -2427,7 +2427,7 @@ CreateExtendedPartitionPage(PINPUT_RECORD Ir)
PartEntry = PartitionList->CurrentPartition;
while (TRUE)
{
MaxSize = (PartEntry->SectorCount.QuadPart * DiskEntry->BytesPerSector) / 1048576; /* in MBytes (rounded) */
MaxSize = (PartEntry->SectorCount.QuadPart * DiskEntry->BytesPerSector) / MB; /* in MBytes (rounded) */
if (MaxSize > PARTITION_MAXSIZE)
MaxSize = PARTITION_MAXSIZE;
@ -2471,7 +2471,7 @@ CreateExtendedPartitionPage(PINPUT_RECORD Ir)
else
{
/* Calculate the sector count from the size in MB */
SectorCount = PartSize * 1048576 / DiskEntry->BytesPerSector;
SectorCount = PartSize * MB / DiskEntry->BytesPerSector;
/* But never get larger than the unpartitioned disk space */
if (SectorCount > PartEntry->SectorCount.QuadPart)
@ -2532,15 +2532,15 @@ CreateLogicalPartitionPage(PINPUT_RECORD Ir)
DiskSize = DiskEntry->SectorCount.QuadPart * DiskEntry->BytesPerSector;
#if 0
if (DiskSize >= 10737418240) /* 10 GB */
if (DiskSize >= 10 * GB) /* 10 GB */
{
DiskSize = DiskSize / 1073741824;
DiskSize = DiskSize / GB;
Unit = MUIGetString(STRING_GB);
}
else
#endif
{
DiskSize = DiskSize / 1048576;
DiskSize = DiskSize / MB;
if (DiskSize == 0)
DiskSize = 1;
@ -2577,7 +2577,7 @@ CreateLogicalPartitionPage(PINPUT_RECORD Ir)
#if 0
CONSOLE_PrintTextXY(8, 10, "Maximum size of the new partition is %I64u MB",
PartitionList->CurrentPartition->SectorCount * DiskEntry->BytesPerSector / 1048576);
PartitionList->CurrentPartition->SectorCount * DiskEntry->BytesPerSector / MB);
#endif
CONSOLE_SetStatusText(MUIGetString(STRING_CREATEPARTITION));
@ -2585,7 +2585,7 @@ CreateLogicalPartitionPage(PINPUT_RECORD Ir)
PartEntry = PartitionList->CurrentPartition;
while (TRUE)
{
MaxSize = (PartEntry->SectorCount.QuadPart * DiskEntry->BytesPerSector) / 1048576; /* in MBytes (rounded) */
MaxSize = (PartEntry->SectorCount.QuadPart * DiskEntry->BytesPerSector) / MB; /* in MBytes (rounded) */
if (MaxSize > PARTITION_MAXSIZE)
MaxSize = PARTITION_MAXSIZE;
@ -2629,7 +2629,7 @@ CreateLogicalPartitionPage(PINPUT_RECORD Ir)
else
{
/* Calculate the sector count from the size in MB */
SectorCount = PartSize * 1048576 / DiskEntry->BytesPerSector;
SectorCount = PartSize * MB / DiskEntry->BytesPerSector;
/* But never get larger than the unpartitioned disk space */
if (SectorCount > PartEntry->SectorCount.QuadPart)
@ -2730,21 +2730,21 @@ DeletePartitionPage(PINPUT_RECORD Ir)
PartSize = PartEntry->SectorCount.QuadPart * DiskEntry->BytesPerSector;
#if 0
if (PartSize >= 10737418240) /* 10 GB */
if (PartSize >= 10 * GB) /* 10 GB */
{
PartSize = PartSize / 1073741824;
PartSize = PartSize / GB;
Unit = MUIGetString(STRING_GB);
}
else
#endif
if (PartSize >= 10485760) /* 10 MB */
if (PartSize >= 10 * MB) /* 10 MB */
{
PartSize = PartSize / 1048576;
PartSize = PartSize / MB;
Unit = MUIGetString(STRING_MB);
}
else
{
PartSize = PartSize / 1024;
PartSize = PartSize / KB;
Unit = MUIGetString(STRING_KB);
}
@ -2771,15 +2771,15 @@ DeletePartitionPage(PINPUT_RECORD Ir)
DiskSize = DiskEntry->SectorCount.QuadPart * DiskEntry->BytesPerSector;
#if 0
if (DiskSize >= 10737418240) /* 10 GB */
if (DiskSize >= 10 * GB) /* 10 GB */
{
DiskSize = DiskSize / 1073741824;
DiskSize = DiskSize / GB;
Unit = MUIGetString(STRING_GB);
}
else
#endif
{
DiskSize = DiskSize / 1048576;
DiskSize = DiskSize / MB;
if (DiskSize == 0)
DiskSize = 1;
@ -2980,27 +2980,27 @@ SelectFileSystemPage(PINPUT_RECORD Ir)
/* Adjust disk size */
DiskSize = DiskEntry->SectorCount.QuadPart * DiskEntry->BytesPerSector;
if (DiskSize >= 10737418240) /* 10 GB */
if (DiskSize >= 10 * GB) /* 10 GB */
{
DiskSize = DiskSize / 1073741824;
DiskSize = DiskSize / GB;
DiskUnit = MUIGetString(STRING_GB);
}
else
{
DiskSize = DiskSize / 1048576;
DiskSize = DiskSize / MB;
DiskUnit = MUIGetString(STRING_MB);
}
/* Adjust partition size */
PartSize = PartEntry->SectorCount.QuadPart * DiskEntry->BytesPerSector;
if (PartSize >= 10737418240) /* 10 GB */
if (PartSize >= 10 * GB) /* 10 GB */
{
PartSize = PartSize / 1073741824;
PartSize = PartSize / GB;
PartUnit = MUIGetString(STRING_GB);
}
else
{
PartSize = PartSize / 1048576;
PartSize = PartSize / MB;
PartUnit = MUIGetString(STRING_MB);
}