void ConvertToOSName2(UString &name) { if (!name.IsEmpty()) { name.Replace(kDirDelimiter, kOSDirDelimiter); if (name.Back() == kOSDirDelimiter) name.DeleteBack(); } }
void CPanel::OpenParentFolder() { LoadFullPath(); // Maybe we don't need it ?? UString focucedName; if (!_currentFolderPrefix.IsEmpty() && _currentFolderPrefix.Back() == WCHAR_PATH_SEPARATOR) { focucedName = _currentFolderPrefix; focucedName.DeleteBack(); if (focucedName != L"\\\\.") { int pos = focucedName.ReverseFind(WCHAR_PATH_SEPARATOR); if (pos >= 0) focucedName = focucedName.Mid(pos + 1); } } CDisableTimerProcessing disableTimerProcessing1(*this); CMyComPtr<IFolderFolder> newFolder; _folder->BindToParentFolder(&newFolder); if (newFolder) _folder = newFolder; else { if (_parentFolders.IsEmpty()) { SetToRootFolder(); if (focucedName.IsEmpty()) focucedName = GetItemName(0); } else { _folder.Release(); _library.Free(); CFolderLink &link = _parentFolders.Back(); _folder = link.ParentFolder; _library.Attach(link.Library.Detach()); focucedName = link.ItemName; if (_parentFolders.Size() > 1) OpenParentArchiveFolder(); _parentFolders.DeleteBack(); if (_parentFolders.IsEmpty()) _flatMode = _flatModeForDisk; } } UStringVector selectedItems; /* if (!focucedName.IsEmpty()) selectedItems.Add(focucedName); */ LoadFullPath(); // ::SetCurrentDirectory(::_currentFolderPrefix); RefreshListCtrl(focucedName, -1, true, selectedItems); _listView.EnsureVisible(_listView.GetFocusedItem(), false); RefreshStatusBar(); }
UString GetOSName2(const UString &name) { if (name.IsEmpty()) return UString(); UString newName = GetOSName(name); if (newName.Back() == kOSDirDelimiter) newName.DeleteBack(); return newName; }
static void AddName(UStringVector &strings, UString &s) { s.Trim(); if (s.Len() >= 2 && s[0] == kQuoteChar && s.Back() == kQuoteChar) { s.DeleteBack(); s.Delete(0); } if (!s.IsEmpty()) strings.Add(s); }
HRESULT SetProperties(IUnknown *unknown, const CObjectVector<CProperty> &properties) { if (properties.IsEmpty()) return S_OK; CMyComPtr<ISetProperties> setProperties; unknown->QueryInterface(IID_ISetProperties, (void **)&setProperties); if (!setProperties) return S_OK; UStringVector realNames; CPropVariant *values = new CPropVariant[properties.Size()]; try { int i; for(i = 0; i < properties.Size(); i++) { const CProperty &property = properties[i]; NCOM::CPropVariant propVariant; UString name = property.Name; if (property.Value.IsEmpty()) { if (!name.IsEmpty()) { wchar_t c = name.Back(); if (c == L'-') propVariant = false; else if (c == L'+') propVariant = true; if (propVariant.vt != VT_EMPTY) name.DeleteBack(); } } else ParseNumberString(property.Value, propVariant); realNames.Add(name); values[i] = propVariant; } CRecordVector<const wchar_t *> names; for(i = 0; i < realNames.Size(); i++) names.Add((const wchar_t *)realNames[i]); RINOK(setProperties->SetProperties(&names.Front(), values, names.Size())); } catch(...) { delete []values; throw; } delete []values; return S_OK; }
void CPanel::LoadFullPathAndShow() { LoadFullPath(); _appState->FolderHistory.AddString(_currentFolderPrefix); _headerComboBox.SetText(_currentFolderPrefix); #ifndef UNDER_CE COMBOBOXEXITEM item; item.mask = 0; UString path = _currentFolderPrefix; if (path.Len() > #ifdef _WIN32 3 #else 1 #endif && path.Back() == WCHAR_PATH_SEPARATOR) path.DeleteBack(); DWORD attrib = FILE_ATTRIBUTE_DIRECTORY; // GetRealIconIndex is slow for direct DVD/UDF path. So we use dummy path if (path.IsPrefixedBy(L"\\\\.\\")) path = L"_TestFolder_"; else { CFileInfo fi; if (fi.Find(us2fs(path))) attrib = fi.Attrib; } item.iImage = GetRealIconIndex(us2fs(path), attrib); if (item.iImage >= 0) { item.iSelectedImage = item.iImage; item.mask |= (CBEIF_IMAGE | CBEIF_SELECTEDIMAGE); } item.iItem = -1; _headerComboBox.SetItem(&item); #endif RefreshTitle(); }
bool CBrowseDialog::GetParentPath(const UString &path, UString &parentPrefix, UString &name) { parentPrefix.Empty(); name.Empty(); if (path.IsEmpty()) return false; if (_topDirPrefix == path) return false; UString s = path; if (s.Back() == WCHAR_PATH_SEPARATOR) s.DeleteBack(); if (s.IsEmpty()) return false; if (s.Back() == WCHAR_PATH_SEPARATOR) return false; int pos = s.ReverseFind_PathSepar(); parentPrefix.SetFrom(s, pos + 1); name = s.Ptr(pos + 1); return true; }
void CPanel::OpenAltStreams() { CRecordVector<UInt32> indices; GetOperatedItemIndices(indices); Int32 realIndex = -1; if (indices.Size() > 1) return; if (indices.Size() == 1) realIndex = indices[0]; if (_folderAltStreams) { CMyComPtr<IFolderFolder> newFolder; _folderAltStreams->BindToAltStreams(realIndex, &newFolder); if (newFolder) { CDisableTimerProcessing disableTimerProcessing(*this); CDisableNotify disableNotify(*this); SetNewFolder(newFolder); RefreshListCtrl(UString(), -1, true, UStringVector()); return; } return; } #if defined(_WIN32) && !defined(UNDER_CE) UString path; if (realIndex >= 0) path = GetItemFullPath(realIndex); else { path = GetFsPath(); if (!NName::IsDriveRootPath_SuperAllowed(us2fs(path))) if (!path.IsEmpty() && IS_PATH_SEPAR(path.Back())) path.DeleteBack(); } path += L':'; BindToPathAndRefresh(path); #endif }
void CHandler::ParseName(Byte replaceByte, IArchiveOpenCallback *callback) { if (!callback) return; CMyComPtr<IArchiveOpenVolumeCallback> volumeCallback; callback->QueryInterface(IID_IArchiveOpenVolumeCallback, (void **)&volumeCallback); if (!volumeCallback) return; NWindows::NCOM::CPropVariant prop; if (volumeCallback->GetProperty(kpidName, &prop) != S_OK || prop.vt != VT_BSTR) return; UString s = prop.bstrVal; if (s.IsEmpty() || s.Back() != L'_') return; s.DeleteBack(); _name = s; if (replaceByte == 0) { if (s.Len() < 3 || s[s.Len() - 3] != '.') return; for (unsigned i = 0; i < ARRAY_SIZE(g_Exts); i++) { const char *ext = g_Exts[i]; if (s[s.Len() - 2] == (Byte)ext[0] && s[s.Len() - 1] == (Byte)ext[1]) { replaceByte = ext[2]; break; } } } if (replaceByte >= 0x20 && replaceByte < 0x80) _name += (wchar_t)replaceByte; }
HRESULT CPanel::BindToPath(const UString &fullPath, const UString &arcFormat, bool &archiveIsOpened, bool &encrypted) { UString path = fullPath; #ifdef _WIN32 path.Replace(L'/', WCHAR_PATH_SEPARATOR); #endif archiveIsOpened = false; encrypted = false; CDisableTimerProcessing disableTimerProcessing(*this); CDisableNotify disableNotify(*this); for (; !_parentFolders.IsEmpty(); CloseOneLevel()) { // ---------- we try to use open archive ---------- const CFolderLink &link = _parentFolders.Back(); const UString &virtPath = link.VirtualPath; if (!path.IsPrefixedBy(virtPath)) continue; UString relatPath = path.Ptr(virtPath.Len()); if (!relatPath.IsEmpty()) { if (!IS_PATH_SEPAR(relatPath[0])) continue; else relatPath.Delete(0); } UString relatPath2 = relatPath; if (!relatPath2.IsEmpty() && !IS_PATH_SEPAR(relatPath2.Back())) relatPath2.Add_PathSepar(); for (;;) { const UString foldPath = GetFolderPath(_folder); if (relatPath2 == foldPath) break; if (relatPath.IsPrefixedBy(foldPath)) { path = relatPath.Ptr(foldPath.Len()); break; } CMyComPtr<IFolderFolder> newFolder; if (_folder->BindToParentFolder(&newFolder) != S_OK) throw 20140918; if (!newFolder) // we exit from loop above if (relatPath.IsPrefixedBy(empty path for root folder) throw 20140918; SetNewFolder(newFolder); } break; } if (_parentFolders.IsEmpty()) { // ---------- we open file or folder from file system ---------- CloseOpenFolders(); UString sysPath = path; unsigned prefixSize = NName::GetRootPrefixSize(sysPath); if (prefixSize == 0 || sysPath[prefixSize] == 0) sysPath.Empty(); #if defined(_WIN32) && !defined(UNDER_CE) if (!sysPath.IsEmpty() && sysPath.Back() == ':' && (sysPath.Len() != 2 || !NName::IsDrivePath2(sysPath))) { UString baseFile = sysPath; baseFile.DeleteBack(); if (NFind::DoesFileOrDirExist(us2fs(baseFile))) sysPath.Empty(); } #endif CFileInfo fileInfo; while (!sysPath.IsEmpty()) { if (fileInfo.Find(us2fs(sysPath))) break; int pos = sysPath.ReverseFind_PathSepar(); if (pos < 0) sysPath.Empty(); else { /* if (reducedParts.Size() > 0 || pos < (int)sysPath.Len() - 1) reducedParts.Add(sysPath.Ptr(pos + 1)); */ #if defined(_WIN32) && !defined(UNDER_CE) if (pos == 2 && NName::IsDrivePath2(sysPath) && sysPath.Len() > 3) pos++; #endif sysPath.DeleteFrom(pos); } } SetToRootFolder(); CMyComPtr<IFolderFolder> newFolder; if (sysPath.IsEmpty()) { _folder->BindToFolder(path, &newFolder); } else if (fileInfo.IsDir()) { NName::NormalizeDirPathPrefix(sysPath); _folder->BindToFolder(sysPath, &newFolder); } else { FString dirPrefix, fileName; NDir::GetFullPathAndSplit(us2fs(sysPath), dirPrefix, fileName); HRESULT res; // = OpenAsArc(fs2us(fileName), arcFormat, encrypted); { CTempFileInfo tfi; tfi.RelPath = fs2us(fileName); tfi.FolderPath = dirPrefix; tfi.FilePath = us2fs(sysPath); res = OpenAsArc(NULL, tfi, sysPath, arcFormat, encrypted); } if (res == S_FALSE) _folder->BindToFolder(fs2us(dirPrefix), &newFolder); else { RINOK(res); archiveIsOpened = true; _parentFolders.Back().ParentFolderPath = fs2us(dirPrefix); path.DeleteFrontal(sysPath.Len()); if (!path.IsEmpty() && IS_PATH_SEPAR(path[0])) path.Delete(0); } } if (newFolder) { SetNewFolder(newFolder); // LoadFullPath(); return S_OK; } } { // ---------- we open folder remPath in archive and sub archives ---------- for (unsigned curPos = 0; curPos != path.Len();) { UString s = path.Ptr(curPos); int slashPos = NName::FindSepar(s); unsigned skipLen = s.Len(); if (slashPos >= 0) { s.DeleteFrom(slashPos); skipLen = slashPos + 1; } CMyComPtr<IFolderFolder> newFolder; _folder->BindToFolder(s, &newFolder); if (newFolder) curPos += skipLen; else if (_folderAltStreams) { int pos = s.Find(L':'); if (pos >= 0) { UString baseName = s; baseName.DeleteFrom(pos); if (_folderAltStreams->BindToAltStreams(baseName, &newFolder) == S_OK && newFolder) curPos += pos + 1; } } if (!newFolder) break; SetNewFolder(newFolder); } } return S_OK; }
void CPanel::OpenParentFolder() { LoadFullPath(); // Maybe we don't need it ?? UString parentFolderPrefix; UString focusedName; if (!_currentFolderPrefix.IsEmpty()) { wchar_t c = _currentFolderPrefix.Back(); if (c == WCHAR_PATH_SEPARATOR || c == ':') { focusedName = _currentFolderPrefix; focusedName.DeleteBack(); /* if (c == ':' && !focusedName.IsEmpty() && focusedName.Back() == WCHAR_PATH_SEPARATOR) { focusedName.DeleteBack(); } else */ if (focusedName != L"\\\\." && focusedName != L"\\\\?") { int pos = focusedName.ReverseFind_PathSepar(); if (pos >= 0) { parentFolderPrefix = focusedName; parentFolderPrefix.DeleteFrom(pos + 1); focusedName.DeleteFrontal(pos + 1); } } } } CDisableTimerProcessing disableTimerProcessing(*this); CDisableNotify disableNotify(*this); CMyComPtr<IFolderFolder> newFolder; _folder->BindToParentFolder(&newFolder); // newFolder.Release(); // for test if (newFolder) SetNewFolder(newFolder); else { bool needSetFolder = true; if (!_parentFolders.IsEmpty()) { { const CFolderLink &link = _parentFolders.Back(); parentFolderPrefix = link.ParentFolderPath; focusedName = link.RelPath; } CloseOneLevel(); needSetFolder = (!_folder); } if (needSetFolder) { { bool archiveIsOpened; bool encrypted; BindToPath(parentFolderPrefix, UString(), archiveIsOpened, encrypted); } } } UStringVector selectedItems; /* if (!focusedName.IsEmpty()) selectedItems.Add(focusedName); */ LoadFullPath(); // ::SetCurrentDirectory(::_currentFolderPrefix); RefreshListCtrl(focusedName, -1, true, selectedItems); // _listView.EnsureVisible(_listView.GetFocusedItem(), false); }
// Make sure the path is terminated with only a single / void FixPathFormat(UString& path) { while (path.Back() == L'/') path.DeleteBack(); path += L'/'; }
STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value) { COM_TRY_BEGIN NCOM::CPropVariant prop; if (index >= (UInt32)_archive.Refs.Size()) { index -= _archive.Refs.Size(); const CBootInitialEntry &be = _archive.BootEntries[index]; switch (propID) { case kpidPath: { AString s = "[BOOT]" STRING_PATH_SEPARATOR; if (_archive.BootEntries.Size() != 1) { char temp[16]; ConvertUInt32ToString(index + 1, temp); s += temp; s += '-'; } s += be.GetName(); prop = s; break; } case kpidIsDir: prop = false; break; case kpidSize: case kpidPackSize: prop = (UInt64)_archive.GetBootItemSize(index); break; } } else { const CRef &ref = _archive.Refs[index]; const CDir &item = ref.Dir->_subItems[ref.Index]; switch (propID) { case kpidPath: // if (item.FileId.GetCapacity() >= 0) { UString s; if (_archive.IsJoliet()) item.GetPathU(s); else s = MultiByteToUnicodeString(item.GetPath(_archive.IsSusp, _archive.SuspSkipSize), CP_OEMCP); if (s.Len() >= 2 && s[s.Len() - 2] == ';' && s.Back() == '1') s.DeleteFrom(s.Len() - 2); if (!s.IsEmpty() && s.Back() == L'.') s.DeleteBack(); NItemName::ConvertToOSName2(s); prop = s; } break; case kpidIsDir: prop = item.IsDir(); break; case kpidSize: case kpidPackSize: if (!item.IsDir()) prop = (UInt64)ref.TotalSize; break; case kpidMTime: { FILETIME utc; if (item.DateTime.GetFileTime(utc)) prop = utc; break; } } } prop.Detach(value); return S_OK; COM_TRY_END }
STDMETHODIMP CFSDrives::CopyTo(const UInt32 *indices, UInt32 numItems, const wchar_t *path, IFolderOperationsExtractCallback *callback) { if (numItems == 0) return S_OK; if (!_volumeMode) return E_NOTIMPL; UInt64 totalSize = 0; UInt32 i; for (i = 0; i < numItems; i++) { const CDriveInfo &di = _drives[indices[i]]; if (di.KnownSizes) totalSize += di.DriveSize; } RINOK(callback->SetTotal(totalSize)); RINOK(callback->SetNumFiles(numItems)); UString destPath = path; if (destPath.IsEmpty()) return E_INVALIDARG; bool directName = (destPath.Back() != WCHAR_PATH_SEPARATOR); if (directName) { if (numItems > 1) return E_INVALIDARG; } UInt64 completedSize = 0; RINOK(callback->SetCompleted(&completedSize)); for (i = 0; i < numItems; i++) { int index = indices[i]; const CDriveInfo &di = _drives[index]; UString destPath2 = destPath; UString name = fs2us(di.Name); if (!directName) { UString destName = name; if (!destName.IsEmpty() && destName.Back() == L':') { destName.DeleteBack(); destName += GetExt(index); } destPath2 += destName; } FString srcPath = di.GetDeviceFileIoName(); UInt64 fileSize = 0; if (GetLength(index, fileSize) != S_OK) { return E_FAIL; } if (!di.KnownSizes) totalSize += fileSize; RINOK(callback->SetTotal(totalSize)); Int32 writeAskResult; CMyComBSTR destPathResult; RINOK(callback->AskWrite(fs2us(srcPath), BoolToInt(false), NULL, &fileSize, destPath2, &destPathResult, &writeAskResult)); if (!IntToBool(writeAskResult)) continue; RINOK(callback->SetCurrentFilePath(fs2us(srcPath))); static const UInt32 kBufferSize = (4 << 20); UInt32 bufferSize = (di.DriveType == DRIVE_REMOVABLE) ? (18 << 10) * 4 : kBufferSize; RINOK(CopyFileSpec(srcPath, us2fs(destPathResult), false, fileSize, bufferSize, completedSize, callback)); completedSize += fileSize; } return S_OK; }