HRESULT CContentsView::CalculateCrc2(const UString &methodName) { CContentsView &srcPanel = *this; CRecordVector<UInt32> indices; srcPanel.GetOperatedIndicesSmart(indices); if (indices.IsEmpty()) return S_OK; if (!srcPanel.Is_IO_FS_Folder()) { CCopyToOptions options; options.streamMode = true; options.showErrorMessages = true; options.hashMethods.Add(methodName); UStringVector messages; return srcPanel.CopyTo(options, indices, &messages); } #ifdef EXTERNAL_CODECS LoadGlobalCodecs(); #endif { CThreadCrc t; { UStringVector methods; methods.Add(methodName); RINOK(t.Hash.SetMethods(EXTERNAL_CODECS_VARS_G methods)); } FOR_VECTOR (i, indices) t.Enumerator.FilePaths.Add(us2fs(srcPanel.GetItemRelPath(indices[i]))); UString basePrefix = srcPanel.GetFsPath(); UString basePrefix2 = basePrefix; if (basePrefix2.Back() == ':') { int pos = basePrefix2.ReverseFind_PathSepar(); if (pos >= 0) basePrefix2.DeleteFrom(pos + 1); } t.Enumerator.BasePrefix = us2fs(basePrefix); t.Enumerator.BasePrefix_for_Open = us2fs(basePrefix2); t.Enumerator.EnterToDirs = !GetFlatMode(); t.ProgressDialog.ShowCompressionInfo = false; UString title = LangString(IDS_CHECKSUM_CALCULATING); t.ProgressDialog.MainWindow = *GetTopLevelParent(); t.ProgressDialog.MainTitle = L"7-Zip"; // LangString(IDS_APP_TITLE); t.ProgressDialog.MainAddTitle = title; t.ProgressDialog.MainAddTitle.Add_Space(); RINOK(t.Create(title, *GetTopLevelParent())); } RefreshTitle(); return S_OK; }
static HRESULT EnumerateDirItems(const NWildcard::CCensorNode &curNode, int phyParent, int logParent, const FString &phyPrefix, const UStringVector &addArchivePrefix, // prefix from curNode CDirItems &dirItems, bool enterToSubFolders, IEnumDirItemCallback *callback, FStringVector &errorPaths, CRecordVector<DWORD> &errorCodes) { if (!enterToSubFolders) if (curNode.NeedCheckSubDirs()) enterToSubFolders = true; if (callback) RINOK(callback->ScanProgress(dirItems.GetNumFolders(), dirItems.Items.Size(), fs2us(phyPrefix))); // try direct_names case at first if (addArchivePrefix.IsEmpty() && !enterToSubFolders) { // check that all names are direct int i; for (i = 0; i < curNode.IncludeItems.Size(); i++) { const NWildcard::CItem &item = curNode.IncludeItems[i]; if (item.Recursive || item.PathParts.Size() != 1) break; const UString &name = item.PathParts.Front(); if (name.IsEmpty() || DoesNameContainWildCard(name)) break; } if (i == curNode.IncludeItems.Size()) { // all names are direct (no wildcards) // so we don't need file_system's dir enumerator CRecordVector<bool> needEnterVector; for (i = 0; i < curNode.IncludeItems.Size(); i++) { const NWildcard::CItem &item = curNode.IncludeItems[i]; const UString &name = item.PathParts.Front(); const FString fullPath = phyPrefix + us2fs(name); NFind::CFileInfo fi; if (!fi.Find(fullPath)) { errorCodes.Add(::GetLastError()); errorPaths.Add(fullPath); continue; } bool isDir = fi.IsDir(); if (isDir && !item.ForDir || !isDir && !item.ForFile) { errorCodes.Add((DWORD)E_FAIL); errorPaths.Add(fullPath); continue; } { UStringVector pathParts; pathParts.Add(fs2us(fi.Name)); if (curNode.CheckPathToRoot(false, pathParts, !isDir)) continue; } AddDirFileInfo(phyParent, logParent, fi, dirItems.Items); if (!isDir) continue; UStringVector addArchivePrefixNew; const NWildcard::CCensorNode *nextNode = 0; int index = curNode.FindSubNode(name); if (index >= 0) { for (int t = needEnterVector.Size(); t <= index; t++) needEnterVector.Add(true); needEnterVector[index] = false; nextNode = &curNode.SubNodes[index]; } else { nextNode = &curNode; addArchivePrefixNew.Add(name); // don't change it to fi.Name. It's for shortnames support } RINOK(EnumerateDirItems_Spec(*nextNode, phyParent, logParent, fi.Name, phyPrefix, addArchivePrefixNew, dirItems, true, callback, errorPaths, errorCodes)); } for (i = 0; i < curNode.SubNodes.Size(); i++) { if (i < needEnterVector.Size()) if (!needEnterVector[i]) continue; const NWildcard::CCensorNode &nextNode = curNode.SubNodes[i]; const FString fullPath = phyPrefix + us2fs(nextNode.Name); NFind::CFileInfo fi; if (!fi.Find(fullPath)) { if (!nextNode.AreThereIncludeItems()) continue; errorCodes.Add(::GetLastError()); errorPaths.Add(fullPath); continue; } if (!fi.IsDir()) { errorCodes.Add((DWORD)E_FAIL); errorPaths.Add(fullPath); continue; } RINOK(EnumerateDirItems_Spec(nextNode, phyParent, logParent, fi.Name, phyPrefix, UStringVector(), dirItems, false, callback, errorPaths, errorCodes)); } return S_OK; } } NFind::CEnumerator enumerator(phyPrefix + FCHAR_ANY_MASK); for (int ttt = 0; ; ttt++) { NFind::CFileInfo fi; bool found; if (!enumerator.Next(fi, found)) { errorCodes.Add(::GetLastError()); errorPaths.Add(phyPrefix); break; } if (!found) break; if (callback && (ttt & 0xFF) == 0xFF) RINOK(callback->ScanProgress(dirItems.GetNumFolders(), dirItems.Items.Size(), fs2us(phyPrefix))); const UString &name = fs2us(fi.Name); bool enterToSubFolders2 = enterToSubFolders; UStringVector addArchivePrefixNew = addArchivePrefix; addArchivePrefixNew.Add(name); { UStringVector addArchivePrefixNewTemp(addArchivePrefixNew); if (curNode.CheckPathToRoot(false, addArchivePrefixNewTemp, !fi.IsDir())) continue; } if (curNode.CheckPathToRoot(true, addArchivePrefixNew, !fi.IsDir())) { AddDirFileInfo(phyParent, logParent, fi, dirItems.Items); if (fi.IsDir()) enterToSubFolders2 = true; } if (!fi.IsDir()) continue; const NWildcard::CCensorNode *nextNode = 0; if (addArchivePrefix.IsEmpty()) { int index = curNode.FindSubNode(name); if (index >= 0) nextNode = &curNode.SubNodes[index]; } if (!enterToSubFolders2 && nextNode == 0) continue; addArchivePrefixNew = addArchivePrefix; if (nextNode == 0) { nextNode = &curNode; addArchivePrefixNew.Add(name); } RINOK(EnumerateDirItems_Spec(*nextNode, phyParent, logParent, fi.Name, phyPrefix, addArchivePrefixNew, dirItems, enterToSubFolders2, callback, errorPaths, errorCodes)); } return S_OK; }
static void WriteArgumentsToStringList(int numArgs, const char *args[], UStringVector &strings) { for (int i = 1; i < numArgs; i++) strings.Add(MultiByteToUnicodeString(args[i])); }
void mySplitCommandLine(int numArguments, char *arguments[],UStringVector &parts) { { // define P7ZIP_HOME_DIR static char p7zip_home_dir[MAX_PATH]; AString dir,name; my_windows_split_path(arguments[0],dir,name); snprintf(p7zip_home_dir,sizeof(p7zip_home_dir),"P7ZIP_HOME_DIR=%s/",(const char *)dir); p7zip_home_dir[sizeof(p7zip_home_dir)-1] = 0; putenv(p7zip_home_dir); } #ifdef ENV_HAVE_LOCALE // set the program's current locale from the user's environment variables setlocale(LC_ALL,""); // auto-detect which conversion p7zip should use char *locale = setlocale(LC_CTYPE,0); if (locale) { size_t len = strlen(locale); char *locale_upper = (char *)malloc(len+1); if (locale_upper) { strcpy(locale_upper,locale); for(size_t i=0;i<len;i++) locale_upper[i] = toupper(locale_upper[i] & 255); if ( (strcmp(locale_upper,"") != 0) && (strcmp(locale_upper,"C") != 0) && (strcmp(locale_upper,"POSIX") != 0) ) { global_use_utf16_conversion = 1; } free(locale_upper); } } #elif defined(LOCALE_IS_UTF8) global_use_utf16_conversion = 1; // assume LC_CTYPE="utf8" #else global_use_utf16_conversion = 0; // assume LC_CTYPE="C" #endif parts.Clear(); for(int ind=0;ind < numArguments; ind++) { if ((ind <= 2) && (strcmp(arguments[ind],"-no-utf16") == 0)) { global_use_utf16_conversion = 0; } else if ((ind <= 2) && (strcmp(arguments[ind],"-utf16") == 0)) { global_use_utf16_conversion = 1; } else { UString tmp = MultiByteToUnicodeString(arguments[ind]); // tmp.Trim(); " " is a valid filename ... if (!tmp.IsEmpty()) { parts.Add(tmp); } // try to hide the password { char * arg = arguments[ind]; size_t len = strlen(arg); if ( (len > 2) && (arg[0] == '-') && ( (arg[1]=='p') || (arg[1]=='P') ) ) { memset(arg+2,'*',len-2); } } } } }
void Correct_FsPath(bool absIsAllowed, UStringVector &parts, bool isDir) { unsigned i = 0; if (absIsAllowed) { #if defined(_WIN32) && !defined(UNDER_CE) bool isDrive = false; #endif if (parts[0].IsEmpty()) { i = 1; #if defined(_WIN32) && !defined(UNDER_CE) if (parts.Size() > 1 && parts[1].IsEmpty()) { i = 2; if (parts.Size() > 2 && parts[2] == L"?") { i = 3; if (parts.Size() > 3 && NWindows::NFile::NName::IsDrivePath2(parts[3])) { isDrive = true; i = 4; } } } #endif } #if defined(_WIN32) && !defined(UNDER_CE) else if (NWindows::NFile::NName::IsDrivePath2(parts[0])) { isDrive = true; i = 1; } if (isDrive) { // we convert "c:name" to "c:\name", if absIsAllowed path. UString &ds = parts[i - 1]; if (ds.Len() > 2) { parts.Insert(i, ds.Ptr(2)); ds.DeleteFrom(2); } } #endif } for (; i < parts.Size();) { UString &s = parts[i]; Correct_PathPart(s); if (s.IsEmpty()) { if (isDir || i != parts.Size() - 1) { parts.Delete(i); continue; } s = k_EmptyReplaceName; } else { #ifdef _WIN32 CorrectUnsupportedName(s); #endif } i++; } if (!isDir) { if (parts.IsEmpty()) parts.Add((UString)k_EmptyReplaceName); else { UString &s = parts.Back(); if (s.IsEmpty()) s = k_EmptyReplaceName; } } }
void CApp::CalculateCrc(const UString &methodName) { int srcPanelIndex = GetFocusedPanelIndex(); CPanel &srcPanel = Panels[srcPanelIndex]; CRecordVector<UInt32> indices; srcPanel.GetOperatedIndicesSmart(indices); if (indices.IsEmpty()) return; if (!srcPanel.IsFsOrDrivesFolder()) { CCopyToOptions options; options.streamMode = true; options.showErrorMessages = true; options.hashMethods.Add(methodName); UStringVector messages; HRESULT res = srcPanel.CopyTo(options, indices, &messages); if (res != S_OK) { if (res != E_ABORT) srcPanel.MessageBoxError(res); } return; } CCodecs *codecs = new CCodecs; #ifdef EXTERNAL_CODECS CExternalCodecs __externalCodecs; __externalCodecs.GetCodecs = codecs; __externalCodecs.GetHashers = codecs; #else CMyComPtr<IUnknown> compressCodecsInfo = codecs; #endif ThrowException_if_Error(codecs->Load()); #ifdef EXTERNAL_CODECS ThrowException_if_Error(__externalCodecs.LoadCodecs()); #endif { CThreadCrc t; { UStringVector methods; methods.Add(methodName); t.Hash.SetMethods(EXTERNAL_CODECS_VARS methods); } FOR_VECTOR (i, indices) t.Enumerator.FilePaths.Add(us2fs(srcPanel.GetItemRelPath(indices[i]))); t.Enumerator.BasePrefix = us2fs(srcPanel.GetFsPath()); t.Enumerator.EnterToDirs = !GetFlatMode(); t.ProgressDialog.ShowCompressionInfo = false; UString title = LangString(IDS_CHECKSUM_CALCULATING); t.ProgressDialog.MainWindow = _window; t.ProgressDialog.MainTitle = L"7-Zip"; // LangString(IDS_APP_TITLE); t.ProgressDialog.MainAddTitle = title + UString(L' '); if (t.Create(title, _window) != S_OK) return; } RefreshTitleAlways(); }
static HRESULT EnumerateDirItems( const NWildcard::CCensorNode &curNode, const UString &diskPrefix, // full disk path prefix const UString &archivePrefix, // prefix from root const UStringVector &addArchivePrefix, // prefix from curNode CObjectVector<CDirItem> &dirItems, bool enterToSubFolders, IEnumDirItemCallback *callback, UStringVector &errorPaths, CRecordVector<DWORD> &errorCodes) { if (!enterToSubFolders) if (curNode.NeedCheckSubDirs()) enterToSubFolders = true; if (callback) RINOK(callback->CheckBreak()); // try direct_names case at first if (addArchivePrefix.IsEmpty() && !enterToSubFolders) { // check that all names are direct int i; for (i = 0; i < curNode.IncludeItems.Size(); i++) { const NWildcard::CItem &item = curNode.IncludeItems[i]; if (item.Recursive || item.PathParts.Size() != 1) break; const UString &name = item.PathParts.Front(); if (name.IsEmpty() || DoesNameContainWildCard(name)) break; } if (i == curNode.IncludeItems.Size()) { // all names are direct (no wildcards) // so we don't need file_system's dir enumerator CRecordVector<bool> needEnterVector; for (i = 0; i < curNode.IncludeItems.Size(); i++) { const NWildcard::CItem &item = curNode.IncludeItems[i]; const UString &name = item.PathParts.Front(); const UString fullPath = diskPrefix + name; NFind::CFileInfoW fileInfo; if (!NFind::FindFile(fullPath, fileInfo)) { errorCodes.Add(::GetLastError()); errorPaths.Add(fullPath); continue; } bool isDir = fileInfo.IsDirectory(); if (isDir && !item.ForDir || !isDir && !item.ForFile) { errorCodes.Add((DWORD)E_FAIL); errorPaths.Add(fullPath); continue; } const UString realName = fileInfo.Name; const UString realDiskPath = diskPrefix + realName; { UStringVector pathParts; pathParts.Add(fileInfo.Name); if (curNode.CheckPathToRoot(false, pathParts, !isDir)) continue; } AddDirFileInfo(archivePrefix, realDiskPath, fileInfo, dirItems); if (!isDir) continue; UStringVector addArchivePrefixNew; const NWildcard::CCensorNode *nextNode = 0; int index = curNode.FindSubNode(name); if (index >= 0) { for (int t = needEnterVector.Size(); t <= index; t++) needEnterVector.Add(true); needEnterVector[index] = false; nextNode = &curNode.SubNodes[index]; } else { nextNode = &curNode; addArchivePrefixNew.Add(name); // don't change it to realName. It's for shortnames support } RINOK(EnumerateDirItems(*nextNode, realDiskPath + wchar_t(kDirDelimiter), archivePrefix + realName + wchar_t(kDirDelimiter), addArchivePrefixNew, dirItems, true, callback, errorPaths, errorCodes)); } for (i = 0; i < curNode.SubNodes.Size(); i++) { if (i < needEnterVector.Size()) if (!needEnterVector[i]) continue; const NWildcard::CCensorNode &nextNode = curNode.SubNodes[i]; const UString fullPath = diskPrefix + nextNode.Name; NFind::CFileInfoW fileInfo; if (!NFind::FindFile(fullPath, fileInfo)) { if (!nextNode.AreThereIncludeItems()) continue; errorCodes.Add(::GetLastError()); errorPaths.Add(fullPath); continue; } if (!fileInfo.IsDirectory()) { errorCodes.Add((DWORD)E_FAIL); errorPaths.Add(fullPath); continue; } RINOK(EnumerateDirItems(nextNode, diskPrefix + fileInfo.Name + wchar_t(kDirDelimiter), archivePrefix + fileInfo.Name + wchar_t(kDirDelimiter), UStringVector(), dirItems, false, callback, errorPaths, errorCodes)); } return S_OK; } } NFind::CEnumeratorW enumerator(diskPrefix + wchar_t(kAnyStringWildcard)); for (;;) { NFind::CFileInfoW fileInfo; bool found; if (!enumerator.Next(fileInfo, found)) { errorCodes.Add(::GetLastError()); errorPaths.Add(diskPrefix); break; } if (!found) break; if (callback) RINOK(callback->CheckBreak()); const UString &name = fileInfo.Name; bool enterToSubFolders2 = enterToSubFolders; UStringVector addArchivePrefixNew = addArchivePrefix; addArchivePrefixNew.Add(name); { UStringVector addArchivePrefixNewTemp(addArchivePrefixNew); if (curNode.CheckPathToRoot(false, addArchivePrefixNewTemp, !fileInfo.IsDirectory())) continue; } if (curNode.CheckPathToRoot(true, addArchivePrefixNew, !fileInfo.IsDirectory())) { AddDirFileInfo(archivePrefix, diskPrefix + name, fileInfo, dirItems); if (fileInfo.IsDirectory()) enterToSubFolders2 = true; } if (!fileInfo.IsDirectory()) continue; const NWildcard::CCensorNode *nextNode = 0; if (addArchivePrefix.IsEmpty()) { int index = curNode.FindSubNode(name); if (index >= 0) nextNode = &curNode.SubNodes[index]; } if (!enterToSubFolders2 && nextNode == 0) continue; addArchivePrefixNew = addArchivePrefix; if (nextNode == 0) { nextNode = &curNode; addArchivePrefixNew.Add(name); } RINOK(EnumerateDirItems(*nextNode, diskPrefix + name + wchar_t(kDirDelimiter), archivePrefix + name + wchar_t(kDirDelimiter), addArchivePrefixNew, dirItems, enterToSubFolders2, callback, errorPaths, errorCodes)); } return S_OK; }
static HRESULT EnumerateForItem( NFind::CFileInfo &fi, const NWildcard::CCensorNode &curNode, int phyParent, int logParent, const FString &phyPrefix, const UStringVector &addArchivePrefix, // prefix from curNode CDirItems &dirItems, bool enterToSubFolders) { const UString name = fs2us(fi.Name); bool enterToSubFolders2 = enterToSubFolders; UStringVector addArchivePrefixNew = addArchivePrefix; addArchivePrefixNew.Add(name); { UStringVector addArchivePrefixNewTemp(addArchivePrefixNew); if (curNode.CheckPathToRoot(false, addArchivePrefixNewTemp, !fi.IsDir())) return S_OK; } int dirItemIndex = -1; if (curNode.CheckPathToRoot(true, addArchivePrefixNew, !fi.IsDir())) { int secureIndex = -1; #ifdef _USE_SECURITY_CODE if (dirItems.ReadSecure) { RINOK(dirItems.AddSecurityItem(phyPrefix + fi.Name, secureIndex)); } #endif dirItemIndex = dirItems.Items.Size(); dirItems.AddDirFileInfo(phyParent, logParent, secureIndex, fi); if (fi.IsDir()) enterToSubFolders2 = true; } #ifndef UNDER_CE if (dirItems.ScanAltStreams) { RINOK(EnumerateAltStreams(fi, curNode, phyParent, logParent, phyPrefix + fi.Name, addArchivePrefixNew, dirItems)); } if (dirItemIndex >= 0) { CDirItem &dirItem = dirItems.Items[dirItemIndex]; RINOK(dirItems.SetLinkInfo(dirItem, fi, phyPrefix)); if (dirItem.ReparseData.Size() != 0) return S_OK; } #endif if (!fi.IsDir()) return S_OK; const NWildcard::CCensorNode *nextNode = 0; if (addArchivePrefix.IsEmpty()) { int index = curNode.FindSubNode(name); if (index >= 0) nextNode = &curNode.SubNodes[index]; } if (!enterToSubFolders2 && nextNode == 0) return S_OK; addArchivePrefixNew = addArchivePrefix; if (nextNode == 0) { nextNode = &curNode; addArchivePrefixNew.Add(name); } return EnumerateDirItems_Spec( *nextNode, phyParent, logParent, fi.Name, phyPrefix, addArchivePrefixNew, dirItems, enterToSubFolders2); }
void zmodifyer::getInfo( std::vector< std::pair< std::wstring, ZFile* > > & fileList, wchar_t const * path, wchar_t const * password ) { if( zdb_->db_.IsEmpty() ) { // 커맨드 스트링 UStringVector commandStrings; commandStrings.Add(L"L"); UString pw( L"-P" ); commandStrings.Add( (pw + ( password ? password : L"") ) ); commandStrings.Add( file_name_ ); CArchiveCommandLineOptions options; OptionSetting( commandStrings, options ); // 압축파일 형식 인덱스 추출. CIntVector formatIndices; if (!codecs_->FindFormatForArchiveType(options.ArcType, formatIndices)) { throw kUnsupportedArcTypeMessage; } UInt64 numErrors = 0; HRESULT result = ListArchives( codecs_, formatIndices, options.StdInMode, options.ArchivePathsSorted, options.ArchivePathsFullSorted, options.WildcardCensor.Pairs.Front().Head, options.EnableHeaders, options.TechMode, #ifndef _NO_CRYPTO options.PasswordEnabled, options.Password, #endif numErrors, zdb_); } ZFile * zfile = 0; std::wstring filePath = path ? path : L""; if( filePath.empty() ) { zfile = &zdb_->folder_; } else { zfile = zdb_->folder_.find( filePath ); } if( zfile ) { zfile->getList( fileList, filePath ); } }
void CArchiveCommandLineParser::Parse2(CArchiveCommandLineOptions &options) { const UStringVector &nonSwitchStrings = parser.NonSwitchStrings; int numNonSwitchStrings = nonSwitchStrings.Size(); if(numNonSwitchStrings < kMinNonSwitchWords) ThrowUserErrorException(); if (!ParseArchiveCommand(nonSwitchStrings[kCommandIndex], options.Command)) ThrowUserErrorException(); options.TechMode = parser[NKey::kTechMode].ThereIs; if (parser[NKey::kCaseSensitive].ThereIs) g_CaseSensitive = (parser[NKey::kCaseSensitive].PostCharIndex < 0); NRecursedType::EEnum recursedType; if (parser[NKey::kRecursed].ThereIs) recursedType = GetRecursedTypeFromIndex(parser[NKey::kRecursed].PostCharIndex); else recursedType = NRecursedType::kNonRecursed; UINT codePage = CP_UTF8; if (parser[NKey::kCharSet].ThereIs) { UString name = parser[NKey::kCharSet].PostStrings.Front(); name.MakeUpper(); int i; for (i = 0; i < kNumCodePages; i++) { const CCodePagePair &pair = g_CodePagePairs[i]; if (name.Compare(pair.Name) == 0) { codePage = pair.CodePage; break; } } if (i >= kNumCodePages) ThrowUserErrorException(); } bool thereAreSwitchIncludes = false; if (parser[NKey::kInclude].ThereIs) { thereAreSwitchIncludes = true; AddSwitchWildCardsToCensor(options.WildcardCensor, parser[NKey::kInclude].PostStrings, true, recursedType, codePage); } if (parser[NKey::kExclude].ThereIs) AddSwitchWildCardsToCensor(options.WildcardCensor, parser[NKey::kExclude].PostStrings, false, recursedType, codePage); int curCommandIndex = kCommandIndex + 1; bool thereIsArchiveName = !parser[NKey::kNoArName].ThereIs && options.Command.CommandType != NCommandType::kBenchmark && options.Command.CommandType != NCommandType::kInfo; if (thereIsArchiveName) { if(curCommandIndex >= numNonSwitchStrings) ThrowUserErrorException(); options.ArchiveName = nonSwitchStrings[curCommandIndex++]; } AddToCensorFromNonSwitchesStrings( curCommandIndex, options.WildcardCensor, nonSwitchStrings, recursedType, thereAreSwitchIncludes, codePage); options.YesToAll = parser[NKey::kYes].ThereIs; bool isExtractGroupCommand = options.Command.IsFromExtractGroup(); options.PasswordEnabled = parser[NKey::kPassword].ThereIs; if(options.PasswordEnabled) options.Password = parser[NKey::kPassword].PostStrings[0]; options.StdInMode = parser[NKey::kStdIn].ThereIs; options.ShowDialog = parser[NKey::kShowDialog].ThereIs; if(isExtractGroupCommand || options.Command.CommandType == NCommandType::kList) { if (options.StdInMode) ThrowException("Reading archives from stdin is not implemented"); if (!options.WildcardCensor.AllAreRelative()) ThrowException("Cannot use absolute pathnames for this command"); NWildcard::CCensor archiveWildcardCensor; if (parser[NKey::kArInclude].ThereIs) { AddSwitchWildCardsToCensor(archiveWildcardCensor, parser[NKey::kArInclude].PostStrings, true, NRecursedType::kNonRecursed, codePage); } if (parser[NKey::kArExclude].ThereIs) AddSwitchWildCardsToCensor(archiveWildcardCensor, parser[NKey::kArExclude].PostStrings, false, NRecursedType::kNonRecursed, codePage); if (thereIsArchiveName) AddCommandLineWildCardToCensr(archiveWildcardCensor, options.ArchiveName, true, NRecursedType::kNonRecursed); #ifdef _WIN32 ConvertToLongNames(archiveWildcardCensor); #endif archiveWildcardCensor.ExtendExclude(); CObjectVector<CDirItem> dirItems; { UStringVector errorPaths; CRecordVector<DWORD> errorCodes; HRESULT res = EnumerateItems(archiveWildcardCensor, dirItems, NULL, errorPaths, errorCodes); if (res != S_OK || errorPaths.Size() > 0) throw "cannot find archive"; } UStringVector archivePaths; int i; for (i = 0; i < dirItems.Size(); i++) { const CDirItem &dirItem = dirItems[i]; if (!dirItem.IsDirectory()) archivePaths.Add(dirItem.FullPath); } if (archivePaths.Size() == 0) throw "there is no such archive"; UStringVector archivePathsFull; for (i = 0; i < archivePaths.Size(); i++) { UString fullPath; NFile::NDirectory::MyGetFullPathName(archivePaths[i], fullPath); archivePathsFull.Add(fullPath); } CIntVector indices; SortFileNames(archivePathsFull, indices); options.ArchivePathsSorted.Reserve(indices.Size()); options.ArchivePathsFullSorted.Reserve(indices.Size()); for (i = 0; i < indices.Size(); i++) { options.ArchivePathsSorted.Add(archivePaths[indices[i]]); options.ArchivePathsFullSorted.Add(archivePathsFull[indices[i]]); } if (isExtractGroupCommand) { SetMethodOptions(parser, options.ExtractProperties); if (options.StdOutMode && options.IsStdOutTerminal && options.IsStdErrTerminal) throw kSameTerminalError; if(parser[NKey::kOutputDir].ThereIs) { options.OutputDir = parser[NKey::kOutputDir].PostStrings[0]; NFile::NName::NormalizeDirPathPrefix(options.OutputDir); } options.OverwriteMode = NExtract::NOverwriteMode::kAskBefore; if(parser[NKey::kOverwrite].ThereIs) options.OverwriteMode = k_OverwriteModes[parser[NKey::kOverwrite].PostCharIndex]; else if (options.YesToAll) options.OverwriteMode = NExtract::NOverwriteMode::kWithoutPrompt; } } else if(options.Command.IsFromUpdateGroup()) { CUpdateOptions &updateOptions = options.UpdateOptions; if(parser[NKey::kArchiveType].ThereIs) options.ArcType = parser[NKey::kArchiveType].PostStrings[0]; SetAddCommandOptions(options.Command.CommandType, parser, updateOptions); SetMethodOptions(parser, updateOptions.MethodMode.Properties); if (parser[NKey::kShareForWrite].ThereIs) updateOptions.OpenShareForWrite = true; options.EnablePercents = !parser[NKey::kDisablePercents].ThereIs; if (options.EnablePercents) { if ((options.StdOutMode && !options.IsStdErrTerminal) || (!options.StdOutMode && !options.IsStdOutTerminal)) options.EnablePercents = false; } updateOptions.EMailMode = parser[NKey::kEmail].ThereIs; if (updateOptions.EMailMode) { updateOptions.EMailAddress = parser[NKey::kEmail].PostStrings.Front(); if (updateOptions.EMailAddress.Length() > 0) if (updateOptions.EMailAddress[0] == L'.') { updateOptions.EMailRemoveAfter = true; updateOptions.EMailAddress.Delete(0); } } updateOptions.StdOutMode = options.StdOutMode; updateOptions.StdInMode = options.StdInMode; if (updateOptions.StdOutMode && updateOptions.EMailMode) throw "stdout mode and email mode cannot be combined"; if (updateOptions.StdOutMode && options.IsStdOutTerminal) throw kTerminalOutError; if(updateOptions.StdInMode) updateOptions.StdInFileName = parser[NKey::kStdIn].PostStrings.Front(); #ifdef _WIN32 ConvertToLongNames(options.WildcardCensor); #endif } else if(options.Command.CommandType == NCommandType::kBenchmark) { options.NumThreads = (UInt32)-1; options.DictionarySize = (UInt32)-1; options.NumIterations = 1; if (curCommandIndex < numNonSwitchStrings) { if (!ConvertStringToUInt32(nonSwitchStrings[curCommandIndex++], options.NumIterations)) ThrowUserErrorException(); } for (int i = 0; i < parser[NKey::kProperty].PostStrings.Size(); i++) { UString postString = parser[NKey::kProperty].PostStrings[i]; postString.MakeUpper(); if (postString.Length() < 2) ThrowUserErrorException(); if (postString[0] == 'D') { int pos = 1; if (postString[pos] == '=') pos++; UInt32 logSize; if (!ConvertStringToUInt32((const wchar_t *)postString + pos, logSize)) ThrowUserErrorException(); if (logSize > 31) ThrowUserErrorException(); options.DictionarySize = 1 << logSize; } else if (postString[0] == 'M' && postString[1] == 'T' ) { int pos = 2; if (postString[pos] == '=') pos++; if (postString[pos] != 0) if (!ConvertStringToUInt32((const wchar_t *)postString + pos, options.NumThreads)) ThrowUserErrorException(); } else if (postString[0] == 'M' && postString[1] == '=' ) { int pos = 2; if (postString[pos] != 0) options.Method = postString.Mid(2); } else ThrowUserErrorException(); } } else if(options.Command.CommandType == NCommandType::kInfo) { } else ThrowUserErrorException(); options.WildcardCensor.ExtendExclude(); }
bool zmodifyer::update( UStringVector & file_names, UStringVector & commandStrings, wchar_t const * password ) { if( file_names.IsEmpty() ) return false; // 프로그래스 뷰 사용안함 commandStrings.Add( L"-BD" ); // 솔리드 압축 사용 안함 commandStrings.Add( L"-MS=OFF" ); // 압축 방식 lzma2 commandStrings.Add( L"-M0=LZMA2" ); // multi thread commandStrings.Add( L"-MMT=+" ); if( password && wcslen(password) ) { UString pw( L"-P" ); commandStrings.Add( (pw + ( password ? password : L"") ) ); } commandStrings.Add( file_name_ ); for( int i=0; i<file_names.Size(); ++i ) commandStrings.Add( file_names[i] ); // 파싱된 커맨드라인 정보로 options 셋팅 ------------ CArchiveCommandLineOptions options; OptionSetting( commandStrings, options ); options.OverwriteMode = NExtract::NOverwriteMode::kWithoutPrompt; // 덮어쓰기 할때 묻지마라. options.YesToAll = true; //------------ // 압축파일 형식 인덱스 추출. CIntVector formatIndices; if (!codecs_->FindFormatForArchiveType(options.ArcType, formatIndices)) { throw kUnsupportedArcTypeMessage; } CUpdateOptions &uo = options.UpdateOptions; if (uo.SfxMode && uo.SfxModule.IsEmpty()) uo.SfxModule = kDefaultSfxModule; COpenCallbackConsole openCallback; openCallback.OutStream = &outStream_; #ifndef _NO_CRYPTO bool passwordIsDefined = options.PasswordEnabled && !options.Password.IsEmpty(); openCallback.PasswordIsDefined = passwordIsDefined; openCallback.Password = options.Password; #endif CUpdateCallbackConsole callback; callback.EnablePercents = options.EnablePercents; #ifndef _NO_CRYPTO callback.PasswordIsDefined = passwordIsDefined; callback.AskPassword = options.PasswordEnabled && options.Password.IsEmpty(); callback.Password = options.Password; #endif callback.StdOutMode = uo.StdOutMode; callback.Init(&outStream_); CUpdateErrorInfo errorInfo; if (!uo.Init(codecs_, formatIndices, options.ArchiveName)) throw kUnsupportedArcTypeMessage; HRESULT result = UpdateArchive(codecs_, options.WildcardCensor, uo, errorInfo, &openCallback, &callback, zdb_); clearDB(); return result == S_OK; }
// file_name.empty() 이면 모든 파일 압축해제 bool zmodifyer::extract(UStringVector & file_names, wchar_t const * password, wchar_t const * outDir, bool allPath) { // 커맨드 스트링 UStringVector commandStrings; if( allPath ) commandStrings.Add( L"X" ); else commandStrings.Add( L"E" ); UString pw( L"-P" ); commandStrings.Add( (pw + ( password ? password : L"") ) ); if( outDir ) { UString od( L"-O" ); commandStrings.Add( (od + outDir) ); } commandStrings.Add( file_name_ ); if( file_names.IsEmpty() ) { commandStrings.Add( L"*" ); } else { for( int i=0; i<file_names.Size(); ++i ) commandStrings.Add( file_names[i] ); } // 파싱된 커맨드라인 정보로 options 셋팅 ------------ CArchiveCommandLineOptions options; OptionSetting( commandStrings, options ); options.OverwriteMode = NExtract::NOverwriteMode::kWithoutPrompt; // 덮어쓰기 할때 묻지마라. options.YesToAll = true; //------------ // 압축파일 형식 인덱스 추출. CIntVector formatIndices; if (!codecs_->FindFormatForArchiveType(options.ArcType, formatIndices)) { //throw kUnsupportedArcTypeMessage; return false; } bool isExtractGroupCommand = options.Command.IsFromExtractGroup(); if (codecs_->Formats.Size() == 0 && (isExtractGroupCommand || options.Command.CommandType == NCommandType::kList || options.Command.IsFromUpdateGroup())) return false; //throw kNoFormats; // 압축 해제 if (isExtractGroupCommand) { CExtractCallbackConsole *ecs = new CExtractCallbackConsole; CMyComPtr<IFolderArchiveExtractCallback> extractCallback = ecs; ecs->OutStream = &outStream_; #ifndef _NO_CRYPTO ecs->PasswordIsDefined = options.PasswordEnabled; ecs->Password = options.Password; #endif ecs->Init(); COpenCallbackConsole openCallback; openCallback.OutStream = &outStream_; #ifndef _NO_CRYPTO openCallback.PasswordIsDefined = options.PasswordEnabled; openCallback.Password = options.Password; #endif CExtractOptions eo; eo.StdInMode = options.StdInMode; eo.StdOutMode = options.StdOutMode; eo.PathMode = options.Command.GetPathMode(); eo.TestMode = options.Command.IsTestMode(); eo.OverwriteMode = options.OverwriteMode; eo.OutputDir = options.OutputDir; eo.YesToAll = options.YesToAll; eo.CalcCrc = options.CalcCrc; #if !defined(_7ZIP_ST) && !defined(_SFX) eo.Properties = options.ExtractProperties; #endif //ZDBS::_currentArchive = file_name_; UString errorMessage; CDecompressStat stat; HRESULT result = DecompressArchives( codecs_, formatIndices, options.ArchivePathsSorted, options.ArchivePathsFullSorted, options.WildcardCensor.Pairs.Front().Head, eo, &openCallback, ecs, errorMessage, stat, zdb_); if( result == S_OK ) return true; } return false; }
unsigned char * zmodifyer::get( UString & file_name, size_t & size, wchar_t const * password /* = 0 */ ) { if( file_name.Length() == 0 ) return 0; // 커맨드 스트링 UStringVector commandStrings; commandStrings.Add( L"G" ); UString pw( L"-P" ); commandStrings.Add( (pw + ( password ? password : L"") ) ); // multi thread commandStrings.Add( L"-MMT=+" ); commandStrings.Add( L"-BD" ); commandStrings.Add( file_name_ ); commandStrings.Add( file_name ); // 파싱된 커맨드라인 정보로 options 셋팅 ------------ CArchiveCommandLineOptions options; //options.HelpMode = true; // 없는 파일이면 작업 중지 if( !zdb_->db_.IsEmpty() ) { typedef std::list< std::wstring > FileList; FileList files; std::wstring tmp = file_name; boost::split( files, tmp, boost::is_any_of(L":") ); for( FileList::iterator iter = files.begin(); iter != files.end(); ++iter ) { if( !zdb_->folder_.find( *iter ) ) return 0; } } OptionSetting( commandStrings, options ); options.OverwriteMode = NExtract::NOverwriteMode::kWithoutPrompt; // 덮어쓰기 할때 묻지마라. options.YesToAll = true; //------------ // 압축파일 형식 인덱스 추출. CIntVector formatIndices; if (!codecs_->FindFormatForArchiveType(options.ArcType, formatIndices)) { throw kUnsupportedArcTypeMessage; } bool isExtractGroupCommand = options.Command.IsFromExtractGroup(); if (codecs_->Formats.Size() == 0 && (isExtractGroupCommand || options.Command.CommandType == NCommandType::kList || options.Command.IsFromUpdateGroup())) throw kNoFormats; // 압축 해제 if (isExtractGroupCommand) { CExtractCallbackConsole *ecs = new CExtractCallbackConsole; CMyComPtr<IFolderArchiveExtractCallback> extractCallback = ecs; ecs->OutStream = &outStream_; #ifndef _NO_CRYPTO ecs->PasswordIsDefined = options.PasswordEnabled; ecs->Password = options.Password; #endif ecs->Init(); COpenCallbackConsole openCallback; openCallback.OutStream = &outStream_; #ifndef _NO_CRYPTO openCallback.PasswordIsDefined = options.PasswordEnabled; openCallback.Password = options.Password; #endif CExtractOptions eo; eo.StdInMode = options.StdInMode; eo.StdOutMode = options.StdOutMode; eo.PathMode = options.Command.GetPathMode(); //eo.TestMode = options.Command.IsTestMode(); eo.TestMode = true; // 테스트 모드로 압축해제(파일 저장 안함) eo.OverwriteMode = options.OverwriteMode; eo.OutputDir = options.OutputDir; eo.YesToAll = options.YesToAll; eo.CalcCrc = options.CalcCrc; #if !defined(_7ZIP_ST) && !defined(_SFX) eo.Properties = options.ExtractProperties; #endif //ZDBS::_currentArchive = file_name_; UString errorMessage; CDecompressStat stat; HRESULT result = DecompressArchives( codecs_, formatIndices, options.ArchivePathsSorted, options.ArchivePathsFullSorted, options.WildcardCensor.Pairs.Front().Head, eo, &openCallback, ecs, errorMessage, stat, zdb_); } return CIOStream::Read( size ); }
int DoExtractArchive(UString archive, UString targetDir, bool overwrite, bool extractPaths, ExtractProgressHandler epc) { CCodecs *codecs = new CCodecs; CMyComPtr<IUnknown> compressCodecsInfo = codecs; HRESULT result = codecs->Load(); if (result != S_OK) throw CSystemException(result); if (codecs->Formats.Size() == 0) throw -1; CIntVector formatIndices; if (!codecs->FindFormatForArchiveType(L"7z", formatIndices)) { throw -1; } BOOL bApisAreAnsi = AreFileApisANSI(); #ifdef _WIN32 if (bApisAreAnsi) SwitchFileAPIEncoding(bApisAreAnsi); #endif CExtractCallbackConsole *ecs = new CExtractCallbackConsole(); CMyComPtr<IFolderArchiveExtractCallback> extractCallback = ecs; ecs->ProgressHandler = epc; wcsncpy(ecs->destDir, targetDir, MAX_PATH); ecs->Init(); COpenCallbackConsole openCallback; CExtractOptions eo; eo.StdOutMode = false; eo.PathMode = extractPaths?NExtract::NPathMode::kCurPaths:NExtract::NPathMode::kNoPaths; eo.TestMode = false; eo.OverwriteMode = overwrite?NExtract::NOverwriteMode::kOverwrite:NExtract::NOverwriteMode::kSkip; eo.OutputDir = targetDir; eo.YesToAll = true; #ifdef COMPRESS_MT CObjectVector<CProperty> prp; eo.Properties = prp; #endif UString errorMessage; CDecompressStat stat; NWildcard::CCensor wildcardCensor; wildcardCensor.AddItem(NWildcard::ECensorPathMode::k_FullPath, true, L"*", true, true); UStringVector ArchivePathsSorted; UStringVector ArchivePathsFullSorted; ArchivePathsSorted.Add(archive); UString fullPath; NFile::NDir::MyGetFullPathName(archive, fullPath); ArchivePathsFullSorted.Add(fullPath); UStringVector v1, v2; v1.Add(fs2us(archive)); v2.Add(fs2us(archive)); const NWildcard::CCensorNode &wildcardCensorHead = wildcardCensor.Pairs.Front().Head; result = Extract( codecs, CObjectVector<COpenType>(), CIntVector(), v1, v2, wildcardCensorHead, eo, ecs, ecs, NULL, // hash errorMessage, stat); #ifdef _WIN32 if (bApisAreAnsi) SwitchFileAPIEncoding(!bApisAreAnsi); #endif if (!errorMessage.IsEmpty()) { if (result == S_OK) result = E_FAIL; } if (ecs->NumArchiveErrors != 0 || ecs->NumFileErrors != 0) { if (result != S_OK) throw CSystemException(result); return NExitCode::kFatalError; } if (result != S_OK) throw CSystemException(result); return 0; }
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(); }
HRESULT CPanel::BindToPath(const UString &fullPath, const UString &arcFormat, bool &archiveIsOpened, bool &encrypted) { archiveIsOpened = false; encrypted = false; CDisableTimerProcessing disableTimerProcessing(*this); CDisableNotify disableNotify(*this); if (_parentFolders.Size() > 0) { const UString &virtPath = _parentFolders.Back().VirtualPath; if (fullPath.IsPrefixedBy(virtPath)) { for (;;) { CMyComPtr<IFolderFolder> newFolder; HRESULT res = _folder->BindToParentFolder(&newFolder); if (!newFolder || res != S_OK) break; SetNewFolder(newFolder); } UStringVector parts; SplitPathToParts(fullPath.Ptr(virtPath.Len()), parts); FOR_VECTOR (i, parts) { 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; SetNewFolder(newFolder); } return S_OK; } } CloseOpenFolders(); UString sysPath = fullPath; CFileInfo fileInfo; UStringVector reducedParts; while (!sysPath.IsEmpty()) { if (fileInfo.Find(us2fs(sysPath))) break; int pos = sysPath.ReverseFind(WCHAR_PATH_SEPARATOR); if (pos < 0) sysPath.Empty(); else { if (reducedParts.Size() > 0 || pos < (int)sysPath.Len() - 1) reducedParts.Add(sysPath.Ptr(pos + 1)); sysPath.DeleteFrom(pos); } } SetToRootFolder(); CMyComPtr<IFolderFolder> newFolder; if (sysPath.IsEmpty()) { if (_folder->BindToFolder(fullPath, &newFolder) == S_OK) SetNewFolder(newFolder); } else if (fileInfo.IsDir()) { NName::NormalizeDirPathPrefix(sysPath); if (_folder->BindToFolder(sysPath, &newFolder) == S_OK) SetNewFolder(newFolder); } else { FString dirPrefix, fileName; NDir::GetFullPathAndSplit(us2fs(sysPath), dirPrefix, fileName); if (_folder->BindToFolder(fs2us(dirPrefix), &newFolder) == S_OK) { SetNewFolder(newFolder); LoadFullPath(); { HRESULT res = OpenItemAsArchive(fs2us(fileName), arcFormat, 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; SetNewFolder(newFolder); } } } } } return S_OK; }
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(); }
HRESULT CPanel::BindToPath(const UString &fullPath, const UString &arcFormat, 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 (fileInfo.Find(sysPath)) 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, arcFormat, 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; }
HRESULT CAgent::RenameItem( const wchar_t *newArchiveName, const UInt32 *indices, UInt32 numItems, const wchar_t *newItemName, IFolderArchiveUpdateCallback *updateCallback100) { if (!CanUpdate()) return E_NOTIMPL; if (numItems != 1) return E_INVALIDARG; CUpdateCallbackAgent updateCallbackAgent; updateCallbackAgent.SetCallback(updateCallback100); CArchiveUpdateCallback *updateCallbackSpec = new CArchiveUpdateCallback; CMyComPtr<IArchiveUpdateCallback> updateCallback(updateCallbackSpec); CUIntVector realIndices; _agentFolder->GetRealIndices(indices, numItems, realIndices); UString fullPrefix = _agentFolder->GetFullPathPrefixPlusPrefix(indices[0]); UString oldItemPath = fullPrefix + _agentFolder->GetName(indices[0]); UString newItemPath = fullPrefix + newItemName; CRecordVector<CUpdatePair2> updatePairs; UStringVector newNames; int curIndex = 0; UInt32 numItemsInArchive; RINOK(GetArchive()->GetNumberOfItems(&numItemsInArchive)); for (UInt32 i = 0; i < numItemsInArchive; i++) { if (curIndex < realIndices.Size()) if (realIndices[curIndex] == i) { CUpdatePair2 up2; up2.NewData = false; up2.NewProps = true; RINOK(GetArc().IsItemAnti(i, up2.IsAnti)); up2.ArcIndex = i; UString oldFullPath; RINOK(GetArc().GetItemPath(i, oldFullPath)); if (oldItemPath.CompareNoCase(oldFullPath.Left(oldItemPath.Length())) != 0) return E_INVALIDARG; up2.NewNameIndex = newNames.Add(newItemPath + oldFullPath.Mid(oldItemPath.Length())); updatePairs.Add(up2); curIndex++; continue; } CUpdatePair2 up2; up2.NewData = up2.NewProps = false; up2.IsAnti = false; up2.ArcIndex = i; updatePairs.Add(up2); } updateCallbackSpec->Callback = &updateCallbackAgent; updateCallbackSpec->UpdatePairs = &updatePairs; updateCallbackSpec->NewNames = &newNames; updateCallbackSpec->Archive = GetArchive(); return CommonUpdate(newArchiveName, updatePairs.Size(), updateCallback); }