From 0aa3c187d863e51896df90f5fdd139d4a1a03d62 Mon Sep 17 00:00:00 2001 From: Hans Leidekker Date: Thu, 19 Feb 2009 14:05:54 +0100 Subject: [PATCH] fusion: Use parsed properties for assembly enumeration instead of trying to parse the display name again. The display name passed in may not be normalized, e.g. if the version number is passed as "1.0.0.00000" instead of "1.0.0.0". This patch should also cut down on case insensitive file searches. --- dlls/fusion/asmenum.c | 55 ++++++++++++++++++------------------ dlls/fusion/tests/asmcache.c | 26 +++++++++++++++++ 2 files changed, 53 insertions(+), 28 deletions(-) diff --git a/dlls/fusion/asmenum.c b/dlls/fusion/asmenum.c index 929fff225e5..44a0cb2ad4b 100644 --- a/dlls/fusion/asmenum.c +++ b/dlls/fusion/asmenum.c @@ -162,17 +162,19 @@ static const IAssemblyEnumVtbl AssemblyEnumVtbl = { static void parse_name(IAssemblyName *name, int depth, LPWSTR path, LPWSTR buf) { WCHAR disp[MAX_PATH]; - LPWSTR ptr, end; LPCWSTR verptr, pubkeyptr; HRESULT hr; - DWORD size; + DWORD size, major_size, minor_size, build_size, revision_size; + WORD major, minor, build, revision; static const WCHAR star[] = {'*',0}; static const WCHAR ss_fmt[] = {'%','s','\\','%','s',0}; static const WCHAR verpubkey[] = {'%','s','\\','%','s','_','_','%','s',0}; - static const WCHAR version[] = {'V','e','r','s','i','o','n','=',0}; - static const WCHAR pubkeytok[] = { - 'P','u','b','l','i','c','K','e','y','T','o','k','e','n','=',0}; + static const WCHAR ver_fmt[] = {'%','u','.','%','u','.','%','u','.','%','u',0}; + + WCHAR version[24]; /* strlen("65535") * 4 + 3 + 1 */ + WCHAR token_str[TOKEN_LENGTH + 1]; + BYTE token[BYTES_PER_TOKEN]; if (depth == 0) { @@ -186,36 +188,33 @@ static void parse_name(IAssemblyName *name, int depth, LPWSTR path, LPWSTR buf) } else if (depth == 1) { - size = MAX_PATH; - hr = IAssemblyName_GetDisplayName(name, disp, &size, 0); - if (FAILED(hr)) - { - sprintfW(buf, verpubkey, path, star, star); - return; - } + major_size = sizeof(major); + IAssemblyName_GetProperty(name, ASM_NAME_MAJOR_VERSION, &major, &major_size); - ptr = disp; - verptr = strstrW(ptr, version); - if (!verptr) - verptr = star; + minor_size = sizeof(minor); + IAssemblyName_GetProperty(name, ASM_NAME_MINOR_VERSION, &minor, &minor_size); + + build_size = sizeof(build); + IAssemblyName_GetProperty(name, ASM_NAME_BUILD_NUMBER, &build, &build_size); + + revision_size = sizeof(revision); + IAssemblyName_GetProperty(name, ASM_NAME_REVISION_NUMBER, &revision, &revision_size); + + if (!major_size || !minor_size || !build_size || !revision_size) verptr = star; else { - verptr = strchrW(verptr, '=') + 1; - if ((end = strchrW(verptr, ','))) - { - *end = '\0'; - ptr = end + 1; - } + sprintfW(version, ver_fmt, major, minor, build, revision); + verptr = version; } - pubkeyptr = strstrW(ptr, pubkeytok); - if (!pubkeyptr) - pubkeyptr = star; + size = sizeof(token); + IAssemblyName_GetProperty(name, ASM_NAME_PUBLIC_KEY_TOKEN, token, &size); + + if (!size) pubkeyptr = star; else { - pubkeyptr = strchrW(pubkeyptr, '=') + 1; - if ((end = strchrW(pubkeyptr, ','))) - *end = '\0'; + token_to_str(token, token_str); + pubkeyptr = token_str; } sprintfW(buf, verpubkey, path, verptr, pubkeyptr); diff --git a/dlls/fusion/tests/asmcache.c b/dlls/fusion/tests/asmcache.c index 295a2c4565c..c5e4acd3f1f 100644 --- a/dlls/fusion/tests/asmcache.c +++ b/dlls/fusion/tests/asmcache.c @@ -989,6 +989,8 @@ static void test_QueryAssemblyInfo(void) static const WCHAR wine[] = {'w','i','n','e',0}; static const WCHAR ver[] = { 'V','e','r','s','i','o','n','=','1','.','0','.','0','.','0',0}; + static const WCHAR otherver[] = { + 'V','e','r','s','i','o','n','=','1','.','0','.','0','.','0','0','0','0','0',0}; static const WCHAR badver[] = { 'V','e','r','s','i','o','n','=','1','.','0','.','0','.','1',0}; static const WCHAR culture[] = { @@ -1303,6 +1305,30 @@ static void test_QueryAssemblyInfo(void) "Expected %d, got %d\n", lstrlenW(asmpath) + 1, info.cchBuf); } + /* display name is "wine, Version=1.0.0.00000" */ + INIT_ASM_INFO(); + lstrcpyW(name, wine); + lstrcatW(name, commasep); + lstrcatW(name, otherver); + hr = IAssemblyCache_QueryAssemblyInfo(cache, QUERYASMINFO_FLAG_GETSIZE, + name, &info); + ok(hr == S_OK, "Expected S_OK, got %08x\n", hr); + ok(info.cbAssemblyInfo == sizeof(ASSEMBLY_INFO), + "Expected sizeof(ASSEMBLY_INFO), got %d\n", info.cbAssemblyInfo); + ok(info.dwAssemblyFlags == ASSEMBLYINFO_FLAG_INSTALLED, + "Expected ASSEMBLYINFO_FLAG_INSTALLED, got %08x\n", info.dwAssemblyFlags); + ok(info.uliAssemblySizeInKB.u.HighPart == 0, + "Expected 0, got %d\n", info.uliAssemblySizeInKB.u.HighPart); + todo_wine + { + ok(info.uliAssemblySizeInKB.u.LowPart == 4, + "Expected 4, got %d\n", info.uliAssemblySizeInKB.u.LowPart); + ok(!lstrcmpW(info.pszCurrentAssemblyPathBuf, asmpath), + "Wrong assembly path returned\n"); + ok(info.cchBuf == lstrlenW(asmpath) + 1, + "Expected %d, got %d\n", lstrlenW(asmpath) + 1, info.cchBuf); + } + /* display name is "wine, Version=1.0.0.1", versions don't match */ INIT_ASM_INFO(); lstrcpyW(name, wine);