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; }
static bool IsThereFolderOfPath(const UString &path) { CFileInfoW fileInfo; if (!FindFile(path, fileInfo)) return false; return fileInfo.IsDir(); }
bool CEnumeratorW::Next(CFileInfoW &fileInfo) { while(true) { if(!NextAny(fileInfo)) return false; if(!fileInfo.IsDots()) return true; } }
bool CEnumeratorW::Next(CFileInfoW &fi) { for (;;) { if (!NextAny(fi)) return false; if (!fi.IsDots()) return true; } }
void CPanel::LoadFullPathAndShow() { LoadFullPath(); _appState->FolderHistory.AddString(_currentFolderPrefix); _headerComboBox.SetText(_currentFolderPrefix); #ifndef UNDER_CE COMBOBOXEXITEM item; item.mask = 0; UString path = _currentFolderPrefix; if (path.Length() > #ifdef _WIN32 3 #else 1 #endif && path[path.Length() - 1] == WCHAR_PATH_SEPARATOR) path.Delete(path.Length() - 1); CFileInfoW info; DWORD attrib = FILE_ATTRIBUTE_DIRECTORY; if (info.Find(path)) attrib = info.Attrib; item.iImage = GetRealIconIndex(path, attrib); if (item.iImage >= 0) { item.iSelectedImage = item.iImage; item.mask |= (CBEIF_IMAGE | CBEIF_SELECTEDIMAGE); } item.iItem = -1; _headerComboBox.SetItem(&item); #endif RefreshTitle(); }
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 CPanel::OnComboBoxCommand(UINT code, LPARAM /* param */, LRESULT &result) { result = FALSE; switch(code) { case CBN_DROPDOWN: { ComboBoxPaths.Clear(); _headerComboBox.ResetContent(); int i; UStringVector pathParts; SplitPathToParts(_currentFolderPrefix, pathParts); UString sumPass; if (!pathParts.IsEmpty()) pathParts.DeleteBack(); for (i = 0; i < pathParts.Size(); i++) { UString name = pathParts[i]; sumPass += name; sumPass += WCHAR_PATH_SEPARATOR; CFileInfoW info; DWORD attrib = FILE_ATTRIBUTE_DIRECTORY; if (info.Find(sumPass)) attrib = info.Attrib; AddComboBoxItem(name.IsEmpty() ? L"\\" : name, GetRealIconIndex(sumPass, attrib), i, false); ComboBoxPaths.Add(sumPass); } #ifndef UNDER_CE int iconIndex; UString name; name = RootFolder_GetName_Documents(iconIndex); AddComboBoxItem(name, iconIndex, 0, true); name = RootFolder_GetName_Computer(iconIndex); AddComboBoxItem(name, iconIndex, 0, true); UStringVector driveStrings; MyGetLogicalDriveStrings(driveStrings); for (i = 0; i < driveStrings.Size(); i++) { UString s = driveStrings[i]; ComboBoxPaths.Add(s); int iconIndex = GetRealIconIndex(s, 0); if (s.Length() > 0 && s[s.Length() - 1] == WCHAR_PATH_SEPARATOR) s.Delete(s.Length() - 1); AddComboBoxItem(s, iconIndex, 1, false); } name = RootFolder_GetName_Network(iconIndex); AddComboBoxItem(name, iconIndex, 0, true); #endif return false; } case CBN_SELENDOK: { code = code; int index = _headerComboBox.GetCurSel(); if (index >= 0) { UString pass = ComboBoxPaths[index]; _headerComboBox.SetCurSel(-1); // _headerComboBox.SetText(pass); // it's fix for seclecting by mouse. if (BindToPathAndRefresh(pass) == S_OK) { PostMessage(kSetFocusToListView); #ifdef UNDER_CE PostMessage(kRefreshHeaderComboBox); #endif return true; } } return false; } /* case CBN_CLOSEUP: { LoadFullPathAndShow(); true; } case CBN_SELCHANGE: { // LoadFullPathAndShow(); return true; } */ } return false; }
// IExtractCallBack3 STDMETHODIMP CExtractCallbackImp::AskWrite( const wchar_t *srcPath, Int32 srcIsFolder, const FILETIME *srcTime, const UInt64 *srcSize, const wchar_t *destPath, BSTR *destPathResult, Int32 *writeAnswer) { UString destPathResultTemp = destPath; /* { CMyComBSTR destPathResultBSTR = destPath; *destPathResult = destPathResultBSTR.Detach(); } */ *destPathResult = 0; *writeAnswer = BoolToInt(false); UString destPathSpec = destPath; UString destPathSys = destPathSpec; bool srcIsFolderSpec = IntToBool(srcIsFolder); CFileInfoW destFileInfo; if (FindFile(destPathSys, destFileInfo)) { if (srcIsFolderSpec) { if (!destFileInfo.IsDirectory()) { UString message = UString(L"can not replace file \'") + destPathSpec + UString(L"\' with folder with same name"); RINOK(MessageError(message)); return E_ABORT; } *writeAnswer = BoolToInt(false); return S_OK; } if (destFileInfo.IsDirectory()) { UString message = UString(L"can not replace folder \'") + destPathSpec + UString(L"\' with file with same name"); RINOK(MessageError(message)); return E_FAIL; } switch(OverwriteMode) { case NExtract::NOverwriteMode::kSkipExisting: return S_OK; case NExtract::NOverwriteMode::kAskBefore: { Int32 overwiteResult; RINOK(AskOverwrite( destPathSpec, &destFileInfo.LastWriteTime, &destFileInfo.Size, srcPath, srcTime, srcSize, &overwiteResult)); switch(overwiteResult) { case NOverwriteAnswer::kCancel: return E_ABORT; case NOverwriteAnswer::kNo: return S_OK; case NOverwriteAnswer::kNoToAll: OverwriteMode = NExtract::NOverwriteMode::kSkipExisting; return S_OK; case NOverwriteAnswer::kYesToAll: OverwriteMode = NExtract::NOverwriteMode::kWithoutPrompt; break; case NOverwriteAnswer::kYes: break; case NOverwriteAnswer::kAutoRename: OverwriteMode = NExtract::NOverwriteMode::kAutoRename; break; default: throw 20413; } } } if (OverwriteMode == NExtract::NOverwriteMode::kAutoRename) { if (!AutoRenamePath(destPathSys)) { UString message = UString(L"can not create name of file ") + destPathSys; RINOK(MessageError(message)); return E_ABORT; } destPathResultTemp = destPathSys; } else if (!NFile::NDirectory::DeleteFileAlways(destPathSys)) { UString message = UString(L"can not delete output file ") + destPathSys; RINOK(MessageError(message)); return E_ABORT; } } CMyComBSTR destPathResultBSTR = destPathResultTemp; *destPathResult = destPathResultBSTR.Detach(); *writeAnswer = BoolToInt(true); return S_OK; }
bool DoesFileOrDirExist(LPCWSTR name) { CFileInfoW fi; return fi.Find(name); }
bool DoesDirExist(LPCWSTR name) { CFileInfoW fi; return fi.Find(name) && fi.IsDir(); }