pidl.c 64.5 KB
Newer Older
Alexandre Julliard's avatar
Alexandre Julliard committed
1
/*
2
 *    pidl Handling
Alexandre Julliard's avatar
Alexandre Julliard committed
3
 *
4
 *    Copyright 1998    Juergen Schmied
Alexandre Julliard's avatar
Alexandre Julliard committed
5
 *
6 7 8 9 10 11 12 13 14 15 16 17
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19
 *
Alexandre Julliard's avatar
Alexandre Julliard committed
20 21 22
 * NOTES
 *  a pidl == NULL means desktop and is legal
 *
Alexandre Julliard's avatar
Alexandre Julliard committed
23 24 25
 */

#include <ctype.h>
26
#include <stdarg.h>
Alexandre Julliard's avatar
Alexandre Julliard committed
27 28
#include <stdlib.h>
#include <string.h>
29

30
#define COBJMACROS
31
#define NONAMELESSUNION
32

33
#include "windef.h"
34
#include "winbase.h"
35
#include "winreg.h"
36
#include "objbase.h"
37
#include "shlguid.h"
Alexandre Julliard's avatar
Alexandre Julliard committed
38 39
#include "winerror.h"
#include "winnls.h"
40
#include "undocshell.h"
Alexandre Julliard's avatar
Alexandre Julliard committed
41
#include "shell32_main.h"
42
#include "shlwapi.h"
Alexandre Julliard's avatar
Alexandre Julliard committed
43 44

#include "pidl.h"
45
#include "wine/debug.h"
Alexandre Julliard's avatar
Alexandre Julliard committed
46

47 48
WINE_DEFAULT_DEBUG_CHANNEL(pidl);
WINE_DECLARE_DEBUG_CHANNEL(shell);
49

50 51 52
/* from comctl32.dll */
extern LPVOID WINAPI Alloc(INT);
extern BOOL WINAPI Free(LPVOID);
53

54 55 56
static LPSTR _ILGetSTextPointer(LPCITEMIDLIST pidl);
static LPWSTR _ILGetTextPointerW(LPCITEMIDLIST pidl);

57
/*************************************************************************
58
 * ILGetDisplayNameExA
59 60 61 62 63
 *
 * Retrieves the display name of an ItemIDList
 *
 * PARAMS
 *  psf        [I]   Shell Folder to start with, if NULL the desktop is used
64
 *  pidl       [I]   ItemIDList relative to the psf to get the display name for
65 66 67 68 69 70 71 72 73
 *  path       [O]   Filled in with the display name, assumed to be at least MAX_PATH long
 *  type       [I]   Type of display name to retrieve
 *                    0 = SHGDN_FORPARSING | SHGDN_FORADDRESSBAR uses always the desktop as root
 *                    1 = SHGDN_NORMAL relative to the root folder
 *                    2 = SHGDN_INFOLDER relative to the root folder, only the last name
 *
 * RETURNS
 *  True if the display name could be retrieved successfully, False otherwise
 */
74
static BOOL ILGetDisplayNameExA(LPSHELLFOLDER psf, LPCITEMIDLIST pidl, LPSTR path, DWORD type)
75
{
76 77
    BOOL ret = FALSE;
    WCHAR wPath[MAX_PATH];
78

79
    TRACE("%p %p %p %d\n", psf, pidl, path, type);
80

81 82
    if (!pidl || !path)
        return FALSE;
83

84 85 86
    ret = ILGetDisplayNameExW(psf, pidl, wPath, type);
    WideCharToMultiByte(CP_ACP, 0, wPath, -1, path, MAX_PATH, NULL, NULL);
    TRACE("%p %p %s\n", psf, pidl, debugstr_a(path));
87

88
    return ret;
89 90
}

91
BOOL ILGetDisplayNameExW(LPSHELLFOLDER psf, LPCITEMIDLIST pidl, LPWSTR path, DWORD type)
92
{
93 94 95 96 97 98
    LPSHELLFOLDER psfParent, lsf = psf;
    HRESULT ret = NO_ERROR;
    LPCITEMIDLIST pidllast;
    STRRET strret;
    DWORD flag;

99
    TRACE("%p %p %p %x\n", psf, pidl, path, type);
100 101 102 103 104 105 106 107 108 109 110

    if (!pidl || !path)
        return FALSE;

    if (!lsf)
    {
        ret = SHGetDesktopFolder(&lsf);
        if (FAILED(ret))
            return FALSE;
    }

111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
    switch (type)
    {
    case ILGDN_FORPARSING:
        flag = SHGDN_FORPARSING | SHGDN_FORADDRESSBAR;
        break;
    case ILGDN_NORMAL:
        flag = SHGDN_NORMAL;
        break;
    case ILGDN_INFOLDER:
        flag = SHGDN_INFOLDER;
        break;
    default:
        FIXME("Unknown type parameter = %x\n", type);
        flag = SHGDN_FORPARSING | SHGDN_FORADDRESSBAR;
        break;
    }

    if (!*(const WORD*)pidl || type == ILGDN_FORPARSING)
129
    {
130 131
        ret = IShellFolder_GetDisplayNameOf(lsf, pidl, flag, &strret);
        if (SUCCEEDED(ret))
132
        {
133 134
            if(!StrRetToStrNW(path, MAX_PATH, &strret, pidl))
                ret = E_FAIL;
135
        }
136 137 138 139 140
    }
    else
    {
        ret = SHBindToParent(pidl, &IID_IShellFolder, (LPVOID*)&psfParent, &pidllast);
        if (SUCCEEDED(ret))
141
        {
142
            ret = IShellFolder_GetDisplayNameOf(psfParent, pidllast, flag, &strret);
143 144
            if (SUCCEEDED(ret))
            {
145
                if(!StrRetToStrNW(path, MAX_PATH, &strret, pidllast))
146
                    ret = E_FAIL;
147
            }
148
            IShellFolder_Release(psfParent);
149 150 151 152 153 154 155 156
        }
    }

    TRACE("%p %p %s\n", psf, pidl, debugstr_w(path));

    if (!psf)
        IShellFolder_Release(lsf);
    return SUCCEEDED(ret);
157 158
}

159 160 161
/*************************************************************************
 * ILGetDisplayNameEx        [SHELL32.186]
 */
162 163
BOOL WINAPI ILGetDisplayNameEx(LPSHELLFOLDER psf, LPCITEMIDLIST pidl, LPVOID path, DWORD type)
{
164
    TRACE_(shell)("%p %p %p %d\n", psf, pidl, path, type);
165 166 167 168

    if (SHELL_OsIsUnicode())
        return ILGetDisplayNameExW(psf, pidl, path, type);
    return ILGetDisplayNameExA(psf, pidl, path, type);
169 170
}

Alexandre Julliard's avatar
Alexandre Julliard committed
171
/*************************************************************************
172
 * ILGetDisplayName            [SHELL32.15]
Alexandre Julliard's avatar
Alexandre Julliard committed
173
 */
174
BOOL WINAPI ILGetDisplayName(LPCITEMIDLIST pidl, LPVOID path)
175
{
176 177 178 179 180
    TRACE_(shell)("%p %p\n", pidl, path);

    if (SHELL_OsIsUnicode())
        return ILGetDisplayNameExW(NULL, pidl, path, ILGDN_FORPARSING);
    return ILGetDisplayNameExA(NULL, pidl, path, ILGDN_FORPARSING);
Alexandre Julliard's avatar
Alexandre Julliard committed
181
}
182

Alexandre Julliard's avatar
Alexandre Julliard committed
183 184
/*************************************************************************
 * ILFindLastID [SHELL32.16]
185 186 187
 *
 * NOTES
 *   observed: pidl=Desktop return=pidl
Alexandre Julliard's avatar
Alexandre Julliard committed
188
 */
189
LPITEMIDLIST WINAPI ILFindLastID(LPCITEMIDLIST pidl)
190
{
191
    LPCITEMIDLIST   pidlLast = pidl;
Alexandre Julliard's avatar
Alexandre Julliard committed
192

193
    TRACE("(pidl=%p)\n",pidl);
Alexandre Julliard's avatar
Alexandre Julliard committed
194

195 196
    if (!pidl)
        return NULL;
197

198 199 200 201 202 203
    while (pidl->mkid.cb)
    {
        pidlLast = pidl;
        pidl = ILGetNext(pidl);
    }
    return (LPITEMIDLIST)pidlLast;
Alexandre Julliard's avatar
Alexandre Julliard committed
204
}
205

Alexandre Julliard's avatar
Alexandre Julliard committed
206 207
/*************************************************************************
 * ILRemoveLastID [SHELL32.17]
208
 *
Alexandre Julliard's avatar
Alexandre Julliard committed
209
 * NOTES
210
 *   when pidl=Desktop return=FALSE
Alexandre Julliard's avatar
Alexandre Julliard committed
211
 */
212
BOOL WINAPI ILRemoveLastID(LPITEMIDLIST pidl)
213
{
214
    TRACE_(shell)("pidl=%p\n",pidl);
215

216
    if (_ILIsEmpty(pidl))
217
        return FALSE;
218
    ILFindLastID(pidl)->mkid.cb = 0;
219
    return TRUE;
Alexandre Julliard's avatar
Alexandre Julliard committed
220 221 222 223 224 225
}

/*************************************************************************
 * ILClone [SHELL32.18]
 *
 * NOTES
Andreas Mohr's avatar
Andreas Mohr committed
226
 *    duplicate an idlist
Alexandre Julliard's avatar
Alexandre Julliard committed
227 228
 */
LPITEMIDLIST WINAPI ILClone (LPCITEMIDLIST pidl)
229 230 231
{
    DWORD    len;
    LPITEMIDLIST  newpidl;
Alexandre Julliard's avatar
Alexandre Julliard committed
232

233 234
    if (!pidl)
        return NULL;
235

236
    len = ILGetSize(pidl);
237
    newpidl = SHAlloc(len);
238 239
    if (newpidl)
        memcpy(newpidl,pidl,len);
240

241 242
    TRACE("pidl=%p newpidl=%p\n",pidl, newpidl);
    pdump(pidl);
243

244
    return newpidl;
Alexandre Julliard's avatar
Alexandre Julliard committed
245
}
246

Alexandre Julliard's avatar
Alexandre Julliard committed
247 248 249 250 251 252 253
/*************************************************************************
 * ILCloneFirst [SHELL32.19]
 *
 * NOTES
 *  duplicates the first idlist of a complex pidl
 */
LPITEMIDLIST WINAPI ILCloneFirst(LPCITEMIDLIST pidl)
254 255 256
{
    DWORD len;
    LPITEMIDLIST pidlNew = NULL;
257

258
    TRACE("pidl=%p\n", pidl);
259
    pdump(pidl);
260

261 262 263
    if (pidl)
    {
        len = pidl->mkid.cb;
264
        pidlNew = SHAlloc(len+2);
265 266 267
        if (pidlNew)
        {
            memcpy(pidlNew,pidl,len+2);        /* 2 -> mind a desktop pidl */
268

269 270 271 272 273
            if (len)
                ILGetNext(pidlNew)->mkid.cb = 0x00;
        }
    }
    TRACE("-- newpidl=%p\n",pidlNew);
Alexandre Julliard's avatar
Alexandre Julliard committed
274

275
    return pidlNew;
Alexandre Julliard's avatar
Alexandre Julliard committed
276
}
277

278
/*************************************************************************
279
 * ILLoadFromStream (SHELL32.26)
280 281 282 283 284
 *
 * NOTES
 *   the first two bytes are the len, the pidl is following then
 */
HRESULT WINAPI ILLoadFromStream (IStream * pStream, LPITEMIDLIST * ppPidl)
285 286 287 288 289 290 291 292
{
    WORD        wLen = 0;
    DWORD       dwBytesRead;
    HRESULT     ret = E_FAIL;


    TRACE_(shell)("%p %p\n", pStream ,  ppPidl);

293 294
    SHFree(*ppPidl);
    *ppPidl = NULL;
295 296 297

    IStream_AddRef (pStream);

298
    if (SUCCEEDED(IStream_Read(pStream, &wLen, 2, &dwBytesRead)))
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333
    {
        TRACE("PIDL length is %d\n", wLen);
        if (wLen != 0)
        {
            *ppPidl = SHAlloc (wLen);
            if (SUCCEEDED(IStream_Read(pStream, *ppPidl , wLen, &dwBytesRead)))
            {
                TRACE("Stream read OK\n");
                ret = S_OK;
            }
            else
            {
                WARN("reading pidl failed\n");
                SHFree(*ppPidl);
                *ppPidl = NULL;
            }
        }
        else
        {
            *ppPidl = NULL;
            ret = S_OK;
        }
    }

    /* we are not yet fully compatible */
    if (*ppPidl && !pcheck(*ppPidl))
    {
        WARN("Check failed\n");
        SHFree(*ppPidl);
        *ppPidl = NULL;
    }

    IStream_Release (pStream);
    TRACE("done\n");
    return ret;
334
}
335 336

