00001 /* Expose contents of remote folder as PIDLs via IEnumIDList interface 00002 00003 Copyright (C) 2007 Alexander Lamaison <awl03@doc.ic.ac.uk> 00004 00005 This program is free software; you can redistribute it and/or modify 00006 it under the terms of the GNU General Public License as published by 00007 the Free Software Foundation; either version 2 of the License, or 00008 (at your option) any later version. 00009 00010 This program is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 GNU General Public License for more details. 00014 00015 You should have received a copy of the GNU General Public License along 00016 with this program; if not, write to the Free Software Foundation, Inc., 00017 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 00018 */ 00019 00020 #include "stdafx.h" 00021 #include "RemoteEnumIDList.h" 00022 #include "RemotePidlManager.h" 00023 00024 /*------------------------------------------------------------------------------ 00025 * CRemoteEnumIDList::BindToFolder 00026 * Save back-reference to folder and increment its reference count to ensure 00027 * that folder remains alive for at least as long as the enumerator. 00028 * 00029 * MUST BE CALLED BEFORE ALL OTHER FUNCTIONS 00030 *----------------------------------------------------------------------------*/ 00031 HRESULT CRemoteEnumIDList::BindToFolder( CRemoteFolder* pFolder ) 00032 { 00033 ATLTRACE("CRemoteEnumIDList::BindToFolder called\n"); 00034 00035 if (pFolder == NULL) 00036 return E_POINTER; 00037 00038 // Save back-reference to folder and increment its reference count to 00039 // ensure that folder remains alive for at least as long as the enumerator 00040 m_pFolder = pFolder; 00041 m_pFolder->AddRef(); 00042 00043 return S_OK; 00044 } 00045 00046 /*------------------------------------------------------------------------------ 00047 * CRemoteEnumIDList::Connect 00048 * Populates the enumerator by connecting to the remote server given in the 00049 * parameter and fetching the file listing (TODO: currently only simulated). 00050 * 00051 * TODO: Ideally, the final EnumIDList will deal with enumeration *only*. 00052 * Connection and retrieval will be handled by other objects. 00053 *----------------------------------------------------------------------------*/ 00054 HRESULT CRemoteEnumIDList::Connect( PCWSTR szUser, PCWSTR szHost, 00055 PCWSTR szPath, UINT uPort ) 00056 { 00057 ATLTRACE("CRemoteEnumIDList::BindToFolder called\n"); 00058 ATLASSERT( m_pFolder ); 00059 00060 if (m_pFolder == NULL) 00061 return E_FAIL; 00062 00063 // Connect to server 00064 // Server->Connect() 00065 00066 // Retrieve file listing 00067 FILEDATA fdTemp; 00068 fdTemp.strPath = _T("bob.jpg"); 00069 fdTemp.dtModified = 0x3DE43B0C; // November 26, 2002 at 7:25p PST 00070 fdTemp.dwPermissions = 0x777; 00071 fdTemp.fIsFolder = false; 00072 fdTemp.strOwner = _T("awl03"); 00073 fdTemp.strGroup = _T("awl03"); 00074 fdTemp.strAuthor = _T("awl03"); 00075 fdTemp.uSize = 1481; 00076 m_vListing.push_back(fdTemp); 00077 00078 return S_OK; 00079 } 00080 00081 /*------------------------------------------------------------------------------ 00082 * CRemoteEnumIDList::Next 00083 * Retrieves the specified number of item identifiers in the enumeration 00084 * sequence and advances the current position by the number of items retrieved. 00085 *----------------------------------------------------------------------------*/ 00086 STDMETHODIMP CRemoteEnumIDList::Next( 00087 ULONG celt, 00088 __out_ecount_part(celt, *pceltFetched) PITEMID_CHILD *rgelt, 00089 __out_opt ULONG *pceltFetched ) 00090 { 00091 ATLTRACE("CRemoteEnumIDList::Next called\n"); 00092 ATLASSERT( m_pFolder ); 00093 if (m_pFolder == NULL) 00094 return E_FAIL; 00095 if (!(pceltFetched || celt <= 1)) 00096 return E_INVALIDARG; 00097 00098 HRESULT hr = S_OK; 00099 ULONG cFetched = 0; 00100 for (ULONG i = 0; i < celt; i++) 00101 { 00102 ULONG index = m_iPos + i; // Existing offset + current retrieval 00103 if (index >= m_vListing.size()) 00104 { 00105 // Ran out of entries before requested number could be fetched 00106 hr = S_FALSE; 00107 break; 00108 } 00109 00110 // Fetch data and create new PIDL from it 00111 ATLASSERT( index < m_vListing.size() ); 00112 hr = m_PidlManager.Create( 00113 m_vListing[index].strPath, 00114 m_vListing[index].strOwner, 00115 m_vListing[index].strGroup, 00116 m_vListing[index].dwPermissions, 00117 m_vListing[index].uSize, 00118 m_vListing[index].dtModified, 00119 m_vListing[index].fIsFolder, 00120 &rgelt[i] 00121 ); 00122 if (FAILED(hr)) 00123 break; 00124 cFetched++; 00125 } 00126 00127 *pceltFetched = cFetched; 00128 m_iPos += cFetched; 00129 return hr; 00130 } 00131 00132 /*------------------------------------------------------------------------------ 00133 * CRemoteEnumIDList::Skip 00134 * Skips the specified number of elements in the enumeration sequence. 00135 *----------------------------------------------------------------------------*/ 00136 STDMETHODIMP CRemoteEnumIDList::Skip( DWORD celt ) 00137 { 00138 ATLTRACE("CRemoteEnumIDList::Skip called\n"); 00139 ATLASSERT( m_pFolder ); 00140 00141 m_iPos += celt; 00142 00143 return S_OK; 00144 } 00145 00146 /*------------------------------------------------------------------------------ 00147 * CRemoteEnumIDList::Reset 00148 * Returns to the beginning of the enumeration sequence. 00149 *----------------------------------------------------------------------------*/ 00150 STDMETHODIMP CRemoteEnumIDList::Reset() 00151 { 00152 ATLTRACE("CRemoteEnumIDList::Reset called\n"); 00153 ATLASSERT( m_pFolder ); 00154 00155 m_iPos = 0; 00156 00157 return S_OK; 00158 } 00159 00160 /*------------------------------------------------------------------------------ 00161 * CRemoteEnumIDList::Clone 00162 * Creates a new item enumeration object with the same contents and state 00163 * as the current one. 00164 *----------------------------------------------------------------------------*/ 00165 STDMETHODIMP CRemoteEnumIDList::Clone( __deref_out IEnumIDList **ppenum ) 00166 { 00167 ATLTRACE("CRemoteEnumIDList::Clone called\n"); 00168 ATLASSERT( m_pFolder ); 00169 00170 // TODO: Implement this 00171 00172 return E_NOTIMPL; 00173 } 00174 00175 // CRemoteEnumIDList 00176