ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

enumidlist.cpp
Go to the documentation of this file.
00001 /*
00002  *    IEnumIDList
00003  *
00004  *    Copyright 1998    Juergen Schmied <juergen.schmied@metronet.de>
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or (at your option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
00019  */
00020 
00021 #include <precomp.h>
00022 
00023 WINE_DEFAULT_DEBUG_CHANNEL(shell);
00024 
00025 IEnumIDListImpl::IEnumIDListImpl()
00026 {
00027     mpFirst = NULL;
00028     mpLast = NULL;
00029     mpCurrent = NULL;
00030 }
00031 
00032 IEnumIDListImpl::~IEnumIDListImpl()
00033 {
00034 }
00035 
00036 /**************************************************************************
00037  *  AddToEnumList()
00038  */
00039 BOOL IEnumIDListImpl::AddToEnumList(LPITEMIDLIST pidl)
00040 {
00041     ENUMLIST *pNew;
00042 
00043     TRACE("(%p)->(pidl=%p)\n", this, pidl);
00044 
00045     if (!pidl)
00046         return FALSE;
00047 
00048     pNew = (ENUMLIST *)SHAlloc(sizeof(ENUMLIST));
00049     if (pNew)
00050     {
00051       /*set the next pointer */
00052       pNew->pNext = NULL;
00053       pNew->pidl = pidl;
00054 
00055       /*is This the first item in the list? */
00056       if (!mpFirst)
00057       {
00058         mpFirst = pNew;
00059         mpCurrent = pNew;
00060       }
00061 
00062       if (mpLast)
00063       {
00064         /*add the new item to the end of the list */
00065         mpLast->pNext = pNew;
00066       }
00067 
00068       /*update the last item pointer */
00069       mpLast = pNew;
00070       TRACE("-- (%p)->(first=%p, last=%p)\n", this, mpFirst, mpLast);
00071       return TRUE;
00072     }
00073     return FALSE;
00074 }
00075 
00076 /**************************************************************************
00077 *   DeleteList()
00078 */
00079 BOOL IEnumIDListImpl::DeleteList()
00080 {
00081     ENUMLIST                    *pDelete;
00082 
00083     TRACE("(%p)->()\n", this);
00084 
00085     while (mpFirst)
00086     {
00087         pDelete = mpFirst;
00088         mpFirst = pDelete->pNext;
00089         SHFree(pDelete->pidl);
00090         SHFree(pDelete);
00091     }
00092     mpFirst = NULL;
00093     mpLast = NULL;
00094     mpCurrent = NULL;
00095     return TRUE;
00096 }
00097 
00098 /**************************************************************************
00099  *  HasItemWithCLSID()
00100  */
00101 BOOL IEnumIDListImpl::HasItemWithCLSID(LPITEMIDLIST pidl)
00102 {
00103     ENUMLIST *pCur;
00104     IID *ptr = _ILGetGUIDPointer(pidl);
00105 
00106     if (ptr)
00107     {
00108         REFIID refid = *ptr;
00109         pCur = mpFirst;
00110 
00111         while(pCur)
00112         {
00113             LPGUID curid = _ILGetGUIDPointer(pCur->pidl);
00114             if (curid && IsEqualGUID(*curid, refid))
00115             {
00116                 return TRUE;
00117             }
00118             pCur = pCur->pNext;
00119         }
00120     }
00121 
00122     return FALSE;
00123 }
00124 
00125 
00126 /**************************************************************************
00127  *  CreateFolderEnumList()
00128  */
00129 BOOL IEnumIDListImpl::CreateFolderEnumList(
00130     LPCWSTR lpszPath,
00131     DWORD dwFlags)
00132 {
00133     WIN32_FIND_DATAW stffile;
00134     HANDLE hFile;
00135     WCHAR  szPath[MAX_PATH];
00136     BOOL succeeded = TRUE;
00137     static const WCHAR stars[] = { '*','.','*',0 };
00138     static const WCHAR dot[] = { '.',0 };
00139     static const WCHAR dotdot[] = { '.','.',0 };
00140 
00141     TRACE("(%p)->(path=%s flags=0x%08x)\n", this, debugstr_w(lpszPath), dwFlags);
00142 
00143     if(!lpszPath || !lpszPath[0]) return FALSE;
00144 
00145     wcscpy(szPath, lpszPath);
00146     PathAddBackslashW(szPath);
00147     wcscat(szPath,stars);
00148 
00149     hFile = FindFirstFileW(szPath,&stffile);
00150     if ( hFile != INVALID_HANDLE_VALUE )
00151     {
00152         BOOL findFinished = FALSE;
00153 
00154         do
00155         {
00156             if ( !(stffile.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN)
00157              || (dwFlags & SHCONTF_INCLUDEHIDDEN) )
00158             {
00159                 LPITEMIDLIST pidl = NULL;
00160 
00161                 if ( (stffile.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) &&
00162                  dwFlags & SHCONTF_FOLDERS &&
00163                  strcmpW(stffile.cFileName, dot) && strcmpW(stffile.cFileName, dotdot))
00164                 {
00165                     pidl = _ILCreateFromFindDataW(&stffile);
00166                     succeeded = succeeded && AddToEnumList(pidl);
00167                 }
00168                 else if (!(stffile.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
00169                  && dwFlags & SHCONTF_NONFOLDERS)
00170                 {
00171                     pidl = _ILCreateFromFindDataW(&stffile);
00172                     succeeded = succeeded && AddToEnumList(pidl);
00173                 }
00174             }
00175             if (succeeded)
00176             {
00177                 if (!FindNextFileW(hFile, &stffile))
00178                 {
00179                     if (GetLastError() == ERROR_NO_MORE_FILES)
00180                         findFinished = TRUE;
00181                     else
00182                         succeeded = FALSE;
00183                 }
00184             }
00185         } while (succeeded && !findFinished);
00186         FindClose(hFile);
00187     }
00188 
00189     return succeeded;
00190 }
00191 
00192 /**************************************************************************
00193  *  IEnumIDList_fnNext
00194  */
00195 
00196 HRESULT WINAPI IEnumIDListImpl::Next(
00197     ULONG celt,
00198     LPITEMIDLIST * rgelt,
00199     ULONG *pceltFetched)
00200 {
00201     ULONG    i;
00202     HRESULT  hr = S_OK;
00203     LPITEMIDLIST  temp;
00204 
00205     TRACE("(%p)->(%d,%p, %p)\n", this, celt, rgelt, pceltFetched);
00206 
00207 /* It is valid to leave pceltFetched NULL when celt is 1. Some of explorer's
00208  * subsystems actually use it (and so may a third party browser)
00209  */
00210     if(pceltFetched)
00211       *pceltFetched = 0;
00212 
00213     *rgelt=0;
00214 
00215     if(celt > 1 && !pceltFetched)
00216     { return E_INVALIDARG;
00217     }
00218 
00219     if(celt > 0 && !mpCurrent)
00220     { return S_FALSE;
00221     }
00222 
00223     for(i = 0; i < celt; i++)
00224     { if(!mpCurrent)
00225         break;
00226 
00227       temp = ILClone(mpCurrent->pidl);
00228       rgelt[i] = temp;
00229       mpCurrent = mpCurrent->pNext;
00230     }
00231     if(pceltFetched)
00232     {  *pceltFetched = i;
00233     }
00234 
00235     return hr;
00236 }
00237 
00238 /**************************************************************************
00239 *  IEnumIDList_fnSkip
00240 */
00241 HRESULT WINAPI IEnumIDListImpl::Skip(
00242     ULONG celt)
00243 {
00244     DWORD    dwIndex;
00245     HRESULT  hr = S_OK;
00246 
00247     TRACE("(%p)->(%u)\n", this, celt);
00248 
00249     for(dwIndex = 0; dwIndex < celt; dwIndex++)
00250     { if(!mpCurrent)
00251       { hr = S_FALSE;
00252         break;
00253       }
00254       mpCurrent = mpCurrent->pNext;
00255     }
00256     return hr;
00257 }
00258 
00259 /**************************************************************************
00260 *  IEnumIDList_fnReset
00261 */
00262 HRESULT WINAPI IEnumIDListImpl::Reset()
00263 {
00264     TRACE("(%p)\n", this);
00265     mpCurrent = mpFirst;
00266     return S_OK;
00267 }
00268 
00269 /**************************************************************************
00270 *  IEnumIDList_fnClone
00271 */
00272 HRESULT WINAPI IEnumIDListImpl::Clone(LPENUMIDLIST *ppenum)
00273 {
00274     TRACE("(%p)->() to (%p)->() E_NOTIMPL\n", this, ppenum);
00275     return E_NOTIMPL;
00276 }
00277 
00278 /**************************************************************************
00279  *  IEnumIDList_Folder_Constructor
00280  *
00281  */
00282 HRESULT IEnumIDList_Constructor(IEnumIDList **enumerator)
00283 {
00284     CComObject<IEnumIDListImpl>                *theEnumerator;
00285     CComPtr<IEnumIDList>                    result;
00286     HRESULT                                    hResult;
00287 
00288     if (enumerator == NULL)
00289         return E_POINTER;
00290     *enumerator = NULL;
00291     ATLTRY (theEnumerator = new CComObject<IEnumIDListImpl>);
00292     if (theEnumerator == NULL)
00293         return E_OUTOFMEMORY;
00294     hResult = theEnumerator->QueryInterface (IID_IEnumIDList, (void **)&result);
00295     if (FAILED (hResult))
00296     {
00297         delete theEnumerator;
00298         return hResult;
00299     }
00300     *enumerator = result.Detach ();
00301     return S_OK;
00302 }

Generated on Thu May 24 2012 04:26:48 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.