/*************************************************************************
337
 * ILSaveToStream (SHELL32.27)
338 339 340 341 342 343
 *
 * NOTES
 *   the first two bytes are the len, the pidl is following then
 */
HRESULT WINAPI ILSaveToStream (IStream * pStream, LPCITEMIDLIST pPidl)
{
344 345
    WORD        wLen = 0;
    HRESULT        ret = E_FAIL;
346

347
    TRACE_(shell)("%p %p\n", pStream, pPidl);
348

349
    IStream_AddRef (pStream);
350

351
    wLen = ILGetSize(pPidl);
352

353
    if (SUCCEEDED(IStream_Write(pStream, &wLen, 2, NULL)))
354 355 356 357 358
    {
        if (SUCCEEDED(IStream_Write(pStream, pPidl, wLen, NULL)))
            ret = S_OK;
    }
    IStream_Release (pStream);
359

360
    return ret;
361 362
}

363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379
/*************************************************************************
 * SHILCreateFromPath        [SHELL32.28]
 *
 * Create an ItemIDList from a path
 *
 * PARAMS
 *  path       [I]
 *  ppidl      [O]
 *  attributes [I/O] requested attributes on call and actual attributes when
 *                   the function returns
 *
 * RETURNS
 *  NO_ERROR if successful, or an OLE errer code otherwise
 *
 * NOTES
 *  Wrapper for IShellFolder_ParseDisplayName().
 */
380
static HRESULT SHILCreateFromPathA(LPCSTR path, LPITEMIDLIST * ppidl, DWORD * attributes)
381
{
382
    WCHAR lpszDisplayName[MAX_PATH];
383

384
    TRACE_(shell)("%s %p 0x%08x\n", path, ppidl, attributes ? *attributes : 0);
385

386 387
    if (!MultiByteToWideChar(CP_ACP, 0, path, -1, lpszDisplayName, MAX_PATH))
        lpszDisplayName[MAX_PATH-1] = 0;
388

389
    return SHILCreateFromPathW(lpszDisplayName, ppidl, attributes);
390
}
Jon Griffiths's avatar
Jon Griffiths committed
391

392
HRESULT SHILCreateFromPathW(LPCWSTR path, LPITEMIDLIST * ppidl, DWORD * attributes)
393
{
394 395 396
    LPSHELLFOLDER sf;
    DWORD pchEaten;
    HRESULT ret = E_FAIL;
397

398
    TRACE_(shell)("%s %p 0x%08x\n", debugstr_w(path), ppidl, attributes ? *attributes : 0);
399

400 401 402 403 404 405
    if (SUCCEEDED (SHGetDesktopFolder(&sf)))
    {
        ret = IShellFolder_ParseDisplayName(sf, 0, NULL, (LPWSTR)path, &pchEaten, ppidl, attributes);
        IShellFolder_Release(sf);
    }
    return ret;
406
}
Jon Griffiths's avatar
Jon Griffiths committed
407

408
HRESULT WINAPI SHILCreateFromPathAW (LPCVOID path, LPITEMIDLIST * ppidl, DWORD * attributes)
409
{
410 411 412
    if ( SHELL_OsIsUnicode())
        return SHILCreateFromPathW (path, ppidl, attributes);
    return SHILCreateFromPathA (path, ppidl, attributes);
413
}
414 415

/*************************************************************************
416
 * SHCloneSpecialIDList      [SHELL32.89]
417
 *
418 419 420
 * Create an ItemIDList to one of the special folders.

 * PARAMS
421
 *  hwndOwner    [in]
422 423
 *  nFolder      [in]    CSIDL_xxxxx
 *  fCreate      [in]    Create folder if it does not exist
424 425
 *
 * RETURNS
426 427 428
 *  Success: The newly created pidl
 *  Failure: NULL, if inputs are invalid.
 *
429
 * NOTES
430 431 432
 *  exported by ordinal.
 *  Caller is responsible for deallocating the returned ItemIDList with the
 *  shells IMalloc interface, aka ILFree.
433
 */
434
LPITEMIDLIST WINAPI SHCloneSpecialIDList(HWND hwndOwner, DWORD nFolder, BOOL fCreate)
435 436
{
    LPITEMIDLIST ppidl;
437
    TRACE_(shell)("(hwnd=%p,csidl=0x%x,%s).\n", hwndOwner, nFolder, fCreate ? "T" : "F");
438

439 440
    if (fCreate)
        nFolder |= CSIDL_FLAG_CREATE;
441

442 443
    SHGetSpecialFolderLocation(hwndOwner, nFolder, &ppidl);
    return ppidl;
444 445
}

446
/*************************************************************************
447 448 449
 * ILGlobalClone             [SHELL32.20]
 *
 * Clones an ItemIDList using Alloc.
450
 *
451 452 453 454 455 456 457 458
 * PARAMS
 *  pidl       [I]   ItemIDList to clone
 *
 * RETURNS
 *  Newly allocated ItemIDList.
 *
 * NOTES
 *  exported by ordinal.
459 460
 */
LPITEMIDLIST WINAPI ILGlobalClone(LPCITEMIDLIST pidl)
461 462 463
{
    DWORD    len;
    LPITEMIDLIST  newpidl;
464

465 466
    if (!pidl)
        return NULL;
467

468
    len = ILGetSize(pidl);
469
    newpidl = Alloc(len);
470 471
    if (newpidl)
        memcpy(newpidl,pidl,len);
472

473 474
    TRACE("pidl=%p newpidl=%p\n",pidl, newpidl);
    pdump(pidl);
475

476
    return newpidl;
477 478
}

Alexandre Julliard's avatar
Alexandre Julliard committed
479 480 481 482
/*************************************************************************
 * ILIsEqual [SHELL32.21]
 *
 */
