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; }