STDMETHODIMP CNetFolder::BindToParentFolder(IFolderFolder **resultFolder) { *resultFolder = 0; if (_parentFolder) { CMyComPtr<IFolderFolder> parentFolder = _parentFolder; *resultFolder = parentFolder.Detach(); return S_OK; } if (_netResourcePointer != 0) { CResourceW resourceParent; DWORD result = GetResourceParent(_netResource, resourceParent); if (result != NO_ERROR) return result; if (!_netResource.RemoteNameIsDefined) return S_OK; CNetFolder *netFolder = new CNetFolder; CMyComPtr<IFolderFolder> subFolder = netFolder; netFolder->Init(&resourceParent, 0, WCHAR_PATH_SEPARATOR); *resultFolder = subFolder.Detach(); } return S_OK; }
STDMETHODIMP CRootFolder::BindToFolder(UInt32 index, IFolderFolder **resultFolder) { if (index == ROOT_INDEX_COMPUTER) { CFSDrives *fsDrivesSpec = new CFSDrives; CMyComPtr<IFolderFolder> subFolder = fsDrivesSpec; fsDrivesSpec->Init(); *resultFolder = subFolder.Detach(); } else if (index == ROOT_INDEX_NETWORK) { CNetFolder *netFolderSpec = new CNetFolder; CMyComPtr<IFolderFolder> subFolder = netFolderSpec; netFolderSpec->Init(0, 0, _names[ROOT_INDEX_NETWORK] + WCHAR_PATH_SEPARATOR); *resultFolder = subFolder.Detach(); } else if (index == ROOT_INDEX_DOCUMENTS) { UString s = GetMyDocsPath(); if (!s.IsEmpty()) { NFsFolder::CFSFolder *fsFolderSpec = new NFsFolder::CFSFolder; CMyComPtr<IFolderFolder> subFolder = fsFolderSpec; RINOK(fsFolderSpec->Init(s, NULL)); *resultFolder = subFolder.Detach(); } } else return E_INVALIDARG; return S_OK; }
STDMETHODIMP CFSFolder::BindToParentFolder(IFolderFolder **resultFolder) { *resultFolder = 0; if (_parentFolder) { CMyComPtr<IFolderFolder> parentFolder = _parentFolder; *resultFolder = parentFolder.Detach(); return S_OK; } if (_path.IsEmpty()) return E_INVALIDARG; int pos = _path.ReverseFind(WCHAR_PATH_SEPARATOR); if (pos < 0 || pos != _path.Length() - 1) return E_FAIL; UString parentPath = _path.Left(pos); pos = parentPath.ReverseFind(WCHAR_PATH_SEPARATOR); if (pos < 0) { #ifdef UNDER_CE *resultFolder = 0; #else CFSDrives *drivesFolderSpec = new CFSDrives; CMyComPtr<IFolderFolder> drivesFolder = drivesFolderSpec; drivesFolderSpec->Init(); *resultFolder = drivesFolder.Detach(); #endif return S_OK; } UString parentPathReduced = parentPath.Left(pos); parentPath = parentPath.Left(pos + 1); #ifndef UNDER_CE pos = parentPathReduced.ReverseFind(WCHAR_PATH_SEPARATOR); if (pos == 1) { if (parentPath[0] != WCHAR_PATH_SEPARATOR) return E_FAIL; CNetFolder *netFolderSpec = new CNetFolder; CMyComPtr<IFolderFolder> netFolder = netFolderSpec; netFolderSpec->Init(parentPath); *resultFolder = netFolder.Detach(); return S_OK; } #endif CFSFolder *parentFolderSpec = new CFSFolder; CMyComPtr<IFolderFolder> parentFolder = parentFolderSpec; RINOK(parentFolderSpec->Init(parentPath, 0)); *resultFolder = parentFolder.Detach(); return S_OK; }
STDMETHODIMP CRootFolder::BindToFolder(UInt32 index, IFolderFolder **resultFolder) { *resultFolder = NULL; CMyComPtr<IFolderFolder> subFolder; #ifdef USE_WIN_PATHS if (index == ROOT_INDEX_COMPUTER || index == ROOT_INDEX_VOLUMES) { CFSDrives *fsDrivesSpec = new CFSDrives; subFolder = fsDrivesSpec; fsDrivesSpec->Init(index == ROOT_INDEX_VOLUMES); } else if (index == ROOT_INDEX_NETWORK) { CNetFolder *netFolderSpec = new CNetFolder; subFolder = netFolderSpec; netFolderSpec->Init(0, 0, _names[ROOT_INDEX_NETWORK] + WCHAR_PATH_SEPARATOR); } else if (index == ROOT_INDEX_DOCUMENTS) { UString s = GetMyDocsPath(); if (!s.IsEmpty()) { NFsFolder::CFSFolder *fsFolderSpec = new NFsFolder::CFSFolder; subFolder = fsFolderSpec; RINOK(fsFolderSpec->Init(us2fs(s))); } } #else if (index == ROOT_INDEX_COMPUTER) { NFsFolder::CFSFolder *fsFolder = new NFsFolder::CFSFolder; subFolder = fsFolder; fsFolder->InitToRoot(); } #endif else return E_INVALIDARG; *resultFolder = subFolder.Detach(); return S_OK; }
STDMETHODIMP CNetFolder::BindToFolder(UInt32 index, IFolderFolder **resultFolder) { *resultFolder = 0; const CResourceEx &resource = _items[index]; if (resource.Usage == RESOURCEUSAGE_CONNECTABLE || resource.DisplayType == RESOURCEDISPLAYTYPE_SHARE) { NFsFolder::CFSFolder *fsFolderSpec = new NFsFolder::CFSFolder; CMyComPtr<IFolderFolder> subFolder = fsFolderSpec; RINOK(fsFolderSpec->Init(us2fs(resource.RemoteName + WCHAR_PATH_SEPARATOR), this)); *resultFolder = subFolder.Detach(); } else { CNetFolder *netFolder = new CNetFolder; CMyComPtr<IFolderFolder> subFolder = netFolder; netFolder->Init(&resource, this, resource.Name + WCHAR_PATH_SEPARATOR); *resultFolder = subFolder.Detach(); } return S_OK; }
STDMETHODIMP CRootFolder::BindToFolder(const wchar_t *name, IFolderFolder **resultFolder) { *resultFolder = 0; UString name2 = name; name2.Trim(); if (name2.IsEmpty()) { CRootFolder *rootFolderSpec = new CRootFolder; CMyComPtr<IFolderFolder> rootFolder = rootFolderSpec; rootFolderSpec->Init(); *resultFolder = rootFolder.Detach(); return S_OK; } for (int i = 0; i < kNumRootFolderItems; i++) if (AreEqualNames(name2, _names[i])) return BindToFolder((UInt32)i, resultFolder); if (AreEqualNames(name2, L"My Documents") || AreEqualNames(name2, L"Documents")) return BindToFolder((UInt32)ROOT_INDEX_DOCUMENTS, resultFolder); if (AreEqualNames(name2, L"My Computer") || AreEqualNames(name2, L"Computer")) return BindToFolder((UInt32)ROOT_INDEX_COMPUTER, resultFolder); if (name2 == UString(WCHAR_PATH_SEPARATOR)) { CMyComPtr<IFolderFolder> subFolder = this; *resultFolder = subFolder.Detach(); return S_OK; } if (name2.Length () < 2) return E_INVALIDARG; CMyComPtr<IFolderFolder> subFolder; if (name2.Left(4) == L"\\\\.\\") { CPhysDriveFolder *folderSpec = new CPhysDriveFolder; subFolder = folderSpec; RINOK(folderSpec->Init(name2.Mid(4, 2))); } else { if (name2[name2.Length () - 1] != WCHAR_PATH_SEPARATOR) name2 += WCHAR_PATH_SEPARATOR; NFsFolder::CFSFolder *fsFolderSpec = new NFsFolder::CFSFolder; subFolder = fsFolderSpec; if (fsFolderSpec->Init(name2, 0) != S_OK) { if (name2[0] == WCHAR_PATH_SEPARATOR) { CNetFolder *netFolderSpec = new CNetFolder; subFolder = netFolderSpec; netFolderSpec->Init(name2); } else return E_INVALIDARG; } } *resultFolder = subFolder.Detach(); return S_OK; }
STDMETHODIMP CFSFolder::BindToParentFolder(IFolderFolder **resultFolder) { *resultFolder = 0; if (_parentFolder) { CMyComPtr<IFolderFolder> parentFolder = _parentFolder; *resultFolder = parentFolder.Detach(); return S_OK; } if (_path.IsEmpty()) return E_INVALIDARG; printf("CFSFolder::BindToParentFolder path='%ls'\n",(const wchar_t *)_path); int pos = _path.ReverseFind(WCHAR_PATH_SEPARATOR); if (pos < 0 || pos != _path.Length() - 1) return E_FAIL; UString parentPath = _path.Left(pos); printf("CFSFolder::BindToParentFolder parentPath='%ls'\n",(const wchar_t *)parentPath); pos = parentPath.ReverseFind(WCHAR_PATH_SEPARATOR); if (pos < 0) { #ifdef _WIN32 parentPath.Empty(); CFSDrives *drivesFolderSpec = new CFSDrives; CMyComPtr<IFolderFolder> drivesFolder = drivesFolderSpec; drivesFolderSpec->Init(); *resultFolder = drivesFolder.Detach(); #else parentPath = WSTRING_PATH_SEPARATOR; CFSFolder *parentFolderSpec = new CFSFolder; CMyComPtr<IFolderFolder> parentFolder = parentFolderSpec; printf("CFSFolder::BindToParentFolder Init-0 with parentPath='%ls'\n",(const wchar_t *)parentPath); RINOK(parentFolderSpec->Init(parentPath, 0)); *resultFolder = parentFolder.Detach(); #endif return S_OK; } UString parentPathReduced = parentPath.Left(pos); parentPath = parentPath.Left(pos + 1); pos = parentPathReduced.ReverseFind(WCHAR_PATH_SEPARATOR); if (pos == 1) { #ifdef _WIN32 if (parentPath[0] != WCHAR_PATH_SEPARATOR) return E_FAIL; CNetFolder *netFolderSpec = new CNetFolder; CMyComPtr<IFolderFolder> netFolder = netFolderSpec; netFolderSpec->Init(parentPath); *resultFolder = netFolder.Detach(); #else parentPath = WSTRING_PATH_SEPARATOR; CFSFolder *parentFolderSpec = new CFSFolder; CMyComPtr<IFolderFolder> parentFolder = parentFolderSpec; printf("CFSFolder::BindToParentFolder Init-1 with parentPath='%ls'\n",(const wchar_t *)parentPath); RINOK(parentFolderSpec->Init(parentPath, 0)); *resultFolder = parentFolder.Detach(); #endif // ifdef _WIN32 return S_OK; } CFSFolder *parentFolderSpec = new CFSFolder; CMyComPtr<IFolderFolder> parentFolder = parentFolderSpec; printf("CFSFolder::BindToParentFolder Init-2 with parentPath='%ls'\n",(const wchar_t *)parentPath); RINOK(parentFolderSpec->Init(parentPath, 0)); *resultFolder = parentFolder.Detach(); return S_OK; }
STDMETHODIMP CRootFolder::BindToFolder(const wchar_t *name, IFolderFolder **resultFolder) { *resultFolder = 0; UString name2 = name; name2.Trim(); if (name2.IsEmpty()) { CRootFolder *rootFolderSpec = new CRootFolder; CMyComPtr<IFolderFolder> rootFolder = rootFolderSpec; rootFolderSpec->Init(); *resultFolder = rootFolder.Detach(); return S_OK; } for (unsigned i = 0; i < kNumRootFolderItems; i++) if (AreEqualNames(name2, _names[i])) return BindToFolder((UInt32)i, resultFolder); #ifdef USE_WIN_PATHS if (AreEqualNames(name2, L"My Documents") || AreEqualNames(name2, L"Documents")) return BindToFolder((UInt32)ROOT_INDEX_DOCUMENTS, resultFolder); #else if (name2 == WSTRING_PATH_SEPARATOR) return BindToFolder((UInt32)ROOT_INDEX_COMPUTER, resultFolder); #endif if (AreEqualNames(name2, L"My Computer") || AreEqualNames(name2, L"Computer")) return BindToFolder((UInt32)ROOT_INDEX_COMPUTER, resultFolder); if (name2 == WSTRING_PATH_SEPARATOR) { CMyComPtr<IFolderFolder> subFolder = this; *resultFolder = subFolder.Detach(); return S_OK; } if (name2.Len() < 2) return E_INVALIDARG; CMyComPtr<IFolderFolder> subFolder; #ifdef USE_WIN_PATHS if (name2.IsPrefixedBy(kVolPrefix)) { CFSDrives *folderSpec = new CFSDrives; subFolder = folderSpec; folderSpec->Init(true); } else if (name2 == NFile::NName::kSuperPathPrefix) { CFSDrives *folderSpec = new CFSDrives; subFolder = folderSpec; folderSpec->Init(false, true); } else if (name2.Back() == ':') { NAltStreamsFolder::CAltStreamsFolder *folderSpec = new NAltStreamsFolder::CAltStreamsFolder; subFolder = folderSpec; if (folderSpec->Init(us2fs(name2)) != S_OK) return E_INVALIDARG; } else #endif { NFile::NName::NormalizeDirPathPrefix(name2); NFsFolder::CFSFolder *fsFolderSpec = new NFsFolder::CFSFolder; subFolder = fsFolderSpec; if (fsFolderSpec->Init(us2fs(name2)) != S_OK) { #ifdef USE_WIN_PATHS if (name2[0] == WCHAR_PATH_SEPARATOR) { CNetFolder *netFolderSpec = new CNetFolder; subFolder = netFolderSpec; netFolderSpec->Init(name2); } else #endif return E_INVALIDARG; } } *resultFolder = subFolder.Detach(); return S_OK; }