483
BOOL WINAPI ILIsEqual(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
484
{
485 486
    char    szData1[MAX_PATH];
    char    szData2[MAX_PATH];
487

488 489
    LPCITEMIDLIST pidltemp1 = pidl1;
    LPCITEMIDLIST pidltemp2 = pidl2;
490

491
    TRACE("pidl1=%p pidl2=%p\n",pidl1, pidl2);
492

493 494 495 496
    /*
     * Explorer reads from registry directly (StreamMRU),
     * so we can only check here
     */
497
    if (!pcheck(pidl1) || !pcheck (pidl2))
498
        return FALSE;
499

500 501
    pdump (pidl1);
    pdump (pidl2);
502

503
    if (!pidl1 || !pidl2)
504
        return FALSE;
505

506 507 508 509
    while (pidltemp1->mkid.cb && pidltemp2->mkid.cb)
    {
        _ILSimpleGetText(pidltemp1, szData1, MAX_PATH);
        _ILSimpleGetText(pidltemp2, szData2, MAX_PATH);
510

511
        if (lstrcmpiA( szData1, szData2 ))
512
            return FALSE;
513

514 515 516
        pidltemp1 = ILGetNext(pidltemp1);
        pidltemp2 = ILGetNext(pidltemp2);
    }
517

518 519
    if (!pidltemp1->mkid.cb && !pidltemp2->mkid.cb)
        return TRUE;
520

521
    return FALSE;
Alexandre Julliard's avatar
Alexandre Julliard committed
522
}
523

524
/*************************************************************************
525 526 527
 * ILIsParent                [SHELL32.23]
 *
 * Verifies that pidlParent is indeed the (immediate) parent of pidlChild.
528
 *
529 530 531 532 533 534 535 536 537 538 539 540 541 542
 * PARAMS
 *  pidlParent [I]
 *  pidlChild  [I]
 *  bImmediate [I]   only return true if the parent is the direct parent
 *                   of the child
 *
 * RETURNS
 *  True if the parent ItemIDlist is a complete part of the child ItemIdList,
 *  False otherwise.
 *
 * NOTES
 *  parent = a/b, child = a/b/c -> true, c is in folder a/b
 *  child = a/b/c/d -> false if bImmediate is true, d is not in folder a/b
 *  child = a/b/c/d -> true if bImmediate is false, d is in a subfolder of a/b
543 544
 *  child = a/b -> false if bImmediate is true
 *  child = a/b -> true if bImmediate is false
545
 */
546
BOOL WINAPI ILIsParent(LPCITEMIDLIST pidlParent, LPCITEMIDLIST pidlChild, BOOL bImmediate)
Juergen Schmied's avatar
Juergen Schmied committed
547
{
548 549 550 551
    char    szData1[MAX_PATH];
    char    szData2[MAX_PATH];
    LPCITEMIDLIST pParent = pidlParent;
    LPCITEMIDLIST pChild = pidlChild;
552

553
    TRACE("%p %p %x\n", pidlParent, pidlChild, bImmediate);
Juergen Schmied's avatar
Juergen Schmied committed
554

555 556
    if (!pParent || !pChild)
        return FALSE;
557

558 559 560 561
    while (pParent->mkid.cb && pChild->mkid.cb)
    {
        _ILSimpleGetText(pParent, szData1, MAX_PATH);
        _ILSimpleGetText(pChild, szData2, MAX_PATH);
Juergen Schmied's avatar
Juergen Schmied committed
562

563
        if (lstrcmpiA( szData1, szData2 ))
564
            return FALSE;
Juergen Schmied's avatar
Juergen Schmied committed
565

566 567 568
        pParent = ILGetNext(pParent);
        pChild = ILGetNext(pChild);
    }
569

570 571
    /* child has shorter name than parent */
    if (pParent->mkid.cb)
572
        return FALSE;
573

574
    /* not immediate descent */
575
    if ((!pChild->mkid.cb || ILGetNext(pChild)->mkid.cb) && bImmediate)
576
        return FALSE;
577

578
    return TRUE;
579 580
}

Alexandre Julliard's avatar
Alexandre Julliard committed
581
/*************************************************************************
582
 * ILFindChild               [SHELL32.24]
Alexandre Julliard's avatar
Alexandre Julliard committed
583
 *
584
 *  Compares elements from pidl1 and pidl2.
585
 *
586 587 588 589 590 591 592 593 594 595 596 597 598
 * PARAMS
 *  pidl1      [I]
 *  pidl2      [I]
 *
 * RETURNS
 *  pidl1 is desktop      pidl2
 *  pidl1 shorter pidl2   pointer to first different element of pidl2
 *                        if there was at least one equal element
 *  pidl2 shorter pidl1   0
 *  pidl2 equal pidl1     pointer to last 0x00-element of pidl2
 *
 * NOTES
 *  exported by ordinal.
Alexandre Julliard's avatar
Alexandre Julliard committed
599
 */
600
LPITEMIDLIST WINAPI ILFindChild(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
601
{
602 603
    char    szData1[MAX_PATH];
    char    szData2[MAX_PATH];
604

605 606 607
    LPCITEMIDLIST pidltemp1 = pidl1;
    LPCITEMIDLIST pidltemp2 = pidl2;
    LPCITEMIDLIST ret=NULL;
608

609
    TRACE("pidl1=%p pidl2=%p\n",pidl1, pidl2);
610

611 612 613 614
    /* explorer reads from registry directly (StreamMRU),
       so we can only check here */
    if ((!pcheck (pidl1)) || (!pcheck (pidl2)))
        return FALSE;
615

616 617
    pdump (pidl1);
    pdump (pidl2);
618

619
    if (_ILIsDesktop(pidl1))
620 621 622 623 624 625 626 627 628
    {
        ret = pidl2;
    }
    else
    {
        while (pidltemp1->mkid.cb && pidltemp2->mkid.cb)
        {
            _ILSimpleGetText(pidltemp1, szData1, MAX_PATH);
            _ILSimpleGetText(pidltemp2, szData2, MAX_PATH);
629

630
            if (lstrcmpiA(szData1,szData2))
631
                break;
632

633 634 635 636
            pidltemp1 = ILGetNext(pidltemp1);
            pidltemp2 = ILGetNext(pidltemp2);
            ret = pidltemp2;
        }
637

638 639 640 641 642
        if (pidltemp1->mkid.cb)
            ret = NULL; /* elements of pidl1 left*/
    }
    TRACE_(shell)("--- %p\n", ret);
    return (LPITEMIDLIST)ret; /* pidl 1 is shorter */
Alexandre Julliard's avatar
Alexandre Julliard committed
643 644 645
}

/*************************************************************************
646 647 648 649 650 651 652 653 654 655 656 657 658
 * ILCombine                 [SHELL32.25]
 *
 * Concatenates two complex ItemIDLists.
 *
 * PARAMS
 *  pidl1      [I]   first complex ItemIDLists
 *  pidl2      [I]   complex ItemIDLists to append
 *
 * RETURNS
 *  if both pidl's == NULL      NULL
 *  if pidl1 == NULL            cloned pidl2
 *  if pidl2 == NULL            cloned pidl1
 *  otherwise new pidl with pidl2 appended to pidl1
Alexandre Julliard's avatar
Alexandre Julliard committed
659 660
 *
 * NOTES
661 662
 *  exported by ordinal.
 *  Does not destroy the passed in ItemIDLists!
Alexandre Julliard's avatar
Alexandre Julliard committed
663
 */
664
LPITEMIDLIST WINAPI ILCombine(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
665
{
666 667
    DWORD    len1,len2;
    LPITEMIDLIST  pidlNew;
668

669
    TRACE("pidl=%p pidl=%p\n",pidl1,pidl2);
670

671
    if (!pidl1 && !pidl2) return NULL;
672

673 674
    pdump (pidl1);
    pdump (pidl2);
675

676
    if (!pidl1)
677 678 679 680
    {
        pidlNew = ILClone(pidl2);
        return pidlNew;
    }
681

682
    if (!pidl2)
683 684 685 686
    {
        pidlNew = ILClone(pidl1);
        return pidlNew;
    }
687

688 689 690
    len1  = ILGetSize(pidl1)-2;
    len2  = ILGetSize(pidl2);
    pidlNew  = SHAlloc(len1+len2);
691

692 693 694 695 696
    if (pidlNew)
    {
        memcpy(pidlNew,pidl1,len1);
        memcpy(((BYTE *)pidlNew)+len1,pidl2,len2);
    }
697

698 699
    /*  TRACE(pidl,"--new pidl=%p\n",pidlNew);*/
    return pidlNew;
Alexandre Julliard's avatar
Alexandre Julliard committed
700
}
701

702 703 704 705 706
/*************************************************************************
 *  SHGetRealIDL [SHELL32.98]
 *
 * NOTES
 */
707
HRESULT WINAPI SHGetRealIDL(LPSHELLFOLDER lpsf, LPCITEMIDLIST pidlSimple, LPITEMIDLIST *pidlReal)
708
{
709 710
    IDataObject* pDataObj;
    HRESULT hr;
711

712 713 714 715 716 717
    hr = IShellFolder_GetUIObjectOf(lpsf, 0, 1, &pidlSimple,
                             &IID_IDataObject, 0, (LPVOID*)&pDataObj);
    if (SUCCEEDED(hr))
    {
        STGMEDIUM medium;
        FORMATETC fmt;
718

719
        fmt.cfFormat = RegisterClipboardFormatW(CFSTR_SHELLIDLISTW);
720 721 722 723
        fmt.ptd = NULL;
        fmt.dwAspect = DVASPECT_CONTENT;
        fmt.lindex = -1;
        fmt.tymed = TYMED_HGLOBAL;
724

725
        hr = IDataObject_GetData(pDataObj, &fmt, &medium);
726

727
        IDataObject_Release(pDataObj);
728

729 730 731
        if (SUCCEEDED(hr))
        {
            /*assert(pida->cidl==1);*/
732
            LPIDA pida = GlobalLock(medium.u.hGlobal);
733

734 735
            LPCITEMIDLIST pidl_folder = (LPCITEMIDLIST) ((LPBYTE)pida+pida->aoffset[0]);
            LPCITEMIDLIST pidl_child = (LPCITEMIDLIST) ((LPBYTE)pida+pida->aoffset[1]);
736

737
            *pidlReal = ILCombine(pidl_folder, pidl_child);
738

739 740
            if (!*pidlReal)
                hr = E_OUTOFMEMORY;
741

742 743 744 745
            GlobalUnlock(medium.u.hGlobal);
            GlobalFree(medium.u.hGlobal);
        }
    }
746

747
    return hr;
748 749
}

Alexandre Julliard's avatar
Alexandre Julliard committed
750 751 752 753
/*************************************************************************
 *  SHLogILFromFSIL [SHELL32.95]
 *
 * NOTES
754
 *  pild = CSIDL_DESKTOP    ret = 0
755
 *  pild = CSIDL_DRIVES     ret = 0
Alexandre Julliard's avatar
Alexandre Julliard committed
756 757
 */
LPITEMIDLIST WINAPI SHLogILFromFSIL(LPITEMIDLIST pidl)
758
{
759
    FIXME("(pidl=%p)\n",pidl);
760

761
    pdump(pidl);
762

763
    return 0;
Alexandre Julliard's avatar
Alexandre Julliard committed
764 765
}

Alexandre Julliard's avatar
Alexandre Julliard committed
766
/*************************************************************************
767 768 769
 * ILGetSize                 [SHELL32.152]
 *
 * Gets the byte size of an ItemIDList including zero terminator
Alexandre Julliard's avatar
Alexandre Julliard committed
770
 *
771 772
 * PARAMS
 *  pidl       [I]   ItemIDList
Alexandre Julliard's avatar
Alexandre Julliard committed
773 774
 *
 * RETURNS
775
 *  size of pidl in bytes
Alexandre Julliard's avatar
Alexandre Julliard committed
776 777 778 779
 *
 * NOTES
 *  exported by ordinal
 */
780
UINT WINAPI ILGetSize(LPCITEMIDLIST pidl)
781
{
782 783
    LPCSHITEMID si = &(pidl->mkid);
    UINT len=0;
Alexandre Julliard's avatar
Alexandre Julliard committed
784

785 786 787 788 789 790 791 792 793 794 795
    if (pidl)
    {
        while (si->cb)
        {
            len += si->cb;
            si  = (LPCSHITEMID)(((const BYTE*)si)+si->cb);
        }
        len += 2;
    }
    TRACE("pidl=%p size=%u\n",pidl, len);
    return len;
Alexandre Julliard's avatar
Alexandre Julliard committed
796
}
797

Alexandre Julliard's avatar
Alexandre Julliard committed
798
/*************************************************************************
799 800 801 802 803 804
 * ILGetNext                 [SHELL32.153]
 *
 * Gets the next ItemID of an ItemIDList
 *
 * PARAMS
 *  pidl       [I]   ItemIDList
Alexandre Julliard's avatar
Alexandre Julliard committed
805
 *
806
 * RETURNS
807 808 809
 *  null -> null
 *  desktop -> null
 *  simple pidl -> pointer to 0x0000 element
Alexandre Julliard's avatar
Alexandre Julliard committed
810
 *
811 812
 * NOTES
 *  exported by ordinal.
Alexandre Julliard's avatar
Alexandre Julliard committed
813
 */
814
LPITEMIDLIST WINAPI ILGetNext(LPCITEMIDLIST pidl)
815
{
816
    WORD len;
817

818
    TRACE("%p\n", pidl);
819

820
    if (pidl)
821 822 823 824 825 826 827 828 829 830
    {
        len =  pidl->mkid.cb;
        if (len)
        {
            pidl = (LPCITEMIDLIST) (((const BYTE*)pidl)+len);
            TRACE("-- %p\n", pidl);
            return (LPITEMIDLIST)pidl;
        }
    }
    return NULL;
Alexandre Julliard's avatar
Alexandre Julliard committed
831
}
832

Alexandre Julliard's avatar
Alexandre Julliard committed
833
/*************************************************************************
834
 * ILAppendID                [SHELL32.154]
835 836 837 838 839 840 841 842 843
 *
 * Adds the single ItemID item to the ItemIDList indicated by pidl.
 * If bEnd is FALSE, inserts the item in the front of the list,
 * otherwise it adds the item to the end. (???)
 *
 * PARAMS
 *  pidl       [I]   ItemIDList to extend
 *  item       [I]   ItemID to prepend/append
 *  bEnd       [I]   Indicates if the item should be appended
Alexandre Julliard's avatar
Alexandre Julliard committed
844 845
 *
 * NOTES
846
 *  Destroys the passed in idlist! (???)
Alexandre Julliard's avatar
Alexandre Julliard committed
847
 */
848
LPITEMIDLIST WINAPI ILAppendID(LPITEMIDLIST pidl, LPCSHITEMID item, BOOL bEnd)
849
{
850
    LPITEMIDLIST idlRet;
851
    LPCITEMIDLIST itemid = (LPCITEMIDLIST)item;
852

853
    WARN("(pidl=%p,pidl=%p,%08u)semi-stub\n",pidl,item,bEnd);
854

855
    pdump (pidl);
856
    pdump (itemid);
857

858 859
    if (_ILIsDesktop(pidl))
    {
860
        idlRet = ILClone(itemid);
861
        SHFree (pidl);
862 863
        return idlRet;
    }
864

865
    if (bEnd)
866
        idlRet = ILCombine(pidl, itemid);
867
    else
868
        idlRet = ILCombine(itemid, pidl);
869

870 871
    SHFree(pidl);
    return idlRet;
Alexandre Julliard's avatar
Alexandre Julliard committed
872
}
873

Alexandre Julliard's avatar
Alexandre Julliard committed
874
/*************************************************************************
875 876 877 878 879 880
 * ILFree                    [SHELL32.155]
 *
 * Frees memory (if not NULL) allocated by SHMalloc allocator
 *
 * PARAMS
 *  pidl         [I]
Alexandre Julliard's avatar
Alexandre Julliard committed
881
 *
882 883 884
 * RETURNS
 *  Nothing
 *
Alexandre Julliard's avatar
Alexandre Julliard committed
885
 * NOTES
886
 *  exported by ordinal
Alexandre Julliard's avatar
Alexandre Julliard committed
887
 */
888
void WINAPI ILFree(LPITEMIDLIST pidl)
Juergen Schmied's avatar
Juergen Schmied committed
889
{
890
    TRACE("(pidl=%p)\n",pidl);
891
    SHFree(pidl);
Alexandre Julliard's avatar
Alexandre Julliard committed
892
}
893

894
/*************************************************************************
895 896 897 898 899 900
 * ILGlobalFree              [SHELL32.156]
 *
 * Frees memory (if not NULL) allocated by Alloc allocator
 *
 * PARAMS
 *  pidl         [I]
901
 *
902 903 904
 * RETURNS
 *  Nothing
 *
905 906
 * NOTES
 *  exported by ordinal.
907
 */
908
void WINAPI ILGlobalFree( LPITEMIDLIST pidl)
909
{
910
    TRACE("%p\n", pidl);
911

912
    Free(pidl);
913
}
914

Alexandre Julliard's avatar
Alexandre Julliard committed
915
/*************************************************************************
916 917 918 919 920 921
 * ILCreateFromPathA         [SHELL32.189]
 *
 * Creates a complex ItemIDList from a path and returns it.
 *
 * PARAMS
 *  path         [I]
Alexandre Julliard's avatar
Alexandre Julliard committed
922
 *
923 924 925 926 927
 * RETURNS
 *  the newly created complex ItemIDList or NULL if failed
 *
 * NOTES
 *  exported by ordinal.
Alexandre Julliard's avatar
Alexandre Julliard committed
928
 */
929
LPITEMIDLIST WINAPI ILCreateFromPathA (LPCSTR path)
930
{
931
    LPITEMIDLIST pidlnew = NULL;
932

933
    TRACE_(shell)("%s\n", debugstr_a(path));
934

935 936 937
    if (SUCCEEDED(SHILCreateFromPathA(path, &pidlnew, NULL)))
        return pidlnew;
    return NULL;
938
}
939 940 941

/*************************************************************************
 * ILCreateFromPathW         [SHELL32.190]
942 943
 *
 * See ILCreateFromPathA.
944
 */
945
LPITEMIDLIST WINAPI ILCreateFromPathW (LPCWSTR path)
946
{
947
    LPITEMIDLIST pidlnew = NULL;
948

949
    TRACE_(shell)("%s\n", debugstr_w(path));
950

951 952 953
    if (SUCCEEDED(SHILCreateFromPathW(path, &pidlnew, NULL)))
        return pidlnew;
    return NULL;
954
}
955 956 957 958

/*************************************************************************
 * ILCreateFromPath          [SHELL32.157]
 */
959
LPITEMIDLIST WINAPI ILCreateFromPathAW (LPCVOID path)
960
{
961 962 963
    if ( SHELL_OsIsUnicode())
        return ILCreateFromPathW (path);
    return ILCreateFromPathA (path);
Alexandre Julliard's avatar
Alexandre Julliard committed
964
}
965

966
/*************************************************************************
967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990
 * _ILParsePathW             [internal]
 *
 * Creates an ItemIDList from a path and returns it.
 *
 * PARAMS
 *  path         [I]   path to parse and convert into an ItemIDList
 *  lpFindFile   [I]   pointer to buffer to initialize the FileSystem
 *                     Bind Data object with
 *  bBindCtx     [I]   indicates to create a BindContext and assign a
 *                     FileSystem Bind Data object
 *  ppidl        [O]   the newly create ItemIDList
 *  prgfInOut    [I/O] requested attributes on input and actual
 *                     attributes on return
 *
 * RETURNS
 *  NO_ERROR on success or an OLE error code
 *
 * NOTES
 *  If either lpFindFile is non-NULL or bBindCtx is TRUE, this function
 *  creates a BindContext object and assigns a FileSystem Bind Data object
 *  to it, passing the BindContext to IShellFolder_ParseDisplayName. Each
 *  IShellFolder uses that FileSystem Bind Data object of the BindContext
 *  to pass data about the current path element to the next object. This
 *  is used to avoid having to verify the current path element on disk, so
991
 *  that creating an ItemIDList from a nonexistent path still can work.
992
 */
993
static HRESULT _ILParsePathW(LPCWSTR path, LPWIN32_FIND_DATAW lpFindFile,
994
                             BOOL bBindCtx, LPITEMIDLIST *ppidl, LPDWORD prgfInOut)
995
{
996 997 998
    LPSHELLFOLDER pSF = NULL;
    LPBC pBC = NULL;
    HRESULT ret;
999

1000
    TRACE("%s %p %d (%p)->%p (%p)->0x%x\n", debugstr_w(path), lpFindFile, bBindCtx,
1001 1002
                                             ppidl, ppidl ? *ppidl : NULL,
                                             prgfInOut, prgfInOut ? *prgfInOut : 0);
1003

1004 1005 1006
    ret = SHGetDesktopFolder(&pSF);
    if (FAILED(ret))
        return ret;
1007

1008 1009
    if (lpFindFile || bBindCtx)
        ret = IFileSystemBindData_Constructor(lpFindFile, &pBC);
1010

1011 1012 1013 1014
    if (SUCCEEDED(ret))
    {
        ret = IShellFolder_ParseDisplayName(pSF, 0, pBC, (LPOLESTR)path, NULL, ppidl, prgfInOut);
    }
1015

1016 1017 1018 1019 1020
    if (pBC)
    {
        IBindCtx_Release(pBC);
        pBC = NULL;
    }
1021

1022
    IShellFolder_Release(pSF);
1023

1024
    if (FAILED(ret) && ppidl)
1025
        *ppidl = NULL;
1026

1027
    TRACE("%s %p 0x%x\n", debugstr_w(path), ppidl ? *ppidl : NULL, prgfInOut ? *prgfInOut : 0);
1028

1029
    return ret;
1030 1031 1032 1033 1034 1035
}

/*************************************************************************
 * SHSimpleIDListFromPath    [SHELL32.162]
 *
 * Creates a simple ItemIDList from a path and returns it. This function
1036
 * does not fail on nonexistent paths.
1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051
 *
 * PARAMS
 *  path         [I]   path to parse and convert into an ItemIDList
 *
 * RETURNS
 *  the newly created simple ItemIDList
 *
 * NOTES
 *  Simple in the name does not mean a relative ItemIDList but rather a
 *  fully qualified list, where only the file name is filled in and the
 *  directory flag for those ItemID elements this is known about, eg.
 *  it is not the last element in the ItemIDList or the actual directory
 *  exists on disk.
 *  exported by ordinal.
 */
1052
LPITEMIDLIST SHSimpleIDListFromPathA(LPCSTR lpszPath)
1053
{
1054 1055 1056
    LPITEMIDLIST pidl = NULL;
    LPWSTR wPath = NULL;
    int len;
1057

1058
    TRACE("%s\n", debugstr_a(lpszPath));
1059

1060 1061 1062
    if (lpszPath)
    {
        len = MultiByteToWideChar(CP_ACP, 0, lpszPath, -1, NULL, 0);
1063
        wPath = heap_alloc(len * sizeof(WCHAR));
1064 1065
        MultiByteToWideChar(CP_ACP, 0, lpszPath, -1, wPath, len);
    }
1066

1067
    _ILParsePathW(wPath, NULL, TRUE, &pidl, NULL);
1068

1069
    heap_free(wPath);
1070 1071
    TRACE("%s %p\n", debugstr_a(lpszPath), pidl);
    return pidl;
1072
}
1073

1074
LPITEMIDLIST SHSimpleIDListFromPathW(LPCWSTR lpszPath)
1075
{
1076
    LPITEMIDLIST pidl = NULL;
1077

1078
    TRACE("%s\n", debugstr_w(lpszPath));
1079

1080 1081 1082
    _ILParsePathW(lpszPath, NULL, TRUE, &pidl, NULL);
    TRACE("%s %p\n", debugstr_w(lpszPath), pidl);
    return pidl;
1083
}
1084

1085
LPITEMIDLIST WINAPI SHSimpleIDListFromPathAW(LPCVOID lpszPath)
1086
{
1087
    if ( SHELL_OsIsUnicode())
1088
        return SHSimpleIDListFromPathW (lpszPath);
1089
    return SHSimpleIDListFromPathA (lpszPath);
1090 1091
}

1092 1093 1094
/*************************************************************************
 * SHGetDataFromIDListA [SHELL32.247]
 *
1095
 * NOTES
1096
 *  the pidl can be a simple one. since we can't get the path out of the pidl
1097
 *  we have to take all data from the pidl
1098
 */
1099 1100
HRESULT WINAPI SHGetDataFromIDListA(LPSHELLFOLDER psf, LPCITEMIDLIST pidl,
                                    int nFormat, LPVOID dest, int len)
1101
{
1102 1103
    LPSTR filename, shortname;
    WIN32_FIND_DATAA * pfd;
1104

1105
    TRACE_(shell)("%p, %p, %d, %p, %d.\n", psf, pidl, nFormat, dest, len);
1106

1107 1108 1109
    pdump(pidl);
    if (!psf || !dest)
        return E_INVALIDARG;
1110

1111 1112 1113 1114
    switch (nFormat)
    {
    case SHGDFIL_FINDDATA:
        pfd = dest;
1115

1116
        if (_ILIsDrive(pidl) || _ILIsSpecialFolder(pidl))
1117
            return E_INVALIDARG;
1118

1119 1120
        if (len < sizeof(WIN32_FIND_DATAA))
            return E_INVALIDARG;
1121

1122 1123 1124 1125
        ZeroMemory(pfd, sizeof (WIN32_FIND_DATAA));
        _ILGetFileDateTime( pidl, &(pfd->ftLastWriteTime));
        pfd->dwFileAttributes = _ILGetFileAttributes(pidl, NULL, 0);
        pfd->nFileSizeLow = _ILGetFileSize ( pidl, NULL, 0);
1126

1127 1128
        filename = _ILGetTextPointer(pidl);
        shortname = _ILGetSTextPointer(pidl);
1129

1130
        if (filename)
1131
            lstrcpynA(pfd->cFileName, filename, sizeof(pfd->cFileName));
1132 1133
        else
            pfd->cFileName[0] = '\0';
1134

1135
        if (shortname)
1136
            lstrcpynA(pfd->cAlternateFileName, shortname, sizeof(pfd->cAlternateFileName));
1137 1138
        else
            pfd->cAlternateFileName[0] = '\0';
1139
        return S_OK;
1140

1141 1142 1143 1144
    case SHGDFIL_NETRESOURCE:
    case SHGDFIL_DESCRIPTIONID:
        FIXME_(shell)("SHGDFIL %i stub\n", nFormat);
        break;
1145

1146 1147 1148 1149 1150
    default:
        ERR_(shell)("Unknown SHGDFIL %i, please report\n", nFormat);
    }

    return E_INVALIDARG;
1151
}
1152

1153
/*************************************************************************
1154
 * SHGetDataFromIDListW [SHELL32.248]
1155 1156
 *
 */
1157 1158
HRESULT WINAPI SHGetDataFromIDListW(LPSHELLFOLDER psf, LPCITEMIDLIST pidl,
                                    int nFormat, LPVOID dest, int len)
1159
{
1160 1161
    LPSTR filename, shortname;
    WIN32_FIND_DATAW * pfd = dest;
Juergen Schmied's avatar
Juergen Schmied committed
1162

1163
    TRACE_(shell)("%p, %p, %d, %p, %d.\n", psf, pidl, nFormat, dest, len);
Juergen Schmied's avatar
Juergen Schmied committed
1164

1165
    pdump(pidl);
1166

1167 1168
    if (!psf || !dest)
        return E_INVALIDARG;
1169

1170 1171 1172 1173
    switch (nFormat)
    {
    case SHGDFIL_FINDDATA:
        pfd = dest;
1174

1175 1176
        if (_ILIsDrive(pidl))
            return E_INVALIDARG;
1177

1178 1179
        if (len < sizeof(WIN32_FIND_DATAW))
            return E_INVALIDARG;
1180

1181
        ZeroMemory(pfd, sizeof (WIN32_FIND_DATAW));
1182 1183 1184
        _ILGetFileDateTime( pidl, &(pfd->ftLastWriteTime));
        pfd->dwFileAttributes = _ILGetFileAttributes(pidl, NULL, 0);
        pfd->nFileSizeLow = _ILGetFileSize ( pidl, NULL, 0);
1185

1186 1187
        filename = _ILGetTextPointer(pidl);
        shortname = _ILGetSTextPointer(pidl);
1188

1189 1190 1191 1192
        if (!filename)
            pfd->cFileName[0] = '\0';
        else if (!MultiByteToWideChar(CP_ACP, 0, filename, -1, pfd->cFileName, MAX_PATH))
            pfd->cFileName[MAX_PATH-1] = 0;
1193

1194 1195 1196 1197
        if (!shortname)
            pfd->cAlternateFileName[0] = '\0';
        else if (!MultiByteToWideChar(CP_ACP, 0, shortname, -1, pfd->cAlternateFileName, 14))
            pfd->cAlternateFileName[13] = 0;
1198
        return S_OK;
1199

1200 1201 1202 1203 1204 1205 1206 1207 1208 1209
    case SHGDFIL_NETRESOURCE:
    case SHGDFIL_DESCRIPTIONID:
        FIXME_(shell)("SHGDFIL %i stub\n", nFormat);
        break;

    default:
        ERR_(shell)("Unknown SHGDFIL %i, please report\n", nFormat);
    }

    return E_INVALIDARG;
1210
}
Alexandre Julliard's avatar
Alexandre Julliard committed
1211

1212
/*************************************************************************
1213
 * SHGetPathFromIDListA        [SHELL32.@][NT 4.0: SHELL32.220]
1214 1215
 *
 * PARAMETERS
1216
 *  pidl,   [IN] pidl
1217 1218
 *  pszPath [OUT] path
 *
1219
 * RETURNS
1220 1221 1222
 *  path from a passed PIDL.
 *
 * NOTES
1223 1224 1225
 *    NULL returns FALSE
 *    desktop pidl gives path to desktop directory back
 *    special pidls returning FALSE
1226
 */
1227
BOOL WINAPI SHGetPathFromIDListA(LPCITEMIDLIST pidl, LPSTR pszPath)
1228
{
1229 1230
    WCHAR wszPath[MAX_PATH];
    BOOL bSuccess;
1231

1232
    bSuccess = SHGetPathFromIDListW(pidl, wszPath);
1233
    WideCharToMultiByte(CP_ACP, 0, wszPath, -1, pszPath, MAX_PATH, NULL, NULL);
1234

1235
    return bSuccess;
1236
}
1237

1238
/*************************************************************************
1239
 * SHGetPathFromIDListW             [SHELL32.@]
1240 1241
 *
 * See SHGetPathFromIDListA.
1242
 */
1243
BOOL WINAPI SHGetPathFromIDListW(LPCITEMIDLIST pidl, LPWSTR pszPath)
1244 1245 1246 1247 1248 1249 1250 1251
{
    return SHGetPathFromIDListEx(pidl, pszPath, MAX_PATH, 0);
}

/*************************************************************************
 * SHGetPathFromIDListEx             [SHELL32.@]
 */
BOOL WINAPI SHGetPathFromIDListEx(LPCITEMIDLIST pidl, WCHAR *path, DWORD path_size, GPFIDL_FLAGS flags)
1252
{
1253
    HRESULT hr;
1254 1255 1256 1257
    LPCITEMIDLIST pidlLast;
    LPSHELLFOLDER psfFolder;
    DWORD dwAttributes;
    STRRET strret;
1258

1259
    TRACE_(shell)("(pidl=%p,%p,%u,%x)\n", pidl, path, path_size, flags);
1260
    pdump(pidl);
1261

1262 1263 1264 1265
    if (flags != GPFIDL_DEFAULT)
        FIXME("Unsupported flags %x\n", flags);

    *path = '\0';
1266 1267
    if (!pidl)
        return FALSE;
1268

1269 1270 1271 1272 1273
    hr = SHBindToParent(pidl, &IID_IShellFolder, (VOID**)&psfFolder, &pidlLast);
    if (FAILED(hr)) return FALSE;

    dwAttributes = SFGAO_FILESYSTEM;
    hr = IShellFolder_GetAttributesOf(psfFolder, 1, &pidlLast, &dwAttributes);
1274 1275 1276 1277
    if (FAILED(hr) || !(dwAttributes & SFGAO_FILESYSTEM)) {
        IShellFolder_Release(psfFolder);
        return FALSE;
    }
1278 1279
                
    hr = IShellFolder_GetDisplayNameOf(psfFolder, pidlLast, SHGDN_FORPARSING, &strret);
1280
    IShellFolder_Release(psfFolder);
1281 1282
    if (FAILED(hr)) return FALSE;

1283
    hr = StrRetToBufW(&strret, pidlLast, path, path_size);
1284

1285
    TRACE_(shell)("-- %s, 0x%08x\n",debugstr_w(path), hr);
1286
    return SUCCEEDED(hr);
1287 1288 1289
}

/*************************************************************************
1290
 *    SHBindToParent        [shell version 5.0]
1291 1292 1293
 */
HRESULT WINAPI SHBindToParent(LPCITEMIDLIST pidl, REFIID riid, LPVOID *ppv, LPCITEMIDLIST *ppidlLast)
{
1294
    IShellFolder    * psfDesktop;
1295
    HRESULT         hr=E_FAIL;
1296

1297 1298
    TRACE_(shell)("pidl=%p\n", pidl);
    pdump(pidl);
1299 1300 1301 1302
    
    if (!pidl || !ppv)
        return E_INVALIDARG;
    
1303 1304 1305
    *ppv = NULL;
    if (ppidlLast)
        *ppidlLast = NULL;
1306

1307 1308 1309 1310
    hr = SHGetDesktopFolder(&psfDesktop);
    if (FAILED(hr))
        return hr;

1311 1312 1313
    if (_ILIsPidlSimple(pidl))
    {
        /* we are on desktop level */
1314
        hr = IShellFolder_QueryInterface(psfDesktop, riid, ppv);
1315 1316 1317
    }
    else
    {
1318
        LPITEMIDLIST pidlParent = ILClone(pidl);
1319
        ILRemoveLastID(pidlParent);
1320
        hr = IShellFolder_BindToObject(psfDesktop, pidlParent, NULL, riid, ppv);
1321 1322
        SHFree (pidlParent);
    }
1323

1324 1325 1326 1327 1328
    IShellFolder_Release(psfDesktop);

    if (SUCCEEDED(hr) && ppidlLast)
        *ppidlLast = ILFindLastID(pidl);

1329
    TRACE_(shell)("-- psf=%p pidl=%p ret=0x%08x\n", *ppv, (ppidlLast)?*ppidlLast:NULL, hr);
1330
    return hr;
1331 1332
}

1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367
HRESULT WINAPI SHBindToObject(IShellFolder *psf, LPCITEMIDLIST pidl, IBindCtx *pbc, REFIID riid, void **ppv)
{
    IShellFolder *psfDesktop = NULL;
    HRESULT hr;

    TRACE_(shell)("%p,%p,%p,%s,%p\n", psf, pidl, pbc, debugstr_guid(riid), ppv);
    pdump(pidl);

    if (!ppv)
        return E_INVALIDARG;

    *ppv = NULL;

    if (!psf)
    {
        hr = SHGetDesktopFolder(&psfDesktop);
        if (FAILED(hr))
            return hr;
        psf = psfDesktop;
    }

    if (_ILIsPidlSimple(pidl))
        /* we are on desktop level */
        hr = IShellFolder_QueryInterface(psf, riid, ppv);
    else
        hr = IShellFolder_BindToObject(psf, pidl, pbc, riid, ppv);

    if (psfDesktop)
        IShellFolder_Release(psfDesktop);

    TRACE_(shell)("-- ppv=%p ret=0x%08x\n", *ppv, hr);
    return hr;
}


1368 1369 1370 1371 1372 1373
/*************************************************************************
 * SHParseDisplayName             [SHELL32.@]
 */
HRESULT WINAPI SHParseDisplayName(LPCWSTR name, IBindCtx *bindctx, LPITEMIDLIST *pidlist,
                                  SFGAOF attr_in, SFGAOF *attr_out)
{
1374 1375 1376 1377 1378 1379 1380
    IShellFolder *desktop;
    HRESULT hr;

    TRACE("%s %p %p %d %p\n", debugstr_w(name), bindctx, pidlist, attr_in, attr_out);

    *pidlist = NULL;

1381
    if (!name) return E_INVALIDARG;
1382 1383 1384 1385 1386 1387 1388 1389 1390 1391

    hr = SHGetDesktopFolder(&desktop);
    if (hr != S_OK) return hr;

    hr = IShellFolder_ParseDisplayName(desktop, NULL, bindctx, (LPWSTR)name, NULL, pidlist, &attr_in);
    if (attr_out) *attr_out = attr_in;

    IShellFolder_Release(desktop);

    return hr;
1392 1393
}

1394 1395 1396 1397 1398 1399 1400 1401 1402 1403
/*************************************************************************
 * SHGetNameFromIDList             [SHELL32.@]
 */
HRESULT WINAPI SHGetNameFromIDList(PCIDLIST_ABSOLUTE pidl, SIGDN sigdnName, PWSTR *ppszName)
{
    IShellFolder *psfparent;
    LPCITEMIDLIST child_pidl;
    STRRET disp_name;
    HRESULT ret;

1404
    TRACE("%p 0x%08x %p\n", pidl, sigdnName, ppszName);
1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451

    *ppszName = NULL;
    ret = SHBindToParent(pidl, &IID_IShellFolder, (void**)&psfparent, &child_pidl);
    if(SUCCEEDED(ret))
    {
        switch(sigdnName)
        {
                                                /* sigdnName & 0xffff */
        case SIGDN_NORMALDISPLAY:               /* SHGDN_NORMAL */
        case SIGDN_PARENTRELATIVEPARSING:       /* SHGDN_INFOLDER | SHGDN_FORPARSING */
        case SIGDN_PARENTRELATIVEEDITING:       /* SHGDN_INFOLDER | SHGDN_FOREDITING */
        case SIGDN_DESKTOPABSOLUTEPARSING:      /* SHGDN_FORPARSING */
        case SIGDN_DESKTOPABSOLUTEEDITING:      /* SHGDN_FOREDITING | SHGDN_FORADDRESSBAR*/
        case SIGDN_PARENTRELATIVEFORADDRESSBAR: /* SIGDN_INFOLDER | SHGDN_FORADDRESSBAR */
        case SIGDN_PARENTRELATIVE:              /* SIGDN_INFOLDER */

            disp_name.uType = STRRET_WSTR;
            ret = IShellFolder_GetDisplayNameOf(psfparent, child_pidl,
                                                sigdnName & 0xffff,
                                                &disp_name);
            if(SUCCEEDED(ret))
                ret = StrRetToStrW(&disp_name, pidl, ppszName);

            break;

        case SIGDN_FILESYSPATH:
            *ppszName = CoTaskMemAlloc(sizeof(WCHAR)*MAX_PATH);
            if(SHGetPathFromIDListW(pidl, *ppszName))
            {
                TRACE("Got string %s\n", debugstr_w(*ppszName));
                ret = S_OK;
            }
            else
            {
                CoTaskMemFree(*ppszName);
                ret = E_INVALIDARG;
            }
            break;

        case SIGDN_URL:
        default:
            FIXME("Unsupported SIGDN %x\n", sigdnName);
            ret = E_FAIL;
        }

        IShellFolder_Release(psfparent);
    }
1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522
    return ret;
}

/*************************************************************************
 * SHGetIDListFromObject             [SHELL32.@]
 */
HRESULT WINAPI SHGetIDListFromObject(IUnknown *punk, PIDLIST_ABSOLUTE *ppidl)
{
    IPersistIDList *ppersidl;
    IPersistFolder2 *ppf2;
    IDataObject *pdo;
    IFolderView *pfv;
    HRESULT ret;

    if(!punk)
        return E_NOINTERFACE;

    *ppidl = NULL;

    /* Try IPersistIDList */
    ret = IUnknown_QueryInterface(punk, &IID_IPersistIDList, (void**)&ppersidl);
    if(SUCCEEDED(ret))
    {
        TRACE("IPersistIDList (%p)\n", ppersidl);
        ret = IPersistIDList_GetIDList(ppersidl, ppidl);
        IPersistIDList_Release(ppersidl);
        if(SUCCEEDED(ret))
            return ret;
    }

    /* Try IPersistFolder2 */
    ret = IUnknown_QueryInterface(punk, &IID_IPersistFolder2, (void**)&ppf2);
    if(SUCCEEDED(ret))
    {
        TRACE("IPersistFolder2 (%p)\n", ppf2);
        ret = IPersistFolder2_GetCurFolder(ppf2, ppidl);
        IPersistFolder2_Release(ppf2);
        if(SUCCEEDED(ret))
            return ret;
    }

    /* Try IDataObject */
    ret = IUnknown_QueryInterface(punk, &IID_IDataObject, (void**)&pdo);
    if(SUCCEEDED(ret))
    {
        IShellItem *psi;
        TRACE("IDataObject (%p)\n", pdo);
        ret = SHGetItemFromDataObject(pdo, DOGIF_ONLY_IF_ONE,
                                      &IID_IShellItem, (void**)&psi);
        if(SUCCEEDED(ret))
        {
            ret = SHGetIDListFromObject((IUnknown*)psi, ppidl);
            IShellItem_Release(psi);
        }
        IDataObject_Release(pdo);

        if(SUCCEEDED(ret))
            return ret;
    }

    /* Try IFolderView */
    ret = IUnknown_QueryInterface(punk, &IID_IFolderView, (void**)&pfv);
    if(SUCCEEDED(ret))
    {
        IShellFolder *psf;
        TRACE("IFolderView (%p)\n", pfv);
        ret = IFolderView_GetFolder(pfv, &IID_IShellFolder, (void**)&psf);
        if(SUCCEEDED(ret))
        {
            /* We might be able to get IPersistFolder2 from a shellfolder. */
            ret = SHGetIDListFromObject((IUnknown*)psf, ppidl);
1523
            IShellFolder_Release(psf);
1524 1525 1526 1527
        }
        IFolderView_Release(pfv);
        return ret;
    }
1528 1529 1530 1531

    return ret;
}

Alexandre Julliard's avatar
Alexandre Julliard committed
1532
/**************************************************************************
1533
 *
1534
 *        internal functions
1535
 *
1536
 *    ### 1. section creating pidls ###
1537 1538
 *
 *************************************************************************
Alexandre Julliard's avatar
Alexandre Julliard committed
1539
 */
1540 1541 1542 1543 1544 1545 1546 1547

/* Basic PIDL constructor.  Allocates size + 5 bytes, where:
 * - two bytes are SHITEMID.cb
 * - one byte is PIDLDATA.type
 * - two bytes are the NULL PIDL terminator
 * Sets type of the returned PIDL to type.
 */
static LPITEMIDLIST _ILAlloc(PIDLTYPE type, unsigned int size)
1548 1549 1550
{
    LPITEMIDLIST pidlOut = NULL;

1551 1552
    pidlOut = SHAlloc(size + 5);
    if(pidlOut)
1553 1554 1555 1556 1557 1558 1559
    {
        LPPIDLDATA pData;
        LPITEMIDLIST pidlNext;

        ZeroMemory(pidlOut, size + 5);
        pidlOut->mkid.cb = size + 3;

1560 1561
        pData = _ILGetDataPointer(pidlOut);
        if (pData)
1562 1563
            pData->type = type;

1564 1565
        pidlNext = ILGetNext(pidlOut);
        if (pidlNext)
1566 1567 1568 1569 1570 1571 1572
            pidlNext->mkid.cb = 0x00;
        TRACE("-- (pidl=%p, size=%u)\n", pidlOut, size);
    }

    return pidlOut;
}

1573
LPITEMIDLIST _ILCreateDesktop(void)
1574 1575 1576 1577 1578 1579 1580 1581
{
    LPITEMIDLIST ret;

    TRACE("()\n");
    ret = SHAlloc(2);
    if (ret)
        ret->mkid.cb = 0;
    return ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
1582
}
1583

1584
LPITEMIDLIST _ILCreateMyComputer(void)
1585 1586 1587
{
    TRACE("()\n");
    return _ILCreateGuid(PT_GUID, &CLSID_MyComputer);
Alexandre Julliard's avatar
Alexandre Julliard committed
1588
}
1589

1590
LPITEMIDLIST _ILCreateMyDocuments(void)
1591 1592 1593 1594 1595
{
    TRACE("()\n");
    return _ILCreateGuid(PT_GUID, &CLSID_MyDocuments);
}

1596
LPITEMIDLIST _ILCreateIExplore(void)
1597 1598 1599
{
    TRACE("()\n");
    return _ILCreateGuid(PT_GUID, &CLSID_Internet);
1600 1601
}

1602
LPITEMIDLIST _ILCreateControlPanel(void)
Juan Lang's avatar
Juan Lang committed
1603 1604 1605 1606 1607 1608
{
    LPITEMIDLIST parent = _ILCreateGuid(PT_GUID, &CLSID_MyComputer), ret = NULL;

    TRACE("()\n");
    if (parent)
    {
1609
        LPITEMIDLIST cpl = _ILCreateGuid(PT_SHELLEXT, &CLSID_ControlPanel);
Juan Lang's avatar
Juan Lang committed
1610 1611 1612 1613 1614 1615 1616 1617 1618

        if (cpl)
        {
            ret = ILCombine(parent, cpl);
            SHFree(cpl);
        }
        SHFree(parent);
    }
    return ret;
1619 1620
}

1621
LPITEMIDLIST _ILCreatePrinters(void)
Juan Lang's avatar
Juan Lang committed
1622 1623 1624 1625 1626 1627
{
    LPITEMIDLIST parent = _ILCreateGuid(PT_GUID, &CLSID_MyComputer), ret = NULL;

    TRACE("()\n");
    if (parent)
    {
1628
        LPITEMIDLIST printers = _ILCreateGuid(PT_YAGUID, &CLSID_Printers);
Juan Lang's avatar
Juan Lang committed
1629 1630 1631 1632 1633 1634 1635 1636 1637

        if (printers)
        {
            ret = ILCombine(parent, printers);
            SHFree(printers);
        }
        SHFree(parent);
    }
    return ret;
1638 1639
}

1640
LPITEMIDLIST _ILCreateNetwork(void)
1641
{
1642 1643
    TRACE("()\n");
    return _ILCreateGuid(PT_GUID, &CLSID_NetworkPlaces);
1644 1645
}

1646
LPITEMIDLIST _ILCreateBitBucket(void)
1647
{
1648 1649
    TRACE("()\n");
    return _ILCreateGuid(PT_GUID, &CLSID_RecycleBin);
1650 1651
}

1652 1653 1654 1655 1656 1657
LPITEMIDLIST _ILCreateNetHood(void)
{
    TRACE("()\n");
    return _ILCreateGuid(PT_GUID, &CLSID_NetworkPlaces);
}

1658 1659 1660 1661
LPITEMIDLIST _ILCreateGuid(PIDLTYPE type, REFIID guid)
{
    LPITEMIDLIST pidlOut;

1662
    if (type == PT_SHELLEXT || type == PT_GUID || type == PT_YAGUID)
1663
    {
1664
        pidlOut = _ILAlloc(type, sizeof(GUIDStruct));
1665 1666 1667 1668
        if (pidlOut)
        {
            LPPIDLDATA pData = _ILGetDataPointer(pidlOut);

1669
            pData->u.guid.guid = *guid;
1670
            TRACE("-- create GUID-pidl %s\n",
1671
                  debugstr_guid(&(pData->u.guid.guid)));
1672 1673 1674 1675 1676 1677 1678 1679
        }
    }
    else
    {
        WARN("%d: invalid type for GUID\n", type);
        pidlOut = NULL;
    }
    return pidlOut;
Alexandre Julliard's avatar
Alexandre Julliard committed
1680
}
1681

1682
LPITEMIDLIST _ILCreateGuidFromStrA(LPCSTR szGUID)
1683
{
1684
    IID iid;
1685

1686
    if (FAILED(SHCLSIDFromStringA(szGUID, &iid)))
1687 1688 1689 1690 1691
    {
        ERR("%s is not a GUID\n", szGUID);
        return NULL;
    }
    return _ILCreateGuid(PT_GUID, &iid);
1692
}
1693

1694 1695 1696 1697
LPITEMIDLIST _ILCreateGuidFromStrW(LPCWSTR szGUID)
{
    IID iid;

1698
    if (FAILED(SHCLSIDFromStringW(szGUID, &iid)))
1699 1700 1701 1702 1703 1704 1705
    {
        ERR("%s is not a GUID\n", debugstr_w(szGUID));
        return NULL;
    }
    return _ILCreateGuid(PT_GUID, &iid);
}

1706
LPITEMIDLIST _ILCreateFromFindDataW( const WIN32_FIND_DATAW *wfd )
1707
{
1708
    DWORD   wlen, alen;
1709 1710
    LPITEMIDLIST pidl;
    PIDLTYPE type;
1711

1712
    if (!wfd)
1713
        return NULL;
Alexandre Julliard's avatar
Alexandre Julliard committed
1714

1715
    TRACE("(%s, %s)\n",debugstr_w(wfd->cAlternateFileName), debugstr_w(wfd->cFileName));
Alexandre Julliard's avatar
Alexandre Julliard committed
1716

1717
    type = (wfd->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? PT_FOLDER : PT_VALUE;
1718

1719
    alen = WideCharToMultiByte( CP_ACP, 0, wfd->cFileName, -1, NULL, 0, NULL, NULL );
1720 1721 1722
    wlen = lstrlenW(wfd->cFileName) + 1;
    pidl = _ILAlloc(type, FIELD_OFFSET(FileStruct, szNames[alen + (alen & 1)]) +
                    FIELD_OFFSET(FileStructW, wszName[wlen]) + sizeof(WORD));
1723
    if (pidl)
1724
    {
1725 1726 1727 1728 1729 1730 1731 1732
        LPPIDLDATA pData = _ILGetDataPointer(pidl);
        FileStruct *fs = &pData->u.file;
        FileStructW *fsw;
        WORD *pOffsetW;

        FileTimeToDosDateTime( &wfd->ftLastWriteTime, &fs->uFileDate, &fs->uFileTime);
        fs->dwFileSize = wfd->nFileSizeLow;
        fs->uFileAttribs = wfd->dwFileAttributes;
1733
        WideCharToMultiByte( CP_ACP, 0, wfd->cFileName, -1, fs->szNames, alen, NULL, NULL );
1734 1735 1736 1737 1738 1739 1740 1741 1742 1743

        fsw = (FileStructW*)(pData->u.file.szNames + alen + (alen & 0x1));
        fsw->cbLen = FIELD_OFFSET(FileStructW, wszName[wlen]) + sizeof(WORD);
        FileTimeToDosDateTime( &wfd->ftCreationTime, &fsw->uCreationDate, &fsw->uCreationTime);
        FileTimeToDosDateTime( &wfd->ftLastAccessTime, &fsw->uLastAccessDate, &fsw->uLastAccessTime);
        memcpy(fsw->wszName, wfd->cFileName, wlen * sizeof(WCHAR));

        pOffsetW = (WORD*)((LPBYTE)pidl + pidl->mkid.cb - sizeof(WORD));
        *pOffsetW = (LPBYTE)fsw - (LPBYTE)pidl;
        TRACE("-- Set Value: %s\n",debugstr_w(fsw->wszName));
1744 1745
    }
    return pidl;
1746

1747 1748
}

1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767
HRESULT _ILCreateFromPathW(LPCWSTR szPath, LPITEMIDLIST* ppidl)
{
    HANDLE hFile;
    WIN32_FIND_DATAW stffile;

    if (!ppidl)
        return E_INVALIDARG;

    hFile = FindFirstFileW(szPath, &stffile);
    if (hFile == INVALID_HANDLE_VALUE)
        return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);

    FindClose(hFile);

    *ppidl = _ILCreateFromFindDataW(&stffile);

    return *ppidl ? S_OK : E_OUTOFMEMORY;
}

1768
LPITEMIDLIST _ILCreateDrive(LPCWSTR lpszNew)
1769
{
1770
    LPITEMIDLIST pidlOut;
1771

1772
    TRACE("(%s)\n",debugstr_w(lpszNew));
1773

1774 1775
    pidlOut = _ILAlloc(PT_DRIVE, sizeof(DriveStruct));
    if (pidlOut)
1776 1777 1778
    {
        LPSTR pszDest;

1779 1780
        pszDest = _ILGetTextPointer(pidlOut);
        if (pszDest)
1781
        {
1782
            strcpy(pszDest, "x:\\");
1783
            pszDest[0]=towupper(lpszNew[0]);
1784 1785 1786 1787
            TRACE("-- create Drive: %s\n", debugstr_a(pszDest));
        }
    }
    return pidlOut;
Alexandre Julliard's avatar
Alexandre Julliard committed
1788 1789
}

1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806
LPITEMIDLIST _ILCreateEntireNetwork(void)
{
    LPITEMIDLIST pidlOut;

    TRACE("\n");

    pidlOut = _ILAlloc(PT_NETWORK, FIELD_OFFSET(PIDLDATA, u.network.szNames[sizeof("Entire Network")]));
    if (pidlOut)
    {
        LPPIDLDATA pData = _ILGetDataPointer(pidlOut);

        pData->u.network.dummy = 0;
        strcpy(pData->u.network.szNames, "Entire Network");
    }
    return pidlOut;
}

Alexandre Julliard's avatar
Alexandre Julliard committed
1807
/**************************************************************************
1808 1809 1810
 *  _ILGetDrive()
 *
 *  Gets the text for the drive eg. 'c:\'
1811 1812
 *
 * RETURNS
1813
 *  strlen (lpszText)
Alexandre Julliard's avatar
Alexandre Julliard committed
1814
 */
1815
DWORD _ILGetDrive(LPCITEMIDLIST pidl,LPSTR pOut, UINT uSize)
1816 1817
{
    TRACE("(%p,%p,%u)\n",pidl,pOut,uSize);
1818

1819 1820
    if(_ILIsMyComputer(pidl))
        pidl = ILGetNext(pidl);
1821

1822 1823
    if (pidl && _ILIsDrive(pidl))
        return _ILSimpleGetText(pidl, pOut, uSize);
1824

1825
    return 0;
1826 1827 1828 1829
}

/**************************************************************************
 *
1830
 *    ### 2. section testing pidls ###
1831 1832
 *
 **************************************************************************
1833
 *  _ILIsUnicode()
1834 1835 1836 1837 1838 1839 1840 1841
 *  _ILIsDesktop()
 *  _ILIsMyComputer()
 *  _ILIsSpecialFolder()
 *  _ILIsDrive()
 *  _ILIsFolder()
 *  _ILIsValue()
 *  _ILIsPidlSimple()
 */
1842 1843 1844 1845 1846 1847 1848 1849 1850
BOOL _ILIsUnicode(LPCITEMIDLIST pidl)
{
    LPPIDLDATA lpPData = _ILGetDataPointer(pidl);

    TRACE("(%p)\n",pidl);

    return (pidl && lpPData && PT_VALUEW == lpPData->type);
}

1851
BOOL _ILIsDesktop(LPCITEMIDLIST pidl)
1852 1853 1854
{
    TRACE("(%p)\n",pidl);

1855
    return !pidl || !pidl->mkid.cb;
1856 1857
}

1858
BOOL _ILIsMyComputer(LPCITEMIDLIST pidl)
1859
{
1860
    REFIID iid = _ILGetGUIDPointer(pidl);
1861

1862
    TRACE("(%p)\n",pidl);
1863

1864 1865 1866
    if (iid)
        return IsEqualIID(iid, &CLSID_MyComputer);
    return FALSE;
1867 1868
}

1869
BOOL _ILIsSpecialFolder (LPCITEMIDLIST pidl)
1870
{
1871 1872 1873 1874
    LPPIDLDATA lpPData = _ILGetDataPointer(pidl);

    TRACE("(%p)\n",pidl);

Huw Davies's avatar
Huw Davies committed
1875
    return (pidl && ( (lpPData && (PT_GUID== lpPData->type || PT_SHELLEXT== lpPData->type || PT_YAGUID == lpPData->type)) ||
1876 1877
              (pidl && pidl->mkid.cb == 0x00)
            ));
1878 1879
}

1880
BOOL _ILIsDrive(LPCITEMIDLIST pidl)
1881 1882 1883 1884 1885 1886 1887 1888 1889
{
    LPPIDLDATA lpPData = _ILGetDataPointer(pidl);

    TRACE("(%p)\n",pidl);

    return (pidl && lpPData && (PT_DRIVE == lpPData->type ||
                    PT_DRIVE1 == lpPData->type ||
                    PT_DRIVE2 == lpPData->type ||
                    PT_DRIVE3 == lpPData->type));
1890 1891
}

1892
BOOL _ILIsFolder(LPCITEMIDLIST pidl)
1893 1894 1895 1896 1897 1898
{
    LPPIDLDATA lpPData = _ILGetDataPointer(pidl);

    TRACE("(%p)\n",pidl);

    return (pidl && lpPData && (PT_FOLDER == lpPData->type || PT_FOLDER1 == lpPData->type));
1899 1900
}

1901
BOOL _ILIsValue(LPCITEMIDLIST pidl)
1902 1903 1904 1905 1906 1907
{
    LPPIDLDATA lpPData = _ILGetDataPointer(pidl);

    TRACE("(%p)\n",pidl);

    return (pidl && lpPData && PT_VALUE == lpPData->type);
1908 1909
}

1910
BOOL _ILIsCPanelStruct(LPCITEMIDLIST pidl)
1911 1912 1913 1914 1915 1916
{
    LPPIDLDATA lpPData = _ILGetDataPointer(pidl);

    TRACE("(%p)\n",pidl);

    return (pidl && lpPData && (lpPData->type == 0));
1917 1918
}

1919
/**************************************************************************
1920
 *    _ILIsPidlSimple
1921
 */
1922
BOOL _ILIsPidlSimple(LPCITEMIDLIST pidl)
1923
{
1924
    BOOL ret = TRUE;
1925

1926 1927 1928 1929
    if(! _ILIsDesktop(pidl))    /* pidl=NULL or mkid.cb=0 */
    {
        WORD len = pidl->mkid.cb;
        LPCITEMIDLIST pidlnext = (LPCITEMIDLIST) (((const BYTE*)pidl) + len );
1930

1931 1932 1933 1934 1935 1936
        if (pidlnext->mkid.cb)
            ret = FALSE;
    }

    TRACE("%s\n", ret ? "Yes" : "No");
    return ret;
1937 1938 1939 1940
}

/**************************************************************************
 *
1941
 *    ### 3. section getting values from pidls ###
1942 1943 1944 1945 1946 1947 1948
 */

 /**************************************************************************
 *  _ILSimpleGetText
 *
 * gets the text for the first item in the pidl (eg. simple pidl)
 *
1949
 * returns the length of the string
1950
 */
1951
DWORD _ILSimpleGetText (LPCITEMIDLIST pidl, LPSTR szOut, UINT uOutSize)
1952
{
1953 1954
    DWORD        dwReturn=0;
    LPSTR        szSrc;
1955
    LPWSTR       szSrcW;
1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985
    GUID const * riid;
    char szTemp[MAX_PATH];

    TRACE("(%p %p %x)\n",pidl,szOut,uOutSize);

    if (!pidl)
        return 0;

    if (szOut)
        *szOut = 0;

    if (_ILIsDesktop(pidl))
    {
        /* desktop */
        if (HCR_GetClassNameA(&CLSID_ShellDesktop, szTemp, MAX_PATH))
        {
            if (szOut)
                lstrcpynA(szOut, szTemp, uOutSize);

            dwReturn = strlen (szTemp);
        }
    }
    else if (( szSrc = _ILGetTextPointer(pidl) ))
    {
        /* filesystem */
        if (szOut)
            lstrcpynA(szOut, szSrc, uOutSize);

        dwReturn = strlen(szSrc);
    }
1986 1987 1988 1989 1990 1991 1992 1993 1994 1995
    else if (( szSrcW = _ILGetTextPointerW(pidl) ))
    {
        /* unicode filesystem */
        WideCharToMultiByte(CP_ACP,0,szSrcW, -1, szTemp, MAX_PATH, NULL, NULL);

        if (szOut)
            lstrcpynA(szOut, szTemp, uOutSize);

        dwReturn = strlen (szTemp);
    }
1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011
    else if (( riid = _ILGetGUIDPointer(pidl) ))
    {
        /* special folder */
        if ( HCR_GetClassNameA(riid, szTemp, MAX_PATH) )
        {
            if (szOut)
                lstrcpynA(szOut, szTemp, uOutSize);

            dwReturn = strlen (szTemp);
        }
    }
    else
    {
        ERR("-- no text\n");
    }

2012
    TRACE("-- (%p=%s 0x%08x)\n",szOut,debugstr_a(szOut),dwReturn);
2013
    return dwReturn;
Alexandre Julliard's avatar
Alexandre Julliard committed
2014 2015
}

2016 2017 2018 2019 2020 2021 2022 2023 2024
 /**************************************************************************
 *  _ILSimpleGetTextW
 *
 * gets the text for the first item in the pidl (eg. simple pidl)
 *
 * returns the length of the string
 */
DWORD _ILSimpleGetTextW (LPCITEMIDLIST pidl, LPWSTR szOut, UINT uOutSize)
{
2025 2026
    DWORD   dwReturn;
    FileStructW *pFileStructW = _ILGetFileStructW(pidl);
2027

2028
    TRACE("(%p %p %x)\n",pidl,szOut,uOutSize);
2029

2030 2031 2032 2033
    if (pFileStructW) {
        lstrcpynW(szOut, pFileStructW->wszName, uOutSize);
        dwReturn = lstrlenW(pFileStructW->wszName);
    } else {
2034 2035 2036 2037 2038
        GUID const * riid;
        WCHAR szTemp[MAX_PATH];
        LPSTR szSrc;
        LPWSTR szSrcW;
        dwReturn=0;
2039

2040 2041 2042 2043
        if (!pidl)
            return 0;

        if (szOut)
2044
            *szOut = 0;
2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089

        if (_ILIsDesktop(pidl))
        {
            /* desktop */
            if (HCR_GetClassNameW(&CLSID_ShellDesktop, szTemp, MAX_PATH))
            {
                if (szOut)
                    lstrcpynW(szOut, szTemp, uOutSize);

                dwReturn = lstrlenW (szTemp);
            }
        }
        else if (( szSrcW = _ILGetTextPointerW(pidl) ))
        {
            /* unicode filesystem */
            if (szOut)
                lstrcpynW(szOut, szSrcW, uOutSize);

            dwReturn = lstrlenW(szSrcW);
        }
        else if (( szSrc = _ILGetTextPointer(pidl) ))
        {
            /* filesystem */
            MultiByteToWideChar(CP_ACP, 0, szSrc, -1, szTemp, MAX_PATH);

            if (szOut)
                lstrcpynW(szOut, szTemp, uOutSize);

            dwReturn = lstrlenW (szTemp);
        }
        else if (( riid = _ILGetGUIDPointer(pidl) ))
        {
            /* special folder */
            if ( HCR_GetClassNameW(riid, szTemp, MAX_PATH) )
            {
                if (szOut)
                    lstrcpynW(szOut, szTemp, uOutSize);

                dwReturn = lstrlenW (szTemp);
            }
        }
        else
        {
            ERR("-- no text\n");
        }
2090
    }
2091

2092
    TRACE("-- (%p=%s 0x%08x)\n",szOut,debugstr_w(szOut),dwReturn);
2093
    return dwReturn;
2094 2095
}

Alexandre Julliard's avatar
Alexandre Julliard committed
2096
/**************************************************************************
2097
 *
2098
 *    ### 4. getting pointers to parts of pidls ###
2099 2100
 *
 **************************************************************************
Alexandre Julliard's avatar
Alexandre Julliard committed
2101
 *  _ILGetDataPointer()
Alexandre Julliard's avatar
Alexandre Julliard committed
2102
 */
2103
LPPIDLDATA _ILGetDataPointer(LPCITEMIDLIST pidl)
2104
{
2105
    if(!_ILIsEmpty(pidl))
2106
        return (LPPIDLDATA)pidl->mkid.abID;
2107
    return NULL;
Alexandre Julliard's avatar
Alexandre Julliard committed
2108
}
2109

2110 2111 2112 2113
/**************************************************************************
 *  _ILGetTextPointerW()
 * gets a pointer to the unicode long filename string stored in the pidl
 */
2114
static LPWSTR _ILGetTextPointerW(LPCITEMIDLIST pidl)
2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153
{
    /* TRACE(pidl,"(pidl%p)\n", pidl);*/

    LPPIDLDATA pdata = _ILGetDataPointer(pidl);

    if (!pdata)
        return NULL;

    switch (pdata->type)
    {
    case PT_GUID:
    case PT_SHELLEXT:
    case PT_YAGUID:
        return NULL;

    case PT_DRIVE:
    case PT_DRIVE1:
    case PT_DRIVE2:
    case PT_DRIVE3:
        /*return (LPSTR)&(pdata->u.drive.szDriveName);*/
        return NULL;

    case PT_FOLDER:
    case PT_FOLDER1:
    case PT_VALUE:
    case PT_IESPECIAL1:
    case PT_IESPECIAL2:
        /*return (LPSTR)&(pdata->u.file.szNames);*/
        return NULL;

    case PT_WORKGRP:
    case PT_COMP:
    case PT_NETWORK:
    case PT_NETPROVIDER:
    case PT_SHARE:
        /*return (LPSTR)&(pdata->u.network.szNames);*/
        return NULL;

    case PT_VALUEW:
2154
        return (LPWSTR)pdata->u.file.szNames;
2155 2156 2157 2158 2159
    }
    return NULL;
}


Alexandre Julliard's avatar
Alexandre Julliard committed
2160
/**************************************************************************
Alexandre Julliard's avatar
Alexandre Julliard committed
2161
 *  _ILGetTextPointer()
2162
 * gets a pointer to the long filename string stored in the pidl
Alexandre Julliard's avatar
Alexandre Julliard committed
2163
 */
2164
LPSTR _ILGetTextPointer(LPCITEMIDLIST pidl)
2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183
{
    /* TRACE(pidl,"(pidl%p)\n", pidl);*/

    LPPIDLDATA pdata = _ILGetDataPointer(pidl);

    if (!pdata)
        return NULL;

    switch (pdata->type)
    {
    case PT_GUID:
    case PT_SHELLEXT:
    case PT_YAGUID:
        return NULL;

    case PT_DRIVE:
    case PT_DRIVE1:
    case PT_DRIVE2:
    case PT_DRIVE3:
2184
        return pdata->u.drive.szDriveName;
2185 2186 2187 2188 2189 2190

    case PT_FOLDER:
    case PT_FOLDER1:
    case PT_VALUE:
    case PT_IESPECIAL1:
    case PT_IESPECIAL2:
2191
        return pdata->u.file.szNames;
2192 2193 2194 2195 2196 2197

    case PT_WORKGRP:
    case PT_COMP:
    case PT_NETWORK:
    case PT_NETPROVIDER:
    case PT_SHARE:
2198
        return pdata->u.network.szNames;
2199 2200
    }
    return NULL;
2201
}
2202

2203 2204
/**************************************************************************
 *  _ILGetSTextPointer()
2205
 * gets a pointer to the short filename string stored in the pidl
2206
 */
2207
static LPSTR _ILGetSTextPointer(LPCITEMIDLIST pidl)
2208 2209
{
    /* TRACE(pidl,"(pidl%p)\n", pidl); */
2210

2211
    LPPIDLDATA pdata =_ILGetDataPointer(pidl);
2212

2213 2214
    if (!pdata)
        return NULL;
2215

2216 2217 2218 2219 2220 2221
    switch (pdata->type)
    {
    case PT_FOLDER:
    case PT_VALUE:
    case PT_IESPECIAL1:
    case PT_IESPECIAL2:
2222
        return pdata->u.file.szNames + strlen (pdata->u.file.szNames) + 1;
2223 2224

    case PT_WORKGRP:
2225
        return pdata->u.network.szNames + strlen (pdata->u.network.szNames) + 1;
2226 2227
    }
    return NULL;
Alexandre Julliard's avatar
Alexandre Julliard committed
2228
}
2229 2230 2231 2232 2233 2234

/**************************************************************************
 * _ILGetGUIDPointer()
 *
 * returns reference to guid stored in some pidls
 */
2235
IID* _ILGetGUIDPointer(LPCITEMIDLIST pidl)
2236
{
2237 2238 2239
    LPPIDLDATA pdata =_ILGetDataPointer(pidl);

    TRACE("%p\n", pidl);
2240

2241 2242
    if (!pdata)
        return NULL;
Alexandre Julliard's avatar
Alexandre Julliard committed
2243

2244 2245 2246 2247 2248
    TRACE("pdata->type 0x%04x\n", pdata->type);
    switch (pdata->type)
    {
    case PT_SHELLEXT:
    case PT_GUID:
Huw Davies's avatar
Huw Davies committed
2249
    case PT_YAGUID:
2250
        return &(pdata->u.guid.guid);
Alexandre Julliard's avatar
Alexandre Julliard committed
2251

2252 2253 2254 2255 2256
    default:
        TRACE("Unknown pidl type 0x%04x\n", pdata->type);
        break;
    }
    return NULL;
2257 2258
}

2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277
/******************************************************************************
 * _ILGetFileStructW [Internal]
 *
 * Get pointer the a SHITEMID's FileStructW field if present
 *
 * PARAMS
 *  pidl [I] The SHITEMID
 *
 * RETURNS
 *  Success: Pointer to pidl's FileStructW field.
 *  Failure: NULL
 */
FileStructW* _ILGetFileStructW(LPCITEMIDLIST pidl) {
    FileStructW *pFileStructW;
    WORD cbOffset;
    
    if (!(_ILIsValue(pidl) || _ILIsFolder(pidl)))
        return NULL;

2278
    cbOffset = *(const WORD *)((const BYTE *)pidl + pidl->mkid.cb - sizeof(WORD));
2279 2280 2281 2282 2283
    pFileStructW = (FileStructW*)((LPBYTE)pidl + cbOffset);

    /* Currently I don't see a fool prove way to figure out if a pidl is for sure of WinXP
     * style with a FileStructW member. If we switch all our shellfolder-implementations to
     * the new format, this won't be a problem. For now, we do as many sanity checks as possible. */
2284
    if ((cbOffset & 0x1) || /* FileStructW member is word aligned in the pidl */
2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297
        /* FileStructW is positioned after FileStruct */
        cbOffset < sizeof(pidl->mkid.cb) + sizeof(PIDLTYPE) + sizeof(FileStruct) ||
        /* There has to be enough space at cbOffset in the pidl to hold FileStructW and cbOffset */
        cbOffset > pidl->mkid.cb - sizeof(cbOffset) - sizeof(FileStructW) ||
        pidl->mkid.cb != cbOffset + pFileStructW->cbLen)
    {
        WARN("Invalid pidl format (cbOffset = %d)!\n", cbOffset);
        return NULL;
    }

    return pFileStructW;
}

2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310
/*************************************************************************
 * _ILGetFileDateTime
 *
 * Given the ItemIdList, get the FileTime
 *
 * PARAMS
 *      pidl        [I] The ItemIDList
 *      pFt         [I] the resulted FILETIME of the file
 *
 * RETURNS
 *     True if Successful
 *
 * NOTES
2311
 *
2312 2313 2314
 */
BOOL _ILGetFileDateTime(LPCITEMIDLIST pidl, FILETIME *pFt)
{
2315
    LPPIDLDATA pdata = _ILGetDataPointer(pidl);
2316

2317 2318
    if (!pdata)
        return FALSE;
Juergen Schmied's avatar
Juergen Schmied committed
2319

2320
    switch (pdata->type)
2321
    {
2322 2323 2324 2325 2326 2327
    case PT_FOLDER:
    case PT_VALUE:
        DosDateTimeToFileTime(pdata->u.file.uFileDate, pdata->u.file.uFileTime, pFt);
        break;
    default:
        return FALSE;
2328 2329 2330 2331
    }
    return TRUE;
}

2332
BOOL _ILGetFileDate (LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
2333
{
2334 2335 2336
    FILETIME ft,lft;
    SYSTEMTIME time;
    BOOL ret;
2337

2338 2339 2340 2341
    if (_ILGetFileDateTime( pidl, &ft ))
    {
        FileTimeToLocalFileTime(&ft, &lft);
        FileTimeToSystemTime (&lft, &time);
2342

2343
        ret = GetDateFormatA(LOCALE_USER_DEFAULT,DATE_SHORTDATE,&time, NULL,  pOut, uOutSize);
2344 2345 2346 2347 2348 2349
        if (ret) 
        {
            /* Append space + time without seconds */
            pOut[ret-1] = ' ';
            GetTimeFormatA(LOCALE_USER_DEFAULT, TIME_NOSECONDS, &time, NULL, &pOut[ret], uOutSize - ret);
        }
2350 2351 2352 2353 2354 2355 2356
    }
    else
    {
        pOut[0] = '\0';
        ret = FALSE;
    }
    return ret;
2357
}
2358

2359 2360 2361 2362 2363 2364
/*************************************************************************
 * _ILGetFileSize
 *
 * Given the ItemIdList, get the FileSize
 *
 * PARAMS
2365 2366 2367
 *    pidl     [I] The ItemIDList
 *    pOut     [I] The buffer to save the result
 *    uOutsize [I] The size of the buffer
2368 2369
 *
 * RETURNS
2370
 *    The FileSize
2371 2372
 *
 * NOTES
2373
 *    pOut can be null when no string is needed
2374
 *
2375
 */
2376
DWORD _ILGetFileSize (LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
2377
{
2378 2379
    LPPIDLDATA pdata = _ILGetDataPointer(pidl);
    DWORD dwSize;
2380

2381 2382
    if (!pdata)
        return 0;
Juergen Schmied's avatar
Juergen Schmied committed
2383

2384 2385 2386 2387 2388
    switch (pdata->type)
    {
    case PT_VALUE:
        dwSize = pdata->u.file.dwFileSize;
        if (pOut)
2389
            StrFormatKBSizeA(dwSize, pOut, uOutSize);
2390 2391 2392 2393 2394
        return dwSize;
    }
    if (pOut)
        *pOut = 0x00;
    return 0;
2395
}
2396

2397
BOOL _ILGetExtension (LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
2398
{
2399 2400 2401
    char szTemp[MAX_PATH];
    const char * pPoint;
    LPCITEMIDLIST  pidlTemp=pidl;
2402

2403
    TRACE("pidl=%p\n",pidl);
2404

2405 2406
    if (!pidl)
        return FALSE;
2407

2408
    pidlTemp = ILFindLastID(pidl);
2409

2410 2411 2412 2413
    if (!_ILIsValue(pidlTemp))
        return FALSE;
    if (!_ILSimpleGetText(pidlTemp, szTemp, MAX_PATH))
        return FALSE;
2414

2415
    pPoint = PathFindExtensionA(szTemp);
2416

2417 2418
    if (!*pPoint)
        return FALSE;
Juergen Schmied's avatar
Juergen Schmied committed
2419

2420 2421 2422
    pPoint++;
    lstrcpynA(pOut, pPoint, uOutSize);
    TRACE("%s\n",pOut);
2423

2424
    return TRUE;
2425
}
2426

2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437
/*************************************************************************
 * _ILGetFileType
 *
 * Given the ItemIdList, get the file type description
 *
 * PARAMS
 *      pidl        [I] The ItemIDList (simple)
 *      pOut        [I] The buffer to save the result
 *      uOutsize    [I] The size of the buffer
 *
 * RETURNS
2438
 *    nothing
2439 2440
 *
 * NOTES
2441
 *    This function copies as much as possible into the buffer.
2442 2443 2444
 */
void _ILGetFileType(LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
{
2445 2446 2447 2448
    if(_ILIsValue(pidl))
    {
        char sTemp[64];

2449 2450 2451 2452 2453
        /* "name" or "name." or any unhandled => "File" */
        lstrcpynA (pOut, "File", uOutSize);

        /* If there's space for more, try to get a better description. */
        if (uOutSize > 6 && _ILGetExtension (pidl, sTemp, 64))
2454 2455
        {
            if (!( HCR_MapTypeToValueA(sTemp, sTemp, 64, TRUE)
2456 2457
                && HCR_MapTypeToValueA(sTemp, pOut, uOutSize, FALSE ))
                && sTemp[0])
2458 2459
            {
                lstrcpynA (pOut, sTemp, uOutSize - 6);
2460
                strcat (pOut, " file");
2461 2462 2463 2464 2465
            }
        }
    }
    else
        lstrcpynA(pOut, "Folder", uOutSize);
2466 2467 2468
}

/*************************************************************************
2469
 * _ILGetFileAttributes
2470 2471 2472 2473 2474 2475 2476 2477 2478
 *
 * Given the ItemIdList, get the Attrib string format
 *
 * PARAMS
 *      pidl        [I] The ItemIDList
 *      pOut        [I] The buffer to save the result
 *      uOutsize    [I] The size of the Buffer
 *
 * RETURNS
2479
 *     Attributes
2480
 *
Juergen Schmied's avatar
Juergen Schmied committed
2481 2482
 * FIXME
 *  return value 0 in case of error is a valid return value
2483
 *
2484
 */
2485
DWORD _ILGetFileAttributes(LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
2486
{
2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517
    LPPIDLDATA pData = _ILGetDataPointer(pidl);
    WORD wAttrib = 0;
    int i;

    if (!pData)
        return 0;

    switch(pData->type)
    {
    case PT_FOLDER:
    case PT_VALUE:
        wAttrib = pData->u.file.uFileAttribs;
        break;
    }

    if(uOutSize >= 6)
    {
        i=0;
        if(wAttrib & FILE_ATTRIBUTE_READONLY)
            pOut[i++] = 'R';
        if(wAttrib & FILE_ATTRIBUTE_HIDDEN)
            pOut[i++] = 'H';
        if(wAttrib & FILE_ATTRIBUTE_SYSTEM)
            pOut[i++] = 'S';
        if(wAttrib & FILE_ATTRIBUTE_ARCHIVE)
            pOut[i++] = 'A';
        if(wAttrib & FILE_ATTRIBUTE_COMPRESSED)
            pOut[i++] = 'C';
        pOut[i] = 0x00;
    }
    return wAttrib;
2518 2519
}

2520
/*************************************************************************
2521 2522
 * ILFreeaPidl
 *
2523
 * frees an aPidl struct
2524
 */
2525 2526
void _ILFreeaPidl(LPITEMIDLIST * apidl, UINT cidl)
{
2527
    UINT   i;
2528

2529 2530 2531 2532 2533 2534
    if (apidl)
    {
        for (i = 0; i < cidl; i++)
            SHFree(apidl[i]);
        SHFree(apidl);
    }
2535 2536 2537
}

/*************************************************************************
2538 2539 2540 2541
 * ILCopyaPidl
 *
 * copies an aPidl struct
 */
2542
LPITEMIDLIST* _ILCopyaPidl(const LPCITEMIDLIST * apidlsrc, UINT cidl)
2543
{
2544 2545 2546 2547 2548
    UINT i;
    LPITEMIDLIST *apidldest;

    if (!apidlsrc)
        return NULL;
2549

2550 2551
    apidldest = SHAlloc(cidl * sizeof(LPITEMIDLIST));

2552 2553
    for (i = 0; i < cidl; i++)
        apidldest[i] = ILClone(apidlsrc[i]);
2554

2555
    return apidldest;
2556 2557 2558
}

/*************************************************************************
2559 2560 2561 2562
 * _ILCopyCidaToaPidl
 *
 * creates aPidl from CIDA
 */
2563
LPITEMIDLIST* _ILCopyCidaToaPidl(LPITEMIDLIST* pidl, const CIDA * cida)
2564
{
2565 2566
    UINT i;
    LPITEMIDLIST *dst;
2567

2568 2569 2570
    dst = SHAlloc(cida->cidl * sizeof(LPITEMIDLIST));
    if (!dst)
        return NULL;
2571

2572
    if (pidl)
2573
        *pidl = ILClone((LPCITEMIDLIST)(&((const BYTE*)cida)[cida->aoffset[0]]));
2574

2575
    for (i = 0; i < cida->cidl; i++)
2576
        dst[i] = ILClone((LPCITEMIDLIST)(&((const BYTE*)cida)[cida->aoffset[i + 1]]));
2577

2578
    return dst;
2579
}