hlink: Split target at hash in HlinkCreateFromString.
This commit is contained in:
parent
a8183a6317
commit
3e041586a6
|
@ -99,6 +99,8 @@ HRESULT WINAPI HlinkCreateFromString( LPCWSTR pwzTarget, LPCWSTR pwzLocation,
|
||||||
{
|
{
|
||||||
IHlink *hl = NULL;
|
IHlink *hl = NULL;
|
||||||
HRESULT r = S_OK;
|
HRESULT r = S_OK;
|
||||||
|
WCHAR *hash, *tgt;
|
||||||
|
const WCHAR *loc;
|
||||||
|
|
||||||
TRACE("%s %s %s %p %i %p %s %p\n", debugstr_w(pwzTarget),
|
TRACE("%s %s %s %p %i %p %s %p\n", debugstr_w(pwzTarget),
|
||||||
debugstr_w(pwzLocation), debugstr_w(pwzFriendlyName), pihlsite,
|
debugstr_w(pwzLocation), debugstr_w(pwzFriendlyName), pihlsite,
|
||||||
|
@ -108,8 +110,44 @@ HRESULT WINAPI HlinkCreateFromString( LPCWSTR pwzTarget, LPCWSTR pwzLocation,
|
||||||
if (FAILED(r))
|
if (FAILED(r))
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
IHlink_SetStringReference(hl, HLINKSETF_TARGET | HLINKSETF_LOCATION,
|
if (pwzTarget)
|
||||||
pwzTarget, pwzLocation);
|
{
|
||||||
|
hash = strchrW(pwzTarget, '#');
|
||||||
|
if (hash)
|
||||||
|
{
|
||||||
|
if (hash == pwzTarget)
|
||||||
|
tgt = NULL;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int tgt_len = hash - pwzTarget;
|
||||||
|
tgt = heap_alloc((tgt_len + 1) * sizeof(WCHAR));
|
||||||
|
if (!tgt)
|
||||||
|
return E_OUTOFMEMORY;
|
||||||
|
memcpy(tgt, pwzTarget, tgt_len * sizeof(WCHAR));
|
||||||
|
tgt[tgt_len] = 0;
|
||||||
|
}
|
||||||
|
if (!pwzLocation)
|
||||||
|
loc = hash + 1;
|
||||||
|
else
|
||||||
|
loc = pwzLocation;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
tgt = hlink_strdupW(pwzTarget);
|
||||||
|
if (!tgt)
|
||||||
|
return E_OUTOFMEMORY;
|
||||||
|
loc = pwzLocation;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
tgt = NULL;
|
||||||
|
loc = pwzLocation;
|
||||||
|
}
|
||||||
|
|
||||||
|
IHlink_SetStringReference(hl, HLINKSETF_TARGET | HLINKSETF_LOCATION, tgt, loc);
|
||||||
|
|
||||||
|
heap_free(tgt);
|
||||||
|
|
||||||
if (pwzFriendlyName)
|
if (pwzFriendlyName)
|
||||||
IHlink_SetFriendlyName(hl, pwzFriendlyName);
|
IHlink_SetFriendlyName(hl, pwzFriendlyName);
|
||||||
|
|
|
@ -1363,6 +1363,83 @@ static void test_HlinkMoniker(void)
|
||||||
IHlink_Release(hlink);
|
IHlink_Release(hlink);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void test_HashLink(void)
|
||||||
|
{
|
||||||
|
IHlink *hlink;
|
||||||
|
IMoniker *pmk;
|
||||||
|
const WCHAR hash_targetW[] = {'a','f','i','l','e','#','a','n','a','n','c','h','o','r',0};
|
||||||
|
const WCHAR two_hash_targetW[] = {'a','f','i','l','e','#','a','n','a','n','c','h','o','r','#','a','n','o','t','h','e','r',0};
|
||||||
|
const WCHAR hash_no_tgtW[] = {'#','a','n','a','n','c','h','o','r',0};
|
||||||
|
const WCHAR tgt_partW[] = {'a','f','i','l','e',0};
|
||||||
|
const WCHAR loc_partW[] = {'a','n','a','n','c','h','o','r',0};
|
||||||
|
const WCHAR two_hash_loc_partW[] = {'a','n','a','n','c','h','o','r','#','a','n','o','t','h','e','r',0};
|
||||||
|
const WCHAR test_locW[] = {'t','e','s','t','l','o','c',0};
|
||||||
|
HRESULT hres;
|
||||||
|
|
||||||
|
/* simple single hash test */
|
||||||
|
hres = HlinkCreateFromString(hash_targetW, NULL, NULL, NULL, 0, NULL, &IID_IHlink, (void*)&hlink);
|
||||||
|
ok(hres == S_OK, "HlinkCreateFromString failed: 0x%08x\n", hres);
|
||||||
|
ok(hlink != NULL, "Didn't get an hlink\n");
|
||||||
|
|
||||||
|
if(hlink){
|
||||||
|
getStringRef(hlink, tgt_partW, loc_partW);
|
||||||
|
pmk = getMonikerRef(hlink, (IMoniker*)0xFFFFFFFF, loc_partW);
|
||||||
|
ok(pmk != NULL, "Found moniker should not be NULL\n");
|
||||||
|
if(pmk)
|
||||||
|
IMoniker_Release(pmk);
|
||||||
|
|
||||||
|
setStringRef(hlink, HLINKSETF_TARGET, hash_targetW, NULL);
|
||||||
|
getStringRef(hlink, hash_targetW, loc_partW);
|
||||||
|
|
||||||
|
IHlink_Release(hlink);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* two hashes in the target */
|
||||||
|
hres = HlinkCreateFromString(two_hash_targetW, NULL, NULL, NULL, 0, NULL, &IID_IHlink, (void*)&hlink);
|
||||||
|
ok(hres == S_OK, "HlinkCreateFromString failed: 0x%08x\n", hres);
|
||||||
|
ok(hlink != NULL, "Didn't get an hlink\n");
|
||||||
|
|
||||||
|
if(hlink){
|
||||||
|
getStringRef(hlink, tgt_partW, two_hash_loc_partW);
|
||||||
|
pmk = getMonikerRef(hlink, (IMoniker*)0xFFFFFFFF, two_hash_loc_partW);
|
||||||
|
ok(pmk != NULL, "Found moniker should not be NULL\n");
|
||||||
|
if(pmk)
|
||||||
|
IMoniker_Release(pmk);
|
||||||
|
|
||||||
|
IHlink_Release(hlink);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* target with hash plus a location string */
|
||||||
|
hres = HlinkCreateFromString(hash_targetW, test_locW, NULL, NULL, 0, NULL, &IID_IHlink, (void*)&hlink);
|
||||||
|
ok(hres == S_OK, "HlinkCreateFromString failed: 0x%08x\n", hres);
|
||||||
|
ok(hlink != NULL, "Didn't get an hlink\n");
|
||||||
|
|
||||||
|
if(hlink){
|
||||||
|
getStringRef(hlink, tgt_partW, test_locW);
|
||||||
|
pmk = getMonikerRef(hlink, (IMoniker*)0xFFFFFFFF, test_locW);
|
||||||
|
ok(pmk != NULL, "Found moniker should not be NULL\n");
|
||||||
|
if(pmk)
|
||||||
|
IMoniker_Release(pmk);
|
||||||
|
|
||||||
|
IHlink_Release(hlink);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* target with hash containing no "target part" */
|
||||||
|
hres = HlinkCreateFromString(hash_no_tgtW, NULL, NULL, NULL, 0, NULL, &IID_IHlink, (void*)&hlink);
|
||||||
|
ok(hres == S_OK, "HlinkCreateFromString failed: 0x%08x\n", hres);
|
||||||
|
ok(hlink != NULL, "Didn't get an hlink\n");
|
||||||
|
|
||||||
|
if(hlink){
|
||||||
|
getStringRef(hlink, NULL, loc_partW);
|
||||||
|
pmk = getMonikerRef(hlink, (IMoniker*)0xFFFFFFFF, loc_partW);
|
||||||
|
ok(pmk == NULL, "Found moniker should be NULL\n");
|
||||||
|
if(pmk)
|
||||||
|
IMoniker_Release(pmk);
|
||||||
|
|
||||||
|
IHlink_Release(hlink);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
START_TEST(hlink)
|
START_TEST(hlink)
|
||||||
{
|
{
|
||||||
CoInitialize(NULL);
|
CoInitialize(NULL);
|
||||||
|
@ -1377,6 +1454,7 @@ START_TEST(hlink)
|
||||||
test_HlinkGetSetMonikerReference();
|
test_HlinkGetSetMonikerReference();
|
||||||
test_HlinkGetSetStringReference();
|
test_HlinkGetSetStringReference();
|
||||||
test_HlinkMoniker();
|
test_HlinkMoniker();
|
||||||
|
test_HashLink();
|
||||||
|
|
||||||
CoUninitialize();
|
CoUninitialize();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue