HRESULT CMultiMethodProps::SetProperty(const wchar_t *nameSpec, const PROPVARIANT &value) { UString name = nameSpec; name.MakeLower_Ascii(); if (name.IsEmpty()) return E_INVALIDARG; if (name[0] == 'x') { name.Delete(0); _level = 9; return ParsePropToUInt32(name, value, _level); } if (name.IsPrefixedBy_Ascii_NoCase("yx")) { name.Delete(0, 2); UInt32 v = 9; RINOK(ParsePropToUInt32(name, value, v)); _analysisLevel = (int)v; return S_OK; } if (name.IsEqualTo("crc")) { name.Delete(0, 3); _crcSize = 4; return ParsePropToUInt32(name, value, _crcSize); } UInt32 number; unsigned index = ParseStringToUInt32(name, number); UString realName = name.Ptr(index); if (index == 0) { if (name.IsPrefixedBy_Ascii_NoCase("mt")) { #ifndef _7ZIP_ST RINOK(ParseMtProp(name.Ptr(2), value, _numProcessors, _numThreads)); #endif return S_OK; } if (name.IsEqualTo("f")) { HRESULT res = PROPVARIANT_to_bool(value, _autoFilter); if (res == S_OK) return res; if (value.vt != VT_BSTR) return E_INVALIDARG; return _filterMethod.ParseMethodFromPROPVARIANT(UString(), value); } number = 0; } if (number > 64) return E_FAIL; for (int j = _methods.Size(); j <= (int)number; j++) _methods.Add(COneMethodInfo()); return _methods[number].ParseMethodFromPROPVARIANT(realName, value); }
static bool ResolveDotsFolders(UString &s) { #ifdef _WIN32 s.Replace(L'/', WCHAR_PATH_SEPARATOR); #endif for (int i = 0;;) { wchar_t c = s[i]; if (c == 0) return true; if (c == '.' && (i == 0 || s[i - 1] == WCHAR_PATH_SEPARATOR)) { wchar_t c1 = s[i + 1]; if (c1 == '.') { wchar_t c2 = s[i + 2]; if (c2 == WCHAR_PATH_SEPARATOR || c2 == 0) { if (i == 0) return false; int k = i - 2; for (; k >= 0; k--) if (s[k] == WCHAR_PATH_SEPARATOR) break; unsigned num; if (k >= 0) { num = i + 2 - k; i = k; } else { num = (c2 == 0 ? (i + 2) : (i + 3)); i = 0; } s.Delete(i, num); continue; } } else { if (c1 == WCHAR_PATH_SEPARATOR || c1 == 0) { unsigned num = 2; if (i != 0) i--; else if (c1 == 0) num = 1; s.Delete(i, num); continue; } } } i++; } }
STDMETHODIMP CHandler::SetProperties(const wchar_t **names, const PROPVARIANT *values, Int32 numProperties) { COM_TRY_BEGIN _binds.Clear(); BeforeSetProperty(); for (int i = 0; i < numProperties; i++) { UString name = names[i]; name.MakeUpper(); if (name.IsEmpty()) return E_INVALIDARG; const PROPVARIANT &value = values[i]; if (name[0] == 'B') { name.Delete(0); CBind bind; RINOK(GetBindInfo(name, bind)); _binds.Add(bind); continue; } RINOK(SetProperty(name, value)); } return S_OK; COM_TRY_END }
void CPanel::LoadFullPathAndShow() { LoadFullPath(); _appState->FolderHistory.AddString(_currentFolderPrefix); _headerComboBox.SetText(_currentFolderPrefix); #ifdef _WIN32 // FIXME COMBOBOXEXITEM item; item.mask = 0; UString path = _currentFolderPrefix; if (path.Length() > 3 && path[path.Length() - 1] == WCHAR_PATH_SEPARATOR) path.Delete(path.Length() - 1); CFileInfoW info; DWORD attrib = FILE_ATTRIBUTE_DIRECTORY; if (NFile::NFind::FindFile(path, info)) 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(); }
UString GetCorrectPath(const UString &path) { UString result = path; int first; for (first = 0; first < result.Length(); first++) if (result[first] != ' ') break; while(result.Length() > first) { if ( #ifdef _WIN32 result[first] == L'\\' || #endif result[first] == L'/') { result.Delete(first); continue; } break; } #ifdef _WIN32 result.Replace(L"..\\", L""); #endif result.Replace(L"../", L""); ReplaceDisk(result); return result; }
void CPanel::OpenParentFolder() { printf("CPanel::OpenParentFolder\n"); LoadFullPath(); // Maybe we don't need it ?? UString focucedName; if (!_currentFolderPrefix.IsEmpty()) { UString string = _currentFolderPrefix; string.Delete(string.Length() - 1); int pos = string.ReverseFind(WCHAR_PATH_SEPARATOR); if (pos < 0) pos = 0; else pos++; focucedName = string.Mid(pos); } printf("CPanel::OpenParentFolder focucedName=%ls\n",(const wchar_t *)focucedName); 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(); } } UStringVector selectedItems; /* if (!focucedName.IsEmpty()) selectedItems.Add(focucedName); */ LoadFullPath(); // ::SetCurrentDirectory(::_currentFolderPrefix); RefreshListCtrl(focucedName, -1, true, selectedItems); _listView.EnsureVisible(_listView.GetFocusedItem(), false); RefreshStatusBar(); printf("CPanel::OpenParentFolder-end\n"); }
static void ReduceString(UString &s) { const unsigned kMaxSize = 64; if (s.Len() <= kMaxSize) return; s.Delete(kMaxSize / 2, s.Len() - kMaxSize); s.Insert(kMaxSize / 2, L" ... "); }
static HRESULT GetBindInfoPart(UString &srcString, UInt32 &coder, UInt32 &stream) { stream = 0; int index = ParseStringToUInt32(srcString, coder); if (index == 0) return E_INVALIDARG; srcString.Delete(0, index); if (srcString[0] == 'S') { srcString.Delete(0); int index = ParseStringToUInt32(srcString, stream); if (index == 0) return E_INVALIDARG; srcString.Delete(0, index); } return S_OK; }
UString GetOSName2(const UString &name) { if (name.IsEmpty()) return UString(); UString newName = GetOSName(name); if (newName[newName.Length() - 1] == kOSDirDelimiter) newName.Delete(newName.Length() - 1); 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); }
static HRESULT GetBindInfo(UString &srcString, CBind &bind) { RINOK(GetBindInfoPart(srcString, bind.OutCoder, bind.OutStream)); if (srcString[0] != ':') return E_INVALIDARG; srcString.Delete(0); RINOK(GetBindInfoPart(srcString, bind.InCoder, bind.InStream)); if (!srcString.IsEmpty()) return E_INVALIDARG; return S_OK; }
// Strip the file name from the full path, keeping the trailing / void StripFile(UString& path) { // remove file name int last = path.ReverseFind(L'/'); if (last != -1) { int namelen = path.Length() - last; path.Delete(last + 1, namelen - 1); } else {// file not directory path.Empty(); } }
static void ShowErrorMessageSpec(const UString &name) { UString message = NError::MyFormatMessage(::GetLastError()); int pos = message.Find(L"%1"); if (pos >= 0) { message.Delete(pos, 2); message.Insert(pos, name); } ShowErrorMessage(NULL, message); }
void CMessagesDialog::AddMessage(LPCWSTR message) { UString s = message; while (!s.IsEmpty()) { int pos = s.Find(L'\n'); if (pos < 0) break; AddMessageDirect(s.Left(pos)); s.Delete(0, pos + 1); } AddMessageDirect(s); }
static void ReplaceDisk(UString &s) { int i; for (i = 0; i < s.Length(); i++) if (s[i] != ' ') break; if (s.Length() > i + 1) { if (s[i + 1] == L':') { s.Delete(i + 1); // s.Insert(i + 1, L'_'); } } }
HRESULT COutHandler::SetProperty(const wchar_t *nameSpec, const PROPVARIANT &value) { UString name = nameSpec; name.MakeUpper(); if (name.IsEmpty()) return E_INVALIDARG; if (name[0] == L'S') { name.Delete(0); if (name.IsEmpty()) return SetSolidFromPROPVARIANT(value); if (value.vt != VT_EMPTY) return E_INVALIDARG; return SetSolidFromString(name); } UInt32 number; int index = ParseStringToUInt32(name, number); UString realName = name.Mid(index); if (index == 0) { if (name.CompareNoCase(L"RSFX") == 0) return PROPVARIANT_to_bool(value, _removeSfxBlock); if (name.CompareNoCase(L"HC") == 0) return PROPVARIANT_to_bool(value, _compressHeaders); if (name.CompareNoCase(L"HCF") == 0) { bool compressHeadersFull = true; RINOK(PROPVARIANT_to_bool(value, compressHeadersFull)); return compressHeadersFull ? S_OK: E_INVALIDARG; } if (name.CompareNoCase(L"HE") == 0) { RINOK(PROPVARIANT_to_bool(value, _encryptHeaders)); _encryptHeadersSpecified = true; return S_OK; } if (name.CompareNoCase(L"TC") == 0) return PROPVARIANT_to_bool(value, WriteCTime); if (name.CompareNoCase(L"TA") == 0) return PROPVARIANT_to_bool(value, WriteATime); if (name.CompareNoCase(L"TM") == 0) return PROPVARIANT_to_bool(value, WriteMTime); if (name.CompareNoCase(L"V") == 0) return PROPVARIANT_to_bool(value, _volumeMode); } return CMultiMethodProps::SetProperty(name, value); }
static UString ReplaceIncorrectChars(const UString &s) { #ifdef _WIN32 UString res; for (int i = 0; i < s.Length(); i++) { wchar_t c = s[i]; if (c < 0x20 || c == '*' || c == '?' || c == '<' || c == '>' || c == '|' || c == ':' || c == '"') c = '_'; res += c; } res.TrimRight(); while (!res.IsEmpty() && res[res.Length() - 1] == '.') res.Delete(res.Length() - 1); return res; #else return s; #endif }
UString MultiByteToUnicodeString(const AString &srcString, UINT /* codePage */ ) { #ifdef ENV_HAVE_MBSTOWCS if ((global_use_utf16_conversion) && (!srcString.IsEmpty())) { UString resultString; int numChars = mbstowcs(resultString.GetBuf(srcString.Len()),srcString,srcString.Len()+1); if (numChars >= 0) { resultString.ReleaseBuf_SetEnd(numChars); #if WCHAR_MAX > 0xffff for (int i = numChars; i >= 0; i--) { if (resultString[i] > 0xffff) { wchar_t c = resultString[i] - 0x10000; resultString.Delete(i); wchar_t texts[]= { ((c >> 10) & 0x3ff) + 0xd800, (c & 0x3ff) + 0xdc00 , 0 }; resultString.Insert(i, texts); numChars++; } }
UString CreateArchiveName(const UString &srcName, bool fromPrev, bool keepName) { UString resultName = L"Archive"; if (fromPrev) { UString dirPrefix; if (NFile::NDirectory::GetOnlyDirPrefix(srcName, dirPrefix)) { if (dirPrefix.Length() > 0) if (dirPrefix[dirPrefix.Length() - 1] == WCHAR_PATH_SEPARATOR) { dirPrefix.Delete(dirPrefix.Length() - 1); NFile::NFind::CFileInfoW fileInfo; if (NFile::NFind::FindFile(dirPrefix, fileInfo)) resultName = fileInfo.Name; } } } else { NFile::NFind::CFileInfoW fileInfo; if (!NFile::NFind::FindFile(srcName, fileInfo)) return resultName; resultName = fileInfo.Name; if (!fileInfo.IsDir() && !keepName) { int dotPos = resultName.ReverseFind('.'); if (dotPos > 0) { UString archiveName2 = resultName.Left(dotPos); if (archiveName2.ReverseFind('.') < 0) resultName = archiveName2; } } } return resultName; }
void OnMenuActivating(HWND /* hWnd */, HMENU hMenu, int position) { HMENU mainMenu = #ifdef UNDER_CE g_App._commandBar.GetMenu(0); #else ::GetMenu(g_HWND) #endif ; if (::GetSubMenu(mainMenu, position) != hMenu) return; if (position == kMenuIndex_File) { CMenu menu; menu.Attach(hMenu); menu.RemoveAllItems(); g_App.GetFocusedPanel().CreateFileMenu(hMenu); } else if (position == kMenuIndex_Edit) { /* CMenu menu; menu.Attach(hMenu); menu.EnableItem(IDM_EDIT_CUT, MF_ENABLED); menu.EnableItem(IDM_EDIT_COPY, MF_ENABLED); menu.EnableItem(IDM_EDIT_PASTE, IsClipboardFormatAvailableHDROP() ? MF_ENABLED : MF_GRAYED); */ } else if (position == kMenuIndex_View) { // View; CMenu menu; menu.Attach(hMenu); menu.CheckRadioItem(IDM_VIEW_LARGE_ICONS, IDM_VIEW_DETAILS, IDM_VIEW_LARGE_ICONS + g_App.GetListViewMode(), MF_BYCOMMAND); menu.CheckRadioItem(IDM_VIEW_ARANGE_BY_NAME, IDM_VIEW_ARANGE_NO_SORT, GetSortControlID(g_App.GetSortID()), MF_BYCOMMAND); menu.CheckItemByID(IDM_VIEW_TWO_PANELS, g_App.NumPanels == 2); menu.CheckItemByID(IDM_VIEW_FLAT_VIEW, g_App.GetFlatMode()); menu.CheckItemByID(IDM_VIEW_ARCHIVE_TOOLBAR, g_App.ShowArchiveToolbar); menu.CheckItemByID(IDM_VIEW_STANDARD_TOOLBAR, g_App.ShowStandardToolbar); menu.CheckItemByID(IDM_VIEW_TOOLBARS_LARGE_BUTTONS, g_App.LargeButtons); menu.CheckItemByID(IDM_VIEW_TOOLBARS_SHOW_BUTTONS_TEXT, g_App.ShowButtonsLables); menu.CheckItemByID(IDM_VIEW_AUTO_REFRESH, g_App.Get_AutoRefresh_Mode()); // menu.CheckItemByID(IDM_VIEW_SHOW_STREAMS, g_App.Get_ShowNtfsStrems_Mode()); // menu.CheckItemByID(IDM_VIEW_SHOW_DELETED, g_App.ShowDeletedFiles); } else if (position == kMenuIndex_Bookmarks) { CMenu menu; menu.Attach(hMenu); CMenu subMenu; subMenu.Attach(menu.GetSubMenu(0)); subMenu.RemoveAllItems(); int i; for (i = 0; i < 10; i++) { UString s = LangString(IDS_BOOKMARK); s.Add_Space(); wchar_t c = (wchar_t)(L'0' + i); s += c; s.AddAscii("\tAlt+Shift+"); s += c; subMenu.AppendItem(MF_STRING, kSetBookmarkMenuID + i, s); } menu.RemoveAllItemsFrom(2); for (i = 0; i < 10; i++) { UString s = g_App.AppState.FastFolders.GetString(i); const int kMaxSize = 100; const int kFirstPartSize = kMaxSize / 2; if (s.Len() > kMaxSize) { s.Delete(kFirstPartSize, s.Len() - kMaxSize); s.Insert(kFirstPartSize, L" ... "); } if (s.IsEmpty()) s = L'-'; s.AddAscii("\tAlt+"); s += (wchar_t)(L'0' + i); menu.AppendItem(MF_STRING, kOpenBookmarkMenuID + i, s); } } }
STDMETHODIMP CHandler::SetProperties(const wchar_t **names, const PROPVARIANT *values, Int32 numProps) { COM_TRY_BEGIN _binds.Clear(); InitProps(); for (int i = 0; i < numProps; i++) { UString name = names[i]; name.MakeUpper(); if (name.IsEmpty()) return E_INVALIDARG; const PROPVARIANT &value = values[i]; if (name[0] == 'B') { if (value.vt != VT_EMPTY) return E_INVALIDARG; name.Delete(0); CBind bind; RINOK(GetBindInfoPart(name, bind.OutCoder, bind.OutStream)); if (name[0] != ':') return E_INVALIDARG; name.Delete(0); RINOK(GetBindInfoPart(name, bind.InCoder, bind.InStream)); if (!name.IsEmpty()) return E_INVALIDARG; _binds.Add(bind); continue; } RINOK(SetProperty(name, value)); } int numEmptyMethods = GetNumEmptyMethods(); if (numEmptyMethods > 0) { int k; for (k = 0; k < _binds.Size(); k++) { const CBind &bind = _binds[k]; if (bind.InCoder < (UInt32)numEmptyMethods || bind.OutCoder < (UInt32)numEmptyMethods) return E_INVALIDARG; } for (k = 0; k < _binds.Size(); k++) { CBind &bind = _binds[k]; bind.InCoder -= (UInt32)numEmptyMethods; bind.OutCoder -= (UInt32)numEmptyMethods; } _methods.Delete(0, numEmptyMethods); } AddDefaultMethod(); if (!_filterMethod.MethodName.IsEmpty()) { for (int k = 0; k < _binds.Size(); k++) { CBind &bind = _binds[k]; bind.InCoder++; bind.OutCoder++; } _methods.Insert(0, _filterMethod); } for (int k = 0; k < _binds.Size(); k++) { const CBind &bind = _binds[k]; if (bind.InCoder >= (UInt32)_methods.Size() || bind.OutCoder >= (UInt32)_methods.Size()) return E_INVALIDARG; } return S_OK; COM_TRY_END }
void CApp::Combine() { int srcPanelIndex = GetFocusedPanelIndex(); CPanel &srcPanel = Panels[srcPanelIndex]; if (!srcPanel.IsFSFolder()) { srcPanel.MessageBoxErrorLang(IDS_OPERATION_IS_NOT_SUPPORTED, 0x03020208); return; } CRecordVector<UInt32> indices; srcPanel.GetOperatedItemIndices(indices); if (indices.IsEmpty()) return; int index = indices[0]; if (indices.Size() != 1 || srcPanel.IsItemFolder(index)) { srcPanel.MessageBoxErrorLang(IDS_COMBINE_SELECT_ONE_FILE, 0x03020620); return; } const UString itemName = srcPanel.GetItemName(index); UString srcPath = srcPanel._currentFolderPrefix + srcPanel.GetItemPrefix(index); UString path = srcPath; int destPanelIndex = (NumPanels <= 1) ? srcPanelIndex : (1 - srcPanelIndex); CPanel &destPanel = Panels[destPanelIndex]; if (NumPanels > 1) if (destPanel.IsFSFolder()) path = destPanel._currentFolderPrefix; CVolSeqName volSeqName; if (!volSeqName.ParseName(itemName)) { srcPanel.MessageBoxErrorLang(IDS_COMBINE_CANT_DETECT_SPLIT_FILE, 0x03020621); return; } { CThreadCombine combiner; UString nextName = itemName; combiner.TotalSize = 0; for (;;) { NFile::NFind::CFileInfoW fileInfo; if (!fileInfo.Find(srcPath + nextName) || fileInfo.IsDir()) break; combiner.Names.Add(nextName); combiner.TotalSize += fileInfo.Size; nextName = volSeqName.GetNextName(); } if (combiner.Names.Size() == 1) { srcPanel.MessageBoxErrorLang(IDS_COMBINE_CANT_FIND_MORE_THAN_ONE_PART, 0x03020622); return; } if (combiner.TotalSize == 0) { srcPanel.MessageBoxMyError(L"No data"); return; } UString info; AddValuePair2(IDS_FILES_COLON, 0x02000320, combiner.Names.Size(), combiner.TotalSize, info); info += L"\n"; info += srcPath; int i; for (i = 0; i < combiner.Names.Size() && i < 2; i++) AddInfoFileName(combiner.Names[i], info); if (i != combiner.Names.Size()) { if (i + 1 != combiner.Names.Size()) AddInfoFileName(L"...", info); AddInfoFileName(combiner.Names.Back(), info); } { CCopyDialog copyDialog; copyDialog.Value = path; copyDialog.Title = LangString(IDS_COMBINE, 0x03020600); copyDialog.Title += ' '; copyDialog.Title += srcPanel.GetItemRelPath(index); copyDialog.Static = LangString(IDS_COMBINE_TO, 0x03020601); copyDialog.Info = info; if (copyDialog.Create(srcPanel.GetParent()) == IDCANCEL) return; path = copyDialog.Value; } NFile::NName::NormalizeDirPathPrefix(path); if (!NFile::NDirectory::CreateComplexDirectory(path)) { srcPanel.MessageBoxMyError(MyFormatNew(IDS_CANNOT_CREATE_FOLDER, 0x02000603, path)); return; } UString outName = volSeqName.UnchangedPart; while (!outName.IsEmpty()) { int lastIndex = outName.Length() - 1; if (outName[lastIndex] != L'.') break; outName.Delete(lastIndex); } if (outName.IsEmpty()) outName = L"file"; NFile::NFind::CFileInfoW fileInfo; UString destFilePath = path + outName; combiner.OutputPath = destFilePath; if (fileInfo.Find(destFilePath)) { srcPanel.MessageBoxMyError(MyFormatNew(IDS_FILE_EXIST, 0x03020A04, destFilePath)); return; } CProgressDialog &progressDialog = combiner.ProgressDialog; progressDialog.ShowCompressionInfo = false; UString progressWindowTitle = LangString(IDS_APP_TITLE, 0x03000000); UString title = LangString(IDS_COMBINING, 0x03020610); progressDialog.MainWindow = _window; progressDialog.MainTitle = progressWindowTitle; progressDialog.MainAddTitle = title + UString(L" "); combiner.InputDirPrefix = srcPath; // CPanel::CDisableTimerProcessing disableTimerProcessing1(srcPanel); // CPanel::CDisableTimerProcessing disableTimerProcessing2(destPanel); if (combiner.Create(title, _window) != 0) return; } RefreshTitleAlways(); // disableTimerProcessing1.Restore(); // disableTimerProcessing2.Restore(); // srcPanel.SetFocusToList(); // srcPanel.RefreshListCtrlSaveFocused(); }
STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value) { COM_TRY_BEGIN NWindows::NCOM::CPropVariant propVariant; const CItemEx &item = _items[index]; switch(propID) { case kpidPath: { UString s = NItemName::WinNameToOSName(MultiByteToUnicodeString(item.GetName(), CP_OEMCP)); if (!s.IsEmpty()) { if (s[s.Length() - 1] == WCHAR_PATH_SEPARATOR) s.Delete(s.Length() - 1); propVariant = s; } break; } case kpidIsFolder: propVariant = item.IsDirectory(); break; case kpidSize: propVariant = item.Size; break; case kpidPackedSize: propVariant = item.PackSize; break; case kpidLastWriteTime: { FILETIME utcFileTime; UInt32 unixTime; if (item.GetUnixTime(unixTime)) { NTime::UnixTimeToFileTime(unixTime, utcFileTime); } else { FILETIME localFileTime; if (DosTimeToFileTime(item.ModifiedTime, localFileTime)) { if (!LocalFileTimeToFileTime(&localFileTime, &utcFileTime)) utcFileTime.dwHighDateTime = utcFileTime.dwLowDateTime = 0; } else utcFileTime.dwHighDateTime = utcFileTime.dwLowDateTime = 0; } propVariant = utcFileTime; break; } /* case kpidAttributes: propVariant = (UInt32)item.Attributes; break; case kpidCommented: propVariant = item.IsCommented(); break; */ case kpidCRC: propVariant = (UInt32)item.CRC; break; case kpidMethod: { wchar_t method2[kMethodIdSize + 1]; method2[kMethodIdSize] = 0; for (int i = 0; i < kMethodIdSize; i++) method2[i] = item.Method[i]; propVariant = method2; break; } case kpidHostOS: propVariant = GetOS(item.OsId); break; } propVariant.Detach(value); return S_OK; COM_TRY_END }
void Process2() { // NCOM::CComInitializer comInitializer; ProgressDialog->WaitCreating(); CVolSeqName volSeqName; if (!volSeqName.ParseName(FirstVolumeName)) throw L"Can not detect file as splitted file"; UString nextName = InputDirPrefix + FirstVolumeName; UInt64 totalSize = 0; for (;;) { NFile::NFind::CFileInfoW fileInfo; if (!NFile::NFind::FindFile(nextName, fileInfo)) break; if (fileInfo.IsDirectory()) break; totalSize += fileInfo.Size; nextName = InputDirPrefix + volSeqName.GetNextName(); } if (totalSize == 0) throw L"no data"; ProgressDialog->ProgressSynch.SetProgress(totalSize, 0); if (!volSeqName.ParseName(FirstVolumeName)) throw L"Can not detect file as splitted file"; UString outName = volSeqName.UnchangedPart; while(!outName.IsEmpty()) { int lastIndex = outName.Length() - 1; if (outName[lastIndex] != L'.') break; outName.Delete(lastIndex); } if (outName.IsEmpty()) outName = L"file"; NFile::NIO::COutFile outFile; if (!outFile.Create(OutputDirPrefix + outName, false)) throw L"Can create open output file"; NFile::NIO::CInFile inFile; CMyBuffer bufferObject; if (!bufferObject.Allocate(kBufSize)) throw L"Can not allocate buffer"; Byte *buffer = (Byte *)(void *)bufferObject; UInt64 pos = 0; nextName = InputDirPrefix + FirstVolumeName; bool needOpen = true; for (;;) { if (needOpen) { NFile::NFind::CFileInfoW fileInfo; if (!NFile::NFind::FindFile(nextName, fileInfo)) break; if (fileInfo.IsDirectory()) break; if (!inFile.Open(nextName)) throw L"Can not open file"; ProgressDialog->ProgressSynch.SetCurrentFileName(fileInfo.Name); nextName = InputDirPrefix + volSeqName.GetNextName(); needOpen = false; } UInt32 processedSize; if (!inFile.Read(buffer, kBufSize, processedSize)) throw L"Can not read input file"; if (processedSize == 0) { needOpen = true; continue; } UInt32 needSize = processedSize; if (!outFile.Write(buffer, needSize, processedSize)) throw L"Can not write output file"; if (needSize != processedSize) throw L"Can not write output file"; pos += processedSize; HRESULT res = ProgressDialog->ProgressSynch.SetPosAndCheckPaused(pos); if (res != S_OK) return; } }
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[destPath.Length() - 1] != 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 = di.Name; if (!directName) { UString destName = name; if (!destName.IsEmpty() && destName[destName.Length() - 1] == L':') { destName.Delete(destName.Length() - 1); destName += GetExt(index); } destPath2 += destName; } UString 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(srcPath, BoolToInt(false), NULL, &fileSize, destPath2, &destPathResult, &writeAskResult)); if (!IntToBool(writeAskResult)) continue; RINOK(callback->SetCurrentFilePath(srcPath)); static const UInt32 kBufferSize = (4 << 20); #ifdef _WIN32 UInt32 bufferSize = (di.DriveType == DRIVE_REMOVABLE) ? (18 << 10) * 4 : kBufferSize; #else UInt32 bufferSize = kBufferSize; #endif RINOK(CopyFileSpec(srcPath, destPathResult, false, fileSize, bufferSize, completedSize, callback)); completedSize += fileSize; } return S_OK; }
bool CPanel::OnComboBoxCommand(UINT code, LPARAM /* param */, LRESULT &result) { result = FALSE; switch(code) { case CBN_DROPDOWN: { ComboBoxPaths.Clear(); _headerComboBox.ResetContent(); int iconIndex; UString name; int i; UStringVector pathParts; SplitPathToParts(_currentFolderPrefix, pathParts); UString sumPass; for (i = 0; i < pathParts.Size(); i++) { UString name = pathParts[i]; if (name.IsEmpty()) continue; sumPass += name; UString curName = sumPass; if (i == 0) curName += WCHAR_PATH_SEPARATOR; CFileInfoW info; DWORD attrib = FILE_ATTRIBUTE_DIRECTORY; if (NFile::NFind::FindFile(sumPass, info)) attrib = info.Attrib; sumPass += WCHAR_PATH_SEPARATOR; AddComboBoxItem(name, GetRealIconIndex(curName, attrib), i, false); ComboBoxPaths.Add(sumPass); } 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); // UStringVector strings; _appState->FolderHistory.GetList(strings); 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); return true; } } return false; } /* case CBN_CLOSEUP: { LoadFullPathAndShow(); true; } case CBN_SELCHANGE: { // LoadFullPathAndShow(); return true; } */ } return false; }
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; }