Example #1
0
HRESULT CCodecs::LoadFormats()
{
  const NDLL::CLibrary &lib = Libs.Back().Lib;
  GetHandlerPropertyFunc getProp = 0;
  GetHandlerPropertyFunc2 getProp2 = (GetHandlerPropertyFunc2)
	  lib.GetProcAddress("GetHandlerProperty2");
  if (getProp2 == NULL)
  {
	getProp = (GetHandlerPropertyFunc)
		lib.GetProcAddress("GetHandlerProperty");
	if (getProp == NULL)
	  return S_OK;
  }

  UInt32 numFormats = 1;
  GetNumberOfFormatsFunc getNumberOfFormats = (GetNumberOfFormatsFunc)
	lib.GetProcAddress("GetNumberOfFormats");
  if (getNumberOfFormats != NULL)
  {
	RINOK(getNumberOfFormats(&numFormats));
  }
  if (getProp2 == NULL)
	numFormats = 1;

  for(UInt32 i = 0; i < numFormats; i++)
  {
	CArcInfoEx item;
	item.LibIndex = Libs.Size() - 1;
	item.FormatIndex = i;

	RINOK(ReadStringProp(getProp, getProp2, i, NArchive::kName, item.Name));

	NCOM::CPropVariant prop;
	if (ReadProp(getProp, getProp2, i, NArchive::kClassID, prop) != S_OK)
	  continue;
	if (prop.vt != VT_BSTR)
	  continue;
	item.ClassID = *(const GUID *)prop.bstrVal;
	prop.Clear();

	UString ext, addExt;
	RINOK(ReadStringProp(getProp, getProp2, i, NArchive::kExtension, ext));
	RINOK(ReadStringProp(getProp, getProp2, i, NArchive::kAddExtension, addExt));
	item.AddExts(ext, addExt);

	ReadBoolProp(getProp, getProp2, i, NArchive::kUpdate, item.UpdateEnabled);
	if (item.UpdateEnabled)
	  ReadBoolProp(getProp, getProp2, i, NArchive::kKeepName, item.KeepName);
	
	if (ReadProp(getProp, getProp2, i, NArchive::kStartSignature, prop) == S_OK)
	  if (prop.vt == VT_BSTR)
	  {
		UINT len = ::SysStringByteLen(prop.bstrVal);
		item.StartSignature.SetCapacity(len);
		memmove(item.StartSignature, prop.bstrVal, len);
	  }
	Formats.Add(item);
  }
  return S_OK;
}
Example #2
0
HRESULT CCodecs::Load()
{
  Formats.Clear();
  #ifdef EXTERNAL_CODECS
  Codecs.Clear();
  #endif
  for (UInt32 i = 0; i < g_NumArcs; i++)
  {
	const CArcInfo &arc = *g_Arcs[i];
	CArcInfoEx item;
	item.Name = arc.Name;
	item.CreateInArchive = arc.CreateInArchive;
	item.CreateOutArchive = arc.CreateOutArchive;
	item.AddExts(arc.Ext, arc.AddExt);
	item.UpdateEnabled = (arc.CreateOutArchive != 0);
	item.KeepName = arc.KeepName;

	#ifndef _SFX
	SetBuffer(item.StartSignature, arc.Signature, arc.SignatureSize);
	#endif
	Formats.Add(item);
  }
  #ifdef EXTERNAL_CODECS
  const CSysString baseFolder = GetBaseFolderPrefixFromRegistry();
  RINOK(LoadDll(baseFolder + kMainDll));
  RINOK(LoadDllsFromFolder(baseFolder + kCodecsFolderName TEXT(STRING_PATH_SEPARATOR)));
  RINOK(LoadDllsFromFolder(baseFolder + kFormatsFolderName TEXT(STRING_PATH_SEPARATOR)));
  #endif
  return S_OK;
}
Example #3
0
bool CArchiveInterface::Init()
{
	QMutexLocker Locker(&m_Mutex);

	if(m_Operational)
		return true;

#ifdef __APPLE__
	m_7z.setFileName(QCoreApplication::applicationDirPath() + "/7z.so");
#endif

	LogLine(LOG_INFO | LOG_DEBUG, QObject::tr("7z: Loading Library..."));
	if(!m_7z.load())
	{
		LogLine(LOG_ERROR | LOG_DEBUG, QObject::tr("7z: failed to load!"));
		return false;
	}

	// Load Available Coders
	/*GetMethodPropertyFunc getMethodPropertyFunc = (GetMethodPropertyFunc)m_7z.resolve("GetMethodProperty");
	GetNumberOfMethodsFunc getNumberOfMethodsFunc = (GetNumberOfMethodsFunc)m_7z.resolve("GetNumberOfMethods");
	if(!getNumberOfMethodsFunc || !getMethodPropertyFunc)
		return false;

	UInt32 numMethods = 1;
	if(getNumberOfMethodsFunc(&numMethods) != S_OK)
		return false;

	for(UInt32 i = 0; i < numMethods; i++)
	{
		CCdrInfo info;
		info.Index = i;
		Q_ASSERT(GetCoderClass(getMethodPropertyFunc, i, NMethodPropID::kEncoder, info.Encoder, info.EncoderIsAssigned) == S_OK);
		Q_ASSERT(GetCoderClass(getMethodPropertyFunc, i, NMethodPropID::kDecoder, info.Decoder, info.DecoderIsAssigned) == S_OK);
		m_Coders.append(info);
	}*/

	// Load Supported Formats
	GetHandlerPropertyFunc getProp = NULL;
	GetHandlerPropertyFunc2 getProp2 = (GetHandlerPropertyFunc2)m_7z.resolve("GetHandlerProperty2");
	if (getProp2 == NULL)
	{
		getProp = (GetHandlerPropertyFunc)m_7z.resolve("GetHandlerProperty");
		if(!getProp)
		{
			LogLine(LOG_ERROR | LOG_DEBUG, QObject::tr("7z: Failed to resolve GetHandlerProperty!"));
			return false;
		}
	}

	UInt32 numFormats = 1;
	GetNumberOfFormatsFunc getNumberOfFormats = (GetNumberOfFormatsFunc)m_7z.resolve("GetNumberOfFormats");
	if (getNumberOfFormats != NULL)
	{
		if(getNumberOfFormats(&numFormats) != S_OK)
		{
			LogLine(LOG_ERROR | LOG_DEBUG, QObject::tr("7z: Failed to enumerate Formats!"));
			return false;
		}
	}
	if (getProp2 == NULL)
		numFormats = 1;

	for(UInt32 i = 0; i < numFormats; i++)
	{
		CArcInfoEx info;

		if(ReadStringProp(getProp, getProp2, i, NArchive::kName, info.Name) != S_OK)
		{
			LogLine(LOG_ERROR | LOG_DEBUG, QObject::tr("7z: Failed to get Formats %1 Name!").arg(i));
			return false;
		}

		NWindows::NCOM::CPropVariant prop;
		if (ReadProp(getProp, getProp2, i, NArchive::kClassID, prop) != S_OK)
			continue;
		if (prop.vt != VT_BSTR)
			continue;
		info.ClassID = *(const GUID *)prop.bstrVal;
		prop.Clear();

		QString ext, addExt;
		if(ReadStringProp(getProp, getProp2, i, NArchive::kExtension, ext) != S_OK)
		{
			LogLine(LOG_ERROR | LOG_DEBUG, QObject::tr("7z: Failed to get Formats %1 Property kExtension!").arg(i));
			return false;
		}
		if(ReadStringProp(getProp, getProp2, i, NArchive::kAddExtension, addExt) != S_OK)
		{
			LogLine(LOG_ERROR | LOG_DEBUG, QObject::tr("7z: Failed to get Formats %1 Property kAddExtension!").arg(i));
			return false;
		}
		info.AddExts(ext, addExt);

		//TRACE(L"Archive Format %S supported %S, %S", QS2CS(info.Name), QS2CS(ext), QS2CS(addExt));

		ReadBoolProp(getProp, getProp2, i, NArchive::kUpdate, info.UpdateEnabled);
		if (info.UpdateEnabled)
			ReadBoolProp(getProp, getProp2, i, NArchive::kKeepName, info.KeepName);

#ifdef _SFX
		if (ReadProp(getProp, getProp2, i, NArchive::kStartSignature, prop) == S_OK)
		{
			if (prop.vt == VT_BSTR)
				info.StartSignature = QByteArray((char*)prop.bstrVal, ::SysStringByteLen(prop.bstrVal));
		}
#endif

		m_Formats.append(info);
	}

	createObjectFunc = (CreateObjectFunc)m_7z.resolve("CreateObject");
	if(createObjectFunc == NULL)
	{
		LogLine(LOG_ERROR | LOG_DEBUG, QObject::tr("7z: Failed to resolve CreateObjectFunc!"));
		return false;
	}

	LogLine(LOG_SUCCESS | LOG_DEBUG, QObject::tr("7z: Loaded Successfuly"));
	m_Operational = true;
	return true;
}