static bool IsThereFolderOfPath(const UString &path) { CFileInfoW fileInfo; if (!FindFile(path, fileInfo)) return false; return fileInfo.IsDir(); }
HRESULT GetFolderSize(const UString &path, UInt64 &numFolders, UInt64 &numFiles, UInt64 &size, IProgress *progress) { RINOK(progress->SetCompleted(NULL)); numFiles = numFolders = size = 0; CEnumeratorW enumerator(path + UString(WSTRING_PATH_SEPARATOR L"*")); CFileInfoW fileInfo; while (enumerator.Next(fileInfo)) { if (fileInfo.IsDir()) { UInt64 subFolders, subFiles, subSize; RINOK(GetFolderSize(path + UString(WCHAR_PATH_SEPARATOR) + fileInfo.Name, subFolders, subFiles, subSize, progress)); numFolders += subFolders; numFolders++; numFiles += subFiles; size += subSize; } else { numFiles++; size += fileInfo.Size; } } return S_OK; }
HRESULT CPanel::BindToPath(const UString &fullPath, bool &archiveIsOpened, bool &encrypted) { archiveIsOpened = false; encrypted = false; CDisableTimerProcessing disableTimerProcessing1(*this); if (_parentFolders.Size() > 0) { const UString &virtPath = _parentFolders.Back().VirtualPath; if (fullPath.Left(virtPath.Length()) == virtPath) { for (;;) { CMyComPtr<IFolderFolder> newFolder; HRESULT res = _folder->BindToParentFolder(&newFolder); if (!newFolder || res != S_OK) break; _folder = newFolder; } UStringVector parts; SplitPathToParts(fullPath.Mid(virtPath.Length()), parts); for (int i = 0; i < parts.Size(); i++) { const UString &s = parts[i]; if ((i == 0 || i == parts.Size() - 1) && s.IsEmpty()) continue; CMyComPtr<IFolderFolder> newFolder; HRESULT res = _folder->BindToFolder(s, &newFolder); if (!newFolder || res != S_OK) break; _folder = newFolder; } return S_OK; } } CloseOpenFolders(); UString sysPath = fullPath; CFileInfoW fileInfo; UStringVector reducedParts; while (!sysPath.IsEmpty()) { if (FindFile(sysPath, fileInfo)) break; int pos = sysPath.ReverseFind(WCHAR_PATH_SEPARATOR); if (pos < 0) sysPath.Empty(); else { if (reducedParts.Size() > 0 || pos < sysPath.Length() - 1) reducedParts.Add(sysPath.Mid(pos + 1)); sysPath = sysPath.Left(pos); } } SetToRootFolder(); CMyComPtr<IFolderFolder> newFolder; if (sysPath.IsEmpty()) { if (_folder->BindToFolder(fullPath, &newFolder) == S_OK) _folder = newFolder; } else if (fileInfo.IsDir()) { NName::NormalizeDirPathPrefix(sysPath); if (_folder->BindToFolder(sysPath, &newFolder) == S_OK) _folder = newFolder; } else { UString dirPrefix; if (!NDirectory::GetOnlyDirPrefix(sysPath, dirPrefix)) dirPrefix.Empty(); if (_folder->BindToFolder(dirPrefix, &newFolder) == S_OK) { _folder = newFolder; LoadFullPath(); UString fileName; if (NDirectory::GetOnlyName(sysPath, fileName)) { HRESULT res = OpenItemAsArchive(fileName, _currentFolderPrefix, _currentFolderPrefix + fileName, _currentFolderPrefix + fileName, encrypted); if (res != S_FALSE) { RINOK(res); } /* if (res == E_ABORT) return res; */ if (res == S_OK) { archiveIsOpened = true; for (int i = reducedParts.Size() - 1; i >= 0; i--) { CMyComPtr<IFolderFolder> newFolder; _folder->BindToFolder(reducedParts[i], &newFolder); if (!newFolder) break; _folder = newFolder; } } } } } return S_OK; }
bool DoesDirExist(LPCWSTR name) { CFileInfoW fi; return fi.Find(name) && fi.IsDir(); }