Example #1
0
bool ArchiveFilter::Filtered(const GUID* puidModule, const GUID* puidPlugin, const GUID* puidFormat)
{
	for (unsigned int i = 0; i < m_pStopFilters.count(); i++)
	{
		ArchiveFilterEntry* pFE = m_pStopFilters[i];

		if ( !pFE->IsEnabled() || !pFE->IsValid() )
			continue;

		bool bFormatFiltered = (pFE->IsAllFormats() || (puidFormat && (pFE->GetFormat()->GetUID() == *puidFormat)));
		bool bPluginFiltered = bFormatFiltered && (pFE->IsAllPlugins() || (puidPlugin && (pFE->GetPlugin()->GetUID() == *puidPlugin)));
		bool bModuleFiltered = bPluginFiltered && (pFE->IsAllModules() || (puidModule && (pFE->GetModule()->GetUID() == *puidModule)));

		if ( bModuleFiltered )
			return true;
	}

	return false;
}
//бля, это пиздец
int ArchiveModuleManager::QueryArchives(
		const TCHAR* lpFileName,
		const unsigned char* pBuffer,
		DWORD dwBufferSize,
		Array<ArchiveFormat*>& result
		)
{
	bool bStopped = false;

	//BADBAD
	if ( !dwBufferSize )
	{
		result.reset();
		return 0;
	};

	ArchiveFilter* pFilter = m_pConfig->GetFilter();

	Array<ArchiveFilterEntry*> filters;

	pFilter->Reset();
	pFilter->QueryFilters(lpFileName, filters, bStopped);

	for (unsigned int i = 0; i < filters.count(); i++)
	{
		ArchiveFilterEntry* pFE = filters[i];
		ArchiveModule* pModule = pFE->GetModule();

		bool bNoPluginsFiltered = true;
		bool bNoFormatsFiltered = true;

		if ( !pFilter->Filtered(&pModule->GetUID(), NULL, NULL) )
		{
			if ( pFE->IsAllPlugins() )
			{
				Array<ArchivePlugin*>& plugins = pModule->GetPlugins();

				for (unsigned int i = 0; i < plugins.count(); i++)
				{
					ArchivePlugin* pPlugin = plugins[i];

					if ( !pFilter->Filtered(&pModule->GetUID(), &pPlugin->GetUID(), NULL) )
					{
						if ( pModule->QueryCapability(AMF_SUPPORT_SINGLE_PLUGIN_QUERY) )
						{
							Array<ArchiveFormat*>& formats = pPlugin->GetFormats();

							for (unsigned int j = 0; j < formats.count(); j++)
							{
								ArchiveFormat* pFormat = formats[i];

								if ( !pFilter->Filtered(&pModule->GetUID(), &pPlugin->GetUID(), &pFormat->GetUID()) )
								{
									if ( pPlugin->QueryCapability(APF_SUPPORT_SINGLE_FORMAT_QUERY) )
										pModule->QueryArchives(&pPlugin->GetUID(), &pFormat->GetUID(), lpFileName, pBuffer, dwBufferSize, result);
								}
								else
									bNoFormatsFiltered = false;
							}

							if ( bNoFormatsFiltered && !pPlugin->QueryCapability(APF_SUPPORT_SINGLE_FORMAT_QUERY) )
								pModule->QueryArchives(&pPlugin->GetUID(), NULL, lpFileName, pBuffer, dwBufferSize, result);
						}
						else
							bNoPluginsFiltered = false;
					}

					if ( bNoPluginsFiltered && !pModule->QueryCapability(AMF_SUPPORT_SINGLE_PLUGIN_QUERY) )
						pModule->QueryArchives(NULL, NULL, lpFileName, pBuffer, dwBufferSize, result);
				}
			}
			else
			{
				if ( pFE->IsAllFormats() )
				{
					ArchivePlugin* pPlugin = pFE->GetPlugin();
				
					if ( !pFilter->Filtered(&pModule->GetUID(), &pPlugin->GetUID(), NULL) )
					{
						Array<ArchiveFormat*>& formats = pPlugin->GetFormats();

						for (unsigned int i = 0; i < formats.count(); i++)
						{
							ArchiveFormat* pFormat = formats[i];

							if ( !pFilter->Filtered(&pModule->GetUID(), &pPlugin->GetUID(), &pFormat->GetUID()) )
							{
								if ( pPlugin->QueryCapability(APF_SUPPORT_SINGLE_FORMAT_QUERY) )
									pModule->QueryArchives(&pPlugin->GetUID(), &pFormat->GetUID(), lpFileName, pBuffer, dwBufferSize, result);
							}
							else
								bNoFormatsFiltered = false;

						}

						if ( bNoFormatsFiltered && !pPlugin->QueryCapability(APF_SUPPORT_SINGLE_FORMAT_QUERY) )
							pModule->QueryArchives(&pPlugin->GetUID(), NULL, lpFileName, pBuffer, dwBufferSize, result);
					}
				}
				else
				{
					ArchiveFormat* pFormat = pFE->GetFormat();
					ArchivePlugin* pPlugin = pFE->GetPlugin();

					if ( !pFilter->Filtered(&pModule->GetUID(), &pPlugin->GetUID(), &pFormat->GetUID()) )
					{
						if ( pPlugin->QueryCapability(APF_SUPPORT_SINGLE_FORMAT_QUERY) )
							pModule->QueryArchives(&pPlugin->GetUID(), &pFormat->GetUID(), lpFileName, pBuffer, dwBufferSize, result);
					}
				}
			}
		}

		pFilter->AddStopFilter(filters[i]);
	}

	if ( !bStopped && pFilter->UseRemaining() )
	{
		for (unsigned int i = 0; i < m_pModules.count(); i++)
		{
			bool bNoPluginsFiltered = true;
			bool bNoFormatsFiltered = true;

			ArchiveModule* pModule = m_pModules[i]; 

			if ( !pFilter->Filtered(&pModule->GetUID(), NULL, NULL) )
			{
				Array<ArchivePlugin*>& plugins = pModule->GetPlugins();

				for (unsigned int j = 0; j < plugins.count(); j++)
				{
					ArchivePlugin* pPlugin = plugins[j];

					if ( !pFilter->Filtered(&pModule->GetUID(), &pPlugin->GetUID(), NULL) )
					{
						Array<ArchiveFormat*>& formats = pPlugin->GetFormats();

						for (unsigned int k = 0; k < formats.count(); k++)
						{
							ArchiveFormat* pFormat = formats[k];

							if ( !pFilter->Filtered(&pModule->GetUID(), &pPlugin->GetUID(), &pFormat->GetUID()) )
							{
								if ( pPlugin->QueryCapability(APF_SUPPORT_SINGLE_FORMAT_QUERY) )
									pModule->QueryArchives(&pPlugin->GetUID(), &pFormat->GetUID(), lpFileName, pBuffer, dwBufferSize, result);
							}
							else
								bNoFormatsFiltered = false;
						}

						if ( bNoFormatsFiltered && !pPlugin->QueryCapability(APF_SUPPORT_SINGLE_FORMAT_QUERY) )
							pModule->QueryArchives(&pPlugin->GetUID(), NULL, lpFileName, pBuffer, dwBufferSize, result);

					}
					else
						bNoPluginsFiltered = false;
				}

				if ( bNoPluginsFiltered && !pModule->QueryCapability(AMF_SUPPORT_SINGLE_PLUGIN_QUERY) )
					pModule->QueryArchives(NULL, NULL, lpFileName, pBuffer, dwBufferSize, result);
			}
		}
	}

	return 0;
}
LONG_PTR __stdcall hndFilterOneFormat(FarDialog* D, int nMsg, int nParam1, LONG_PTR nParam2)
{
	ArchiveFilterEntry* pFE = (ArchiveFilterEntry*)D->GetDlgData();

	if ( (nMsg == DN_LISTCHANGE) && (nParam1 == ID_FOF_ACTIONLIST) )
	{
		if ( nParam2 == 1 ) //do block
		{	
			FarListPos pos;

			D->ListGetCurrentPos(ID_FOF_MODULELIST, &pos);


			FarListInsert ins;

			ins.Index = 0;
			ins.Item.Flags = 0;
#ifdef UNICODE
			ins.Item.Text = _T("All");
#else
			strcpy(ins.Item.Text, _T("All"));
#endif

			int index = D->ListInsert(ID_FOF_MODULELIST, &ins);
			D->ListSetDataEx(ID_FOF_MODULELIST, index, (void*)0, sizeof(void*));

			pos.SelectPos++;
			D->ListSetCurrentPos(ID_FOF_MODULELIST, &pos);

		}
		else
		{
			FarListDelete del;

			del.StartIndex = 0;
			del.Count = 1;

			D->ListDelete(ID_FOF_MODULELIST, &del);
////////////
			FarListPos pos;
			D->ListGetCurrentPos(ID_FOF_MODULELIST, &pos);

			if ( pos.SelectPos != -1 )
			{
				ArchiveModule* pModule = (ArchiveModule*)D->ListGetData(ID_FOF_MODULELIST, pos.SelectPos);

				UpdatePlugins(D, pModule, NULL);
			}

			return TRUE;
//////////////


		}

		return TRUE;
	}
	else

	if ( (nMsg == DN_LISTCHANGE) && (nParam1 == ID_FOF_MODULELIST) )
	{
		FarListPos pos;
		D->ListGetCurrentPos(ID_FOF_MODULELIST, &pos);

		if ( pos.SelectPos != -1 )
		{
			ArchiveModule* pModule = (ArchiveModule*)D->ListGetData(ID_FOF_MODULELIST, pos.SelectPos);

			UpdatePlugins(D, pModule, NULL);
		}

		return TRUE;
	}
	else

	if ( (nMsg == DN_LISTCHANGE) && (nParam1 == ID_FOF_PLUGINLIST) )
	{
		FarListPos pos;
		D->ListGetCurrentPos(ID_FOF_PLUGINLIST, &pos);

		if ( pos.SelectPos != -1 )
		{
			ArchivePlugin* pPlugin = (ArchivePlugin*)D->ListGetData(ID_FOF_PLUGINLIST, pos.SelectPos);

			UpdateFormats(D, pPlugin, NULL);
		}

		return TRUE;
	}
	else

	if ( nMsg == DN_INITDIALOG )
	{
		FarListPos pos;

		D->ListAddStr(ID_FOF_ACTIONLIST, _T("Process"));
		D->ListAddStr(ID_FOF_ACTIONLIST, _T("Block"));

		pos.SelectPos = pFE->IsExclude()?1:0;

		D->ListSetCurrentPos(ID_FOF_ACTIONLIST, &pos);
		
		pos.SelectPos = 0;
		pos.TopPos = -1;

		Array<ArchiveModule*> modules;
		
		pManager->GetModules(modules);

		for (unsigned int i = 0; i < modules.count(); i++)
		{
			const ArchiveModule* pModule = modules[i];

			int index = D->ListAddStr(ID_FOF_MODULELIST, FSF.PointToName(pModule->GetModuleName()));
			D->ListSetDataEx(ID_FOF_MODULELIST, index, (void*)pModule, sizeof(void*));

			if ( pFE && !pFE->IsAllModules() && pFE->GetModule() && (pFE->GetModule()->GetUID() == pModule->GetUID()) )
				pos.SelectPos = index;
		}

		D->ListSetCurrentPos(ID_FOF_MODULELIST, &pos); 

		ArchiveModule* pModule = (ArchiveModule*)D->ListGetData(ID_FOF_MODULELIST, pos.SelectPos);
		UpdatePlugins(D, pModule, pFE); 

		//return TRUE; hmm
	}
	else

	if ( (nMsg == DN_CLOSE) && (nParam1 == D->FirstButton()) )
	{
		string strName = D->GetConstTextPtr(ID_FOF_NAMEEDIT);

		if ( strName.IsEmpty() )
		{
			msgError(_T("name empty"));
			return FALSE;
		}

		string strMask = D->GetConstTextPtr(ID_FOF_MASKEDIT);

		if ( strMask.IsEmpty() )
		{
			msgError(_T("mask empty"));
			return FALSE;
		}

		FarListPos pos;

		D->ListGetCurrentPos(ID_FOF_ACTIONLIST, &pos);

		pFE->SetExclude(pos.SelectPos == 1);
		pFE->SetName(strName);
		pFE->SetMask(strMask);

		pFE->SetAllFormats(true);
		pFE->SetAllModules(true);
		pFE->SetAllPlugins(true);

		D->ListGetCurrentPos(ID_FOF_MODULELIST, &pos);
		ArchiveModule* pModule = (ArchiveModule*)D->ListGetData(ID_FOF_MODULELIST, pos.SelectPos);

		if ( pModule )
		{
			pFE->SetModule(pModule);

			D->ListGetCurrentPos(ID_FOF_PLUGINLIST, &pos);
			ArchivePlugin* pPlugin = (ArchivePlugin*)D->ListGetData(ID_FOF_PLUGINLIST, pos.SelectPos);

			if ( pPlugin )
			{
				pFE->SetPlugin(pPlugin);

				D->ListGetCurrentPos(ID_FOF_FORMATLIST, &pos);
				ArchiveFormat* pFormat = (ArchiveFormat*)D->ListGetData(ID_FOF_FORMATLIST, pos.SelectPos);

				if ( pFormat )
					pFE->SetFormat(pFormat);
			}
		}

		return TRUE;
	}
	
	return D->DefDlgProc(nMsg, nParam1, nParam2);
}