HRESULT CPlugin::ExtractFiles( bool decompressAllItems, const UInt32 *indices, UInt32 numIndices, bool silent, NExtract::NPathMode::EEnum pathMode, NExtract::NOverwriteMode::EEnum overwriteMode, const UString &destPath, bool passwordIsDefined, const UString &password) { CScreenRestorer screenRestorer; CProgressBox progressBox; CProgressBox *progressBoxPointer = NULL; if (!silent) { screenRestorer.Save(); progressBoxPointer = &progressBox; progressBox.Init( // g_StartupInfo.GetMsgString(NMessageID::kWaitTitle), g_StartupInfo.GetMsgString(NMessageID::kExtracting)); } CExtractCallbackImp *extractCallbackSpec = new CExtractCallbackImp; CMyComPtr<IFolderArchiveExtractCallback> extractCallback(extractCallbackSpec); extractCallbackSpec->Init( CP_OEMCP, progressBoxPointer, /* GetDefaultName(m_FileName, m_ArchiverInfo.Extension), m_FileInfo.MTime, m_FileInfo.Attributes, */ passwordIsDefined, password); if (decompressAllItems) return m_ArchiveHandler->Extract(pathMode, overwriteMode, destPath, BoolToInt(false), extractCallback); else { CMyComPtr<IArchiveFolder> archiveFolder; _folder.QueryInterface(IID_IArchiveFolder, &archiveFolder); return archiveFolder->Extract(indices, numIndices, BoolToInt(true), // includeAltStreams BoolToInt(false), // replaceAltStreamChars pathMode, overwriteMode, destPath, BoolToInt(false), extractCallback); } }
static HRESULT ExtractGroupCommand(const UStringVector &arcPaths, bool showDialog, const UString &outFolder, bool testMode) { HRESULT result; MY_TRY_BEGIN CREATE_CODECS CExtractOptions eo; eo.OutputDir = outFolder; eo.TestMode = testMode; CExtractCallbackImp *ecs = new CExtractCallbackImp; CMyComPtr<IFolderArchiveExtractCallback> extractCallback = ecs; ecs->Init(); // eo.CalcCrc = options.CalcCrc; UStringVector arcPathsSorted; UStringVector arcFullPathsSorted; { NWildcard::CCensor acrCensor; for (int i = 0; i < arcPaths.Size(); i++) acrCensor.AddItem(true, arcPaths[i], false); EnumerateDirItemsAndSort(acrCensor, arcPathsSorted, arcFullPathsSorted); } CIntVector formatIndices; NWildcard::CCensor censor; censor.AddItem(true, L"*", false); bool messageWasDisplayed = false; result = ExtractGUI(codecs, formatIndices, arcPathsSorted, arcFullPathsSorted, censor.Pairs.Front().Head, eo, showDialog, messageWasDisplayed, ecs, g_HWND); if (result != S_OK) { if (result != E_ABORT && messageWasDisplayed) return E_FAIL; throw CSystemException(result); } return ecs->IsOK() ? S_OK : E_FAIL; MY_TRY_FINISH return result; }
void Process2() { NFind::CFileInfo fi; if (!fi.Find(FileName)) { ErrorMessage = kCantFindArchive; Result = E_FAIL; return; } CObjectVector<COpenType> incl; CIntVector excl; COpenOptions options; options.codecs = Codecs; options.types = &incl; options.excludedFormats = ! options.filePath = fs2us(FileName); Result = ArchiveLink.Open2(options, ExtractCallbackSpec); if (Result != S_OK) { if (Result != S_OK) ErrorMessage = kCantOpenArchive; return; } FString dirPath = DestFolder; NName::NormalizeDirPathPrefix(dirPath); if (!CreateComplexDir(dirPath)) { ErrorMessage = MyFormatNew(IDS_CANNOT_CREATE_FOLDER, #ifdef LANG 0x02000603, #endif fs2us(dirPath)); Result = E_FAIL; return; } ExtractCallbackSpec->Init(ArchiveLink.GetArchive(), dirPath, L"Default", fi.MTime, 0); Result = ArchiveLink.GetArchive()->Extract(0, (UInt32)(Int32)-1 , BoolToInt(false), ExtractCallback); }
void Process() { NFile::NFind::CFileInfoW fi; if (!NFile::NFind::FindFile(FileName, fi)) { ErrorMessage = kCantFindArchive; Result = E_FAIL; return; } Result = MyOpenArchive(Codecs, CIntVector(), FileName, ArchiveLink, ExtractCallbackSpec); if (Result != S_OK) { if (Result != S_OK) ErrorMessage = kCantOpenArchive; return; } UString dirPath = DestFolder; NFile::NName::NormalizeDirPathPrefix(dirPath); if (!NFile::NDirectory::CreateComplexDirectory(dirPath)) { ErrorMessage = MyFormatNew(IDS_CANNOT_CREATE_FOLDER, #ifdef LANG 0x02000603, #endif dirPath); Result = E_FAIL; return; } ExtractCallbackSpec->Init(ArchiveLink.GetArchive(), dirPath, L"Default", fi.MTime, 0); #ifndef _NO_PROGRESS if (ShowProgress) ExtractCallbackSpec->ProgressDialog.WaitCreating(); #endif Result = ArchiveLink.GetArchive()->Extract(0, (UInt32)-1 , BoolToInt(false), ExtractCallback); #ifndef _NO_PROGRESS if (ShowProgress) ExtractCallbackSpec->ProgressDialog.MyClose(); #endif }
int Main2(int argc,TCHAR **argv) { UStringVector commandStrings; #ifdef _WIN32 NCommandLineParser::SplitCommandLine(GetCommandLineW(), commandStrings); #else extern void mySplitCommandLineW(int numArguments,TCHAR **arguments,UStringVector &parts); mySplitCommandLineW(argc,argv,commandStrings); #endif #ifndef UNDER_CE if (commandStrings.Size() > 0) commandStrings.Delete(0); #endif if (commandStrings.Size() == 0) { MessageBoxW(0, L"Specify command", L"7-Zip", 0); return 0; } /* { CSysString resultPath; NWindows::NFile::NDirectory::MyGetCurrentDirectory(resultPath); ::MessageBoxW(0, resultPath, L"7-Zip - curDir", 0); } */ CArchiveCommandLineOptions options; CArchiveCommandLineParser parser; parser.Parse1(commandStrings, options); parser.Parse2(options); #if defined(_WIN32) && defined(_7ZIP_LARGE_PAGES) if (options.LargePages) NSecurity::EnableLockMemoryPrivilege(); #endif CCodecs *codecs = new CCodecs; CMyComPtr<IUnknown> compressCodecsInfo = codecs; HRESULT result = codecs->Load(); if (result != S_OK) throw CSystemException(result); bool isExtractGroupCommand = options.Command.IsFromExtractGroup(); if (codecs->Formats.Size() == 0 && (isExtractGroupCommand || options.Command.IsFromUpdateGroup())) throw kNoFormats; CIntVector formatIndices; if (!codecs->FindFormatForArchiveType(options.ArcType, formatIndices)) { ErrorLangMessage(IDS_UNSUPPORTED_ARCHIVE_TYPE, 0x0200060D); return NExitCode::kFatalError; } if (options.Command.CommandType == NCommandType::kBenchmark) { HRESULT res; #ifdef EXTERNAL_CODECS CObjectVector<CCodecInfoEx> externalCodecs; res = LoadExternalCodecs(codecs, externalCodecs); if (res != S_OK) throw CSystemException(res); #endif res = Benchmark( #ifdef EXTERNAL_CODECS codecs, &externalCodecs, #endif options.NumThreads, options.DictionarySize); if (res != S_OK) throw CSystemException(res); } else if (isExtractGroupCommand) { CExtractCallbackImp *ecs = new CExtractCallbackImp; CMyComPtr<IFolderArchiveExtractCallback> extractCallback = ecs; #ifndef _NO_CRYPTO ecs->PasswordIsDefined = options.PasswordEnabled; ecs->Password = options.Password; #endif ecs->Init(); CExtractOptions eo; eo.StdOutMode = options.StdOutMode; eo.OutputDir = options.OutputDir; eo.YesToAll = options.YesToAll; eo.OverwriteMode = options.OverwriteMode; eo.PathMode = options.Command.GetPathMode(); eo.TestMode = options.Command.IsTestMode(); eo.CalcCrc = options.CalcCrc; #if !defined(_7ZIP_ST) && !defined(_SFX) eo.Properties = options.ExtractProperties; #endif bool messageWasDisplayed = false; HRESULT result = ExtractGUI(codecs, formatIndices, options.ArchivePathsSorted, options.ArchivePathsFullSorted, options.WildcardCensor.Pairs.Front().Head, eo, options.ShowDialog, messageWasDisplayed, ecs); if (result != S_OK) { if (result != E_ABORT && messageWasDisplayed) return NExitCode::kFatalError; throw CSystemException(result); } if (!ecs->IsOK()) return NExitCode::kFatalError; } else if (options.Command.IsFromUpdateGroup()) { #ifndef _NO_CRYPTO bool passwordIsDefined = options.PasswordEnabled && !options.Password.IsEmpty(); #endif CUpdateCallbackGUI 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 = options.UpdateOptions.StdOutMode; callback.Init(); if (!options.UpdateOptions.Init(codecs, formatIndices, options.ArchiveName)) { ErrorLangMessage(IDS_UPDATE_NOT_SUPPORTED, 0x02000601); return NExitCode::kFatalError; } bool messageWasDisplayed = false; HRESULT result = UpdateGUI( codecs, options.WildcardCensor, options.UpdateOptions, options.ShowDialog, messageWasDisplayed, &callback); if (result != S_OK) { if (result != E_ABORT && messageWasDisplayed) return NExitCode::kFatalError; throw CSystemException(result); } if (callback.FailedFiles.Size() > 0) { if (!messageWasDisplayed) throw CSystemException(E_FAIL); return NExitCode::kWarning; } } else { throw "Unsupported command"; } return 0; }
int APIENTRY WinMain2() { UString password; bool assumeYes = false; bool outputFolderDefined = false; UString outputFolder; UStringVector subStrings; NCommandLineParser::SplitCommandLine(GetCommandLineW(), subStrings); for (int i = 1; i < subStrings.Size(); i++) { const UString &s = subStrings[i]; if (s.CompareNoCase(L"-y") == 0) assumeYes = true; else if (s.Left(2).CompareNoCase(L"-o") == 0) { outputFolder = s.Mid(2); NWindows::NFile::NName::NormalizeDirPathPrefix(outputFolder); outputFolderDefined = !outputFolder.IsEmpty(); } else if (s.Left(2).CompareNoCase(L"-p") == 0) { password = s.Mid(2); } } UString path; NWindows::NDLL::MyGetModuleFileName(g_hInstance, path); UString fullPath; int fileNamePartStartIndex; if (!NWindows::NFile::NDirectory::MyGetFullPathName(path, fullPath, fileNamePartStartIndex)) { ShowErrorMessage(L"Error 1329484"); return 1; } CCodecs *codecs = new CCodecs; CMyComPtr<IUnknown> compressCodecsInfo = codecs; HRESULT result = codecs->Load(); if (result != S_OK) { ErrorMessageForHRESULT(result); return 1; } // COpenCallbackGUI openCallback; // openCallback.PasswordIsDefined = !password.IsEmpty(); // openCallback.Password = password; CExtractCallbackImp *ecs = new CExtractCallbackImp; CMyComPtr<IFolderArchiveExtractCallback> extractCallback = ecs; ecs->Init(); ecs->PasswordIsDefined = !password.IsEmpty(); ecs->Password = password; CExtractOptions eo; eo.OutputDir = outputFolderDefined ? outputFolder : fullPath.Left(fileNamePartStartIndex); eo.YesToAll = assumeYes; eo.OverwriteMode = assumeYes ? NExtract::NOverwriteMode::kWithoutPrompt : NExtract::NOverwriteMode::kAskBefore; eo.PathMode = NExtract::NPathMode::kFullPathnames; eo.TestMode = false; UStringVector v1, v2; v1.Add(fullPath); v2.Add(fullPath); NWildcard::CCensorNode wildcardCensor; wildcardCensor.AddItem(true, L"*", true, true, true); result = ExtractGUI(codecs, CIntVector(), v1, v2, wildcardCensor, eo, (assumeYes ? false: true), ecs); if (result == S_OK) { if (ecs->Messages.Size() > 0 || ecs->NumArchiveErrors != 0) return NExitCode::kFatalError; return 0; } if (result == E_ABORT) return NExitCode::kUserBreak; if (result == S_FALSE) ShowErrorMessage(L"Error in archive"); else ErrorMessageForHRESULT(result); if (result == E_OUTOFMEMORY) return NExitCode::kMemoryError; return NExitCode::kFatalError; }
int APIENTRY WinMain2() { // OleInitialize is required for ProgressBar in TaskBar. #ifndef UNDER_CE OleInitialize(NULL); #endif #ifndef UNDER_CE g_ComCtl32Version = ::GetDllVersion(TEXT("comctl32.dll")); g_LVN_ITEMACTIVATE_Support = (g_ComCtl32Version >= MAKELONG(71, 4)); #endif UString password; bool assumeYes = false; bool outputFolderDefined = false; FString outputFolder; UStringVector commandStrings; NCommandLineParser::SplitCommandLine(GetCommandLineW(), commandStrings); #ifndef UNDER_CE if (commandStrings.Size() > 0) commandStrings.Delete(0); #endif FOR_VECTOR (i, commandStrings) { const UString &s = commandStrings[i]; if (s.Len() > 1 && s[0] == '-') { wchar_t c = MyCharLower_Ascii(s[1]); if (c == 'y') { assumeYes = true; if (s.Len() != 2) { ShowErrorMessage(L"Bad command"); return 1; } } else if (c == 'o') { outputFolder = us2fs(s.Ptr(2)); NName::NormalizeDirPathPrefix(outputFolder); outputFolderDefined = !outputFolder.IsEmpty(); } else if (c == 'p') { password = s.Ptr(2); } } } FString path; NDLL::MyGetModuleFileName(path); FString fullPath; if (!MyGetFullPathName(path, fullPath)) { ShowErrorMessage(L"Error 1329484"); return 1; } CCodecs *codecs = new CCodecs; CMyComPtr<IUnknown> compressCodecsInfo = codecs; HRESULT result = codecs->Load(); if (result != S_OK) { ErrorMessageForHRESULT(result); return 1; } // COpenCallbackGUI openCallback; // openCallback.PasswordIsDefined = !password.IsEmpty(); // openCallback.Password = password; CExtractCallbackImp *ecs = new CExtractCallbackImp; CMyComPtr<IFolderArchiveExtractCallback> extractCallback = ecs; ecs->Init(); #ifndef _NO_CRYPTO ecs->PasswordIsDefined = !password.IsEmpty(); ecs->Password = password; #endif CExtractOptions eo; FString dirPrefix; if (!GetOnlyDirPrefix(path, dirPrefix)) { ShowErrorMessage(L"Error 1329485"); return 1; } eo.OutputDir = outputFolderDefined ? outputFolder : dirPrefix; eo.YesToAll = assumeYes; eo.OverwriteMode = assumeYes ? NExtract::NOverwriteMode::kOverwrite : NExtract::NOverwriteMode::kAsk; eo.PathMode = NExtract::NPathMode::kFullPaths; eo.TestMode = false; UStringVector v1, v2; v1.Add(fs2us(fullPath)); v2.Add(fs2us(fullPath)); NWildcard::CCensorNode wildcardCensor; wildcardCensor.AddItem(true, L"*", true, true, true, true); bool messageWasDisplayed = false; result = ExtractGUI(codecs, CObjectVector<COpenType>(), CIntVector(), v1, v2, wildcardCensor, eo, (assumeYes ? false: true), messageWasDisplayed, ecs); if (result == S_OK) { if (!ecs->IsOK()) return NExitCode::kFatalError; return 0; } if (result == E_ABORT) return NExitCode::kUserBreak; if (!messageWasDisplayed) { if (result == S_FALSE) ShowErrorMessage(L"Error in archive"); else ErrorMessageForHRESULT(result); } if (result == E_OUTOFMEMORY) return NExitCode::kMemoryError; return NExitCode::kFatalError; }