void CPanel::GetSelectedNames(UStringVector &selectedNames) { selectedNames.Clear(); CRecordVector<UInt32> indices; GetSelectedItemsIndices(indices); selectedNames.Reserve(indices.Size()); for (int i = 0; i < indices.Size(); i++) selectedNames.Add(GetItemRelPath(indices[i])); /* for (int i = 0; i < _listView.GetItemCount(); i++) { const int kSize = 1024; WCHAR name[kSize + 1]; LVITEMW item; item.iItem = i; item.pszText = name; item.cchTextMax = kSize; item.iSubItem = 0; item.mask = LVIF_TEXT | LVIF_PARAM; if (!_listView.GetItem(&item)) continue; int realIndex = GetRealIndex(item); if (realIndex == kParentIndex) continue; if (_selectedStatusVector[realIndex]) selectedNames.Add(item.pszText); } */ selectedNames.Sort(); }
void CDrop::QueryFileNames(UStringVector &fileNames) { fileNames.Clear(); UINT numFiles = QueryCountOfFiles(); fileNames.Reserve(numFiles); for(UINT i = 0; i < numFiles; i++) fileNames.Add(QueryFileName(i)); }
void EnumerateDirItemsAndSort(NWildcard::CCensor &wildcardCensor, UStringVector &sortedPaths, UStringVector &sortedFullPaths) { UStringVector paths; { CDirItems dirItems; { UStringVector errorPaths; CRecordVector<DWORD> errorCodes; HRESULT res = EnumerateItems(wildcardCensor, dirItems, NULL, errorPaths, errorCodes); if (res != S_OK || errorPaths.Size() > 0) throw "cannot find archive"; } for (int i = 0; i < dirItems.Items.Size(); i++) { const CDirItem &dirItem = dirItems.Items[i]; if (!dirItem.IsDir()) paths.Add(dirItems.GetPhyPath(i)); } } if (paths.Size() == 0) throw "there is no such archive"; UStringVector fullPaths; int i; for (i = 0; i < paths.Size(); i++) { UString fullPath; NFile::NDirectory::MyGetFullPathName(paths[i], fullPath); fullPaths.Add(fullPath); } CIntVector indices; SortFileNames(fullPaths, indices); sortedPaths.Reserve(indices.Size()); sortedFullPaths.Reserve(indices.Size()); for (i = 0; i < indices.Size(); i++) { int index = indices[i]; sortedPaths.Add(paths[index]); sortedFullPaths.Add(fullPaths[index]); } }
void SortStrings(const UStringVector &src, UStringVector &dest) { CIntVector indices; SortStringsToIndices(src, indices); dest.Clear(); dest.Reserve(indices.Size()); for (int i = 0; i < indices.Size(); i++) dest.Add(src[indices[i]]); }
NFileOperationReturnCode::EEnum CPlugin::PutFiles( struct PluginPanelItem *panelItems, int numItems, int moveMode, int opMode) { if (moveMode != 0) { g_StartupInfo.ShowMessage(NMessageID::kMoveIsNotSupported); return NFileOperationReturnCode::kError; } if (numItems == 0) return NFileOperationReturnCode::kError; /* if (!m_ArchiverInfo.UpdateEnabled) { g_StartupInfo.ShowMessage(NMessageID::kUpdateNotSupportedForThisArchive); return NFileOperationReturnCode::kError; } */ const int kYSize = 14; const int kXMid = 38; NCompression::CInfo compressionInfo; compressionInfo.Load(); int methodIndex = 0; int i; for (i = sizeof(g_MethodMap) / sizeof(g_MethodMap[0]) - 1; i >= 0; i--) if (compressionInfo.Level >= g_MethodMap[i]) { methodIndex = i; break; } const int kMethodRadioIndex = 2; const int kModeRadioIndex = kMethodRadioIndex + 7; struct CInitDialogItem initItems[]={ { DI_DOUBLEBOX, 3, 1, 72, kYSize - 2, false, false, 0, false, NMessageID::kUpdateTitle, NULL, NULL }, { DI_SINGLEBOX, 4, 2, kXMid - 2, 2 + 7, false, false, 0, false, NMessageID::kUpdateMethod, NULL, NULL }, { DI_RADIOBUTTON, 6, 3, 0, 0, methodIndex == 0, methodIndex == 0, DIF_GROUP, false, NMessageID::kUpdateMethodStore, NULL, NULL }, { DI_RADIOBUTTON, 6, 4, 0, 0, methodIndex == 1, methodIndex == 1, 0, false, NMessageID::kUpdateMethodFastest, NULL, NULL }, { DI_RADIOBUTTON, 6, 5, 0, 0, methodIndex == 2, methodIndex == 2, 0, false, NMessageID::kUpdateMethodFast, NULL, NULL }, { DI_RADIOBUTTON, 6, 6, 0, 0, methodIndex == 3, methodIndex == 3, 0, false, NMessageID::kUpdateMethodNormal, NULL, NULL }, { DI_RADIOBUTTON, 6, 7, 0, 0, methodIndex == 4, methodIndex == 4, 0, false, NMessageID::kUpdateMethodMaximum, NULL, NULL }, { DI_RADIOBUTTON, 6, 8, 0, 0, methodIndex == 5, methodIndex == 5, 0, false, NMessageID::kUpdateMethodUltra, NULL, NULL }, { DI_SINGLEBOX, kXMid, 2, 70, 2 + 5, false, false, 0, false, NMessageID::kUpdateMode, NULL, NULL }, { DI_RADIOBUTTON, kXMid + 2, 3, 0, 0, false, true, DIF_GROUP, false, NMessageID::kUpdateModeAdd, NULL, NULL }, { DI_RADIOBUTTON, kXMid + 2, 4, 0, 0, false, false, 0, false, NMessageID::kUpdateModeUpdate, NULL, NULL }, { DI_RADIOBUTTON, kXMid + 2, 5, 0, 0, false, false, 0, false, NMessageID::kUpdateModeFreshen, NULL, NULL }, { DI_RADIOBUTTON, kXMid + 2, 6, 0, 0, false, false, 0, false, NMessageID::kUpdateModeSynchronize, NULL, NULL }, { DI_TEXT, 3, kYSize - 4, 0, 0, false, false, DIF_BOXCOLOR|DIF_SEPARATOR, false, -1, "", NULL }, { DI_BUTTON, 0, kYSize - 3, 0, 0, false, false, DIF_CENTERGROUP, true, NMessageID::kUpdateAdd, NULL, NULL }, { DI_BUTTON, 0, kYSize - 3, 0, 0, false, false, DIF_CENTERGROUP, false, NMessageID::kCancel, NULL, NULL } }; const int kNumDialogItems = sizeof(initItems) / sizeof(initItems[0]); const int kOkButtonIndex = kNumDialogItems - 2; FarDialogItem dialogItems[kNumDialogItems]; g_StartupInfo.InitDialogItems(initItems, dialogItems, kNumDialogItems); int askCode = g_StartupInfo.ShowDialog(76, kYSize, kHelpTopic, dialogItems, kNumDialogItems); if (askCode != kOkButtonIndex) return NFileOperationReturnCode::kInterruptedByUser; compressionInfo.Level = g_MethodMap[0]; for (i = 0; i < sizeof(g_MethodMap)/ sizeof(g_MethodMap[0]); i++) if (dialogItems[kMethodRadioIndex + i].Selected) compressionInfo.Level = g_MethodMap[i]; const CActionSet *actionSet; if (dialogItems[kModeRadioIndex].Selected) actionSet = &kAddActionSet; else if (dialogItems[kModeRadioIndex + 1].Selected) actionSet = &kUpdateActionSet; else if (dialogItems[kModeRadioIndex + 2].Selected) actionSet = &kFreshActionSet; else if (dialogItems[kModeRadioIndex + 3].Selected) actionSet = &kSynchronizeActionSet; else throw 51751; compressionInfo.Save(); CWorkDirTempFile tempFile;; if (tempFile.CreateTempFile(m_FileName) != S_OK) return NFileOperationReturnCode::kError; /* CSysStringVector fileNames; for (int i = 0; i < numItems; i++) { const PluginPanelItem &panelItem = panelItems[i]; CSysString fullName; if (!MyGetFullPathName(panelItem.FindData.cFileName, fullName)) return NFileOperationReturnCode::kError; fileNames.Add(fullName); } */ CScreenRestorer screenRestorer; CProgressBox progressBox; CProgressBox *progressBoxPointer = NULL; if ((opMode & OPM_SILENT) == 0 && (opMode & OPM_FIND ) == 0) { screenRestorer.Save(); progressBoxPointer = &progressBox; progressBox.Init( // g_StartupInfo.GetMsgString(NMessageID::kWaitTitle), g_StartupInfo.GetMsgString(NMessageID::kUpdating), 48); } UStringVector pathVector; GetPathParts(pathVector); UStringVector fileNames; fileNames.Reserve(numItems); for (i = 0; i < numItems; i++) fileNames.Add(MultiByteToUnicodeString(panelItems[i].FindData.cFileName, CP_OEMCP)); CRecordVector<const wchar_t *> fileNamePointers; fileNamePointers.Reserve(numItems); for (i = 0; i < numItems; i++) fileNamePointers.Add(fileNames[i]); CMyComPtr<IOutFolderArchive> outArchive; HRESULT result = m_ArchiveHandler.QueryInterface(IID_IOutFolderArchive, &outArchive); if (result != S_OK) { g_StartupInfo.ShowMessage(NMessageID::kUpdateNotSupportedForThisArchive); return NFileOperationReturnCode::kError; } outArchive->SetFolder(_folder); outArchive->SetFiles(L"", &fileNamePointers.Front(), fileNamePointers.Size()); BYTE actionSetByte[NUpdateArchive::NPairState::kNumValues]; for (i = 0; i < NUpdateArchive::NPairState::kNumValues; i++) actionSetByte[i] = (BYTE)actionSet->StateActions[i]; CUpdateCallback100Imp *updateCallbackSpec = new CUpdateCallback100Imp; CMyComPtr<IFolderArchiveUpdateCallback> updateCallback(updateCallbackSpec ); updateCallbackSpec->Init(/* m_ArchiveHandler, */ progressBoxPointer); if (SetOutProperties(outArchive, compressionInfo.Level) != S_OK) return NFileOperationReturnCode::kError; result = outArchive->DoOperation2(tempFile.OutStream, actionSetByte, NULL, updateCallback); updateCallback.Release(); outArchive.Release(); if (result == S_OK) { result = AfterUpdate(tempFile, pathVector); } if (result != S_OK) { ShowErrorMessage(result); return NFileOperationReturnCode::kError; } /* if (moveMode != 0) { for (int i = 0; i < numItems; i++) { const PluginPanelItem &pluginPanelItem = panelItems[i]; bool result; if (NFile::NFind::NAttributes::IsDir(pluginPanelItem.FindData.dwFileAttributes)) result = NFile::NDirectory::RemoveDirectoryWithSubItems(pluginPanelItem.FindData.cFileName); else result = NFile::NDirectory::DeleteFileAlways(pluginPanelItem.FindData.cFileName); if (!result) return NFileOperationReturnCode::kError; } } */ return NFileOperationReturnCode::kSuccess; }
void CApp::OnCopy(bool move, bool copyToSame, int srcPanelIndex) { int destPanelIndex = (NumPanels <= 1) ? srcPanelIndex : (1 - srcPanelIndex); CPanel &srcPanel = Panels[srcPanelIndex]; CPanel &destPanel = Panels[destPanelIndex]; CPanel::CDisableTimerProcessing disableTimerProcessing1(destPanel); CPanel::CDisableTimerProcessing disableTimerProcessing2(srcPanel); if (!srcPanel.DoesItSupportOperations()) { srcPanel.MessageBox(LangString(IDS_OPERATION_IS_NOT_SUPPORTED, 0x03020208)); return; } CRecordVector<UInt32> indices; UString destPath; bool useDestPanel = false; { if (copyToSame) { int focusedItem = srcPanel._listView.GetFocusedItem(); if (focusedItem < 0) return; int realIndex = srcPanel.GetRealItemIndex(focusedItem); if (realIndex == kParentIndex) return; indices.Add(realIndex); destPath = srcPanel.GetItemName(realIndex); } else { srcPanel.GetOperatedItemIndices(indices); if (indices.Size() == 0) return; destPath = destPanel._currentFolderPrefix; if (NumPanels == 1) ReducePathToRealFileSystemPath(destPath); } CCopyDialog copyDialog; UStringVector copyFolders; ReadCopyHistory(copyFolders); copyDialog.Strings = copyFolders; copyDialog.Value = destPath; copyDialog.Title = move ? LangString(IDS_MOVE, 0x03020202): LangString(IDS_COPY, 0x03020201); copyDialog.Static = move ? LangString(IDS_MOVE_TO, 0x03020204): LangString(IDS_COPY_TO, 0x03020203); copyDialog.Info = srcPanel.GetItemsInfoString(indices); if (copyDialog.Create(srcPanel.GetParent()) == IDCANCEL) return; destPath = copyDialog.Value; if (destPath.IsEmpty()) { srcPanel.MessageBox(LangString(IDS_OPERATION_IS_NOT_SUPPORTED, 0x03020208)); return; } if (!IsPathAbsolute(destPath)) { if (!srcPanel.IsFSFolder()) { srcPanel.MessageBox(LangString(IDS_OPERATION_IS_NOT_SUPPORTED, 0x03020208)); return; } destPath = srcPanel._currentFolderPrefix + destPath; } printf("destPath='%ls'\n",(const wchar_t *)destPath); #ifdef _WIN32 if (destPath.Length() > 0 && destPath[0] == CHAR_PATH_SEPARATOR) if (destPath.Length() == 1 || destPath[1] != CHAR_PATH_SEPARATOR) { srcPanel.MessageBox(LangString(IDS_OPERATION_IS_NOT_SUPPORTED, 0x03020208)); return; } #endif if (indices.Size() > 1 || (destPath.Length() > 0 && destPath.ReverseFind(CHAR_PATH_SEPARATOR) == destPath.Length() - 1) || IsThereFolderOfPath(destPath)) { NDirectory::CreateComplexDirectory(destPath); NName::NormalizeDirPathPrefix(destPath); if (!CheckFolderPath(destPath)) { if (NumPanels < 2 || destPath != destPanel._currentFolderPrefix || !destPanel.DoesItSupportOperations()) { srcPanel.MessageBox(LangString(IDS_OPERATION_IS_NOT_SUPPORTED, 0x03020208)); return; } useDestPanel = true; } } else { int pos = destPath.ReverseFind(CHAR_PATH_SEPARATOR); if (pos >= 0) { UString prefix = destPath.Left(pos + 1); NDirectory::CreateComplexDirectory(prefix); if (!CheckFolderPath(prefix)) { srcPanel.MessageBox(LangString(IDS_OPERATION_IS_NOT_SUPPORTED, 0x03020208)); return; } } } AddUniqueStringToHeadOfList(copyFolders, destPath); while (copyFolders.Size() > 20) copyFolders.DeleteBack(); SaveCopyHistory(copyFolders); } bool useSrcPanel = (!useDestPanel || !srcPanel.IsFSFolder() || destPanel.IsFSFolder()); bool useTemp = useSrcPanel && useDestPanel; // FIXME NFile::NDirectory::CTempDirectoryW tempDirectory; UString tempDirPrefix; if (useTemp) { /* FIXME tempDirectory.Create(kTempDirPrefix); tempDirPrefix = tempDirectory.GetPath(); NFile::NName::NormalizeDirPathPrefix(tempDirPrefix); */ printf("useTemp : Not Implemented\n"); exit(EXIT_FAILURE); } CSelectedState srcSelState; CSelectedState destSelState; srcPanel.SaveSelectedState(srcSelState); destPanel.SaveSelectedState(destSelState); HRESULT result; if (useSrcPanel) { UString folder = useTemp ? tempDirPrefix : destPath; result = srcPanel.CopyTo(indices, folder, move, true, 0); if (result != S_OK) { disableTimerProcessing1.Restore(); disableTimerProcessing2.Restore(); // For Password: srcPanel.SetFocusToList(); if (result != E_ABORT) srcPanel.MessageBoxError(result, L"Error"); return; } } if (useDestPanel) { UStringVector filePaths; UString folderPrefix; if (useTemp) folderPrefix = tempDirPrefix; else folderPrefix = srcPanel._currentFolderPrefix; filePaths.Reserve(indices.Size()); for(int i = 0; i < indices.Size(); i++) filePaths.Add(srcPanel.GetItemRelPath(indices[i])); result = destPanel.CopyFrom(folderPrefix, filePaths, true, 0); if (result != S_OK) { disableTimerProcessing1.Restore(); disableTimerProcessing2.Restore(); // For Password: srcPanel.SetFocusToList(); if (result != E_ABORT) srcPanel.MessageBoxError(result, L"Error"); return; } } RefreshTitleAlways(); if (copyToSame || move) { srcPanel.RefreshListCtrl(srcSelState); } if (!copyToSame) { destPanel.RefreshListCtrl(destSelState); srcPanel.KillSelection(); } disableTimerProcessing1.Restore(); disableTimerProcessing2.Restore(); srcPanel.SetFocusToList(); }
void CApp::OnCopy(bool move, bool copyToSame, int srcPanelIndex) { int destPanelIndex = (NumPanels <= 1) ? srcPanelIndex : (1 - srcPanelIndex); CPanel &srcPanel = Panels[srcPanelIndex]; CPanel &destPanel = Panels[destPanelIndex]; CPanel::CDisableTimerProcessing disableTimerProcessing1(destPanel); CPanel::CDisableTimerProcessing disableTimerProcessing2(srcPanel); if (!srcPanel.DoesItSupportOperations()) { srcPanel.MessageBoxErrorLang(IDS_OPERATION_IS_NOT_SUPPORTED, 0x03020208); return; } CRecordVector<UInt32> indices; UString destPath; bool useDestPanel = false; { if (copyToSame) { int focusedItem = srcPanel._listView.GetFocusedItem(); if (focusedItem < 0) return; int realIndex = srcPanel.GetRealItemIndex(focusedItem); if (realIndex == kParentIndex) return; indices.Add(realIndex); destPath = srcPanel.GetItemName(realIndex); } else { srcPanel.GetOperatedIndicesSmart(indices); if (indices.Size() == 0) return; destPath = destPanel._currentFolderPrefix; if (NumPanels == 1) ReducePathToRealFileSystemPath(destPath); } CCopyDialog copyDialog; UStringVector copyFolders; ReadCopyHistory(copyFolders); copyDialog.Strings = copyFolders; copyDialog.Value = destPath; copyDialog.Title = move ? LangString(IDS_MOVE, 0x03020202): LangString(IDS_COPY, 0x03020201); copyDialog.Static = move ? LangString(IDS_MOVE_TO, 0x03020204): LangString(IDS_COPY_TO, 0x03020203); copyDialog.Info = srcPanel.GetItemsInfoString(indices); if (copyDialog.Create(srcPanel.GetParent()) == IDCANCEL) return; destPath = copyDialog.Value; if (destPath.IsEmpty()) { srcPanel.MessageBoxErrorLang(IDS_OPERATION_IS_NOT_SUPPORTED, 0x03020208); return; } if (!IsPathAbsolute(destPath)) { if (!srcPanel.IsFSFolder()) { srcPanel.MessageBoxErrorLang(IDS_OPERATION_IS_NOT_SUPPORTED, 0x03020208); return; } destPath = srcPanel._currentFolderPrefix + destPath; } #ifndef UNDER_CE if (destPath.Length() > 0 && destPath[0] == '\\') if (destPath.Length() == 1 || destPath[1] != '\\') { srcPanel.MessageBoxErrorLang(IDS_OPERATION_IS_NOT_SUPPORTED, 0x03020208); return; } #endif if (indices.Size() > 1 || (!destPath.IsEmpty() && destPath.Back() == WCHAR_PATH_SEPARATOR) || NFind::DoesDirExist(us2fs(destPath)) || srcPanel.IsArcFolder()) { NDirectory::CreateComplexDirectory(us2fs(destPath)); NName::NormalizeDirPathPrefix(destPath); if (!CheckFolderPath(destPath)) { if (NumPanels < 2 || destPath != destPanel._currentFolderPrefix || !destPanel.DoesItSupportOperations()) { srcPanel.MessageBoxErrorLang(IDS_OPERATION_IS_NOT_SUPPORTED, 0x03020208); return; } useDestPanel = true; } } else { if (!IsCorrectFsName(destPath)) { srcPanel.MessageBoxError(E_INVALIDARG); return; } int pos = destPath.ReverseFind(WCHAR_PATH_SEPARATOR); if (pos >= 0) { UString prefix = destPath.Left(pos + 1); NDirectory::CreateComplexDirectory(us2fs(prefix)); if (!CheckFolderPath(prefix)) { srcPanel.MessageBoxErrorLang(IDS_OPERATION_IS_NOT_SUPPORTED, 0x03020208); return; } } } AddUniqueStringToHeadOfList(copyFolders, destPath); while (copyFolders.Size() > 20) copyFolders.DeleteBack(); SaveCopyHistory(copyFolders); } /* if (destPath == destPanel._currentFolderPrefix) { if (destPanel.GetFolderTypeID() == L"PhysDrive") useDestPanel = true; } */ bool useSrcPanel = (!useDestPanel || !srcPanel.IsFsOrDrivesFolder() || destPanel.IsFSFolder()); bool useTemp = useSrcPanel && useDestPanel; NFile::NDirectory::CTempDir tempDirectory; FString tempDirPrefix; if (useTemp) { tempDirectory.Create(kTempDirPrefix); tempDirPrefix = tempDirectory.GetPath(); NFile::NName::NormalizeDirPathPrefix(tempDirPrefix); } CSelectedState srcSelState; CSelectedState destSelState; srcPanel.SaveSelectedState(srcSelState); destPanel.SaveSelectedState(destSelState); HRESULT result; if (useSrcPanel) { UString folder = useTemp ? fs2us(tempDirPrefix) : destPath; result = srcPanel.CopyTo(indices, folder, move, true, 0); if (result != S_OK) { disableTimerProcessing1.Restore(); disableTimerProcessing2.Restore(); // For Password: srcPanel.SetFocusToList(); if (result != E_ABORT) srcPanel.MessageBoxError(result, L"Error"); return; } } if (useDestPanel) { UStringVector filePaths; UString folderPrefix; if (useTemp) folderPrefix = fs2us(tempDirPrefix); else folderPrefix = srcPanel._currentFolderPrefix; filePaths.Reserve(indices.Size()); for (int i = 0; i < indices.Size(); i++) filePaths.Add(srcPanel.GetItemRelPath(indices[i])); result = destPanel.CopyFrom(folderPrefix, filePaths, true, 0); if (result != S_OK) { disableTimerProcessing1.Restore(); disableTimerProcessing2.Restore(); // For Password: srcPanel.SetFocusToList(); if (result != E_ABORT) srcPanel.MessageBoxError(result, L"Error"); return; } } RefreshTitleAlways(); if (copyToSame || move) { srcPanel.RefreshListCtrl(srcSelState); } if (!copyToSame) { destPanel.RefreshListCtrl(destSelState); srcPanel.KillSelection(); } disableTimerProcessing1.Restore(); disableTimerProcessing2.Restore(); srcPanel.SetFocusToList(); }