示例#1
0
文件: Main.cpp 项目: bks/qz7
static bool AddNameToCensor(NWildcard::CCensor &wildcardCensor,
    const UString &name, bool include, NRecursedType::EEnum type)
{
  /*
  if(!IsWildCardFilePathLegal(name))
    return false;
  */
  bool isWildCard = DoesNameContainWildCard(name);
  bool recursed = false;

  switch (type)
  {
    case NRecursedType::kWildCardOnlyRecursed:
      recursed = isWildCard;
      break;
    case NRecursedType::kRecursed:
      recursed = true;
      break;
    case NRecursedType::kNonRecursed:
      recursed = false;
      break;
  }
  wildcardCensor.AddItem(include, name, recursed);
  return true;
}
示例#2
0
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;
}
static void AddNameToCensor(NWildcard::CCensor &wildcardCensor,
    const UString &name, bool include, NRecursedType::EEnum type)
{
  bool recursed = false;

  switch (type)
  {
    case NRecursedType::kWildCardOnlyRecursed:
      recursed = DoesNameContainWildCard(name);
      break;
    case NRecursedType::kRecursed:
      recursed = true;
      break;
  }
  wildcardCensor.AddItem(include, name, recursed);
}
示例#4
0
文件: Main.cpp 项目: liao0818/nsis7z
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;
}
示例#5
0
HRESULT CompressFiles(
    const UString &arcPathPrefix,
    const UString &arcName,
    const UString &arcType,
    const UStringVector &names,
    bool email, bool showDialog, bool /* waitFinish */)
{


  //::MessageBoxW(NULL, (LPCWSTR)L"CompressCall2::CompressFiles", (LPCWSTR)L"mooo", MB_OK);

  HRESULT result;
  MY_TRY_BEGIN
  CREATE_CODECS

  CUpdateCallbackGUI callback;
  
  callback.Init();

  CUpdateOptions uo;
  uo.EMailMode = email;
  uo.SetAddActionCommand();

  CIntVector formatIndices;
  if (!codecs->FindFormatForArchiveType(arcType, formatIndices))
  {
    ErrorLangMessage(IDS_UNSUPPORTED_ARCHIVE_TYPE, 0x0200060D);
    return E_FAIL;
  }
  if (!uo.Init(codecs, formatIndices, arcPathPrefix + arcName))
  {
    ErrorLangMessage(IDS_UPDATE_NOT_SUPPORTED, 0x02000601);
    return E_FAIL;
  }

  NWildcard::CCensor censor;
  for (int i = 0; i < names.Size(); i++)
    censor.AddItem(true, names[i], false);

  //::MessageBoxW(NULL, (LPCWSTR)L"CompressCall2::CompressFiles2", (LPCWSTR)L"mooo", MB_OK);

  bool messageWasDisplayed = false;
  result = UpdateGUI(codecs, censor, uo, showDialog, messageWasDisplayed, &callback, g_HWND);

  //::MessageBoxW(NULL, (LPCWSTR)L"CompressCall2::CompressFiles3", (LPCWSTR)L"mooo", MB_OK);

  if (result != S_OK)
  {
    if (result != E_ABORT && messageWasDisplayed)
      return E_FAIL;
    throw CSystemException(result);
  }
  if (callback.FailedFiles.Size() > 0)
  {
    if (!messageWasDisplayed)
      throw CSystemException(E_FAIL);
    return E_FAIL;
  }
  MY_TRY_FINISH
  return S_OK;
}