Skip to content

Commit 8aa516f

Browse files
committed
Implement SetupDiGetActualSectionToInstallExA/W
svn path=/trunk/; revision=20269
1 parent d680237 commit 8aa516f

File tree

4 files changed

+226
-85
lines changed

4 files changed

+226
-85
lines changed

reactos/lib/setupapi/devinst.c

Lines changed: 218 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,8 @@ static const WCHAR ClassInstall32[] = {'C','l','a','s','s','I','n','s','t','a',
3131
static const WCHAR DeviceInstance[] = {'D','e','v','i','c','e','I','n','s','t','a','n','c','e',0};
3232
static const WCHAR DotServices[] = {'.','S','e','r','v','i','c','e','s',0};
3333
static const WCHAR InterfaceInstall32[] = {'I','n','t','e','r','f','a','c','e','I','n','s','t','a','l','l','3','2',0};
34-
static const WCHAR NtExtension[] = {'.','N','T',0};
35-
static const WCHAR NtPlatformExtension[] = {'.','N','T','x','8','6',0};
3634
static const WCHAR SymbolicLink[] = {'S','y','m','b','o','l','i','c','L','i','n','k',0};
3735
static const WCHAR Version[] = {'V','e','r','s','i','o','n',0};
38-
static const WCHAR WinExtension[] = {'.','W','i','n',0};
3936

4037
/* FIXME: header mess */
4138
DEFINE_GUID(GUID_NULL,
@@ -823,16 +820,53 @@ BOOL WINAPI SetupDiEnumDeviceInfo(
823820
/***********************************************************************
824821
* SetupDiGetActualSectionToInstallA (SETUPAPI.@)
825822
*/
826-
BOOL WINAPI SetupDiGetActualSectionToInstallA(
827-
HINF InfHandle,
828-
PCSTR InfSectionName,
829-
PSTR InfSectionWithExt,
830-
DWORD InfSectionWithExtSize,
831-
PDWORD RequiredSize,
832-
PSTR *Extension)
823+
BOOL WINAPI
824+
SetupDiGetActualSectionToInstallA(
825+
IN HINF InfHandle,
826+
IN PCSTR InfSectionName,
827+
OUT PSTR InfSectionWithExt OPTIONAL,
828+
IN DWORD InfSectionWithExtSize,
829+
OUT PDWORD RequiredSize OPTIONAL,
830+
OUT PSTR *Extension OPTIONAL)
831+
{
832+
return SetupDiGetActualSectionToInstallExA(InfHandle, InfSectionName,
833+
NULL, InfSectionWithExt, InfSectionWithExtSize, RequiredSize,
834+
Extension, NULL);
835+
}
836+
837+
/***********************************************************************
838+
* SetupDiGetActualSectionToInstallW (SETUPAPI.@)
839+
*/
840+
BOOL WINAPI
841+
SetupDiGetActualSectionToInstallW(
842+
IN HINF InfHandle,
843+
IN PCWSTR InfSectionName,
844+
OUT PWSTR InfSectionWithExt OPTIONAL,
845+
IN DWORD InfSectionWithExtSize,
846+
OUT PDWORD RequiredSize OPTIONAL,
847+
OUT PWSTR *Extension OPTIONAL)
848+
{
849+
return SetupDiGetActualSectionToInstallExW(InfHandle, InfSectionName,
850+
NULL, InfSectionWithExt, InfSectionWithExtSize, RequiredSize,
851+
Extension, NULL);
852+
}
853+
854+
/***********************************************************************
855+
* SetupDiGetActualSectionToInstallExA (SETUPAPI.@)
856+
*/
857+
BOOL WINAPI
858+
SetupDiGetActualSectionToInstallExA(
859+
IN HINF InfHandle,
860+
IN PCSTR InfSectionName,
861+
IN PSP_ALTPLATFORM_INFO AlternatePlatformInfo OPTIONAL,
862+
OUT PSTR InfSectionWithExt OPTIONAL,
863+
IN DWORD InfSectionWithExtSize,
864+
OUT PDWORD RequiredSize OPTIONAL,
865+
OUT PSTR* Extension OPTIONAL,
866+
IN PVOID Reserved)
833867
{
834868
LPWSTR InfSectionNameW = NULL;
835-
PWSTR InfSectionWithExtW = NULL;
869+
LPWSTR InfSectionWithExtW = NULL;
836870
PWSTR ExtensionW;
837871
BOOL bResult = FALSE;
838872

@@ -841,18 +875,23 @@ BOOL WINAPI SetupDiGetActualSectionToInstallA(
841875
if (InfSectionName)
842876
{
843877
InfSectionNameW = MultiByteToUnicode(InfSectionName, CP_ACP);
844-
if (InfSectionNameW == NULL) goto end;
878+
if (InfSectionNameW == NULL)
879+
goto cleanup;
845880
}
846881
if (InfSectionWithExt)
847882
{
848-
InfSectionWithExtW = HeapAlloc(GetProcessHeap(), 0, InfSectionWithExtSize * sizeof(WCHAR));
849-
if (InfSectionWithExtW == NULL) goto end;
883+
InfSectionWithExtW = MyMalloc(InfSectionWithExtSize * sizeof(WCHAR));
884+
if (InfSectionWithExtW == NULL)
885+
goto cleanup;
850886
}
851887

852-
bResult = SetupDiGetActualSectionToInstallW(InfHandle, InfSectionNameW,
853-
InfSectionWithExt ? InfSectionNameW : NULL,
854-
InfSectionWithExtSize, RequiredSize,
855-
Extension ? &ExtensionW : NULL);
888+
bResult = SetupDiGetActualSectionToInstallExW(
889+
InfHandle, InfSectionNameW, AlternatePlatformInfo,
890+
InfSectionWithExt ? InfSectionWithExtW : NULL,
891+
InfSectionWithExtSize,
892+
RequiredSize,
893+
Extension ? &ExtensionW : NULL,
894+
Reserved);
856895

857896
if (bResult && InfSectionWithExt)
858897
{
@@ -867,93 +906,188 @@ BOOL WINAPI SetupDiGetActualSectionToInstallA(
867906
*Extension = &InfSectionWithExt[ExtensionW - InfSectionWithExtW];
868907
}
869908

870-
end:
871-
if (InfSectionNameW) MyFree(InfSectionNameW);
872-
if (InfSectionWithExtW) HeapFree(GetProcessHeap(), 0, InfSectionWithExtW);
909+
cleanup:
910+
MyFree(InfSectionNameW);
911+
MyFree(InfSectionWithExtW);
873912

874913
return bResult;
875914
}
876915

877916
/***********************************************************************
878-
* SetupDiGetActualSectionToInstallW (SETUPAPI.@)
917+
* SetupDiGetActualSectionToInstallExW (SETUPAPI.@)
879918
*/
880-
BOOL WINAPI SetupDiGetActualSectionToInstallW(
881-
HINF InfHandle,
882-
PCWSTR InfSectionName,
883-
PWSTR InfSectionWithExt,
884-
DWORD InfSectionWithExtSize,
885-
PDWORD RequiredSize,
886-
PWSTR *Extension)
919+
BOOL WINAPI
920+
SetupDiGetActualSectionToInstallExW(
921+
IN HINF InfHandle,
922+
IN PCWSTR InfSectionName,
923+
IN PSP_ALTPLATFORM_INFO AlternatePlatformInfo OPTIONAL,
924+
OUT PWSTR InfSectionWithExt OPTIONAL,
925+
IN DWORD InfSectionWithExtSize,
926+
OUT PDWORD RequiredSize OPTIONAL,
927+
OUT PWSTR* Extension OPTIONAL,
928+
IN PVOID Reserved)
887929
{
888-
WCHAR szBuffer[MAX_PATH];
889-
DWORD dwLength;
890-
DWORD dwFullLength;
891-
LONG lLineCount = -1;
892-
893-
TRACE("%p %s %p %lu %p %p\n", InfHandle, debugstr_w(InfSectionName),
894-
InfSectionWithExt, InfSectionWithExtSize, RequiredSize, Extension);
895-
896-
lstrcpyW(szBuffer, InfSectionName);
897-
dwLength = lstrlenW(szBuffer);
930+
BOOL ret = FALSE;
898931

899-
if (OsVersionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT)
900-
{
901-
/* Test section name with '.NTx86' extension */
902-
lstrcpyW(&szBuffer[dwLength], NtPlatformExtension);
903-
lLineCount = SetupGetLineCountW(InfHandle, szBuffer);
932+
TRACE("%p %s %p %p %lu %p %p %p\n", InfHandle, debugstr_w(InfSectionName),
933+
AlternatePlatformInfo, InfSectionWithExt, InfSectionWithExtSize,
934+
RequiredSize, Extension, Reserved);
904935

905-
if (lLineCount == -1)
906-
{
907-
/* Test section name with '.NT' extension */
908-
lstrcpyW(&szBuffer[dwLength], NtExtension);
909-
lLineCount = SetupGetLineCountW(InfHandle, szBuffer);
910-
}
911-
}
936+
if (!InfHandle || InfHandle == (HINF)INVALID_HANDLE_VALUE)
937+
SetLastError(ERROR_INVALID_HANDLE);
938+
else if (!InfSectionName)
939+
SetLastError(ERROR_INVALID_PARAMETER);
940+
else if (AlternatePlatformInfo && AlternatePlatformInfo->cbSize != sizeof(SP_ALTPLATFORM_INFO))
941+
SetLastError(ERROR_INVALID_USER_BUFFER);
942+
else if (Reserved != NULL)
943+
SetLastError(ERROR_INVALID_PARAMETER);
912944
else
913945
{
914-
/* Test section name with '.Win' extension */
915-
lstrcpyW(&szBuffer[dwLength], WinExtension);
916-
lLineCount = SetupGetLineCountW(InfHandle, szBuffer);
917-
}
946+
static SP_ALTPLATFORM_INFO CurrentPlatform = { 0, };
947+
PSP_ALTPLATFORM_INFO pPlatformInfo = &CurrentPlatform;
948+
LPCWSTR pExtensionPlatform, pExtensionArchitecture;
949+
WCHAR SectionName[LINE_LEN + 1];
950+
LONG lLineCount = -1;
951+
DWORD dwFullLength;
952+
953+
/* Fill platform info if needed */
954+
if (AlternatePlatformInfo)
955+
pPlatformInfo = AlternatePlatformInfo;
956+
else if (CurrentPlatform.cbSize != sizeof(SP_ALTPLATFORM_INFO))
957+
{
958+
/* That's the first time we go here. We need to fill in the structure */
959+
OSVERSIONINFO VersionInfo;
960+
SYSTEM_INFO SystemInfo;
961+
VersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
962+
ret = GetVersionEx(&VersionInfo);
963+
if (!ret)
964+
goto done;
965+
GetSystemInfo(&SystemInfo);
966+
CurrentPlatform.cbSize = sizeof(SP_ALTPLATFORM_INFO);
967+
CurrentPlatform.Platform = VersionInfo.dwPlatformId;
968+
CurrentPlatform.MajorVersion = VersionInfo.dwMajorVersion;
969+
CurrentPlatform.MinorVersion = VersionInfo.dwMinorVersion;
970+
CurrentPlatform.ProcessorArchitecture = SystemInfo.wProcessorArchitecture;
971+
CurrentPlatform.Reserved = 0;
972+
}
918973

919-
if (lLineCount == -1)
920-
{
921-
/* Test section name without extension */
922-
szBuffer[dwLength] = 0;
923-
lLineCount = SetupGetLineCountW(InfHandle, szBuffer);
924-
}
974+
static const WCHAR ExtensionPlatformNone[] = {'.',0};
975+
static const WCHAR ExtensionPlatformNT[] = {'.','N','T',0};
976+
static const WCHAR ExtensionPlatformWindows[] = {'.','W','i','n',0};
925977

926-
if (lLineCount == -1)
927-
{
928-
SetLastError(ERROR_INVALID_PARAMETER);
929-
return FALSE;
930-
}
978+
static const WCHAR ExtensionArchitectureNone[] = {0};
979+
static const WCHAR ExtensionArchitectureamd64[] = {'a','m','d','6','4',0};
980+
static const WCHAR ExtensionArchitectureppc[] = {'p','p','c',0};
981+
static const WCHAR ExtensionArchitecturex86[] = {'x','8','6',0};
931982

932-
dwFullLength = lstrlenW(szBuffer);
983+
/* Set various extensions values */
984+
switch (pPlatformInfo->Platform)
985+
{
986+
case VER_PLATFORM_WIN32_WINDOWS:
987+
pExtensionPlatform = ExtensionPlatformWindows;
988+
break;
989+
case VER_PLATFORM_WIN32_NT:
990+
pExtensionPlatform = ExtensionPlatformNT;
991+
break;
992+
default:
993+
pExtensionPlatform = ExtensionPlatformNone;
994+
break;
995+
}
996+
switch (pPlatformInfo->ProcessorArchitecture)
997+
{
998+
case PROCESSOR_ARCHITECTURE_AMD64:
999+
pExtensionArchitecture = ExtensionArchitectureamd64;
1000+
break;
1001+
case PROCESSOR_ARCHITECTURE_INTEL:
1002+
pExtensionArchitecture = ExtensionArchitecturex86;
1003+
break;
1004+
case PROCESSOR_ARCHITECTURE_PPC:
1005+
pExtensionArchitecture = ExtensionArchitectureppc;
1006+
break;
1007+
default:
1008+
ERR("Unknown processor architecture 0x%x\n", pPlatformInfo->ProcessorArchitecture);
1009+
case PROCESSOR_ARCHITECTURE_UNKNOWN:
1010+
pExtensionArchitecture = ExtensionArchitectureNone;
1011+
break;
1012+
}
9331013

934-
if (InfSectionWithExt != NULL && InfSectionWithExtSize != 0)
935-
{
936-
if (InfSectionWithExtSize < (dwFullLength + 1))
937-
{
938-
SetLastError(ERROR_INSUFFICIENT_BUFFER);
939-
return FALSE;
940-
}
1014+
SectionName[LINE_LEN] = UNICODE_NULL;
1015+
1016+
/* Test with platform.architecture.major.minor extension */
1017+
snprintfW(SectionName, LINE_LEN, L"%s%s%s.%lu.%lu", InfSectionName,
1018+
pExtensionPlatform, pExtensionArchitecture, pPlatformInfo->MajorVersion, pPlatformInfo->MinorVersion);
1019+
lLineCount = SetupGetLineCountW(InfHandle, SectionName);
1020+
if (lLineCount != -1) goto sectionfound;
1021+
1022+
/* Test with platform.major.minor extension */
1023+
snprintfW(SectionName, LINE_LEN, L"%s%s.%lu.%lu", InfSectionName,
1024+
pExtensionPlatform, pPlatformInfo->MajorVersion, pPlatformInfo->MinorVersion);
1025+
lLineCount = SetupGetLineCountW(InfHandle, SectionName);
1026+
if (lLineCount != -1) goto sectionfound;
1027+
1028+
/* Test with platform.architecture.major extension */
1029+
snprintfW(SectionName, LINE_LEN, L"%s%s%s.%lu", InfSectionName,
1030+
pExtensionPlatform, pExtensionArchitecture, pPlatformInfo->MajorVersion);
1031+
lLineCount = SetupGetLineCountW(InfHandle, SectionName);
1032+
if (lLineCount != -1) goto sectionfound;
1033+
1034+
/* Test with platform.major extension */
1035+
snprintfW(SectionName, LINE_LEN, L"%s%s.%lu", InfSectionName,
1036+
pExtensionPlatform, pPlatformInfo->MajorVersion);
1037+
lLineCount = SetupGetLineCountW(InfHandle, SectionName);
1038+
if (lLineCount != -1) goto sectionfound;
1039+
1040+
/* Test with platform.architecture extension */
1041+
snprintfW(SectionName, LINE_LEN, L"%s%s%s", InfSectionName,
1042+
pExtensionPlatform, pExtensionArchitecture);
1043+
lLineCount = SetupGetLineCountW(InfHandle, SectionName);
1044+
if (lLineCount != -1) goto sectionfound;
1045+
1046+
/* Test with platform extension */
1047+
snprintfW(SectionName, LINE_LEN, L"%s%s", InfSectionName,
1048+
pExtensionPlatform);
1049+
lLineCount = SetupGetLineCountW(InfHandle, SectionName);
1050+
if (lLineCount != -1) goto sectionfound;
1051+
1052+
/* Test without extension */
1053+
snprintfW(SectionName, LINE_LEN, L"%s", InfSectionName);
1054+
lLineCount = SetupGetLineCountW(InfHandle, SectionName);
1055+
if (lLineCount != -1) goto sectionfound;
1056+
1057+
/* No appropriate section found */
1058+
SetLastError(ERROR_INVALID_PARAMETER);
1059+
goto done;
9411060

942-
lstrcpyW(InfSectionWithExt, szBuffer);
943-
if (Extension != NULL)
944-
{
945-
*Extension = (dwLength == dwFullLength) ? NULL : &InfSectionWithExt[dwLength];
946-
}
947-
}
1061+
sectionfound:
1062+
dwFullLength = lstrlenW(SectionName);
1063+
if (InfSectionWithExt != NULL && InfSectionWithExtSize != 0)
1064+
{
1065+
if (InfSectionWithExtSize < (dwFullLength + 1))
1066+
{
1067+
SetLastError(ERROR_INSUFFICIENT_BUFFER);
1068+
goto done;
1069+
}
9481070

949-
if (RequiredSize != NULL)
950-
{
951-
*RequiredSize = dwFullLength + 1;
1071+
lstrcpyW(InfSectionWithExt, SectionName);
1072+
if (Extension != NULL)
1073+
{
1074+
DWORD dwLength = lstrlenW(SectionName);
1075+
*Extension = (dwLength == dwFullLength) ? NULL : &InfSectionWithExt[dwLength];
1076+
}
1077+
}
1078+
1079+
if (RequiredSize != NULL)
1080+
*RequiredSize = dwFullLength + 1;
1081+
1082+
ret = TRUE;
9521083
}
9531084

954-
return TRUE;
1085+
done:
1086+
TRACE("Returning %d\n", ret);
1087+
return ret;
9551088
}
9561089

1090+
9571091
/***********************************************************************
9581092
* SetupDiGetClassDescriptionA (SETUPAPI.@)
9591093
*/

reactos/lib/setupapi/setupapi.spec

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,8 @@
300300
@ stdcall SetupDiEnumDriverInfoA(long ptr long long ptr)
301301
@ stdcall SetupDiEnumDriverInfoW(long ptr long long ptr)
302302
@ stdcall SetupDiGetActualSectionToInstallA(long str str long ptr ptr)
303+
@ stdcall SetupDiGetActualSectionToInstallExA(long str ptr str long ptr ptr ptr)
304+
@ stdcall SetupDiGetActualSectionToInstallExW(long wstr ptr wstr long ptr ptr ptr)
303305
@ stdcall SetupDiGetActualSectionToInstallW(long wstr wstr long ptr ptr)
304306
@ stub SetupDiGetClassBitmapIndex
305307
@ stdcall SetupDiGetClassDescriptionA(ptr str long ptr)

reactos/w32api/include/setupapi.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,6 +1200,8 @@ WINSETUPAPI BOOL WINAPI SetupDiEnumDeviceInterfaces(HDEVINFO,PSP_DEVINFO_DATA,CO
12001200
WINSETUPAPI BOOL WINAPI SetupDiEnumDriverInfoA(HDEVINFO,PSP_DEVINFO_DATA,DWORD,DWORD,PSP_DRVINFO_DATA_A);
12011201
WINSETUPAPI BOOL WINAPI SetupDiEnumDriverInfoW(HDEVINFO,PSP_DEVINFO_DATA,DWORD,DWORD,PSP_DRVINFO_DATA_W);
12021202
WINSETUPAPI BOOL WINAPI SetupDiGetActualSectionToInstallA(HINF,PCSTR,PSTR,DWORD,PDWORD,PSTR*);
1203+
WINSETUPAPI BOOL WINAPI SetupDiGetActualSectionToInstallExA(HINF,PCSTR,PSP_ALTPLATFORM_INFO,PSTR,DWORD,PDWORD,PSTR*,PVOID);
1204+
WINSETUPAPI BOOL WINAPI SetupDiGetActualSectionToInstallExW(HINF,PCWSTR,PSP_ALTPLATFORM_INFO,PWSTR,DWORD,PDWORD,PWSTR*,PVOID);
12031205
WINSETUPAPI BOOL WINAPI SetupDiGetActualSectionToInstallW(HINF,PCWSTR,PWSTR,DWORD,PDWORD,PWSTR*);
12041206
WINSETUPAPI BOOL WINAPI SetupDiGetClassBitmapIndex(CONST GUID*,PINT);
12051207
WINSETUPAPI BOOL WINAPI SetupDiGetClassDescriptionA(CONST GUID*,PSTR,DWORD,PDWORD);
@@ -1475,6 +1477,7 @@ WINSETUPAPI BOOL WINAPI UnmapAndCloseFile(HANDLE, HANDLE, PVOID);
14751477
#define SetupDiCreateDevRegKey SetupDiCreateDevRegKeyW
14761478
#define SetupDiEnumDriverInfo SetupDiEnumDriverInfoW
14771479
#define SetupDiGetActualSectionToInstall SetupDiGetActualSectionToInstallW
1480+
#define SetupDiGetActualSectionToInstallEx SetupDiGetActualSectionToInstallExW
14781481
#define SetupDiGetClassDescriptionEx SetupDiGetClassDescriptionExW
14791482
#define SetupDiGetClassDescription SetupDiGetClassDescriptionW
14801483
#define SetupDiGetClassDevPropertySheets SetupDiGetClassDevPropertySheetsW
@@ -1595,6 +1598,7 @@ WINSETUPAPI BOOL WINAPI UnmapAndCloseFile(HANDLE, HANDLE, PVOID);
15951598
#define SetupDiDeleteInterfaceDeviceData SetupDiDeleteDeviceInterfaceData
15961599
#define SetupDiEnumDriverInfo SetupDiEnumDriverInfoA
15971600
#define SetupDiGetActualSectionToInstall SetupDiGetActualSectionToInstallA
1601+
#define SetupDiGetActualSectionToInstallEx SetupDiGetActualSectionToInstallExA
15981602
#define SetupDiGetClassDescription SetupDiGetClassDescriptionA
15991603
#define SetupDiGetClassDescriptionEx SetupDiGetClassDescriptionExA
16001604
#define SetupDiGetClassDevPropertySheets SetupDiGetClassDevPropertySheetsA

0 commit comments

Comments
 (0)