00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "stdafx.h"
00021 #include "RemotePidlManager.h"
00022
00041 HRESULT CRemotePidlManager::Create(
00042 __in LPCWSTR pwszPath, __in LPCWSTR pwszOwner, __in LPCWSTR pwszGroup,
00043 __in DWORD dwPermissions, __in ULONGLONG uSize, __in time_t dtModified,
00044 __in BOOL fIsFolder, __deref_out PITEMID_CHILD *ppidlOut )
00045 {
00046 ATLASSERT(sizeof(REMOTEPIDL) % sizeof(DWORD) == 0);
00047
00048 PITEMID_CHILD pidl = NULL;
00049
00050
00051 pidl = (PITEMID_CHILD)CoTaskMemAlloc(sizeof(REMOTEPIDL) + sizeof(USHORT));
00052 if(!pidl)
00053 return E_OUTOFMEMORY;
00054
00055
00056 PREMOTEPIDL pidlRemote = (PREMOTEPIDL)pidl;
00057
00058
00059 pidlRemote->cb = sizeof REMOTEPIDL;
00060 pidlRemote->dwFingerprint = REMOTEPIDL_FINGERPRINT;
00061 CopyWSZString(pidlRemote->wszPath,
00062 ARRAYSIZE(pidlRemote->wszPath), pwszPath);
00063 CopyWSZString(pidlRemote->wszOwner,
00064 ARRAYSIZE(pidlRemote->wszOwner), pwszOwner);
00065 CopyWSZString(pidlRemote->wszGroup,
00066 ARRAYSIZE(pidlRemote->wszGroup), pwszGroup);
00067 pidlRemote->dwPermissions = dwPermissions;
00068 pidlRemote->uSize = uSize;
00069 pidlRemote->dtModified = dtModified;
00070 pidlRemote->fIsFolder = fIsFolder;
00071
00072
00073 LPITEMIDLIST pidlNext = GetNextItem(pidl);
00074 ATLASSERT(pidlNext != NULL);
00075 pidlNext->mkid.cb = 0;
00076
00077 *ppidlOut = pidl;
00078 ATLASSERT(SUCCEEDED(IsValid(*ppidlOut)));
00079 ATLASSERT(ILGetNext(ILGetNext(*ppidlOut)) == NULL);
00080 ATLASSERT(ILGetSize(*ppidlOut) == sizeof(REMOTEPIDL) + sizeof(USHORT));
00081
00082 return S_OK;
00083 }
00084
00114 PREMOTEPIDL CRemotePidlManager::Validate( PCIDLIST_RELATIVE pidl )
00115 {
00116 PREMOTEPIDL pRemotePidl = NULL;
00117
00118 if (pidl)
00119 {
00120 pRemotePidl = (PREMOTEPIDL)pidl;
00121 if (pRemotePidl->cb == sizeof(REMOTEPIDL_FINGERPRINT) &&
00122 pRemotePidl->dwFingerprint == REMOTEPIDL_FINGERPRINT)
00123 return pRemotePidl;
00124 }
00125
00126 return NULL;
00127 }
00128
00143 HRESULT CRemotePidlManager::IsValid( PCIDLIST_RELATIVE pidl )
00144 {
00145 PREMOTEPIDL pRemotePidl = Validate(pidl);
00146 return pRemotePidl ? S_OK : E_INVALIDARG;
00147 }
00148
00160 CString CRemotePidlManager::GetPath( LPCITEMIDLIST pidl )
00161 {
00162 if (pidl == NULL) return _T("");
00163
00164 return GetDataSegment(pidl)->wszPath;
00165 }
00166
00178 CString CRemotePidlManager::GetOwner( LPCITEMIDLIST pidl )
00179 {
00180 if (pidl == NULL) return _T("");
00181
00182 return GetDataSegment(pidl)->wszOwner;
00183 }
00184
00196 CString CRemotePidlManager::GetGroup( LPCITEMIDLIST pidl )
00197 {
00198 if (pidl == NULL) return _T("");
00199
00200 return GetDataSegment(pidl)->wszGroup;
00201 }
00202
00214 DWORD CRemotePidlManager::GetPermissions( LPCITEMIDLIST pidl )
00215 {
00216 if (pidl == NULL) return 0;
00217
00218 return GetDataSegment(pidl)->dwPermissions;
00219 }
00220
00236 CString CRemotePidlManager::GetPermissionsStr( LPCITEMIDLIST pidl )
00237 {
00238 if (pidl == NULL) return _T("");
00239
00240
00241 return _T("todo");
00242 }
00243
00255 ULONGLONG CRemotePidlManager::GetFileSize( LPCITEMIDLIST pidl )
00256 {
00257 if (pidl == NULL) return 0;
00258
00259 return GetDataSegment(pidl)->uSize;
00260 }
00261
00273 CTime CRemotePidlManager::GetLastModified( LPCITEMIDLIST pidl )
00274 {
00275 if (pidl == NULL) return 0;
00276
00277 return GetDataSegment(pidl)->dtModified;
00278 }
00279
00291 BOOL CRemotePidlManager::IsFolder( LPCITEMIDLIST pidl )
00292 {
00293 if (pidl == NULL) return 0;
00294
00295 return GetDataSegment(pidl)->fIsFolder;
00296 }
00297
00309 PREMOTEPIDL CRemotePidlManager::GetDataSegment( LPCITEMIDLIST pidl )
00310 {
00311
00312
00313 PITEMID_CHILD pidlRemote = CPidlManager::GetDataSegment( pidl );
00314
00315 ATLASSERT(SUCCEEDED(IsValid( pidlRemote )));
00316
00317
00318 return Validate( pidlRemote );
00319 }