示例#1
0
STDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numItems,
    IArchiveUpdateCallback *updateCallback)
{
  if (numItems != 1)
    return E_INVALIDARG;

  Int32 newData;
  Int32 newProperties;
  UInt32 indexInArchive;
  if (!updateCallback)
    return E_FAIL;
  RINOK(updateCallback->GetUpdateItemInfo(0,&newData, &newProperties, &indexInArchive));
 
  if (IntToBool(newProperties))
  {
    {
      NCOM::CPropVariant prop;
      RINOK(updateCallback->GetProperty(0, kpidIsFolder, &prop));
      if (prop.vt == VT_BOOL)
      {
        if (prop.boolVal != VARIANT_FALSE)
          return E_INVALIDARG;
      }
      else if (prop.vt != VT_EMPTY)
        return E_INVALIDARG;
    }
  }
  
  if (IntToBool(newData))
  {
    UInt64 size;
    {
      NCOM::CPropVariant prop;
      RINOK(updateCallback->GetProperty(0, kpidSize, &prop));
      if (prop.vt != VT_UI8)
        return E_INVALIDARG;
      size = prop.uhVal.QuadPart;
    }
  
    UInt32 dicSize = _dicSize;
    if (dicSize == 0xFFFFFFFF)
      dicSize = (_level >= 5 ? kDicSizeX5 : 
                (_level >= 3 ? kDicSizeX3 : 
                               kDicSizeX1));

    UInt32 numPasses = _numPasses;
    if (numPasses == 0xFFFFFFFF)
      numPasses = (_level >= 9 ? kNumPassesX9 : 
                  (_level >= 7 ? kNumPassesX7 : 
                                 kNumPassesX1));

    return UpdateArchive(
        EXTERNAL_CODECS_VARS
        size, outStream, 0, dicSize, numPasses, 
        #ifdef COMPRESS_MT
        _numThreads, 
        #endif
        updateCallback);
  }
  if (indexInArchive != 0)
    return E_INVALIDARG;
  RINOK(_stream->Seek(_streamStartPosition, STREAM_SEEK_SET, NULL));
  return CopyStreams(_stream, outStream);
}
示例#2
0
STDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numItems,
    IArchiveUpdateCallback *updateCallback)
{
  if (numItems != 1)
    return E_INVALIDARG;

  UInt64 size;
  Int32 newData;
  Int32 newProperties;
  UInt32 indexInArchive;
  UInt32 itemIndex = 0;
  if (!updateCallback)
    return E_FAIL;
  RINOK(updateCallback->GetUpdateItemInfo(0, &newData, &newProperties, &indexInArchive));

  CItem newItem = m_Item;
  newItem.ExtraFlags = 0;
  newItem.Flags = 0;
  if (IntToBool(newProperties))
  {
    FILETIME utcTime;
    UString name;
    {
      NCOM::CPropVariant prop;
      RINOK(updateCallback->GetProperty(itemIndex, kpidMTime, &prop));
      if (prop.vt != VT_FILETIME)
        return E_INVALIDARG;
      utcTime = prop.filetime;
    }
    {
      NCOM::CPropVariant prop;
      RINOK(updateCallback->GetProperty(itemIndex, kpidPath, &prop));
      if (prop.vt == VT_EMPTY)
        name.Empty();
      else if (prop.vt != VT_BSTR)
        return E_INVALIDARG;
      else
        name = prop.bstrVal;
    }
    {
      NCOM::CPropVariant prop;
      RINOK(updateCallback->GetProperty(itemIndex, kpidIsDir, &prop));
      if (prop.vt == VT_BOOL)
      {
        if (prop.boolVal != VARIANT_FALSE)
          return E_INVALIDARG;
      }
      else if (prop.vt != VT_EMPTY)
        return E_INVALIDARG;
    }
    if(!FileTimeToUnixTime(utcTime, newItem.Time))
      return E_INVALIDARG;
    newItem.Name = UnicodeStringToMultiByte(name, CP_ACP);
    int dirDelimiterPos = newItem.Name.ReverseFind(CHAR_PATH_SEPARATOR);
    if (dirDelimiterPos >= 0)
      newItem.Name = newItem.Name.Mid(dirDelimiterPos + 1);
    
    newItem.SetNameIsPresentFlag(!newItem.Name.IsEmpty());
  }

  if (IntToBool(newData))
  {
    {
      NCOM::CPropVariant prop;
      RINOK(updateCallback->GetProperty(itemIndex, kpidSize, &prop));
      if (prop.vt != VT_UI8)
        return E_INVALIDARG;
      size = prop.uhVal.QuadPart;
    }
    newItem.UnPackSize32 = (UInt32)size;

    UInt32 level = m_Level;
    if (level == 0xFFFFFFFF)
      level = 5;
    if (m_Method.NumPasses == 0xFFFFFFFF)
      m_Method.NumPasses = (level >= 9 ? kNumPassesX9 :
                           (level >= 7 ? kNumPassesX7 :
                                         kNumPassesX1));
    if (m_Method.NumFastBytes == 0xFFFFFFFF)
      m_Method.NumFastBytes = (level >= 9 ? kNumFastBytesX9 :
                              (level >= 7 ? kNumFastBytesX7 :
                                            kNumFastBytesX1));
    if (m_Method.Algo == 0xFFFFFFFF)
      m_Method.Algo =
                    (level >= 5 ? kAlgoX5 :
                                  kAlgoX1);

    return UpdateArchive(
        EXTERNAL_CODECS_VARS
        m_Stream, size, outStream, newItem, m_Method, itemIndex, updateCallback);
  }
    
  if (indexInArchive != 0)
    return E_INVALIDARG;

  if (IntToBool(newProperties))
  {
    COutArchive outArchive;
    outArchive.Create(outStream);
    outArchive.WriteHeader(newItem);
    RINOK(m_Stream->Seek(m_StreamStartPosition + m_DataOffset, STREAM_SEEK_SET, NULL));
  }
  else
  {
    RINOK(m_Stream->Seek(m_StreamStartPosition, STREAM_SEEK_SET, NULL));
  }
  return CopyStreams(m_Stream, outStream);
}
示例#3
0
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;
}